| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 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 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 WebInspector.CSSModel = class extends WebInspector.SDKModel { | 34 SDK.CSSModel = class extends SDK.SDKModel { |
| 35 /** | 35 /** |
| 36 * @param {!WebInspector.Target} target | 36 * @param {!SDK.Target} target |
| 37 * @param {!WebInspector.DOMModel} domModel | 37 * @param {!SDK.DOMModel} domModel |
| 38 */ | 38 */ |
| 39 constructor(target, domModel) { | 39 constructor(target, domModel) { |
| 40 super(WebInspector.CSSModel, target); | 40 super(SDK.CSSModel, target); |
| 41 this._domModel = domModel; | 41 this._domModel = domModel; |
| 42 this._agent = target.cssAgent(); | 42 this._agent = target.cssAgent(); |
| 43 this._styleLoader = new WebInspector.CSSModel.ComputedStyleLoader(this); | 43 this._styleLoader = new SDK.CSSModel.ComputedStyleLoader(this); |
| 44 WebInspector.targetManager.addEventListener( | 44 SDK.targetManager.addEventListener( |
| 45 WebInspector.TargetManager.Events.MainFrameNavigated, this._mainFrameNav
igated, this); | 45 SDK.TargetManager.Events.MainFrameNavigated, this._mainFrameNavigated, t
his); |
| 46 target.registerCSSDispatcher(new WebInspector.CSSDispatcher(this)); | 46 target.registerCSSDispatcher(new SDK.CSSDispatcher(this)); |
| 47 this._agent.enable().then(this._wasEnabled.bind(this)); | 47 this._agent.enable().then(this._wasEnabled.bind(this)); |
| 48 /** @type {!Map.<string, !WebInspector.CSSStyleSheetHeader>} */ | 48 /** @type {!Map.<string, !SDK.CSSStyleSheetHeader>} */ |
| 49 this._styleSheetIdToHeader = new Map(); | 49 this._styleSheetIdToHeader = new Map(); |
| 50 /** @type {!Map.<string, !Object.<!Protocol.Page.FrameId, !Array.<!Protocol.
CSS.StyleSheetId>>>} */ | 50 /** @type {!Map.<string, !Object.<!Protocol.Page.FrameId, !Array.<!Protocol.
CSS.StyleSheetId>>>} */ |
| 51 this._styleSheetIdsForURL = new Map(); | 51 this._styleSheetIdsForURL = new Map(); |
| 52 | 52 |
| 53 /** @type {!Map.<!WebInspector.CSSStyleSheetHeader, !Promise<string>>} */ | 53 /** @type {!Map.<!SDK.CSSStyleSheetHeader, !Promise<string>>} */ |
| 54 this._originalStyleSheetText = new Map(); | 54 this._originalStyleSheetText = new Map(); |
| 55 | 55 |
| 56 /** @type {!Multimap<string, !Protocol.CSS.StyleSheetId>} */ | 56 /** @type {!Multimap<string, !Protocol.CSS.StyleSheetId>} */ |
| 57 this._sourceMapLoadingStyleSheetsIds = new Multimap(); | 57 this._sourceMapLoadingStyleSheetsIds = new Multimap(); |
| 58 | 58 |
| 59 /** @type {!Map<string, !WebInspector.SourceMap>} */ | 59 /** @type {!Map<string, !SDK.SourceMap>} */ |
| 60 this._sourceMapByURL = new Map(); | 60 this._sourceMapByURL = new Map(); |
| 61 /** @type {!Multimap<string, !WebInspector.CSSStyleSheetHeader>} */ | 61 /** @type {!Multimap<string, !SDK.CSSStyleSheetHeader>} */ |
| 62 this._sourceMapURLToHeaders = new Multimap(); | 62 this._sourceMapURLToHeaders = new Multimap(); |
| 63 WebInspector.moduleSetting('cssSourceMapsEnabled').addChangeListener(this._t
oggleSourceMapSupport, this); | 63 Common.moduleSetting('cssSourceMapsEnabled').addChangeListener(this._toggleS
ourceMapSupport, this); |
| 64 } | 64 } |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * @param {string} text | 67 * @param {string} text |
| 68 * @return {string} | 68 * @return {string} |
| 69 */ | 69 */ |
| 70 static trimSourceURL(text) { | 70 static trimSourceURL(text) { |
| 71 var sourceURLIndex = text.lastIndexOf('/*# sourceURL='); | 71 var sourceURLIndex = text.lastIndexOf('/*# sourceURL='); |
| 72 if (sourceURLIndex === -1) { | 72 if (sourceURLIndex === -1) { |
| 73 sourceURLIndex = text.lastIndexOf('/*@ sourceURL='); | 73 sourceURLIndex = text.lastIndexOf('/*@ sourceURL='); |
| 74 if (sourceURLIndex === -1) | 74 if (sourceURLIndex === -1) |
| 75 return text; | 75 return text; |
| 76 } | 76 } |
| 77 var sourceURLLineIndex = text.lastIndexOf('\n', sourceURLIndex); | 77 var sourceURLLineIndex = text.lastIndexOf('\n', sourceURLIndex); |
| 78 if (sourceURLLineIndex === -1) | 78 if (sourceURLLineIndex === -1) |
| 79 return text; | 79 return text; |
| 80 var sourceURLLine = text.substr(sourceURLLineIndex + 1).split('\n', 1)[0]; | 80 var sourceURLLine = text.substr(sourceURLLineIndex + 1).split('\n', 1)[0]; |
| 81 var sourceURLRegex = /[\040\t]*\/\*[#@] sourceURL=[\040\t]*([^\s]*)[\040\t]*
\*\/[\040\t]*$/; | 81 var sourceURLRegex = /[\040\t]*\/\*[#@] sourceURL=[\040\t]*([^\s]*)[\040\t]*
\*\/[\040\t]*$/; |
| 82 if (sourceURLLine.search(sourceURLRegex) === -1) | 82 if (sourceURLLine.search(sourceURLRegex) === -1) |
| 83 return text; | 83 return text; |
| 84 return text.substr(0, sourceURLLineIndex) + text.substr(sourceURLLineIndex +
sourceURLLine.length + 1); | 84 return text.substr(0, sourceURLLineIndex) + text.substr(sourceURLLineIndex +
sourceURLLine.length + 1); |
| 85 } | 85 } |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * @param {!WebInspector.Target} target | 88 * @param {!SDK.Target} target |
| 89 * @return {?WebInspector.CSSModel} | 89 * @return {?SDK.CSSModel} |
| 90 */ | 90 */ |
| 91 static fromTarget(target) { | 91 static fromTarget(target) { |
| 92 return /** @type {?WebInspector.CSSModel} */ (target.model(WebInspector.CSSM
odel)); | 92 return /** @type {?SDK.CSSModel} */ (target.model(SDK.CSSModel)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 /** | 95 /** |
| 96 * @param {!WebInspector.DOMNode} node | 96 * @param {!SDK.DOMNode} node |
| 97 * @return {!WebInspector.CSSModel} | 97 * @return {!SDK.CSSModel} |
| 98 */ | 98 */ |
| 99 static fromNode(node) { | 99 static fromNode(node) { |
| 100 return /** @type {!WebInspector.CSSModel} */ (WebInspector.CSSModel.fromTarg
et(node.target())); | 100 return /** @type {!SDK.CSSModel} */ (SDK.CSSModel.fromTarget(node.target()))
; |
| 101 } | 101 } |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * @param {!WebInspector.Event} event | 104 * @param {!Common.Event} event |
| 105 */ | 105 */ |
| 106 _toggleSourceMapSupport(event) { | 106 _toggleSourceMapSupport(event) { |
| 107 var enabled = /** @type {boolean} */ (event.data); | 107 var enabled = /** @type {boolean} */ (event.data); |
| 108 var headers = this.styleSheetHeaders(); | 108 var headers = this.styleSheetHeaders(); |
| 109 for (var header of headers) { | 109 for (var header of headers) { |
| 110 if (enabled) | 110 if (enabled) |
| 111 this._attachSourceMap(header); | 111 this._attachSourceMap(header); |
| 112 else | 112 else |
| 113 this._detachSourceMap(header); | 113 this._detachSourceMap(header); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 /** | 117 /** |
| 118 * @param {!WebInspector.CSSStyleSheetHeader} header | 118 * @param {!SDK.CSSStyleSheetHeader} header |
| 119 * @return {?WebInspector.SourceMap} | 119 * @return {?SDK.SourceMap} |
| 120 */ | 120 */ |
| 121 sourceMapForHeader(header) { | 121 sourceMapForHeader(header) { |
| 122 return this._sourceMapByURL.get(header.sourceMapURL) || null; | 122 return this._sourceMapByURL.get(header.sourceMapURL) || null; |
| 123 } | 123 } |
| 124 | 124 |
| 125 _sourceMapLoadedForTest() { | 125 _sourceMapLoadedForTest() { |
| 126 } | 126 } |
| 127 | 127 |
| 128 /** | 128 /** |
| 129 * @param {!WebInspector.SourceMap} sourceMap | 129 * @param {!SDK.SourceMap} sourceMap |
| 130 * @return {!Array<!WebInspector.CSSStyleSheetHeader>} | 130 * @return {!Array<!SDK.CSSStyleSheetHeader>} |
| 131 */ | 131 */ |
| 132 headersForSourceMap(sourceMap) { | 132 headersForSourceMap(sourceMap) { |
| 133 return this._sourceMapURLToHeaders.get(sourceMap.url()).valuesArray(); | 133 return this._sourceMapURLToHeaders.get(sourceMap.url()).valuesArray(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 /** | 136 /** |
| 137 * @param {!WebInspector.CSSStyleSheetHeader} header | 137 * @param {!SDK.CSSStyleSheetHeader} header |
| 138 */ | 138 */ |
| 139 _attachSourceMap(header) { | 139 _attachSourceMap(header) { |
| 140 var sourceMapURL = header.sourceMapURL; | 140 var sourceMapURL = header.sourceMapURL; |
| 141 if (!sourceMapURL || !WebInspector.moduleSetting('cssSourceMapsEnabled').get
()) | 141 if (!sourceMapURL || !Common.moduleSetting('cssSourceMapsEnabled').get()) |
| 142 return; | 142 return; |
| 143 if (this._sourceMapByURL.has(sourceMapURL)) { | 143 if (this._sourceMapByURL.has(sourceMapURL)) { |
| 144 attach.call(this, sourceMapURL, header); | 144 attach.call(this, sourceMapURL, header); |
| 145 return; | 145 return; |
| 146 } | 146 } |
| 147 if (!this._sourceMapLoadingStyleSheetsIds.has(sourceMapURL)) { | 147 if (!this._sourceMapLoadingStyleSheetsIds.has(sourceMapURL)) { |
| 148 WebInspector.TextSourceMap.load(sourceMapURL, header.sourceURL) | 148 SDK.TextSourceMap.load(sourceMapURL, header.sourceURL) |
| 149 .then(onTextSourceMapLoaded.bind(this, sourceMapURL)) | 149 .then(onTextSourceMapLoaded.bind(this, sourceMapURL)) |
| 150 .then(onSourceMap.bind(this, sourceMapURL)); | 150 .then(onSourceMap.bind(this, sourceMapURL)); |
| 151 } | 151 } |
| 152 this._sourceMapLoadingStyleSheetsIds.set(sourceMapURL, header.id); | 152 this._sourceMapLoadingStyleSheetsIds.set(sourceMapURL, header.id); |
| 153 | 153 |
| 154 /** | 154 /** |
| 155 * @param {string} sourceMapURL | 155 * @param {string} sourceMapURL |
| 156 * @param {?WebInspector.TextSourceMap} sourceMap | 156 * @param {?SDK.TextSourceMap} sourceMap |
| 157 * @return {!Promise<?WebInspector.SourceMap>} | 157 * @return {!Promise<?SDK.SourceMap>} |
| 158 * @this {WebInspector.CSSModel} | 158 * @this {SDK.CSSModel} |
| 159 */ | 159 */ |
| 160 function onTextSourceMapLoaded(sourceMapURL, sourceMap) { | 160 function onTextSourceMapLoaded(sourceMapURL, sourceMap) { |
| 161 if (!sourceMap) | 161 if (!sourceMap) |
| 162 return Promise.resolve(/** @type {?WebInspector.SourceMap} */ (null)); | 162 return Promise.resolve(/** @type {?SDK.SourceMap} */ (null)); |
| 163 var factoryExtension = this._factoryForSourceMap(sourceMap); | 163 var factoryExtension = this._factoryForSourceMap(sourceMap); |
| 164 if (!factoryExtension) | 164 if (!factoryExtension) |
| 165 return Promise.resolve(/** @type {?WebInspector.SourceMap} */ (sourceMap
)); | 165 return Promise.resolve(/** @type {?SDK.SourceMap} */ (sourceMap)); |
| 166 return factoryExtension.instance() | 166 return factoryExtension.instance() |
| 167 .then(factory => factory.editableSourceMap(this.target(), sourceMap)) | 167 .then(factory => factory.editableSourceMap(this.target(), sourceMap)) |
| 168 .then(map => map || sourceMap) | 168 .then(map => map || sourceMap) |
| 169 .catchException(/** @type {?WebInspector.SourceMap} */ (null)); | 169 .catchException(/** @type {?SDK.SourceMap} */ (null)); |
| 170 } | 170 } |
| 171 | 171 |
| 172 /** | 172 /** |
| 173 * @param {string} sourceMapURL | 173 * @param {string} sourceMapURL |
| 174 * @param {?WebInspector.SourceMap} sourceMap | 174 * @param {?SDK.SourceMap} sourceMap |
| 175 * @this {WebInspector.CSSModel} | 175 * @this {SDK.CSSModel} |
| 176 */ | 176 */ |
| 177 function onSourceMap(sourceMapURL, sourceMap) { | 177 function onSourceMap(sourceMapURL, sourceMap) { |
| 178 this._sourceMapLoadedForTest(); | 178 this._sourceMapLoadedForTest(); |
| 179 var styleSheetIds = this._sourceMapLoadingStyleSheetsIds.get(sourceMapURL)
; | 179 var styleSheetIds = this._sourceMapLoadingStyleSheetsIds.get(sourceMapURL)
; |
| 180 this._sourceMapLoadingStyleSheetsIds.removeAll(sourceMapURL); | 180 this._sourceMapLoadingStyleSheetsIds.removeAll(sourceMapURL); |
| 181 if (!sourceMap) | 181 if (!sourceMap) |
| 182 return; | 182 return; |
| 183 var headers = new Set(); | 183 var headers = new Set(); |
| 184 for (var styleSheetId of styleSheetIds) { | 184 for (var styleSheetId of styleSheetIds) { |
| 185 var header = this.styleSheetHeaderForId(styleSheetId); | 185 var header = this.styleSheetHeaderForId(styleSheetId); |
| 186 if (header) | 186 if (header) |
| 187 headers.add(header); | 187 headers.add(header); |
| 188 } | 188 } |
| 189 if (!headers.size) | 189 if (!headers.size) |
| 190 return; | 190 return; |
| 191 this._sourceMapByURL.set(sourceMapURL, sourceMap); | 191 this._sourceMapByURL.set(sourceMapURL, sourceMap); |
| 192 for (var header of headers) | 192 for (var header of headers) |
| 193 attach.call(this, sourceMapURL, header); | 193 attach.call(this, sourceMapURL, header); |
| 194 } | 194 } |
| 195 | 195 |
| 196 /** | 196 /** |
| 197 * @param {string} sourceMapURL | 197 * @param {string} sourceMapURL |
| 198 * @param {!WebInspector.CSSStyleSheetHeader} header | 198 * @param {!SDK.CSSStyleSheetHeader} header |
| 199 * @this {WebInspector.CSSModel} | 199 * @this {SDK.CSSModel} |
| 200 */ | 200 */ |
| 201 function attach(sourceMapURL, header) { | 201 function attach(sourceMapURL, header) { |
| 202 this._sourceMapURLToHeaders.set(sourceMapURL, header); | 202 this._sourceMapURLToHeaders.set(sourceMapURL, header); |
| 203 this.dispatchEventToListeners(WebInspector.CSSModel.Events.SourceMapAttach
ed, header); | 203 this.dispatchEventToListeners(SDK.CSSModel.Events.SourceMapAttached, heade
r); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 /** | 207 /** |
| 208 * @param {!WebInspector.SourceMap} sourceMap | 208 * @param {!SDK.SourceMap} sourceMap |
| 209 * @return {?Runtime.Extension} | 209 * @return {?Runtime.Extension} |
| 210 */ | 210 */ |
| 211 _factoryForSourceMap(sourceMap) { | 211 _factoryForSourceMap(sourceMap) { |
| 212 var sourceExtensions = new Set(); | 212 var sourceExtensions = new Set(); |
| 213 for (var url of sourceMap.sourceURLs()) | 213 for (var url of sourceMap.sourceURLs()) |
| 214 sourceExtensions.add(WebInspector.ParsedURL.extractExtension(url)); | 214 sourceExtensions.add(Common.ParsedURL.extractExtension(url)); |
| 215 for (var runtimeExtension of self.runtime.extensions(WebInspector.SourceMapF
actory)) { | 215 for (var runtimeExtension of self.runtime.extensions(SDK.SourceMapFactory))
{ |
| 216 var supportedExtensions = new Set(runtimeExtension.descriptor()['extension
s']); | 216 var supportedExtensions = new Set(runtimeExtension.descriptor()['extension
s']); |
| 217 if (supportedExtensions.containsAll(sourceExtensions)) | 217 if (supportedExtensions.containsAll(sourceExtensions)) |
| 218 return runtimeExtension; | 218 return runtimeExtension; |
| 219 } | 219 } |
| 220 return null; | 220 return null; |
| 221 } | 221 } |
| 222 | 222 |
| 223 /** | 223 /** |
| 224 * @param {!WebInspector.CSSStyleSheetHeader} header | 224 * @param {!SDK.CSSStyleSheetHeader} header |
| 225 */ | 225 */ |
| 226 _detachSourceMap(header) { | 226 _detachSourceMap(header) { |
| 227 if (!header.sourceMapURL || !this._sourceMapURLToHeaders.hasValue(header.sou
rceMapURL, header)) | 227 if (!header.sourceMapURL || !this._sourceMapURLToHeaders.hasValue(header.sou
rceMapURL, header)) |
| 228 return; | 228 return; |
| 229 this._sourceMapURLToHeaders.remove(header.sourceMapURL, header); | 229 this._sourceMapURLToHeaders.remove(header.sourceMapURL, header); |
| 230 if (!this._sourceMapURLToHeaders.has(header.sourceMapURL)) | 230 if (!this._sourceMapURLToHeaders.has(header.sourceMapURL)) |
| 231 this._sourceMapByURL.delete(header.sourceMapURL); | 231 this._sourceMapByURL.delete(header.sourceMapURL); |
| 232 this.dispatchEventToListeners(WebInspector.CSSModel.Events.SourceMapDetached
, header); | 232 this.dispatchEventToListeners(SDK.CSSModel.Events.SourceMapDetached, header)
; |
| 233 } | 233 } |
| 234 | 234 |
| 235 /** | 235 /** |
| 236 * @return {!WebInspector.DOMModel} | 236 * @return {!SDK.DOMModel} |
| 237 */ | 237 */ |
| 238 domModel() { | 238 domModel() { |
| 239 return this._domModel; | 239 return this._domModel; |
| 240 } | 240 } |
| 241 | 241 |
| 242 /** | 242 /** |
| 243 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | 243 * @param {!Protocol.CSS.StyleSheetId} styleSheetId |
| 244 * @param {!WebInspector.TextRange} range | 244 * @param {!Common.TextRange} range |
| 245 * @param {string} text | 245 * @param {string} text |
| 246 * @param {boolean} majorChange | 246 * @param {boolean} majorChange |
| 247 * @return {!Promise<boolean>} | 247 * @return {!Promise<boolean>} |
| 248 */ | 248 */ |
| 249 setStyleText(styleSheetId, range, text, majorChange) { | 249 setStyleText(styleSheetId, range, text, majorChange) { |
| 250 var original = this._innerSetStyleTexts.bind(this, [styleSheetId], [range],
[text], majorChange); | 250 var original = this._innerSetStyleTexts.bind(this, [styleSheetId], [range],
[text], majorChange); |
| 251 var header = this.styleSheetHeaderForId(styleSheetId); | 251 var header = this.styleSheetHeaderForId(styleSheetId); |
| 252 if (!header) | 252 if (!header) |
| 253 return original(); | 253 return original(); |
| 254 | 254 |
| 255 var sourceMap = this.sourceMapForHeader(header); | 255 var sourceMap = this.sourceMapForHeader(header); |
| 256 if (!sourceMap) | 256 if (!sourceMap) |
| 257 return original(); | 257 return original(); |
| 258 | 258 |
| 259 var originalAndDetach = originalAndDetachIfSuccess.bind(this, header); | 259 var originalAndDetach = originalAndDetachIfSuccess.bind(this, header); |
| 260 | 260 |
| 261 if (!sourceMap.editable()) | 261 if (!sourceMap.editable()) |
| 262 return original(); | 262 return original(); |
| 263 | 263 |
| 264 return /** @type {!Promise<boolean>} */ ( | 264 return /** @type {!Promise<boolean>} */ ( |
| 265 sourceMap.editCompiled([range], [text]).then(onEditingDone.bind(this)).c
atch(onError.bind(this, header))); | 265 sourceMap.editCompiled([range], [text]).then(onEditingDone.bind(this)).c
atch(onError.bind(this, header))); |
| 266 | 266 |
| 267 /** | 267 /** |
| 268 * @param {?WebInspector.SourceMap.EditResult} editResult | 268 * @param {?SDK.SourceMap.EditResult} editResult |
| 269 * @return {!Promise<boolean>} | 269 * @return {!Promise<boolean>} |
| 270 * @this {WebInspector.CSSModel} | 270 * @this {SDK.CSSModel} |
| 271 */ | 271 */ |
| 272 function onEditingDone(editResult) { | 272 function onEditingDone(editResult) { |
| 273 if (!editResult) | 273 if (!editResult) |
| 274 return Promise.resolve(false); | 274 return Promise.resolve(false); |
| 275 | 275 |
| 276 var edits = editResult.compiledEdits; | 276 var edits = editResult.compiledEdits; |
| 277 if (!edits.length) | 277 if (!edits.length) |
| 278 return onCSSPatched.call(this, editResult, true); | 278 return onCSSPatched.call(this, editResult, true); |
| 279 | 279 |
| 280 edits.sort(WebInspector.SourceEdit.comparator); | 280 edits.sort(Common.SourceEdit.comparator); |
| 281 edits = edits.reverse(); | 281 edits = edits.reverse(); |
| 282 | 282 |
| 283 var styleSheetIds = []; | 283 var styleSheetIds = []; |
| 284 var ranges = []; | 284 var ranges = []; |
| 285 var texts = []; | 285 var texts = []; |
| 286 for (var edit of edits) { | 286 for (var edit of edits) { |
| 287 styleSheetIds.push(header.id); | 287 styleSheetIds.push(header.id); |
| 288 ranges.push(edit.oldRange); | 288 ranges.push(edit.oldRange); |
| 289 texts.push(edit.newText); | 289 texts.push(edit.newText); |
| 290 } | 290 } |
| 291 return this._innerSetStyleTexts(styleSheetIds, ranges, texts, majorChange) | 291 return this._innerSetStyleTexts(styleSheetIds, ranges, texts, majorChange) |
| 292 .then(onCSSPatched.bind(this, editResult)); | 292 .then(onCSSPatched.bind(this, editResult)); |
| 293 } | 293 } |
| 294 | 294 |
| 295 /** | 295 /** |
| 296 * @param {!WebInspector.SourceMap.EditResult} editResult | 296 * @param {!SDK.SourceMap.EditResult} editResult |
| 297 * @param {boolean} success | 297 * @param {boolean} success |
| 298 * @return {!Promise<boolean>} | 298 * @return {!Promise<boolean>} |
| 299 * @this {WebInspector.CSSModel} | 299 * @this {SDK.CSSModel} |
| 300 */ | 300 */ |
| 301 function onCSSPatched(editResult, success) { | 301 function onCSSPatched(editResult, success) { |
| 302 if (!success) | 302 if (!success) |
| 303 return originalAndDetach(); | 303 return originalAndDetach(); |
| 304 | 304 |
| 305 this._sourceMapByURL.set(header.sourceMapURL, editResult.map); | 305 this._sourceMapByURL.set(header.sourceMapURL, editResult.map); |
| 306 this.dispatchEventToListeners( | 306 this.dispatchEventToListeners( |
| 307 WebInspector.CSSModel.Events.SourceMapChanged, | 307 SDK.CSSModel.Events.SourceMapChanged, |
| 308 {sourceMap: editResult.map, newSources: editResult.newSources}); | 308 {sourceMap: editResult.map, newSources: editResult.newSources}); |
| 309 return Promise.resolve(true); | 309 return Promise.resolve(true); |
| 310 } | 310 } |
| 311 | 311 |
| 312 /** | 312 /** |
| 313 * @param {!WebInspector.CSSStyleSheetHeader} header | 313 * @param {!SDK.CSSStyleSheetHeader} header |
| 314 * @param {*} error | 314 * @param {*} error |
| 315 * @return {!Promise<boolean>} | 315 * @return {!Promise<boolean>} |
| 316 * @this {WebInspector.CSSModel} | 316 * @this {SDK.CSSModel} |
| 317 */ | 317 */ |
| 318 function onError(header, error) { | 318 function onError(header, error) { |
| 319 WebInspector.console.error(WebInspector.UIString('LiveSASS failed: %s', so
urceMap.compiledURL())); | 319 Common.console.error(Common.UIString('LiveSASS failed: %s', sourceMap.comp
iledURL())); |
| 320 console.error(error); | 320 console.error(error); |
| 321 this._detachSourceMap(header); | 321 this._detachSourceMap(header); |
| 322 return original(); | 322 return original(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 /** | 325 /** |
| 326 * @param {!WebInspector.CSSStyleSheetHeader} header | 326 * @param {!SDK.CSSStyleSheetHeader} header |
| 327 * @return {!Promise<boolean>} | 327 * @return {!Promise<boolean>} |
| 328 * @this {WebInspector.CSSModel} | 328 * @this {SDK.CSSModel} |
| 329 */ | 329 */ |
| 330 function originalAndDetachIfSuccess(header) { | 330 function originalAndDetachIfSuccess(header) { |
| 331 return this._innerSetStyleTexts([styleSheetId], [range], [text], majorChan
ge).then(detachIfSuccess.bind(this)); | 331 return this._innerSetStyleTexts([styleSheetId], [range], [text], majorChan
ge).then(detachIfSuccess.bind(this)); |
| 332 | 332 |
| 333 /** | 333 /** |
| 334 * @param {boolean} success | 334 * @param {boolean} success |
| 335 * @return {boolean} | 335 * @return {boolean} |
| 336 * @this {WebInspector.CSSModel} | 336 * @this {SDK.CSSModel} |
| 337 */ | 337 */ |
| 338 function detachIfSuccess(success) { | 338 function detachIfSuccess(success) { |
| 339 if (success) | 339 if (success) |
| 340 this._detachSourceMap(header); | 340 this._detachSourceMap(header); |
| 341 return success; | 341 return success; |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 | 345 |
| 346 /** | 346 /** |
| 347 * @param {!Array<!Protocol.CSS.StyleSheetId>} styleSheetIds | 347 * @param {!Array<!Protocol.CSS.StyleSheetId>} styleSheetIds |
| 348 * @param {!Array<!WebInspector.TextRange>} ranges | 348 * @param {!Array<!Common.TextRange>} ranges |
| 349 * @param {!Array<string>} texts | 349 * @param {!Array<string>} texts |
| 350 * @param {boolean} majorChange | 350 * @param {boolean} majorChange |
| 351 * @return {!Promise<boolean>} | 351 * @return {!Promise<boolean>} |
| 352 */ | 352 */ |
| 353 _innerSetStyleTexts(styleSheetIds, ranges, texts, majorChange) { | 353 _innerSetStyleTexts(styleSheetIds, ranges, texts, majorChange) { |
| 354 /** | 354 /** |
| 355 * @param {?Protocol.Error} error | 355 * @param {?Protocol.Error} error |
| 356 * @param {?Array<!Protocol.CSS.CSSStyle>} stylePayloads | 356 * @param {?Array<!Protocol.CSS.CSSStyle>} stylePayloads |
| 357 * @return {boolean} | 357 * @return {boolean} |
| 358 * @this {WebInspector.CSSModel} | 358 * @this {SDK.CSSModel} |
| 359 */ | 359 */ |
| 360 function parsePayload(error, stylePayloads) { | 360 function parsePayload(error, stylePayloads) { |
| 361 if (error || !stylePayloads || stylePayloads.length !== ranges.length) | 361 if (error || !stylePayloads || stylePayloads.length !== ranges.length) |
| 362 return false; | 362 return false; |
| 363 | 363 |
| 364 if (majorChange) | 364 if (majorChange) |
| 365 this._domModel.markUndoableState(); | 365 this._domModel.markUndoableState(); |
| 366 for (var i = 0; i < ranges.length; ++i) { | 366 for (var i = 0; i < ranges.length; ++i) { |
| 367 var edit = new WebInspector.CSSModel.Edit(styleSheetIds[i], ranges[i], t
exts[i], stylePayloads[i]); | 367 var edit = new SDK.CSSModel.Edit(styleSheetIds[i], ranges[i], texts[i],
stylePayloads[i]); |
| 368 this._fireStyleSheetChanged(styleSheetIds[i], edit); | 368 this._fireStyleSheetChanged(styleSheetIds[i], edit); |
| 369 } | 369 } |
| 370 return true; | 370 return true; |
| 371 } | 371 } |
| 372 | 372 |
| 373 console.assert( | 373 console.assert( |
| 374 styleSheetIds.length === ranges.length && ranges.length === texts.length
, 'Array lengths must be equal'); | 374 styleSheetIds.length === ranges.length && ranges.length === texts.length
, 'Array lengths must be equal'); |
| 375 var edits = []; | 375 var edits = []; |
| 376 var ensureContentPromises = []; | 376 var ensureContentPromises = []; |
| 377 for (var i = 0; i < styleSheetIds.length; ++i) { | 377 for (var i = 0; i < styleSheetIds.length; ++i) { |
| 378 edits.push({styleSheetId: styleSheetIds[i], range: ranges[i].serializeToOb
ject(), text: texts[i]}); | 378 edits.push({styleSheetId: styleSheetIds[i], range: ranges[i].serializeToOb
ject(), text: texts[i]}); |
| 379 ensureContentPromises.push(this._ensureOriginalStyleSheetText(styleSheetId
s[i])); | 379 ensureContentPromises.push(this._ensureOriginalStyleSheetText(styleSheetId
s[i])); |
| 380 } | 380 } |
| 381 | 381 |
| 382 return Promise.all(ensureContentPromises) | 382 return Promise.all(ensureContentPromises) |
| 383 .then(() => this._agent.setStyleTexts(edits, parsePayload.bind(this))) | 383 .then(() => this._agent.setStyleTexts(edits, parsePayload.bind(this))) |
| 384 .catchException(false); | 384 .catchException(false); |
| 385 } | 385 } |
| 386 | 386 |
| 387 /** | 387 /** |
| 388 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | 388 * @param {!Protocol.CSS.StyleSheetId} styleSheetId |
| 389 * @param {!WebInspector.TextRange} range | 389 * @param {!Common.TextRange} range |
| 390 * @param {string} text | 390 * @param {string} text |
| 391 * @return {!Promise<boolean>} | 391 * @return {!Promise<boolean>} |
| 392 */ | 392 */ |
| 393 setSelectorText(styleSheetId, range, text) { | 393 setSelectorText(styleSheetId, range, text) { |
| 394 /** | 394 /** |
| 395 * @param {?Protocol.Error} error | 395 * @param {?Protocol.Error} error |
| 396 * @param {?Protocol.CSS.SelectorList} selectorPayload | 396 * @param {?Protocol.CSS.SelectorList} selectorPayload |
| 397 * @return {boolean} | 397 * @return {boolean} |
| 398 * @this {WebInspector.CSSModel} | 398 * @this {SDK.CSSModel} |
| 399 */ | 399 */ |
| 400 function callback(error, selectorPayload) { | 400 function callback(error, selectorPayload) { |
| 401 if (error || !selectorPayload) | 401 if (error || !selectorPayload) |
| 402 return false; | 402 return false; |
| 403 this._domModel.markUndoableState(); | 403 this._domModel.markUndoableState(); |
| 404 var edit = new WebInspector.CSSModel.Edit(styleSheetId, range, text, selec
torPayload); | 404 var edit = new SDK.CSSModel.Edit(styleSheetId, range, text, selectorPayloa
d); |
| 405 this._fireStyleSheetChanged(styleSheetId, edit); | 405 this._fireStyleSheetChanged(styleSheetId, edit); |
| 406 return true; | 406 return true; |
| 407 } | 407 } |
| 408 | 408 |
| 409 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.StyleRu
leEdited); | 409 Host.userMetrics.actionTaken(Host.UserMetrics.Action.StyleRuleEdited); |
| 410 return this._ensureOriginalStyleSheetText(styleSheetId) | 410 return this._ensureOriginalStyleSheetText(styleSheetId) |
| 411 .then(() => this._agent.setRuleSelector(styleSheetId, range, text, callb
ack.bind(this))) | 411 .then(() => this._agent.setRuleSelector(styleSheetId, range, text, callb
ack.bind(this))) |
| 412 .catchException(false); | 412 .catchException(false); |
| 413 } | 413 } |
| 414 | 414 |
| 415 /** | 415 /** |
| 416 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | 416 * @param {!Protocol.CSS.StyleSheetId} styleSheetId |
| 417 * @param {!WebInspector.TextRange} range | 417 * @param {!Common.TextRange} range |
| 418 * @param {string} text | 418 * @param {string} text |
| 419 * @return {!Promise<boolean>} | 419 * @return {!Promise<boolean>} |
| 420 */ | 420 */ |
| 421 setKeyframeKey(styleSheetId, range, text) { | 421 setKeyframeKey(styleSheetId, range, text) { |
| 422 /** | 422 /** |
| 423 * @param {?Protocol.Error} error | 423 * @param {?Protocol.Error} error |
| 424 * @param {!Protocol.CSS.Value} payload | 424 * @param {!Protocol.CSS.Value} payload |
| 425 * @return {boolean} | 425 * @return {boolean} |
| 426 * @this {WebInspector.CSSModel} | 426 * @this {SDK.CSSModel} |
| 427 */ | 427 */ |
| 428 function callback(error, payload) { | 428 function callback(error, payload) { |
| 429 if (error || !payload) | 429 if (error || !payload) |
| 430 return false; | 430 return false; |
| 431 this._domModel.markUndoableState(); | 431 this._domModel.markUndoableState(); |
| 432 var edit = new WebInspector.CSSModel.Edit(styleSheetId, range, text, paylo
ad); | 432 var edit = new SDK.CSSModel.Edit(styleSheetId, range, text, payload); |
| 433 this._fireStyleSheetChanged(styleSheetId, edit); | 433 this._fireStyleSheetChanged(styleSheetId, edit); |
| 434 return true; | 434 return true; |
| 435 } | 435 } |
| 436 | 436 |
| 437 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.StyleRu
leEdited); | 437 Host.userMetrics.actionTaken(Host.UserMetrics.Action.StyleRuleEdited); |
| 438 return this._ensureOriginalStyleSheetText(styleSheetId) | 438 return this._ensureOriginalStyleSheetText(styleSheetId) |
| 439 .then(() => this._agent.setKeyframeKey(styleSheetId, range, text, callba
ck.bind(this))) | 439 .then(() => this._agent.setKeyframeKey(styleSheetId, range, text, callba
ck.bind(this))) |
| 440 .catchException(false); | 440 .catchException(false); |
| 441 } | 441 } |
| 442 | 442 |
| 443 startRuleUsageTracking() { | 443 startRuleUsageTracking() { |
| 444 this._agent.startRuleUsageTracking(); | 444 this._agent.startRuleUsageTracking(); |
| 445 } | 445 } |
| 446 | 446 |
| 447 /** | 447 /** |
| 448 * @return {!Promise<!Array<!WebInspector.CSSModel.RuleUsage>>} | 448 * @return {!Promise<!Array<!SDK.CSSModel.RuleUsage>>} |
| 449 */ | 449 */ |
| 450 ruleListPromise() { | 450 ruleListPromise() { |
| 451 /** | 451 /** |
| 452 * @param {?string} error | 452 * @param {?string} error |
| 453 * @param {!Array<!Protocol.CSS.RuleUsage>=} ruleUsage | 453 * @param {!Array<!Protocol.CSS.RuleUsage>=} ruleUsage |
| 454 * @return {!Array<!WebInspector.CSSModel.RuleUsage>} | 454 * @return {!Array<!SDK.CSSModel.RuleUsage>} |
| 455 */ | 455 */ |
| 456 function usedRulesCallback(error, ruleUsage) { | 456 function usedRulesCallback(error, ruleUsage) { |
| 457 if (error || !ruleUsage) | 457 if (error || !ruleUsage) |
| 458 return []; | 458 return []; |
| 459 | 459 |
| 460 return ruleUsage.map(rule => ({range: rule.range, styleSheetId: rule.style
SheetId, wasUsed: rule.used})); | 460 return ruleUsage.map(rule => ({range: rule.range, styleSheetId: rule.style
SheetId, wasUsed: rule.used})); |
| 461 } | 461 } |
| 462 | 462 |
| 463 return this._agent.stopRuleUsageTracking(usedRulesCallback); | 463 return this._agent.stopRuleUsageTracking(usedRulesCallback); |
| 464 } | 464 } |
| 465 | 465 |
| 466 /** | 466 /** |
| 467 * @return {!Promise.<!Array.<!WebInspector.CSSMedia>>} | 467 * @return {!Promise.<!Array.<!SDK.CSSMedia>>} |
| 468 */ | 468 */ |
| 469 mediaQueriesPromise() { | 469 mediaQueriesPromise() { |
| 470 /** | 470 /** |
| 471 * @param {?Protocol.Error} error | 471 * @param {?Protocol.Error} error |
| 472 * @param {?Array.<!Protocol.CSS.CSSMedia>} payload | 472 * @param {?Array.<!Protocol.CSS.CSSMedia>} payload |
| 473 * @return {!Array.<!WebInspector.CSSMedia>} | 473 * @return {!Array.<!SDK.CSSMedia>} |
| 474 * @this {!WebInspector.CSSModel} | 474 * @this {!SDK.CSSModel} |
| 475 */ | 475 */ |
| 476 function parsePayload(error, payload) { | 476 function parsePayload(error, payload) { |
| 477 return !error && payload ? WebInspector.CSSMedia.parseMediaArrayPayload(th
is, payload) : []; | 477 return !error && payload ? SDK.CSSMedia.parseMediaArrayPayload(this, paylo
ad) : []; |
| 478 } | 478 } |
| 479 | 479 |
| 480 return this._agent.getMediaQueries(parsePayload.bind(this)); | 480 return this._agent.getMediaQueries(parsePayload.bind(this)); |
| 481 } | 481 } |
| 482 | 482 |
| 483 /** | 483 /** |
| 484 * @return {boolean} | 484 * @return {boolean} |
| 485 */ | 485 */ |
| 486 isEnabled() { | 486 isEnabled() { |
| 487 return this._isEnabled; | 487 return this._isEnabled; |
| 488 } | 488 } |
| 489 | 489 |
| 490 /** | 490 /** |
| 491 * @param {?Protocol.Error} error | 491 * @param {?Protocol.Error} error |
| 492 */ | 492 */ |
| 493 _wasEnabled(error) { | 493 _wasEnabled(error) { |
| 494 if (error) { | 494 if (error) { |
| 495 console.error('Failed to enabled CSS agent: ' + error); | 495 console.error('Failed to enabled CSS agent: ' + error); |
| 496 return; | 496 return; |
| 497 } | 497 } |
| 498 this._isEnabled = true; | 498 this._isEnabled = true; |
| 499 this.dispatchEventToListeners(WebInspector.CSSModel.Events.ModelWasEnabled); | 499 this.dispatchEventToListeners(SDK.CSSModel.Events.ModelWasEnabled); |
| 500 } | 500 } |
| 501 | 501 |
| 502 /** | 502 /** |
| 503 * @param {!Protocol.DOM.NodeId} nodeId | 503 * @param {!Protocol.DOM.NodeId} nodeId |
| 504 * @return {!Promise.<?WebInspector.CSSMatchedStyles>} | 504 * @return {!Promise.<?SDK.CSSMatchedStyles>} |
| 505 */ | 505 */ |
| 506 matchedStylesPromise(nodeId) { | 506 matchedStylesPromise(nodeId) { |
| 507 /** | 507 /** |
| 508 * @param {?Protocol.Error} error | 508 * @param {?Protocol.Error} error |
| 509 * @param {?Protocol.CSS.CSSStyle=} inlinePayload | 509 * @param {?Protocol.CSS.CSSStyle=} inlinePayload |
| 510 * @param {?Protocol.CSS.CSSStyle=} attributesPayload | 510 * @param {?Protocol.CSS.CSSStyle=} attributesPayload |
| 511 * @param {!Array.<!Protocol.CSS.RuleMatch>=} matchedPayload | 511 * @param {!Array.<!Protocol.CSS.RuleMatch>=} matchedPayload |
| 512 * @param {!Array.<!Protocol.CSS.PseudoElementMatches>=} pseudoPayload | 512 * @param {!Array.<!Protocol.CSS.PseudoElementMatches>=} pseudoPayload |
| 513 * @param {!Array.<!Protocol.CSS.InheritedStyleEntry>=} inheritedPayload | 513 * @param {!Array.<!Protocol.CSS.InheritedStyleEntry>=} inheritedPayload |
| 514 * @param {!Array.<!Protocol.CSS.CSSKeyframesRule>=} animationsPayload | 514 * @param {!Array.<!Protocol.CSS.CSSKeyframesRule>=} animationsPayload |
| 515 * @return {?WebInspector.CSSMatchedStyles} | 515 * @return {?SDK.CSSMatchedStyles} |
| 516 * @this {WebInspector.CSSModel} | 516 * @this {SDK.CSSModel} |
| 517 */ | 517 */ |
| 518 function callback( | 518 function callback( |
| 519 error, inlinePayload, attributesPayload, matchedPayload, pseudoPayload,
inheritedPayload, animationsPayload) { | 519 error, inlinePayload, attributesPayload, matchedPayload, pseudoPayload,
inheritedPayload, animationsPayload) { |
| 520 if (error) | 520 if (error) |
| 521 return null; | 521 return null; |
| 522 | 522 |
| 523 var node = this._domModel.nodeForId(nodeId); | 523 var node = this._domModel.nodeForId(nodeId); |
| 524 if (!node) | 524 if (!node) |
| 525 return null; | 525 return null; |
| 526 | 526 |
| 527 return new WebInspector.CSSMatchedStyles( | 527 return new SDK.CSSMatchedStyles( |
| 528 this, node, inlinePayload || null, attributesPayload || null, matchedP
ayload || [], pseudoPayload || [], | 528 this, node, inlinePayload || null, attributesPayload || null, matchedP
ayload || [], pseudoPayload || [], |
| 529 inheritedPayload || [], animationsPayload || []); | 529 inheritedPayload || [], animationsPayload || []); |
| 530 } | 530 } |
| 531 | 531 |
| 532 return this._agent.getMatchedStylesForNode(nodeId, callback.bind(this)); | 532 return this._agent.getMatchedStylesForNode(nodeId, callback.bind(this)); |
| 533 } | 533 } |
| 534 | 534 |
| 535 /** | 535 /** |
| 536 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | 536 * @param {!Protocol.CSS.StyleSheetId} styleSheetId |
| 537 * @return {!Promise<!Array<string>>} | 537 * @return {!Promise<!Array<string>>} |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 * @return {?Array.<!Protocol.CSS.PlatformFontUsage>} | 583 * @return {?Array.<!Protocol.CSS.PlatformFontUsage>} |
| 584 */ | 584 */ |
| 585 function platformFontsCallback(error, fonts) { | 585 function platformFontsCallback(error, fonts) { |
| 586 return !error && fonts ? fonts : null; | 586 return !error && fonts ? fonts : null; |
| 587 } | 587 } |
| 588 | 588 |
| 589 return this._agent.getPlatformFontsForNode(nodeId, platformFontsCallback); | 589 return this._agent.getPlatformFontsForNode(nodeId, platformFontsCallback); |
| 590 } | 590 } |
| 591 | 591 |
| 592 /** | 592 /** |
| 593 * @return {!Array.<!WebInspector.CSSStyleSheetHeader>} | 593 * @return {!Array.<!SDK.CSSStyleSheetHeader>} |
| 594 */ | 594 */ |
| 595 allStyleSheets() { | 595 allStyleSheets() { |
| 596 var values = this._styleSheetIdToHeader.valuesArray(); | 596 var values = this._styleSheetIdToHeader.valuesArray(); |
| 597 /** | 597 /** |
| 598 * @param {!WebInspector.CSSStyleSheetHeader} a | 598 * @param {!SDK.CSSStyleSheetHeader} a |
| 599 * @param {!WebInspector.CSSStyleSheetHeader} b | 599 * @param {!SDK.CSSStyleSheetHeader} b |
| 600 * @return {number} | 600 * @return {number} |
| 601 */ | 601 */ |
| 602 function styleSheetComparator(a, b) { | 602 function styleSheetComparator(a, b) { |
| 603 if (a.sourceURL < b.sourceURL) | 603 if (a.sourceURL < b.sourceURL) |
| 604 return -1; | 604 return -1; |
| 605 else if (a.sourceURL > b.sourceURL) | 605 else if (a.sourceURL > b.sourceURL) |
| 606 return 1; | 606 return 1; |
| 607 return a.startLine - b.startLine || a.startColumn - b.startColumn; | 607 return a.startLine - b.startLine || a.startColumn - b.startColumn; |
| 608 } | 608 } |
| 609 values.sort(styleSheetComparator); | 609 values.sort(styleSheetComparator); |
| 610 | 610 |
| 611 return values; | 611 return values; |
| 612 } | 612 } |
| 613 | 613 |
| 614 /** | 614 /** |
| 615 * @param {!Protocol.DOM.NodeId} nodeId | 615 * @param {!Protocol.DOM.NodeId} nodeId |
| 616 * @return {!Promise.<?WebInspector.CSSModel.InlineStyleResult>} | 616 * @return {!Promise.<?SDK.CSSModel.InlineStyleResult>} |
| 617 */ | 617 */ |
| 618 inlineStylesPromise(nodeId) { | 618 inlineStylesPromise(nodeId) { |
| 619 /** | 619 /** |
| 620 * @param {?Protocol.Error} error | 620 * @param {?Protocol.Error} error |
| 621 * @param {?Protocol.CSS.CSSStyle=} inlinePayload | 621 * @param {?Protocol.CSS.CSSStyle=} inlinePayload |
| 622 * @param {?Protocol.CSS.CSSStyle=} attributesStylePayload | 622 * @param {?Protocol.CSS.CSSStyle=} attributesStylePayload |
| 623 * @return {?WebInspector.CSSModel.InlineStyleResult} | 623 * @return {?SDK.CSSModel.InlineStyleResult} |
| 624 * @this {WebInspector.CSSModel} | 624 * @this {SDK.CSSModel} |
| 625 */ | 625 */ |
| 626 function callback(error, inlinePayload, attributesStylePayload) { | 626 function callback(error, inlinePayload, attributesStylePayload) { |
| 627 if (error || !inlinePayload) | 627 if (error || !inlinePayload) |
| 628 return null; | 628 return null; |
| 629 var inlineStyle = inlinePayload ? | 629 var inlineStyle = inlinePayload ? |
| 630 new WebInspector.CSSStyleDeclaration( | 630 new SDK.CSSStyleDeclaration( |
| 631 this, null, inlinePayload, WebInspector.CSSStyleDeclaration.Type.I
nline) : | 631 this, null, inlinePayload, SDK.CSSStyleDeclaration.Type.Inline) : |
| 632 null; | 632 null; |
| 633 var attributesStyle = attributesStylePayload ? | 633 var attributesStyle = attributesStylePayload ? |
| 634 new WebInspector.CSSStyleDeclaration( | 634 new SDK.CSSStyleDeclaration( |
| 635 this, null, attributesStylePayload, WebInspector.CSSStyleDeclarati
on.Type.Attributes) : | 635 this, null, attributesStylePayload, SDK.CSSStyleDeclaration.Type.A
ttributes) : |
| 636 null; | 636 null; |
| 637 return new WebInspector.CSSModel.InlineStyleResult(inlineStyle, attributes
Style); | 637 return new SDK.CSSModel.InlineStyleResult(inlineStyle, attributesStyle); |
| 638 } | 638 } |
| 639 | 639 |
| 640 return this._agent.getInlineStylesForNode(nodeId, callback.bind(this)); | 640 return this._agent.getInlineStylesForNode(nodeId, callback.bind(this)); |
| 641 } | 641 } |
| 642 | 642 |
| 643 /** | 643 /** |
| 644 * @param {!WebInspector.DOMNode} node | 644 * @param {!SDK.DOMNode} node |
| 645 * @param {string} pseudoClass | 645 * @param {string} pseudoClass |
| 646 * @param {boolean} enable | 646 * @param {boolean} enable |
| 647 * @return {boolean} | 647 * @return {boolean} |
| 648 */ | 648 */ |
| 649 forcePseudoState(node, pseudoClass, enable) { | 649 forcePseudoState(node, pseudoClass, enable) { |
| 650 var pseudoClasses = node.marker(WebInspector.CSSModel.PseudoStateMarker) ||
[]; | 650 var pseudoClasses = node.marker(SDK.CSSModel.PseudoStateMarker) || []; |
| 651 if (enable) { | 651 if (enable) { |
| 652 if (pseudoClasses.indexOf(pseudoClass) >= 0) | 652 if (pseudoClasses.indexOf(pseudoClass) >= 0) |
| 653 return false; | 653 return false; |
| 654 pseudoClasses.push(pseudoClass); | 654 pseudoClasses.push(pseudoClass); |
| 655 node.setMarker(WebInspector.CSSModel.PseudoStateMarker, pseudoClasses); | 655 node.setMarker(SDK.CSSModel.PseudoStateMarker, pseudoClasses); |
| 656 } else { | 656 } else { |
| 657 if (pseudoClasses.indexOf(pseudoClass) < 0) | 657 if (pseudoClasses.indexOf(pseudoClass) < 0) |
| 658 return false; | 658 return false; |
| 659 pseudoClasses.remove(pseudoClass); | 659 pseudoClasses.remove(pseudoClass); |
| 660 if (pseudoClasses.length) | 660 if (pseudoClasses.length) |
| 661 node.setMarker(WebInspector.CSSModel.PseudoStateMarker, pseudoClasses); | 661 node.setMarker(SDK.CSSModel.PseudoStateMarker, pseudoClasses); |
| 662 else | 662 else |
| 663 node.setMarker(WebInspector.CSSModel.PseudoStateMarker, null); | 663 node.setMarker(SDK.CSSModel.PseudoStateMarker, null); |
| 664 } | 664 } |
| 665 | 665 |
| 666 this._agent.forcePseudoState(node.id, pseudoClasses); | 666 this._agent.forcePseudoState(node.id, pseudoClasses); |
| 667 this.dispatchEventToListeners( | 667 this.dispatchEventToListeners( |
| 668 WebInspector.CSSModel.Events.PseudoStateForced, {node: node, pseudoClass
: pseudoClass, enable: enable}); | 668 SDK.CSSModel.Events.PseudoStateForced, {node: node, pseudoClass: pseudoC
lass, enable: enable}); |
| 669 return true; | 669 return true; |
| 670 } | 670 } |
| 671 | 671 |
| 672 /** | 672 /** |
| 673 * @param {!WebInspector.DOMNode} node | 673 * @param {!SDK.DOMNode} node |
| 674 * @return {?Array<string>} state | 674 * @return {?Array<string>} state |
| 675 */ | 675 */ |
| 676 pseudoState(node) { | 676 pseudoState(node) { |
| 677 return node.marker(WebInspector.CSSModel.PseudoStateMarker) || []; | 677 return node.marker(SDK.CSSModel.PseudoStateMarker) || []; |
| 678 } | 678 } |
| 679 | 679 |
| 680 /** | 680 /** |
| 681 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | 681 * @param {!Protocol.CSS.StyleSheetId} styleSheetId |
| 682 * @param {!WebInspector.TextRange} range | 682 * @param {!Common.TextRange} range |
| 683 * @param {string} newMediaText | 683 * @param {string} newMediaText |
| 684 * @return {!Promise<boolean>} | 684 * @return {!Promise<boolean>} |
| 685 */ | 685 */ |
| 686 setMediaText(styleSheetId, range, newMediaText) { | 686 setMediaText(styleSheetId, range, newMediaText) { |
| 687 /** | 687 /** |
| 688 * @param {?Protocol.Error} error | 688 * @param {?Protocol.Error} error |
| 689 * @param {!Protocol.CSS.CSSMedia} mediaPayload | 689 * @param {!Protocol.CSS.CSSMedia} mediaPayload |
| 690 * @return {boolean} | 690 * @return {boolean} |
| 691 * @this {WebInspector.CSSModel} | 691 * @this {SDK.CSSModel} |
| 692 */ | 692 */ |
| 693 function parsePayload(error, mediaPayload) { | 693 function parsePayload(error, mediaPayload) { |
| 694 if (!mediaPayload) | 694 if (!mediaPayload) |
| 695 return false; | 695 return false; |
| 696 this._domModel.markUndoableState(); | 696 this._domModel.markUndoableState(); |
| 697 var edit = new WebInspector.CSSModel.Edit(styleSheetId, range, newMediaTex
t, mediaPayload); | 697 var edit = new SDK.CSSModel.Edit(styleSheetId, range, newMediaText, mediaP
ayload); |
| 698 this._fireStyleSheetChanged(styleSheetId, edit); | 698 this._fireStyleSheetChanged(styleSheetId, edit); |
| 699 return true; | 699 return true; |
| 700 } | 700 } |
| 701 | 701 |
| 702 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.StyleRu
leEdited); | 702 Host.userMetrics.actionTaken(Host.UserMetrics.Action.StyleRuleEdited); |
| 703 return this._ensureOriginalStyleSheetText(styleSheetId) | 703 return this._ensureOriginalStyleSheetText(styleSheetId) |
| 704 .then(() => this._agent.setMediaText(styleSheetId, range, newMediaText,
parsePayload.bind(this))) | 704 .then(() => this._agent.setMediaText(styleSheetId, range, newMediaText,
parsePayload.bind(this))) |
| 705 .catchException(false); | 705 .catchException(false); |
| 706 } | 706 } |
| 707 | 707 |
| 708 /** | 708 /** |
| 709 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | 709 * @param {!Protocol.CSS.StyleSheetId} styleSheetId |
| 710 * @param {string} ruleText | 710 * @param {string} ruleText |
| 711 * @param {!WebInspector.TextRange} ruleLocation | 711 * @param {!Common.TextRange} ruleLocation |
| 712 * @return {!Promise<?WebInspector.CSSStyleRule>} | 712 * @return {!Promise<?SDK.CSSStyleRule>} |
| 713 */ | 713 */ |
| 714 addRule(styleSheetId, ruleText, ruleLocation) { | 714 addRule(styleSheetId, ruleText, ruleLocation) { |
| 715 return this._ensureOriginalStyleSheetText(styleSheetId) | 715 return this._ensureOriginalStyleSheetText(styleSheetId) |
| 716 .then(() => this._agent.addRule(styleSheetId, ruleText, ruleLocation, pa
rsePayload.bind(this))) | 716 .then(() => this._agent.addRule(styleSheetId, ruleText, ruleLocation, pa
rsePayload.bind(this))) |
| 717 .catchException(/** @type {?WebInspector.CSSStyleRule} */ (null)); | 717 .catchException(/** @type {?SDK.CSSStyleRule} */ (null)); |
| 718 | 718 |
| 719 /** | 719 /** |
| 720 * @param {?Protocol.Error} error | 720 * @param {?Protocol.Error} error |
| 721 * @param {?Protocol.CSS.CSSRule} rulePayload | 721 * @param {?Protocol.CSS.CSSRule} rulePayload |
| 722 * @return {?WebInspector.CSSStyleRule} | 722 * @return {?SDK.CSSStyleRule} |
| 723 * @this {WebInspector.CSSModel} | 723 * @this {SDK.CSSModel} |
| 724 */ | 724 */ |
| 725 function parsePayload(error, rulePayload) { | 725 function parsePayload(error, rulePayload) { |
| 726 if (error || !rulePayload) | 726 if (error || !rulePayload) |
| 727 return null; | 727 return null; |
| 728 this._domModel.markUndoableState(); | 728 this._domModel.markUndoableState(); |
| 729 var edit = new WebInspector.CSSModel.Edit(styleSheetId, ruleLocation, rule
Text, rulePayload); | 729 var edit = new SDK.CSSModel.Edit(styleSheetId, ruleLocation, ruleText, rul
ePayload); |
| 730 this._fireStyleSheetChanged(styleSheetId, edit); | 730 this._fireStyleSheetChanged(styleSheetId, edit); |
| 731 return new WebInspector.CSSStyleRule(this, rulePayload); | 731 return new SDK.CSSStyleRule(this, rulePayload); |
| 732 } | 732 } |
| 733 } | 733 } |
| 734 | 734 |
| 735 /** | 735 /** |
| 736 * @param {!WebInspector.DOMNode} node | 736 * @param {!SDK.DOMNode} node |
| 737 * @param {function(?WebInspector.CSSStyleSheetHeader)} userCallback | 737 * @param {function(?SDK.CSSStyleSheetHeader)} userCallback |
| 738 */ | 738 */ |
| 739 requestViaInspectorStylesheet(node, userCallback) { | 739 requestViaInspectorStylesheet(node, userCallback) { |
| 740 var frameId = node.frameId() || WebInspector.ResourceTreeModel.fromTarget(th
is.target()).mainFrame.id; | 740 var frameId = node.frameId() || SDK.ResourceTreeModel.fromTarget(this.target
()).mainFrame.id; |
| 741 var headers = this._styleSheetIdToHeader.valuesArray(); | 741 var headers = this._styleSheetIdToHeader.valuesArray(); |
| 742 for (var i = 0; i < headers.length; ++i) { | 742 for (var i = 0; i < headers.length; ++i) { |
| 743 var styleSheetHeader = headers[i]; | 743 var styleSheetHeader = headers[i]; |
| 744 if (styleSheetHeader.frameId === frameId && styleSheetHeader.isViaInspecto
r()) { | 744 if (styleSheetHeader.frameId === frameId && styleSheetHeader.isViaInspecto
r()) { |
| 745 userCallback(styleSheetHeader); | 745 userCallback(styleSheetHeader); |
| 746 return; | 746 return; |
| 747 } | 747 } |
| 748 } | 748 } |
| 749 | 749 |
| 750 /** | 750 /** |
| 751 * @param {?Protocol.Error} error | 751 * @param {?Protocol.Error} error |
| 752 * @param {?Protocol.CSS.StyleSheetId} styleSheetId | 752 * @param {?Protocol.CSS.StyleSheetId} styleSheetId |
| 753 * @return {?WebInspector.CSSStyleSheetHeader} | 753 * @return {?SDK.CSSStyleSheetHeader} |
| 754 * @this {WebInspector.CSSModel} | 754 * @this {SDK.CSSModel} |
| 755 */ | 755 */ |
| 756 function innerCallback(error, styleSheetId) { | 756 function innerCallback(error, styleSheetId) { |
| 757 return !error && styleSheetId ? this._styleSheetIdToHeader.get(styleSheetI
d) || null : null; | 757 return !error && styleSheetId ? this._styleSheetIdToHeader.get(styleSheetI
d) || null : null; |
| 758 } | 758 } |
| 759 | 759 |
| 760 this._agent.createStyleSheet(frameId, innerCallback.bind(this)).catchExcepti
on(null).then(userCallback); | 760 this._agent.createStyleSheet(frameId, innerCallback.bind(this)).catchExcepti
on(null).then(userCallback); |
| 761 } | 761 } |
| 762 | 762 |
| 763 mediaQueryResultChanged() { | 763 mediaQueryResultChanged() { |
| 764 this.dispatchEventToListeners(WebInspector.CSSModel.Events.MediaQueryResultC
hanged); | 764 this.dispatchEventToListeners(SDK.CSSModel.Events.MediaQueryResultChanged); |
| 765 } | 765 } |
| 766 | 766 |
| 767 fontsUpdated() { | 767 fontsUpdated() { |
| 768 this.dispatchEventToListeners(WebInspector.CSSModel.Events.FontsUpdated); | 768 this.dispatchEventToListeners(SDK.CSSModel.Events.FontsUpdated); |
| 769 } | 769 } |
| 770 | 770 |
| 771 /** | 771 /** |
| 772 * @param {!Protocol.CSS.StyleSheetId} id | 772 * @param {!Protocol.CSS.StyleSheetId} id |
| 773 * @return {?WebInspector.CSSStyleSheetHeader} | 773 * @return {?SDK.CSSStyleSheetHeader} |
| 774 */ | 774 */ |
| 775 styleSheetHeaderForId(id) { | 775 styleSheetHeaderForId(id) { |
| 776 return this._styleSheetIdToHeader.get(id) || null; | 776 return this._styleSheetIdToHeader.get(id) || null; |
| 777 } | 777 } |
| 778 | 778 |
| 779 /** | 779 /** |
| 780 * @return {!Array.<!WebInspector.CSSStyleSheetHeader>} | 780 * @return {!Array.<!SDK.CSSStyleSheetHeader>} |
| 781 */ | 781 */ |
| 782 styleSheetHeaders() { | 782 styleSheetHeaders() { |
| 783 return this._styleSheetIdToHeader.valuesArray(); | 783 return this._styleSheetIdToHeader.valuesArray(); |
| 784 } | 784 } |
| 785 | 785 |
| 786 /** | 786 /** |
| 787 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | 787 * @param {!Protocol.CSS.StyleSheetId} styleSheetId |
| 788 * @param {!WebInspector.CSSModel.Edit=} edit | 788 * @param {!SDK.CSSModel.Edit=} edit |
| 789 */ | 789 */ |
| 790 _fireStyleSheetChanged(styleSheetId, edit) { | 790 _fireStyleSheetChanged(styleSheetId, edit) { |
| 791 this.dispatchEventToListeners( | 791 this.dispatchEventToListeners( |
| 792 WebInspector.CSSModel.Events.StyleSheetChanged, {styleSheetId: styleShee
tId, edit: edit}); | 792 SDK.CSSModel.Events.StyleSheetChanged, {styleSheetId: styleSheetId, edit
: edit}); |
| 793 } | 793 } |
| 794 | 794 |
| 795 /** | 795 /** |
| 796 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | 796 * @param {!Protocol.CSS.StyleSheetId} styleSheetId |
| 797 * @return {!Promise<string>} | 797 * @return {!Promise<string>} |
| 798 */ | 798 */ |
| 799 _ensureOriginalStyleSheetText(styleSheetId) { | 799 _ensureOriginalStyleSheetText(styleSheetId) { |
| 800 var header = this.styleSheetHeaderForId(styleSheetId); | 800 var header = this.styleSheetHeaderForId(styleSheetId); |
| 801 if (!header) | 801 if (!header) |
| 802 return Promise.resolve(''); | 802 return Promise.resolve(''); |
| 803 var promise = this._originalStyleSheetText.get(header); | 803 var promise = this._originalStyleSheetText.get(header); |
| 804 if (!promise) { | 804 if (!promise) { |
| 805 promise = this.getStyleSheetText(header.id); | 805 promise = this.getStyleSheetText(header.id); |
| 806 this._originalStyleSheetText.set(header, promise); | 806 this._originalStyleSheetText.set(header, promise); |
| 807 this._originalContentRequestedForTest(header); | 807 this._originalContentRequestedForTest(header); |
| 808 } | 808 } |
| 809 return promise; | 809 return promise; |
| 810 } | 810 } |
| 811 | 811 |
| 812 /** | 812 /** |
| 813 * @param {!WebInspector.CSSStyleSheetHeader} header | 813 * @param {!SDK.CSSStyleSheetHeader} header |
| 814 */ | 814 */ |
| 815 _originalContentRequestedForTest(header) { | 815 _originalContentRequestedForTest(header) { |
| 816 } | 816 } |
| 817 | 817 |
| 818 /** | 818 /** |
| 819 * @param {!WebInspector.CSSStyleSheetHeader} header | 819 * @param {!SDK.CSSStyleSheetHeader} header |
| 820 * @return {!Promise<string>} | 820 * @return {!Promise<string>} |
| 821 */ | 821 */ |
| 822 originalStyleSheetText(header) { | 822 originalStyleSheetText(header) { |
| 823 return this._ensureOriginalStyleSheetText(header.id); | 823 return this._ensureOriginalStyleSheetText(header.id); |
| 824 } | 824 } |
| 825 | 825 |
| 826 /** | 826 /** |
| 827 * @param {!Protocol.CSS.CSSStyleSheetHeader} header | 827 * @param {!Protocol.CSS.CSSStyleSheetHeader} header |
| 828 */ | 828 */ |
| 829 _styleSheetAdded(header) { | 829 _styleSheetAdded(header) { |
| 830 console.assert(!this._styleSheetIdToHeader.get(header.styleSheetId)); | 830 console.assert(!this._styleSheetIdToHeader.get(header.styleSheetId)); |
| 831 var styleSheetHeader = new WebInspector.CSSStyleSheetHeader(this, header); | 831 var styleSheetHeader = new SDK.CSSStyleSheetHeader(this, header); |
| 832 this._styleSheetIdToHeader.set(header.styleSheetId, styleSheetHeader); | 832 this._styleSheetIdToHeader.set(header.styleSheetId, styleSheetHeader); |
| 833 var url = styleSheetHeader.resourceURL(); | 833 var url = styleSheetHeader.resourceURL(); |
| 834 if (!this._styleSheetIdsForURL.get(url)) | 834 if (!this._styleSheetIdsForURL.get(url)) |
| 835 this._styleSheetIdsForURL.set(url, {}); | 835 this._styleSheetIdsForURL.set(url, {}); |
| 836 var frameIdToStyleSheetIds = this._styleSheetIdsForURL.get(url); | 836 var frameIdToStyleSheetIds = this._styleSheetIdsForURL.get(url); |
| 837 var styleSheetIds = frameIdToStyleSheetIds[styleSheetHeader.frameId]; | 837 var styleSheetIds = frameIdToStyleSheetIds[styleSheetHeader.frameId]; |
| 838 if (!styleSheetIds) { | 838 if (!styleSheetIds) { |
| 839 styleSheetIds = []; | 839 styleSheetIds = []; |
| 840 frameIdToStyleSheetIds[styleSheetHeader.frameId] = styleSheetIds; | 840 frameIdToStyleSheetIds[styleSheetHeader.frameId] = styleSheetIds; |
| 841 } | 841 } |
| 842 styleSheetIds.push(styleSheetHeader.id); | 842 styleSheetIds.push(styleSheetHeader.id); |
| 843 this._attachSourceMap(styleSheetHeader); | 843 this._attachSourceMap(styleSheetHeader); |
| 844 this.dispatchEventToListeners(WebInspector.CSSModel.Events.StyleSheetAdded,
styleSheetHeader); | 844 this.dispatchEventToListeners(SDK.CSSModel.Events.StyleSheetAdded, styleShee
tHeader); |
| 845 } | 845 } |
| 846 | 846 |
| 847 /** | 847 /** |
| 848 * @param {!Protocol.CSS.StyleSheetId} id | 848 * @param {!Protocol.CSS.StyleSheetId} id |
| 849 */ | 849 */ |
| 850 _styleSheetRemoved(id) { | 850 _styleSheetRemoved(id) { |
| 851 var header = this._styleSheetIdToHeader.get(id); | 851 var header = this._styleSheetIdToHeader.get(id); |
| 852 console.assert(header); | 852 console.assert(header); |
| 853 if (!header) | 853 if (!header) |
| 854 return; | 854 return; |
| 855 this._styleSheetIdToHeader.remove(id); | 855 this._styleSheetIdToHeader.remove(id); |
| 856 var url = header.resourceURL(); | 856 var url = header.resourceURL(); |
| 857 var frameIdToStyleSheetIds = /** @type {!Object.<!Protocol.Page.FrameId, !Ar
ray.<!Protocol.CSS.StyleSheetId>>} */ ( | 857 var frameIdToStyleSheetIds = /** @type {!Object.<!Protocol.Page.FrameId, !Ar
ray.<!Protocol.CSS.StyleSheetId>>} */ ( |
| 858 this._styleSheetIdsForURL.get(url)); | 858 this._styleSheetIdsForURL.get(url)); |
| 859 console.assert(frameIdToStyleSheetIds, 'No frameId to styleSheetId map is av
ailable for given style sheet URL.'); | 859 console.assert(frameIdToStyleSheetIds, 'No frameId to styleSheetId map is av
ailable for given style sheet URL.'); |
| 860 frameIdToStyleSheetIds[header.frameId].remove(id); | 860 frameIdToStyleSheetIds[header.frameId].remove(id); |
| 861 if (!frameIdToStyleSheetIds[header.frameId].length) { | 861 if (!frameIdToStyleSheetIds[header.frameId].length) { |
| 862 delete frameIdToStyleSheetIds[header.frameId]; | 862 delete frameIdToStyleSheetIds[header.frameId]; |
| 863 if (!Object.keys(frameIdToStyleSheetIds).length) | 863 if (!Object.keys(frameIdToStyleSheetIds).length) |
| 864 this._styleSheetIdsForURL.remove(url); | 864 this._styleSheetIdsForURL.remove(url); |
| 865 } | 865 } |
| 866 this._originalStyleSheetText.remove(header); | 866 this._originalStyleSheetText.remove(header); |
| 867 this._detachSourceMap(header); | 867 this._detachSourceMap(header); |
| 868 this.dispatchEventToListeners(WebInspector.CSSModel.Events.StyleSheetRemoved
, header); | 868 this.dispatchEventToListeners(SDK.CSSModel.Events.StyleSheetRemoved, header)
; |
| 869 } | 869 } |
| 870 | 870 |
| 871 /** | 871 /** |
| 872 * @param {string} url | 872 * @param {string} url |
| 873 * @return {!Array.<!Protocol.CSS.StyleSheetId>} | 873 * @return {!Array.<!Protocol.CSS.StyleSheetId>} |
| 874 */ | 874 */ |
| 875 styleSheetIdsForURL(url) { | 875 styleSheetIdsForURL(url) { |
| 876 var frameIdToStyleSheetIds = this._styleSheetIdsForURL.get(url); | 876 var frameIdToStyleSheetIds = this._styleSheetIdsForURL.get(url); |
| 877 if (!frameIdToStyleSheetIds) | 877 if (!frameIdToStyleSheetIds) |
| 878 return []; | 878 return []; |
| 879 | 879 |
| 880 var result = []; | 880 var result = []; |
| 881 for (var frameId in frameIdToStyleSheetIds) | 881 for (var frameId in frameIdToStyleSheetIds) |
| 882 result = result.concat(frameIdToStyleSheetIds[frameId]); | 882 result = result.concat(frameIdToStyleSheetIds[frameId]); |
| 883 return result; | 883 return result; |
| 884 } | 884 } |
| 885 | 885 |
| 886 /** | 886 /** |
| 887 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | 887 * @param {!Protocol.CSS.StyleSheetId} styleSheetId |
| 888 * @param {string} newText | 888 * @param {string} newText |
| 889 * @param {boolean} majorChange | 889 * @param {boolean} majorChange |
| 890 * @return {!Promise.<?Protocol.Error>} | 890 * @return {!Promise.<?Protocol.Error>} |
| 891 */ | 891 */ |
| 892 setStyleSheetText(styleSheetId, newText, majorChange) { | 892 setStyleSheetText(styleSheetId, newText, majorChange) { |
| 893 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (this._styleSh
eetIdToHeader.get(styleSheetId)); | 893 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (this._styleSheetIdToHe
ader.get(styleSheetId)); |
| 894 console.assert(header); | 894 console.assert(header); |
| 895 newText = WebInspector.CSSModel.trimSourceURL(newText); | 895 newText = SDK.CSSModel.trimSourceURL(newText); |
| 896 if (header.hasSourceURL) | 896 if (header.hasSourceURL) |
| 897 newText += '\n/*# sourceURL=' + header.sourceURL + ' */'; | 897 newText += '\n/*# sourceURL=' + header.sourceURL + ' */'; |
| 898 return this._ensureOriginalStyleSheetText(styleSheetId) | 898 return this._ensureOriginalStyleSheetText(styleSheetId) |
| 899 .then(() => this._agent.setStyleSheetText(header.id, newText, callback.b
ind(this))); | 899 .then(() => this._agent.setStyleSheetText(header.id, newText, callback.b
ind(this))); |
| 900 | 900 |
| 901 /** | 901 /** |
| 902 * @param {?Protocol.Error} error | 902 * @param {?Protocol.Error} error |
| 903 * @param {string=} sourceMapURL | 903 * @param {string=} sourceMapURL |
| 904 * @return {?Protocol.Error} | 904 * @return {?Protocol.Error} |
| 905 * @this {WebInspector.CSSModel} | 905 * @this {SDK.CSSModel} |
| 906 */ | 906 */ |
| 907 function callback(error, sourceMapURL) { | 907 function callback(error, sourceMapURL) { |
| 908 this._detachSourceMap(header); | 908 this._detachSourceMap(header); |
| 909 header.setSourceMapURL(sourceMapURL); | 909 header.setSourceMapURL(sourceMapURL); |
| 910 this._attachSourceMap(header); | 910 this._attachSourceMap(header); |
| 911 if (error) | 911 if (error) |
| 912 return error; | 912 return error; |
| 913 if (majorChange) | 913 if (majorChange) |
| 914 this._domModel.markUndoableState(); | 914 this._domModel.markUndoableState(); |
| 915 this._fireStyleSheetChanged(styleSheetId); | 915 this._fireStyleSheetChanged(styleSheetId); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 926 * @param {?Protocol.Error} error | 926 * @param {?Protocol.Error} error |
| 927 * @param {?string} text | 927 * @param {?string} text |
| 928 * @return {string} | 928 * @return {string} |
| 929 */ | 929 */ |
| 930 function textCallback(error, text) { | 930 function textCallback(error, text) { |
| 931 if (error || text === null) { | 931 if (error || text === null) { |
| 932 console.error('Failed to get text for stylesheet ' + styleSheetId + ': '
+ error); | 932 console.error('Failed to get text for stylesheet ' + styleSheetId + ': '
+ error); |
| 933 text = ''; | 933 text = ''; |
| 934 // Fall through. | 934 // Fall through. |
| 935 } | 935 } |
| 936 return WebInspector.CSSModel.trimSourceURL(text); | 936 return SDK.CSSModel.trimSourceURL(text); |
| 937 } | 937 } |
| 938 | 938 |
| 939 return this._agent.getStyleSheetText(styleSheetId, textCallback).catchExcept
ion(/** @type {string} */ ('')); | 939 return this._agent.getStyleSheetText(styleSheetId, textCallback).catchExcept
ion(/** @type {string} */ ('')); |
| 940 } | 940 } |
| 941 | 941 |
| 942 /** | 942 /** |
| 943 * @param {!WebInspector.Event} event | 943 * @param {!Common.Event} event |
| 944 */ | 944 */ |
| 945 _mainFrameNavigated(event) { | 945 _mainFrameNavigated(event) { |
| 946 if (event.data.target() !== this.target()) | 946 if (event.data.target() !== this.target()) |
| 947 return; | 947 return; |
| 948 this._resetStyleSheets(); | 948 this._resetStyleSheets(); |
| 949 } | 949 } |
| 950 | 950 |
| 951 _resetStyleSheets() { | 951 _resetStyleSheets() { |
| 952 var headers = this._styleSheetIdToHeader.valuesArray(); | 952 var headers = this._styleSheetIdToHeader.valuesArray(); |
| 953 this._styleSheetIdsForURL.clear(); | 953 this._styleSheetIdsForURL.clear(); |
| 954 this._styleSheetIdToHeader.clear(); | 954 this._styleSheetIdToHeader.clear(); |
| 955 for (var i = 0; i < headers.length; ++i) { | 955 for (var i = 0; i < headers.length; ++i) { |
| 956 this._detachSourceMap(headers[i]); | 956 this._detachSourceMap(headers[i]); |
| 957 this.dispatchEventToListeners(WebInspector.CSSModel.Events.StyleSheetRemov
ed, headers[i]); | 957 this.dispatchEventToListeners(SDK.CSSModel.Events.StyleSheetRemoved, heade
rs[i]); |
| 958 } | 958 } |
| 959 this._sourceMapByURL.clear(); | 959 this._sourceMapByURL.clear(); |
| 960 this._sourceMapURLToHeaders.clear(); | 960 this._sourceMapURLToHeaders.clear(); |
| 961 this._sourceMapLoadingStyleSheetsIds.clear(); | 961 this._sourceMapLoadingStyleSheetsIds.clear(); |
| 962 } | 962 } |
| 963 | 963 |
| 964 /** | 964 /** |
| 965 * @override | 965 * @override |
| 966 * @return {!Promise} | 966 * @return {!Promise} |
| 967 */ | 967 */ |
| 968 suspendModel() { | 968 suspendModel() { |
| 969 this._isEnabled = false; | 969 this._isEnabled = false; |
| 970 return this._agent.disable().then(this._resetStyleSheets.bind(this)); | 970 return this._agent.disable().then(this._resetStyleSheets.bind(this)); |
| 971 } | 971 } |
| 972 | 972 |
| 973 /** | 973 /** |
| 974 * @override | 974 * @override |
| 975 * @return {!Promise} | 975 * @return {!Promise} |
| 976 */ | 976 */ |
| 977 resumeModel() { | 977 resumeModel() { |
| 978 return this._agent.enable().then(this._wasEnabled.bind(this)); | 978 return this._agent.enable().then(this._wasEnabled.bind(this)); |
| 979 } | 979 } |
| 980 | 980 |
| 981 /** | 981 /** |
| 982 * @param {!Protocol.CSS.StyleSheetId} id | 982 * @param {!Protocol.CSS.StyleSheetId} id |
| 983 * @param {!Protocol.CSS.SourceRange} range | 983 * @param {!Protocol.CSS.SourceRange} range |
| 984 */ | 984 */ |
| 985 _layoutEditorChange(id, range) { | 985 _layoutEditorChange(id, range) { |
| 986 this.dispatchEventToListeners(WebInspector.CSSModel.Events.LayoutEditorChang
e, {id: id, range: range}); | 986 this.dispatchEventToListeners(SDK.CSSModel.Events.LayoutEditorChange, {id: i
d, range: range}); |
| 987 } | 987 } |
| 988 | 988 |
| 989 /** | 989 /** |
| 990 * @param {number} nodeId | 990 * @param {number} nodeId |
| 991 * @param {string} name | 991 * @param {string} name |
| 992 * @param {string} value | 992 * @param {string} value |
| 993 */ | 993 */ |
| 994 setEffectivePropertyValueForNode(nodeId, name, value) { | 994 setEffectivePropertyValueForNode(nodeId, name, value) { |
| 995 this._agent.setEffectivePropertyValueForNode(nodeId, name, value); | 995 this._agent.setEffectivePropertyValueForNode(nodeId, name, value); |
| 996 } | 996 } |
| 997 | 997 |
| 998 /** | 998 /** |
| 999 * @param {!WebInspector.DOMNode} node | 999 * @param {!SDK.DOMNode} node |
| 1000 * @return {!Promise.<?WebInspector.CSSMatchedStyles>} | 1000 * @return {!Promise.<?SDK.CSSMatchedStyles>} |
| 1001 */ | 1001 */ |
| 1002 cachedMatchedCascadeForNode(node) { | 1002 cachedMatchedCascadeForNode(node) { |
| 1003 if (this._cachedMatchedCascadeNode !== node) | 1003 if (this._cachedMatchedCascadeNode !== node) |
| 1004 this.discardCachedMatchedCascade(); | 1004 this.discardCachedMatchedCascade(); |
| 1005 this._cachedMatchedCascadeNode = node; | 1005 this._cachedMatchedCascadeNode = node; |
| 1006 if (!this._cachedMatchedCascadePromise) | 1006 if (!this._cachedMatchedCascadePromise) |
| 1007 this._cachedMatchedCascadePromise = this.matchedStylesPromise(node.id); | 1007 this._cachedMatchedCascadePromise = this.matchedStylesPromise(node.id); |
| 1008 return this._cachedMatchedCascadePromise; | 1008 return this._cachedMatchedCascadePromise; |
| 1009 } | 1009 } |
| 1010 | 1010 |
| 1011 discardCachedMatchedCascade() { | 1011 discardCachedMatchedCascade() { |
| 1012 delete this._cachedMatchedCascadeNode; | 1012 delete this._cachedMatchedCascadeNode; |
| 1013 delete this._cachedMatchedCascadePromise; | 1013 delete this._cachedMatchedCascadePromise; |
| 1014 } | 1014 } |
| 1015 }; | 1015 }; |
| 1016 | 1016 |
| 1017 /** @typedef {!{range: !Protocol.CSS.SourceRange, styleSheetId: !Protocol.CSS.St
yleSheetId, wasUsed: boolean}} */ | 1017 /** @typedef {!{range: !Protocol.CSS.SourceRange, styleSheetId: !Protocol.CSS.St
yleSheetId, wasUsed: boolean}} */ |
| 1018 WebInspector.CSSModel.RuleUsage; | 1018 SDK.CSSModel.RuleUsage; |
| 1019 | 1019 |
| 1020 /** @enum {symbol} */ | 1020 /** @enum {symbol} */ |
| 1021 WebInspector.CSSModel.Events = { | 1021 SDK.CSSModel.Events = { |
| 1022 LayoutEditorChange: Symbol('LayoutEditorChange'), | 1022 LayoutEditorChange: Symbol('LayoutEditorChange'), |
| 1023 FontsUpdated: Symbol('FontsUpdated'), | 1023 FontsUpdated: Symbol('FontsUpdated'), |
| 1024 MediaQueryResultChanged: Symbol('MediaQueryResultChanged'), | 1024 MediaQueryResultChanged: Symbol('MediaQueryResultChanged'), |
| 1025 ModelWasEnabled: Symbol('ModelWasEnabled'), | 1025 ModelWasEnabled: Symbol('ModelWasEnabled'), |
| 1026 PseudoStateForced: Symbol('PseudoStateForced'), | 1026 PseudoStateForced: Symbol('PseudoStateForced'), |
| 1027 StyleSheetAdded: Symbol('StyleSheetAdded'), | 1027 StyleSheetAdded: Symbol('StyleSheetAdded'), |
| 1028 StyleSheetChanged: Symbol('StyleSheetChanged'), | 1028 StyleSheetChanged: Symbol('StyleSheetChanged'), |
| 1029 StyleSheetRemoved: Symbol('StyleSheetRemoved'), | 1029 StyleSheetRemoved: Symbol('StyleSheetRemoved'), |
| 1030 SourceMapAttached: Symbol('SourceMapAttached'), | 1030 SourceMapAttached: Symbol('SourceMapAttached'), |
| 1031 SourceMapDetached: Symbol('SourceMapDetached'), | 1031 SourceMapDetached: Symbol('SourceMapDetached'), |
| 1032 SourceMapChanged: Symbol('SourceMapChanged') | 1032 SourceMapChanged: Symbol('SourceMapChanged') |
| 1033 }; | 1033 }; |
| 1034 | 1034 |
| 1035 WebInspector.CSSModel.MediaTypes = | 1035 SDK.CSSModel.MediaTypes = |
| 1036 ['all', 'braille', 'embossed', 'handheld', 'print', 'projection', 'screen',
'speech', 'tty', 'tv']; | 1036 ['all', 'braille', 'embossed', 'handheld', 'print', 'projection', 'screen',
'speech', 'tty', 'tv']; |
| 1037 | 1037 |
| 1038 WebInspector.CSSModel.PseudoStateMarker = 'pseudo-state-marker'; | 1038 SDK.CSSModel.PseudoStateMarker = 'pseudo-state-marker'; |
| 1039 | 1039 |
| 1040 /** | 1040 /** |
| 1041 * @unrestricted | 1041 * @unrestricted |
| 1042 */ | 1042 */ |
| 1043 WebInspector.CSSModel.Edit = class { | 1043 SDK.CSSModel.Edit = class { |
| 1044 /** | 1044 /** |
| 1045 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | 1045 * @param {!Protocol.CSS.StyleSheetId} styleSheetId |
| 1046 * @param {!WebInspector.TextRange} oldRange | 1046 * @param {!Common.TextRange} oldRange |
| 1047 * @param {string} newText | 1047 * @param {string} newText |
| 1048 * @param {?Object} payload | 1048 * @param {?Object} payload |
| 1049 */ | 1049 */ |
| 1050 constructor(styleSheetId, oldRange, newText, payload) { | 1050 constructor(styleSheetId, oldRange, newText, payload) { |
| 1051 this.styleSheetId = styleSheetId; | 1051 this.styleSheetId = styleSheetId; |
| 1052 this.oldRange = oldRange; | 1052 this.oldRange = oldRange; |
| 1053 this.newRange = WebInspector.TextRange.fromEdit(oldRange, newText); | 1053 this.newRange = Common.TextRange.fromEdit(oldRange, newText); |
| 1054 this.payload = payload; | 1054 this.payload = payload; |
| 1055 } | 1055 } |
| 1056 }; | 1056 }; |
| 1057 | 1057 |
| 1058 | 1058 |
| 1059 /** | 1059 /** |
| 1060 * @unrestricted | 1060 * @unrestricted |
| 1061 */ | 1061 */ |
| 1062 WebInspector.CSSLocation = class extends WebInspector.SDKObject { | 1062 SDK.CSSLocation = class extends SDK.SDKObject { |
| 1063 /** | 1063 /** |
| 1064 * @param {!WebInspector.CSSStyleSheetHeader} header | 1064 * @param {!SDK.CSSStyleSheetHeader} header |
| 1065 * @param {number} lineNumber | 1065 * @param {number} lineNumber |
| 1066 * @param {number=} columnNumber | 1066 * @param {number=} columnNumber |
| 1067 */ | 1067 */ |
| 1068 constructor(header, lineNumber, columnNumber) { | 1068 constructor(header, lineNumber, columnNumber) { |
| 1069 super(header.target()); | 1069 super(header.target()); |
| 1070 this._header = header; | 1070 this._header = header; |
| 1071 this.styleSheetId = header.id; | 1071 this.styleSheetId = header.id; |
| 1072 this.url = header.resourceURL(); | 1072 this.url = header.resourceURL(); |
| 1073 this.lineNumber = lineNumber; | 1073 this.lineNumber = lineNumber; |
| 1074 this.columnNumber = columnNumber || 0; | 1074 this.columnNumber = columnNumber || 0; |
| 1075 } | 1075 } |
| 1076 | 1076 |
| 1077 /** | 1077 /** |
| 1078 * @return {!WebInspector.CSSModel} | 1078 * @return {!SDK.CSSModel} |
| 1079 */ | 1079 */ |
| 1080 cssModel() { | 1080 cssModel() { |
| 1081 return this._header.cssModel(); | 1081 return this._header.cssModel(); |
| 1082 } | 1082 } |
| 1083 | 1083 |
| 1084 /** | 1084 /** |
| 1085 * @return {!WebInspector.CSSStyleSheetHeader} | 1085 * @return {!SDK.CSSStyleSheetHeader} |
| 1086 */ | 1086 */ |
| 1087 header() { | 1087 header() { |
| 1088 return this._header; | 1088 return this._header; |
| 1089 } | 1089 } |
| 1090 }; | 1090 }; |
| 1091 | 1091 |
| 1092 /** | 1092 /** |
| 1093 * @implements {Protocol.CSSDispatcher} | 1093 * @implements {Protocol.CSSDispatcher} |
| 1094 * @unrestricted | 1094 * @unrestricted |
| 1095 */ | 1095 */ |
| 1096 WebInspector.CSSDispatcher = class { | 1096 SDK.CSSDispatcher = class { |
| 1097 /** | 1097 /** |
| 1098 * @param {!WebInspector.CSSModel} cssModel | 1098 * @param {!SDK.CSSModel} cssModel |
| 1099 */ | 1099 */ |
| 1100 constructor(cssModel) { | 1100 constructor(cssModel) { |
| 1101 this._cssModel = cssModel; | 1101 this._cssModel = cssModel; |
| 1102 } | 1102 } |
| 1103 | 1103 |
| 1104 /** | 1104 /** |
| 1105 * @override | 1105 * @override |
| 1106 */ | 1106 */ |
| 1107 mediaQueryResultChanged() { | 1107 mediaQueryResultChanged() { |
| 1108 this._cssModel.mediaQueryResultChanged(); | 1108 this._cssModel.mediaQueryResultChanged(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 * @param {!Protocol.CSS.SourceRange} range | 1145 * @param {!Protocol.CSS.SourceRange} range |
| 1146 */ | 1146 */ |
| 1147 layoutEditorChange(id, range) { | 1147 layoutEditorChange(id, range) { |
| 1148 this._cssModel._layoutEditorChange(id, range); | 1148 this._cssModel._layoutEditorChange(id, range); |
| 1149 } | 1149 } |
| 1150 }; | 1150 }; |
| 1151 | 1151 |
| 1152 /** | 1152 /** |
| 1153 * @unrestricted | 1153 * @unrestricted |
| 1154 */ | 1154 */ |
| 1155 WebInspector.CSSModel.ComputedStyleLoader = class { | 1155 SDK.CSSModel.ComputedStyleLoader = class { |
| 1156 /** | 1156 /** |
| 1157 * @param {!WebInspector.CSSModel} cssModel | 1157 * @param {!SDK.CSSModel} cssModel |
| 1158 */ | 1158 */ |
| 1159 constructor(cssModel) { | 1159 constructor(cssModel) { |
| 1160 this._cssModel = cssModel; | 1160 this._cssModel = cssModel; |
| 1161 /** @type {!Map<!Protocol.DOM.NodeId, !Promise<?Map<string, string>>>} */ | 1161 /** @type {!Map<!Protocol.DOM.NodeId, !Promise<?Map<string, string>>>} */ |
| 1162 this._nodeIdToPromise = new Map(); | 1162 this._nodeIdToPromise = new Map(); |
| 1163 } | 1163 } |
| 1164 | 1164 |
| 1165 /** | 1165 /** |
| 1166 * @param {!Protocol.DOM.NodeId} nodeId | 1166 * @param {!Protocol.DOM.NodeId} nodeId |
| 1167 * @return {!Promise<?Map<string, string>>} | 1167 * @return {!Promise<?Map<string, string>>} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1183 return null; | 1183 return null; |
| 1184 var result = new Map(); | 1184 var result = new Map(); |
| 1185 for (var property of computedPayload) | 1185 for (var property of computedPayload) |
| 1186 result.set(property.name, property.value); | 1186 result.set(property.name, property.value); |
| 1187 return result; | 1187 return result; |
| 1188 } | 1188 } |
| 1189 | 1189 |
| 1190 /** | 1190 /** |
| 1191 * @param {?Map.<string, string>} computedStyle | 1191 * @param {?Map.<string, string>} computedStyle |
| 1192 * @return {?Map.<string, string>} | 1192 * @return {?Map.<string, string>} |
| 1193 * @this {WebInspector.CSSModel.ComputedStyleLoader} | 1193 * @this {SDK.CSSModel.ComputedStyleLoader} |
| 1194 */ | 1194 */ |
| 1195 function cleanUp(computedStyle) { | 1195 function cleanUp(computedStyle) { |
| 1196 this._nodeIdToPromise.delete(nodeId); | 1196 this._nodeIdToPromise.delete(nodeId); |
| 1197 return computedStyle; | 1197 return computedStyle; |
| 1198 } | 1198 } |
| 1199 } | 1199 } |
| 1200 }; | 1200 }; |
| 1201 | 1201 |
| 1202 | 1202 |
| 1203 /** | 1203 /** |
| 1204 * @unrestricted | 1204 * @unrestricted |
| 1205 */ | 1205 */ |
| 1206 WebInspector.CSSModel.InlineStyleResult = class { | 1206 SDK.CSSModel.InlineStyleResult = class { |
| 1207 /** | 1207 /** |
| 1208 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle | 1208 * @param {?SDK.CSSStyleDeclaration} inlineStyle |
| 1209 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle | 1209 * @param {?SDK.CSSStyleDeclaration} attributesStyle |
| 1210 */ | 1210 */ |
| 1211 constructor(inlineStyle, attributesStyle) { | 1211 constructor(inlineStyle, attributesStyle) { |
| 1212 this.inlineStyle = inlineStyle; | 1212 this.inlineStyle = inlineStyle; |
| 1213 this.attributesStyle = attributesStyle; | 1213 this.attributesStyle = attributesStyle; |
| 1214 } | 1214 } |
| 1215 }; | 1215 }; |
| OLD | NEW |