| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @extends {WebInspector.SDKModel} | 33 * @extends {WebInspector.SDKModel} |
| 34 * @param {!WebInspector.Target} target | 34 * @param {!WebInspector.Target} target |
| 35 * @param {!WebInspector.DOMModel} domModel |
| 35 */ | 36 */ |
| 36 WebInspector.CSSModel = function(target) | 37 WebInspector.CSSModel = function(target, domModel) |
| 37 { | 38 { |
| 38 WebInspector.SDKModel.call(this, WebInspector.CSSModel, target); | 39 WebInspector.SDKModel.call(this, WebInspector.CSSModel, target); |
| 39 this._domModel = WebInspector.DOMModel.fromTarget(target); | 40 this._domModel = domModel; |
| 40 this._agent = target.cssAgent(); | 41 this._agent = target.cssAgent(); |
| 41 this._styleLoader = new WebInspector.CSSModel.ComputedStyleLoader(this); | 42 this._styleLoader = new WebInspector.CSSModel.ComputedStyleLoader(this); |
| 42 target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Eve
ntTypes.MainFrameNavigated, this._mainFrameNavigated, this); | 43 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event
s.MainFrameNavigated, this._mainFrameNavigated, this); |
| 43 target.registerCSSDispatcher(new WebInspector.CSSDispatcher(this)); | 44 target.registerCSSDispatcher(new WebInspector.CSSDispatcher(this)); |
| 44 this._agent.enable().then(this._wasEnabled.bind(this)); | 45 this._agent.enable().then(this._wasEnabled.bind(this)); |
| 45 /** @type {!Map.<string, !WebInspector.CSSStyleSheetHeader>} */ | 46 /** @type {!Map.<string, !WebInspector.CSSStyleSheetHeader>} */ |
| 46 this._styleSheetIdToHeader = new Map(); | 47 this._styleSheetIdToHeader = new Map(); |
| 47 /** @type {!Map.<string, !Object.<!PageAgent.FrameId, !Array.<!CSSAgent.Styl
eSheetId>>>} */ | 48 /** @type {!Map.<string, !Object.<!PageAgent.FrameId, !Array.<!CSSAgent.Styl
eSheetId>>>} */ |
| 48 this._styleSheetIdsForURL = new Map(); | 49 this._styleSheetIdsForURL = new Map(); |
| 49 | 50 |
| 50 /** @type {!Map.<!WebInspector.CSSStyleSheetHeader, !Promise<string>>} */ | 51 /** @type {!Map.<!WebInspector.CSSStyleSheetHeader, !Promise<string>>} */ |
| 51 this._originalStyleSheetText = new Map(); | 52 this._originalStyleSheetText = new Map(); |
| 52 | 53 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 if (!this._sourceMapURLToHeaders.has(header.sourceMapURL)) | 231 if (!this._sourceMapURLToHeaders.has(header.sourceMapURL)) |
| 231 this._sourceMapByURL.delete(header.sourceMapURL); | 232 this._sourceMapByURL.delete(header.sourceMapURL); |
| 232 this.dispatchEventToListeners(WebInspector.CSSModel.Events.SourceMapDeta
ched, header); | 233 this.dispatchEventToListeners(WebInspector.CSSModel.Events.SourceMapDeta
ched, header); |
| 233 }, | 234 }, |
| 234 | 235 |
| 235 /** | 236 /** |
| 236 * @return {!WebInspector.DOMModel} | 237 * @return {!WebInspector.DOMModel} |
| 237 */ | 238 */ |
| 238 domModel: function() | 239 domModel: function() |
| 239 { | 240 { |
| 240 return /** @type {!WebInspector.DOMModel} */(this._domModel); | 241 return this._domModel; |
| 241 }, | 242 }, |
| 242 | 243 |
| 243 /** | 244 /** |
| 244 * @param {!CSSAgent.StyleSheetId} styleSheetId | 245 * @param {!CSSAgent.StyleSheetId} styleSheetId |
| 245 * @param {!WebInspector.TextRange} range | 246 * @param {!WebInspector.TextRange} range |
| 246 * @param {string} text | 247 * @param {string} text |
| 247 * @param {boolean} majorChange | 248 * @param {boolean} majorChange |
| 248 * @return {!Promise<boolean>} | 249 * @return {!Promise<boolean>} |
| 249 */ | 250 */ |
| 250 setStyleText: function(styleSheetId, range, text, majorChange) | 251 setStyleText: function(styleSheetId, range, text, majorChange) |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 return new WebInspector.CSSStyleRule(this, rulePayload); | 722 return new WebInspector.CSSStyleRule(this, rulePayload); |
| 722 } | 723 } |
| 723 }, | 724 }, |
| 724 | 725 |
| 725 /** | 726 /** |
| 726 * @param {!WebInspector.DOMNode} node | 727 * @param {!WebInspector.DOMNode} node |
| 727 * @param {function(?WebInspector.CSSStyleSheetHeader)} userCallback | 728 * @param {function(?WebInspector.CSSStyleSheetHeader)} userCallback |
| 728 */ | 729 */ |
| 729 requestViaInspectorStylesheet: function(node, userCallback) | 730 requestViaInspectorStylesheet: function(node, userCallback) |
| 730 { | 731 { |
| 731 var frameId = node.frameId() || this.target().resourceTreeModel.mainFram
e.id; | 732 var frameId = node.frameId() || WebInspector.ResourceTreeModel.fromTarge
t(this.target()).mainFrame.id; |
| 732 var headers = this._styleSheetIdToHeader.valuesArray(); | 733 var headers = this._styleSheetIdToHeader.valuesArray(); |
| 733 for (var i = 0; i < headers.length; ++i) { | 734 for (var i = 0; i < headers.length; ++i) { |
| 734 var styleSheetHeader = headers[i]; | 735 var styleSheetHeader = headers[i]; |
| 735 if (styleSheetHeader.frameId === frameId && styleSheetHeader.isViaIn
spector()) { | 736 if (styleSheetHeader.frameId === frameId && styleSheetHeader.isViaIn
spector()) { |
| 736 userCallback(styleSheetHeader); | 737 userCallback(styleSheetHeader); |
| 737 return; | 738 return; |
| 738 } | 739 } |
| 739 } | 740 } |
| 740 | 741 |
| 741 /** | 742 /** |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 text = ""; | 939 text = ""; |
| 939 // Fall through. | 940 // Fall through. |
| 940 } | 941 } |
| 941 return WebInspector.CSSModel.trimSourceURL(text); | 942 return WebInspector.CSSModel.trimSourceURL(text); |
| 942 } | 943 } |
| 943 | 944 |
| 944 return this._agent.getStyleSheetText(styleSheetId, textCallback) | 945 return this._agent.getStyleSheetText(styleSheetId, textCallback) |
| 945 .catchException(/** @type {string} */("")); | 946 .catchException(/** @type {string} */("")); |
| 946 }, | 947 }, |
| 947 | 948 |
| 948 _mainFrameNavigated: function() | 949 /** |
| 950 * @param {!WebInspector.Event} event |
| 951 */ |
| 952 _mainFrameNavigated: function(event) |
| 949 { | 953 { |
| 954 if (event.data.target() !== this.target()) |
| 955 return; |
| 950 this._resetStyleSheets(); | 956 this._resetStyleSheets(); |
| 951 }, | 957 }, |
| 952 | 958 |
| 953 _resetStyleSheets: function() | 959 _resetStyleSheets: function() |
| 954 { | 960 { |
| 955 var headers = this._styleSheetIdToHeader.valuesArray(); | 961 var headers = this._styleSheetIdToHeader.valuesArray(); |
| 956 this._styleSheetIdsForURL.clear(); | 962 this._styleSheetIdsForURL.clear(); |
| 957 this._styleSheetIdToHeader.clear(); | 963 this._styleSheetIdToHeader.clear(); |
| 958 for (var i = 0; i < headers.length; ++i) { | 964 for (var i = 0; i < headers.length; ++i) { |
| 959 this._detachSourceMap(headers[i]); | 965 this._detachSourceMap(headers[i]); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 /** | 1228 /** |
| 1223 * @constructor | 1229 * @constructor |
| 1224 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle | 1230 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle |
| 1225 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle | 1231 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle |
| 1226 */ | 1232 */ |
| 1227 WebInspector.CSSModel.InlineStyleResult = function(inlineStyle, attributesStyle) | 1233 WebInspector.CSSModel.InlineStyleResult = function(inlineStyle, attributesStyle) |
| 1228 { | 1234 { |
| 1229 this.inlineStyle = inlineStyle; | 1235 this.inlineStyle = inlineStyle; |
| 1230 this.attributesStyle = attributesStyle; | 1236 this.attributesStyle = attributesStyle; |
| 1231 } | 1237 } |
| OLD | NEW |