diff options
author | pfeldman <pfeldman@chromium.org> | 2015-12-14 16:19:04 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-15 00:20:43 +0000 |
commit | 80b21c78d9b898185a0da875a95079bfb392865f (patch) | |
tree | 36eb854a51b21c1c366e0ff3ae61c2be1825830e | |
parent | 8525c868f0b175ee926751857c8a47593e0ee4e8 (diff) | |
download | chromium_src-80b21c78d9b898185a0da875a95079bfb392865f.zip chromium_src-80b21c78d9b898185a0da875a95079bfb392865f.tar.gz chromium_src-80b21c78d9b898185a0da875a95079bfb392865f.tar.bz2 |
DevTools: refactor CSSLocation to be based on the header, not id.
BUG=569457
NOTRY=true
Review URL: https://codereview.chromium.org/1521333002
Cr-Commit-Position: refs/heads/master@{#365130}
6 files changed, 33 insertions, 26 deletions
diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector/elements/styles/update-locations-on-filesystem-scss-load.html b/third_party/WebKit/LayoutTests/http/tests/inspector/elements/styles/update-locations-on-filesystem-scss-load.html index f74f4bb..2ca60bd 100644 --- a/third_party/WebKit/LayoutTests/http/tests/inspector/elements/styles/update-locations-on-filesystem-scss-load.html +++ b/third_party/WebKit/LayoutTests/http/tests/inspector/elements/styles/update-locations-on-filesystem-scss-load.html @@ -34,7 +34,7 @@ function test() { InspectorTest.addResult("Stylesheet was added, dumping location:"); var header = event.data; - var cssLocation = new WebInspector.CSSLocation(header.cssModel(), header.id, header.sourceURL, 0, 1); + var cssLocation = new WebInspector.CSSLocation(header, 0, 1); liveLocation = WebInspector.cssWorkspaceBinding.createLiveLocation(cssLocation, function() {}); InspectorTest.addSniffer(WebInspector.CSSWorkspaceBinding.prototype, "pushSourceMapping", afterBind); dumpLiveLocation(); diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector/stylesheet-source-mapping.html b/third_party/WebKit/LayoutTests/http/tests/inspector/stylesheet-source-mapping.html index e82b82c..3ec8759 100644 --- a/third_party/WebKit/LayoutTests/http/tests/inspector/stylesheet-source-mapping.html +++ b/third_party/WebKit/LayoutTests/http/tests/inspector/stylesheet-source-mapping.html @@ -23,7 +23,8 @@ function test() function locationsUpdated() { - var uiLocation = InspectorTest.testCSSWorkspaceBinding.rawLocationToUILocation(new WebInspector.CSSLocation(cssModel, styleSheetId, styleSheetURL, 2, 3)); + var header = cssModel.styleSheetHeaderForId(styleSheetId); + var uiLocation = InspectorTest.testCSSWorkspaceBinding.rawLocationToUILocation(new WebInspector.CSSLocation(header, 2, 3)); var networkURL = InspectorTest.testNetworkMapping.networkURL(uiLocation.uiSourceCode); if (networkURL.indexOf(".scss") === -1) return; @@ -73,7 +74,8 @@ function test() function rawLocationToUILocation(line, column) { - return InspectorTest.testCSSWorkspaceBinding.rawLocationToUILocation(new WebInspector.CSSLocation(cssModel, styleSheetId, styleSheetURL, line, column)); + var header = cssModel.styleSheetHeaderForId(styleSheetId); + return InspectorTest.testCSSWorkspaceBinding.rawLocationToUILocation(new WebInspector.CSSLocation(header, line, column)); } function afterStyleSheetAdded() diff --git a/third_party/WebKit/LayoutTests/inspector/elements/styles-1/disable-property-workingcopy-update.html b/third_party/WebKit/LayoutTests/inspector/elements/styles-1/disable-property-workingcopy-update.html index 74554ab..609c650 100644 --- a/third_party/WebKit/LayoutTests/inspector/elements/styles-1/disable-property-workingcopy-update.html +++ b/third_party/WebKit/LayoutTests/inspector/elements/styles-1/disable-property-workingcopy-update.html @@ -22,7 +22,7 @@ function test() var headers = InspectorTest.cssModel.styleSheetHeaders(); for (var i = 0; i < headers.length; ++i) { if (headers[i].sourceURL.endsWith(".css")) { - var cssLocation = new WebInspector.CSSLocation(InspectorTest.cssModel, headers[i].id, headers[i].sourceURL, 0); + var cssLocation = new WebInspector.CSSLocation(headers[i], 0); InspectorTest.showUISourceCode(WebInspector.cssWorkspaceBinding.rawLocationToUILocation(cssLocation).uiSourceCode, callback); break; } diff --git a/third_party/WebKit/Source/devtools/front_end/bindings/CSSWorkspaceBinding.js b/third_party/WebKit/Source/devtools/front_end/bindings/CSSWorkspaceBinding.js index 1266faa..5b251ff 100644 --- a/third_party/WebKit/Source/devtools/front_end/bindings/CSSWorkspaceBinding.js +++ b/third_party/WebKit/Source/devtools/front_end/bindings/CSSWorkspaceBinding.js @@ -142,15 +142,14 @@ WebInspector.CSSWorkspaceBinding.prototype = { if (!range) return null; - var url = style.parentRule.resourceURL(); - if (!url) + var header = style.cssModel().styleSheetHeaderForId(style.styleSheetId); + if (!header) return null; var line = forName ? range.startLine : range.endLine; // End of range is exclusive, so subtract 1 from the end offset. var column = forName ? range.startColumn : range.endColumn - (cssProperty.text && cssProperty.text.endsWith(";") ? 2 : 1); - var header = style.cssModel().styleSheetHeaderForId(style.styleSheetId); - var rawLocation = new WebInspector.CSSLocation(style.cssModel(), style.styleSheetId, url, header.lineNumberInSource(line), header.columnNumberInSource(line, column)); + var rawLocation = new WebInspector.CSSLocation(header, header.lineNumberInSource(line), header.columnNumberInSource(line, column)); return this.rawLocationToUILocation(rawLocation); }, @@ -290,7 +289,7 @@ WebInspector.CSSWorkspaceBinding.HeaderInfo.prototype = { _rawLocationToUILocation: function(lineNumber, columnNumber) { var uiLocation = null; - var rawLocation = new WebInspector.CSSLocation(this._header.cssModel(), this._header.id, this._header.resourceURL(), lineNumber, columnNumber); + var rawLocation = new WebInspector.CSSLocation(this._header, lineNumber, columnNumber); for (var i = this._sourceMappings.length - 1; !uiLocation && i >= 0; --i) uiLocation = this._sourceMappings[i].rawLocationToUILocation(rawLocation); return uiLocation; diff --git a/third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.js b/third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.js index 93e7a2b..be31b48 100644 --- a/third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.js +++ b/third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.js @@ -1288,9 +1288,12 @@ WebInspector.StylePropertiesSection.prototype = { return; if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEvent} */(event)) && this.navigable) { - var cssModel = this._parentPane._cssModel; - var rawLocation = new WebInspector.CSSLocation(cssModel, /** @type {string} */(media.parentStyleSheetId), media.sourceURL, /** @type {number} */(media.lineNumberInSource()), media.columnNumberInSource()); - var uiLocation = WebInspector.cssWorkspaceBinding.rawLocationToUILocation(rawLocation); + var location = media.rawLocation(); + if (!location) { + event.consume(true); + return; + } + var uiLocation = WebInspector.cssWorkspaceBinding.rawLocationToUILocation(location); if (uiLocation) WebInspector.Revealer.reveal(uiLocation); event.consume(true); @@ -1386,7 +1389,12 @@ WebInspector.StylePropertiesSection.prototype = { var index = event.target._selectorIndex; var cssModel = this._parentPane._cssModel; var rule = this._style.parentRule; - var rawLocation = new WebInspector.CSSLocation(cssModel, /** @type {string} */(rule.styleSheetId), rule.sourceURL, rule.lineNumberInSource(index), rule.columnNumberInSource(index)); + var header = cssModel.styleSheetHeaderForId(/** @type {string} */(rule.styleSheetId)); + if (!header) { + event.consume(true); + return; + } + var rawLocation = new WebInspector.CSSLocation(header, rule.lineNumberInSource(index), rule.columnNumberInSource(index)); var uiLocation = WebInspector.cssWorkspaceBinding.rawLocationToUILocation(rawLocation); if (uiLocation) WebInspector.Revealer.reveal(uiLocation); @@ -1577,10 +1585,9 @@ WebInspector.StylePropertiesSection.createRuleOriginNode = function(cssModel, li WebInspector.StylePropertiesSection._linkifyRuleLocation = function(cssModel, linkifier, styleSheetId, ruleLocation) { var styleSheetHeader = cssModel.styleSheetHeaderForId(styleSheetId); - var sourceURL = styleSheetHeader.resourceURL(); var lineNumber = styleSheetHeader.lineNumberInSource(ruleLocation.startLine); var columnNumber = styleSheetHeader.columnNumberInSource(ruleLocation.startLine, ruleLocation.startColumn); - var matchingSelectorLocation = new WebInspector.CSSLocation(cssModel, styleSheetId, sourceURL, lineNumber, columnNumber); + var matchingSelectorLocation = new WebInspector.CSSLocation(styleSheetHeader, lineNumber, columnNumber); return linkifier.linkifyCSSLocation(matchingSelectorLocation); } diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/CSSStyleModel.js b/third_party/WebKit/Source/devtools/front_end/sdk/CSSStyleModel.js index ec4c6aa..540e7d2 100644 --- a/third_party/WebKit/Source/devtools/front_end/sdk/CSSStyleModel.js +++ b/third_party/WebKit/Source/devtools/front_end/sdk/CSSStyleModel.js @@ -628,18 +628,16 @@ WebInspector.CSSStyleModel.prototype = { /** * @constructor * @extends {WebInspector.SDKObject} - * @param {!WebInspector.CSSStyleModel} cssModel - * @param {!CSSAgent.StyleSheetId} styleSheetId - * @param {string} url + * @param {!WebInspector.CSSStyleSheetHeader} header * @param {number} lineNumber * @param {number=} columnNumber */ -WebInspector.CSSLocation = function(cssModel, styleSheetId, url, lineNumber, columnNumber) +WebInspector.CSSLocation = function(header, lineNumber, columnNumber) { - WebInspector.SDKObject.call(this, cssModel.target()); - this._cssModel = cssModel; - this.styleSheetId = styleSheetId; - this.url = url; + WebInspector.SDKObject.call(this, header.target()); + this._header = header; + this.styleSheetId = header.id; + this.url = header.resourceURL(); this.lineNumber = lineNumber; this.columnNumber = columnNumber || 0; } @@ -650,7 +648,7 @@ WebInspector.CSSLocation.prototype = { */ cssModel: function() { - return this._cssModel; + return this._header.cssModel(); }, __proto__: WebInspector.SDKObject.prototype @@ -1741,10 +1739,11 @@ WebInspector.CSSMedia.prototype = { */ rawLocation: function() { - if (!this.header() || this.lineNumberInSource() === undefined) + var header = this.header(); + if (!header || this.lineNumberInSource() === undefined) return null; var lineNumber = Number(this.lineNumberInSource()); - return new WebInspector.CSSLocation(this._cssModel, this.header().id, this.sourceURL, lineNumber, this.columnNumberInSource()); + return new WebInspector.CSSLocation(header, lineNumber, this.columnNumberInSource()); } } |