| 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 27 matching lines...) Expand all Loading... |
| 38 WebInspector.SDKModel.call(this, WebInspector.CSSStyleModel, target); | 38 WebInspector.SDKModel.call(this, WebInspector.CSSStyleModel, target); |
| 39 this._domModel = WebInspector.DOMModel.fromTarget(target); | 39 this._domModel = WebInspector.DOMModel.fromTarget(target); |
| 40 this._agent = target.cssAgent(); | 40 this._agent = target.cssAgent(); |
| 41 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event
s.SuspendStateChanged, this._suspendStateChanged, this); | 41 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event
s.SuspendStateChanged, this._suspendStateChanged, this); |
| 42 this._pendingCommandsMajorState = []; | 42 this._pendingCommandsMajorState = []; |
| 43 this._styleLoader = new WebInspector.CSSStyleModel.ComputedStyleLoader(this)
; | 43 this._styleLoader = new WebInspector.CSSStyleModel.ComputedStyleLoader(this)
; |
| 44 this._domModel.addEventListener(WebInspector.DOMModel.Events.UndoRedoRequest
ed, this._undoRedoRequested, this); | 44 this._domModel.addEventListener(WebInspector.DOMModel.Events.UndoRedoRequest
ed, this._undoRedoRequested, this); |
| 45 this._domModel.addEventListener(WebInspector.DOMModel.Events.UndoRedoComplet
ed, this._undoRedoCompleted, this); | 45 this._domModel.addEventListener(WebInspector.DOMModel.Events.UndoRedoComplet
ed, this._undoRedoCompleted, this); |
| 46 target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Eve
ntTypes.MainFrameNavigated, this._mainFrameNavigated, this); | 46 target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Eve
ntTypes.MainFrameNavigated, this._mainFrameNavigated, this); |
| 47 target.registerCSSDispatcher(new WebInspector.CSSDispatcher(this)); | 47 target.registerCSSDispatcher(new WebInspector.CSSDispatcher(this)); |
| 48 this._agent.enable(this._wasEnabled.bind(this)); | 48 this._agent.enable().then(this._wasEnabled.bind(this)); |
| 49 /** @type {!Map.<string, !WebInspector.CSSStyleSheetHeader>} */ | 49 /** @type {!Map.<string, !WebInspector.CSSStyleSheetHeader>} */ |
| 50 this._styleSheetIdToHeader = new Map(); | 50 this._styleSheetIdToHeader = new Map(); |
| 51 /** @type {!Map.<string, !Object.<!PageAgent.FrameId, !Array.<!CSSAgent.Styl
eSheetId>>>} */ | 51 /** @type {!Map.<string, !Object.<!PageAgent.FrameId, !Array.<!CSSAgent.Styl
eSheetId>>>} */ |
| 52 this._styleSheetIdsForURL = new Map(); | 52 this._styleSheetIdsForURL = new Map(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 WebInspector.CSSStyleModel.PseudoStatePropertyName = "pseudoState"; | 55 WebInspector.CSSStyleModel.PseudoStatePropertyName = "pseudoState"; |
| 56 | 56 |
| 57 /** | 57 /** |
| 58 * @param {!WebInspector.CSSStyleModel} cssModel | 58 * @param {!WebInspector.CSSStyleModel} cssModel |
| (...skipping 24 matching lines...) Expand all Loading... |
| 83 | 83 |
| 84 WebInspector.CSSStyleModel.prototype = { | 84 WebInspector.CSSStyleModel.prototype = { |
| 85 /** | 85 /** |
| 86 * @param {function(!Array.<!WebInspector.CSSMedia>)} userCallback | 86 * @param {function(!Array.<!WebInspector.CSSMedia>)} userCallback |
| 87 */ | 87 */ |
| 88 getMediaQueries: function(userCallback) | 88 getMediaQueries: function(userCallback) |
| 89 { | 89 { |
| 90 /** | 90 /** |
| 91 * @param {?Protocol.Error} error | 91 * @param {?Protocol.Error} error |
| 92 * @param {?Array.<!CSSAgent.CSSMedia>} payload | 92 * @param {?Array.<!CSSAgent.CSSMedia>} payload |
| 93 * @return {!Array.<!WebInspector.CSSMedia>} |
| 93 * @this {!WebInspector.CSSStyleModel} | 94 * @this {!WebInspector.CSSStyleModel} |
| 94 */ | 95 */ |
| 95 function callback(error, payload) | 96 function parsePayload(error, payload) |
| 96 { | 97 { |
| 97 var models = []; | 98 return !error && payload ? WebInspector.CSSMedia.parseMediaArrayPayl
oad(this, payload) : []; |
| 98 if (!error && payload) | |
| 99 models = WebInspector.CSSMedia.parseMediaArrayPayload(this, payl
oad); | |
| 100 userCallback(models); | |
| 101 } | 99 } |
| 102 this._agent.getMediaQueries(callback.bind(this)); | 100 |
| 101 this._agent.getMediaQueries(parsePayload.bind(this)) |
| 102 .catchException([]) |
| 103 .then(userCallback); |
| 103 }, | 104 }, |
| 104 | 105 |
| 105 /** | 106 /** |
| 106 * @return {boolean} | 107 * @return {boolean} |
| 107 */ | 108 */ |
| 108 isEnabled: function() | 109 isEnabled: function() |
| 109 { | 110 { |
| 110 return this._isEnabled; | 111 return this._isEnabled; |
| 111 }, | 112 }, |
| 112 | 113 |
| 113 _wasEnabled: function() | 114 /** |
| 115 * @param {?Protocol.Error} error |
| 116 */ |
| 117 _wasEnabled: function(error) |
| 114 { | 118 { |
| 119 if (error) { |
| 120 console.error("Failed to enabled CSS agent: " + error); |
| 121 return; |
| 122 } |
| 115 this._isEnabled = true; | 123 this._isEnabled = true; |
| 116 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.ModelWas
Enabled); | 124 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.ModelWas
Enabled); |
| 117 }, | 125 }, |
| 118 | 126 |
| 119 /** | 127 /** |
| 120 * @param {!DOMAgent.NodeId} nodeId | 128 * @param {!DOMAgent.NodeId} nodeId |
| 121 * @param {boolean} excludePseudo | 129 * @param {boolean} excludePseudo |
| 122 * @param {boolean} excludeInherited | 130 * @param {boolean} excludeInherited |
| 131 * @return {!Promise.<?WebInspector.CSSStyleModel.MatchedStyleResult>} |
| 132 */ |
| 133 matchedStylesPromise: function(nodeId, excludePseudo, excludeInherited) |
| 134 { |
| 135 /** |
| 136 * @param {?Protocol.Error} error |
| 137 * @param {!Array.<!CSSAgent.RuleMatch>=} matchedPayload |
| 138 * @param {!Array.<!CSSAgent.PseudoIdMatches>=} pseudoPayload |
| 139 * @param {!Array.<!CSSAgent.InheritedStyleEntry>=} inheritedPayload |
| 140 * @return {?WebInspector.CSSStyleModel.MatchedStyleResult} |
| 141 * @this {WebInspector.CSSStyleModel} |
| 142 */ |
| 143 function callback(error, matchedPayload, pseudoPayload, inheritedPayload
) |
| 144 { |
| 145 if (error) |
| 146 return null; |
| 147 |
| 148 var matchedRules = WebInspector.CSSStyleModel.parseRuleMatchArrayPay
load(this, matchedPayload); |
| 149 |
| 150 var pseudoElements = []; |
| 151 if (pseudoPayload) { |
| 152 for (var i = 0; i < pseudoPayload.length; ++i) { |
| 153 var entryPayload = pseudoPayload[i]; |
| 154 pseudoElements.push(new WebInspector.CSSStyleModel.PseudoEle
mentMatches(entryPayload.pseudoId, WebInspector.CSSStyleModel.parseRuleMatchArra
yPayload(this, entryPayload.matches))); |
| 155 } |
| 156 } |
| 157 |
| 158 var inherited = []; |
| 159 if (inheritedPayload) { |
| 160 for (var i = 0; i < inheritedPayload.length; ++i) { |
| 161 var entryPayload = inheritedPayload[i]; |
| 162 var inlineStyle = entryPayload.inlineStyle ? WebInspector.CS
SStyleDeclaration.parsePayload(this, entryPayload.inlineStyle) : null; |
| 163 var matchedCSSRules = entryPayload.matchedCSSRules ? WebInsp
ector.CSSStyleModel.parseRuleMatchArrayPayload(this, entryPayload.matchedCSSRule
s) : null; |
| 164 inherited.push(new WebInspector.CSSStyleModel.InheritedMatch
es(inlineStyle, matchedCSSRules)); |
| 165 } |
| 166 } |
| 167 return new WebInspector.CSSStyleModel.MatchedStyleResult(matchedRule
s, inherited, pseudoElements); |
| 168 } |
| 169 |
| 170 return this._agent.getMatchedStylesForNode(nodeId, excludePseudo, exclud
eInherited, callback.bind(this)); |
| 171 }, |
| 172 |
| 173 /** |
| 174 * @param {!DOMAgent.NodeId} nodeId |
| 175 * @param {boolean} excludePseudo |
| 176 * @param {boolean} excludeInherited |
| 123 * @param {function(?WebInspector.CSSStyleModel.MatchedStyleResult)} userCal
lback | 177 * @param {function(?WebInspector.CSSStyleModel.MatchedStyleResult)} userCal
lback |
| 124 */ | 178 */ |
| 125 getMatchedStylesAsync: function(nodeId, excludePseudo, excludeInherited, use
rCallback) | 179 getMatchedStylesAsync: function(nodeId, excludePseudo, excludeInherited, use
rCallback) |
| 126 { | 180 { |
| 127 /** | 181 this.matchedStylesPromise(nodeId, excludePseudo, excludeInherited) |
| 128 * @param {?Protocol.Error} error | 182 .catchException(null) |
| 129 * @param {!Array.<!CSSAgent.RuleMatch>=} matchedPayload | 183 .then(userCallback); |
| 130 * @param {!Array.<!CSSAgent.PseudoIdMatches>=} pseudoPayload | |
| 131 * @param {!Array.<!CSSAgent.InheritedStyleEntry>=} inheritedPayload | |
| 132 * @this {WebInspector.CSSStyleModel} | |
| 133 */ | |
| 134 function callback(error, matchedPayload, pseudoPayload, inheritedPayload
) | |
| 135 { | |
| 136 if (error) { | |
| 137 if (userCallback) | |
| 138 userCallback(null); | |
| 139 return; | |
| 140 } | |
| 141 | |
| 142 // Due to CSSOM inconsistencies, backend might send us illegal data.
@see crbug.com/178410 | |
| 143 var result = null; | |
| 144 try { | |
| 145 var matchedRules = WebInspector.CSSStyleModel.parseRuleMatchArra
yPayload(this, matchedPayload); | |
| 146 | |
| 147 var pseudoElements = []; | |
| 148 if (pseudoPayload) { | |
| 149 for (var i = 0; i < pseudoPayload.length; ++i) { | |
| 150 var entryPayload = pseudoPayload[i]; | |
| 151 pseudoElements.push(new WebInspector.CSSStyleModel.Pseud
oElementMatches(entryPayload.pseudoId, WebInspector.CSSStyleModel.parseRuleMatch
ArrayPayload(this, entryPayload.matches))); | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 var inherited = []; | |
| 156 if (inheritedPayload) { | |
| 157 for (var i = 0; i < inheritedPayload.length; ++i) { | |
| 158 var entryPayload = inheritedPayload[i]; | |
| 159 var inlineStyle = entryPayload.inlineStyle ? WebInspecto
r.CSSStyleDeclaration.parsePayload(this, entryPayload.inlineStyle) : null; | |
| 160 var matchedCSSRules = entryPayload.matchedCSSRules ? Web
Inspector.CSSStyleModel.parseRuleMatchArrayPayload(this, entryPayload.matchedCSS
Rules) : null; | |
| 161 inherited.push(new WebInspector.CSSStyleModel.InheritedM
atches(inlineStyle, matchedCSSRules)); | |
| 162 } | |
| 163 } | |
| 164 result = new WebInspector.CSSStyleModel.MatchedStyleResult(match
edRules, inherited, pseudoElements); | |
| 165 } catch (e) { | |
| 166 console.error(e); | |
| 167 } | |
| 168 | |
| 169 if (userCallback) | |
| 170 userCallback(result); | |
| 171 } | |
| 172 | |
| 173 this._agent.getMatchedStylesForNode(nodeId, excludePseudo, excludeInheri
ted, callback.bind(this)); | |
| 174 }, | 184 }, |
| 175 | 185 |
| 176 /** | 186 /** |
| 177 * @param {!DOMAgent.NodeId} nodeId | 187 * @param {!DOMAgent.NodeId} nodeId |
| 178 * @param {function(?WebInspector.CSSStyleDeclaration)} userCallback | 188 * @param {function(?WebInspector.CSSStyleDeclaration)} userCallback |
| 179 */ | 189 */ |
| 180 getComputedStyleAsync: function(nodeId, userCallback) | 190 getComputedStyleAsync: function(nodeId, userCallback) |
| 181 { | 191 { |
| 182 this._styleLoader.getComputedStyle(nodeId, userCallback); | 192 this._styleLoader.getComputedStyle(nodeId, userCallback); |
| 183 }, | 193 }, |
| 184 | 194 |
| 185 /** | 195 /** |
| 186 * @param {number} nodeId | 196 * @param {number} nodeId |
| 187 * @param {function(?Array.<!CSSAgent.PlatformFontUsage>)} callback | 197 * @param {function(?Array.<!CSSAgent.PlatformFontUsage>)} callback |
| 188 */ | 198 */ |
| 189 getPlatformFontsForNode: function(nodeId, callback) | 199 getPlatformFontsForNode: function(nodeId, callback) |
| 190 { | 200 { |
| 201 /** |
| 202 * @param {?Protocol.Error} error |
| 203 * @param {?Array.<!CSSAgent.PlatformFontUsage>} fonts |
| 204 * @return {?Array.<!CSSAgent.PlatformFontUsage>} |
| 205 */ |
| 191 function platformFontsCallback(error, fonts) | 206 function platformFontsCallback(error, fonts) |
| 192 { | 207 { |
| 193 if (error) | 208 return !error && fonts ? fonts : null; |
| 194 callback(null); | |
| 195 else | |
| 196 callback(fonts); | |
| 197 } | 209 } |
| 198 this._agent.getPlatformFontsForNode(nodeId, platformFontsCallback); | 210 |
| 211 this._agent.getPlatformFontsForNode(nodeId, platformFontsCallback) |
| 212 .catchException(null) |
| 213 .then(callback) |
| 199 }, | 214 }, |
| 200 | 215 |
| 201 /** | 216 /** |
| 202 * @return {!Array.<!WebInspector.CSSStyleSheetHeader>} | 217 * @return {!Array.<!WebInspector.CSSStyleSheetHeader>} |
| 203 */ | 218 */ |
| 204 allStyleSheets: function() | 219 allStyleSheets: function() |
| 205 { | 220 { |
| 206 var values = this._styleSheetIdToHeader.valuesArray(); | 221 var values = this._styleSheetIdToHeader.valuesArray(); |
| 207 /** | 222 /** |
| 208 * @param {!WebInspector.CSSStyleSheetHeader} a | 223 * @param {!WebInspector.CSSStyleSheetHeader} a |
| 209 * @param {!WebInspector.CSSStyleSheetHeader} b | 224 * @param {!WebInspector.CSSStyleSheetHeader} b |
| 210 * @return {number} | 225 * @return {number} |
| 211 */ | 226 */ |
| 212 function styleSheetComparator(a, b) | 227 function styleSheetComparator(a, b) |
| 213 { | 228 { |
| 214 if (a.sourceURL < b.sourceURL) | 229 if (a.sourceURL < b.sourceURL) |
| 215 return -1; | 230 return -1; |
| 216 else if (a.sourceURL > b.sourceURL) | 231 else if (a.sourceURL > b.sourceURL) |
| 217 return 1; | 232 return 1; |
| 218 return a.startLine - b.startLine || a.startColumn - b.startColumn; | 233 return a.startLine - b.startLine || a.startColumn - b.startColumn; |
| 219 } | 234 } |
| 220 values.sort(styleSheetComparator); | 235 values.sort(styleSheetComparator); |
| 221 | 236 |
| 222 return values; | 237 return values; |
| 223 }, | 238 }, |
| 224 | 239 |
| 225 /** | 240 /** |
| 226 * @param {!DOMAgent.NodeId} nodeId | 241 * @param {!DOMAgent.NodeId} nodeId |
| 242 * @return {!Promise.<?WebInspector.CSSStyleModel.InlineStyleResult>} |
| 243 */ |
| 244 inlineStylesPromise: function(nodeId) |
| 245 { |
| 246 /** |
| 247 * @param {?Protocol.Error} error |
| 248 * @param {?CSSAgent.CSSStyle=} inlinePayload |
| 249 * @param {?CSSAgent.CSSStyle=} attributesStylePayload |
| 250 * @return {?WebInspector.CSSStyleModel.InlineStyleResult} |
| 251 * @this {WebInspector.CSSStyleModel} |
| 252 */ |
| 253 function callback(error, inlinePayload, attributesStylePayload) |
| 254 { |
| 255 if (error || !inlinePayload) |
| 256 return null; |
| 257 var inlineStyle = inlinePayload ? WebInspector.CSSStyleDeclaration.p
arsePayload(this, inlinePayload) : null; |
| 258 var attributesStyle = attributesStylePayload ? WebInspector.CSSStyle
Declaration.parsePayload(this, attributesStylePayload) : null; |
| 259 return new WebInspector.CSSStyleModel.InlineStyleResult(inlineStyle,
attributesStyle); |
| 260 } |
| 261 |
| 262 return this._agent.getInlineStylesForNode(nodeId, callback.bind(this)); |
| 263 }, |
| 264 |
| 265 /** |
| 266 * @param {!DOMAgent.NodeId} nodeId |
| 227 * @param {function(?WebInspector.CSSStyleModel.InlineStyleResult)} userCall
back | 267 * @param {function(?WebInspector.CSSStyleModel.InlineStyleResult)} userCall
back |
| 228 */ | 268 */ |
| 229 getInlineStylesAsync: function(nodeId, userCallback) | 269 getInlineStylesAsync: function(nodeId, userCallback) |
| 230 { | 270 { |
| 231 /** | 271 this.inlineStylesPromise(nodeId) |
| 232 * @param {?Protocol.Error} error | 272 .catchException(null) |
| 233 * @param {?CSSAgent.CSSStyle=} inlinePayload | 273 .then(userCallback); |
| 234 * @param {?CSSAgent.CSSStyle=} attributesStylePayload | |
| 235 * @this {WebInspector.CSSStyleModel} | |
| 236 */ | |
| 237 function callback(error, inlinePayload, attributesStylePayload) | |
| 238 { | |
| 239 if (error || !inlinePayload) { | |
| 240 userCallback(null); | |
| 241 return; | |
| 242 } | |
| 243 var inlineStyle = inlinePayload ? WebInspector.CSSStyleDeclaration.p
arsePayload(this, inlinePayload) : null; | |
| 244 var attributesStyle = attributesStylePayload ? WebInspector.CSSStyle
Declaration.parsePayload(this, attributesStylePayload) : null; | |
| 245 userCallback(new WebInspector.CSSStyleModel.InlineStyleResult(inline
Style, attributesStyle)); | |
| 246 } | |
| 247 | |
| 248 this._agent.getInlineStylesForNode(nodeId, callback.bind(this)); | |
| 249 }, | 274 }, |
| 250 | 275 |
| 251 /** | 276 /** |
| 252 * @param {!WebInspector.DOMNode} node | 277 * @param {!WebInspector.DOMNode} node |
| 253 * @param {string} pseudoClass | 278 * @param {string} pseudoClass |
| 254 * @param {boolean} enable | 279 * @param {boolean} enable |
| 255 * @return {boolean} | 280 * @return {boolean} |
| 256 */ | 281 */ |
| 257 forcePseudoState: function(node, pseudoClass, enable) | 282 forcePseudoState: function(node, pseudoClass, enable) |
| 258 { | 283 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 272 | 297 |
| 273 this._agent.forcePseudoState(node.id, pseudoClasses); | 298 this._agent.forcePseudoState(node.id, pseudoClasses); |
| 274 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.PseudoSt
ateForced, { node: node, pseudoClass: pseudoClass, enable: enable }); | 299 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.PseudoSt
ateForced, { node: node, pseudoClass: pseudoClass, enable: enable }); |
| 275 return true; | 300 return true; |
| 276 }, | 301 }, |
| 277 | 302 |
| 278 /** | 303 /** |
| 279 * @param {!CSSAgent.CSSRule} rule | 304 * @param {!CSSAgent.CSSRule} rule |
| 280 * @param {!DOMAgent.NodeId} nodeId | 305 * @param {!DOMAgent.NodeId} nodeId |
| 281 * @param {string} newSelector | 306 * @param {string} newSelector |
| 282 * @param {function(!WebInspector.CSSRule)} successCallback | 307 * @param {function(?WebInspector.CSSRule)} userCallback |
| 283 * @param {function()} failureCallback | |
| 284 */ | 308 */ |
| 285 setRuleSelector: function(rule, nodeId, newSelector, successCallback, failur
eCallback) | 309 setRuleSelector: function(rule, nodeId, newSelector, userCallback) |
| 286 { | 310 { |
| 287 /** | 311 /** |
| 288 * @param {!DOMAgent.NodeId} nodeId | |
| 289 * @param {function(!WebInspector.CSSRule)} successCallback | |
| 290 * @param {function()} failureCallback | |
| 291 * @param {?Protocol.Error} error | 312 * @param {?Protocol.Error} error |
| 292 * @param {string} newSelector | 313 * @param {?CSSAgent.CSSRule} rulePayload |
| 293 * @param {!CSSAgent.CSSRule} rulePayload | 314 * @return {?CSSAgent.CSSRule} |
| 294 * @this {WebInspector.CSSStyleModel} | 315 * @this {WebInspector.CSSStyleModel} |
| 295 */ | 316 */ |
| 296 function callback(nodeId, successCallback, failureCallback, newSelector,
error, rulePayload) | 317 function callback(error, rulePayload) |
| 297 { | 318 { |
| 298 this._pendingCommandsMajorState.pop(); | 319 this._pendingCommandsMajorState.pop(); |
| 299 if (error) { | 320 if (error || !rulePayload) |
| 300 failureCallback(); | 321 return null; |
| 301 return; | |
| 302 } | |
| 303 this._domModel.markUndoableState(); | 322 this._domModel.markUndoableState(); |
| 304 this._computeMatchingSelectors(rulePayload, nodeId, successCallback,
failureCallback); | 323 return rulePayload; |
| 305 } | 324 } |
| 306 | 325 |
| 307 if (!rule.styleSheetId) | 326 if (!rule.styleSheetId) |
| 308 throw "No rule stylesheet id"; | 327 throw "No rule stylesheet id"; |
| 309 WebInspector.userMetrics.StyleRuleEdited.record(); | 328 WebInspector.userMetrics.StyleRuleEdited.record(); |
| 310 this._pendingCommandsMajorState.push(true); | 329 this._pendingCommandsMajorState.push(true); |
| 311 this._agent.setRuleSelector(rule.styleSheetId, rule.selectorRange, newSe
lector, callback.bind(this, nodeId, successCallback, failureCallback, newSelecto
r)); | 330 this._agent.setRuleSelector(rule.styleSheetId, rule.selectorRange, newSe
lector, callback.bind(this)) |
| 331 .then(this._computeMatchingSelectors.bind(this, nodeId)) |
| 332 .catchException(null) |
| 333 .then(userCallback); |
| 312 }, | 334 }, |
| 313 | 335 |
| 314 /** | 336 /** |
| 315 * @param {!WebInspector.CSSMedia} media | 337 * @param {!WebInspector.CSSMedia} media |
| 316 * @param {string} newMediaText | 338 * @param {string} newMediaText |
| 317 * @param {function(!WebInspector.CSSMedia)} successCallback | 339 * @param {function(?WebInspector.CSSMedia)} userCallback |
| 318 * @param {function()} failureCallback | |
| 319 */ | 340 */ |
| 320 setMediaText: function(media, newMediaText, successCallback, failureCallback
) | 341 setMediaText: function(media, newMediaText, userCallback) |
| 321 { | 342 { |
| 322 /** | 343 /** |
| 323 * @param {function(!WebInspector.CSSMedia)} successCallback | |
| 324 * @param {function()} failureCallback | |
| 325 * @param {?Protocol.Error} error | 344 * @param {?Protocol.Error} error |
| 326 * @param {!CSSAgent.CSSMedia} mediaPayload | 345 * @param {!CSSAgent.CSSMedia} mediaPayload |
| 346 * @return {?WebInspector.CSSMedia} |
| 327 * @this {WebInspector.CSSStyleModel} | 347 * @this {WebInspector.CSSStyleModel} |
| 328 */ | 348 */ |
| 329 function callback(successCallback, failureCallback, error, mediaPayload) | 349 function parsePayload(error, mediaPayload) |
| 330 { | 350 { |
| 331 this._pendingCommandsMajorState.pop(); | 351 this._pendingCommandsMajorState.pop(); |
| 332 if (error) { | 352 if (!mediaPayload) |
| 333 failureCallback(); | 353 return null; |
| 334 return; | |
| 335 } | |
| 336 this._domModel.markUndoableState(); | 354 this._domModel.markUndoableState(); |
| 337 successCallback(WebInspector.CSSMedia.parsePayload(this, mediaPayloa
d)); | 355 return WebInspector.CSSMedia.parsePayload(this, mediaPayload); |
| 338 } | 356 } |
| 339 | 357 |
| 340 console.assert(!!media.parentStyleSheetId); | 358 console.assert(!!media.parentStyleSheetId); |
| 341 WebInspector.userMetrics.StyleRuleEdited.record(); | 359 WebInspector.userMetrics.StyleRuleEdited.record(); |
| 342 this._pendingCommandsMajorState.push(true); | 360 this._pendingCommandsMajorState.push(true); |
| 343 this._agent.setMediaText(media.parentStyleSheetId, media.range, newMedia
Text, callback.bind(this, successCallback, failureCallback)); | 361 this._agent.setMediaText(media.parentStyleSheetId, media.range, newMedia
Text, parsePayload.bind(this)) |
| 362 .catchException(null) |
| 363 .then(userCallback); |
| 344 }, | 364 }, |
| 345 | 365 |
| 346 /** | 366 /** |
| 347 * @param {!CSSAgent.CSSRule} rulePayload | |
| 348 * @param {!DOMAgent.NodeId} nodeId | 367 * @param {!DOMAgent.NodeId} nodeId |
| 349 * @param {function(!WebInspector.CSSRule)} successCallback | 368 * @param {?CSSAgent.CSSRule} rulePayload |
| 350 * @param {function()} failureCallback | 369 * @return {!Promise.<?WebInspector.CSSRule>} |
| 351 */ | 370 */ |
| 352 _computeMatchingSelectors: function(rulePayload, nodeId, successCallback, fa
ilureCallback) | 371 _computeMatchingSelectors: function(nodeId, rulePayload) |
| 353 { | 372 { |
| 354 var ownerDocumentId = this._ownerDocumentId(nodeId); | 373 var ownerDocumentId = this._ownerDocumentId(nodeId); |
| 355 if (!ownerDocumentId) { | 374 if (!ownerDocumentId || !rulePayload) |
| 356 failureCallback(); | 375 return Promise.resolve(/** @type {?WebInspector.CSSRule} */(null)); |
| 357 return; | |
| 358 } | |
| 359 var rule = WebInspector.CSSRule.parsePayload(this, rulePayload); | 376 var rule = WebInspector.CSSRule.parsePayload(this, rulePayload); |
| 360 var matchingSelectors = []; | 377 var matchingSelectors = []; |
| 361 var allSelectorsBarrier = new CallbackBarrier(); | 378 var allSelectorsBarrier = new CallbackBarrier(); |
| 362 for (var i = 0; i < rule.selectors.length; ++i) { | 379 for (var i = 0; i < rule.selectors.length; ++i) { |
| 363 var selector = rule.selectors[i]; | 380 var selector = rule.selectors[i]; |
| 364 var boundCallback = allSelectorsBarrier.createCallback(selectorQueri
ed.bind(null, i, nodeId, matchingSelectors)); | 381 var boundCallback = allSelectorsBarrier.createCallback(selectorQueri
ed.bind(null, i, nodeId, matchingSelectors)); |
| 365 this._domModel.querySelectorAll(ownerDocumentId, selector.value, bou
ndCallback); | 382 this._domModel.querySelectorAll(ownerDocumentId, selector.value, bou
ndCallback); |
| 366 } | 383 } |
| 367 allSelectorsBarrier.callWhenDone(function() { | 384 return new Promise(promiseConstructor); |
| 368 rule.matchingSelectors = matchingSelectors; | 385 |
| 369 successCallback(rule); | 386 /** |
| 370 }); | 387 * @param {function(!WebInspector.CSSRule)} resolve |
| 388 */ |
| 389 function promiseConstructor(resolve) |
| 390 { |
| 391 allSelectorsBarrier.callWhenDone(function() { |
| 392 rule.matchingSelectors = matchingSelectors; |
| 393 resolve(rule); |
| 394 }); |
| 395 } |
| 371 | 396 |
| 372 /** | 397 /** |
| 373 * @param {number} index | 398 * @param {number} index |
| 374 * @param {!DOMAgent.NodeId} nodeId | 399 * @param {!DOMAgent.NodeId} nodeId |
| 375 * @param {!Array.<number>} matchingSelectors | 400 * @param {!Array.<number>} matchingSelectors |
| 376 * @param {!Array.<!DOMAgent.NodeId>=} matchingNodeIds | 401 * @param {!Array.<!DOMAgent.NodeId>=} matchingNodeIds |
| 377 */ | 402 */ |
| 378 function selectorQueried(index, nodeId, matchingSelectors, matchingNodeI
ds) | 403 function selectorQueried(index, nodeId, matchingSelectors, matchingNodeI
ds) |
| 379 { | 404 { |
| 380 if (!matchingNodeIds) | 405 if (!matchingNodeIds) |
| 381 return; | 406 return; |
| 382 if (matchingNodeIds.indexOf(nodeId) !== -1) | 407 if (matchingNodeIds.indexOf(nodeId) !== -1) |
| 383 matchingSelectors.push(index); | 408 matchingSelectors.push(index); |
| 384 } | 409 } |
| 385 }, | 410 }, |
| 386 | 411 |
| 387 /** | 412 /** |
| 388 * @param {!CSSAgent.StyleSheetId} styleSheetId | 413 * @param {!CSSAgent.StyleSheetId} styleSheetId |
| 389 * @param {!WebInspector.DOMNode} node | 414 * @param {!WebInspector.DOMNode} node |
| 390 * @param {string} ruleText | 415 * @param {string} ruleText |
| 391 * @param {!WebInspector.TextRange} ruleLocation | 416 * @param {!WebInspector.TextRange} ruleLocation |
| 392 * @param {function(!WebInspector.CSSRule)} successCallback | 417 * @param {function(?WebInspector.CSSRule)} userCallback |
| 393 * @param {function()} failureCallback | |
| 394 */ | 418 */ |
| 395 addRule: function(styleSheetId, node, ruleText, ruleLocation, successCallbac
k, failureCallback) | 419 addRule: function(styleSheetId, node, ruleText, ruleLocation, userCallback) |
| 396 { | 420 { |
| 397 this._pendingCommandsMajorState.push(true); | 421 this._pendingCommandsMajorState.push(true); |
| 398 this._agent.addRule(styleSheetId, ruleText, ruleLocation, callback.bind(
this)); | 422 this._agent.addRule(styleSheetId, ruleText, ruleLocation, parsePayload.b
ind(this)) |
| 423 .then(this._computeMatchingSelectors.bind(this, node.id)) |
| 424 .catchException(null) |
| 425 .then(userCallback); |
| 399 | 426 |
| 400 /** | 427 /** |
| 401 * @param {?Protocol.Error} error | 428 * @param {?Protocol.Error} error |
| 402 * @param {!CSSAgent.CSSRule} rulePayload | 429 * @param {?CSSAgent.CSSRule} rulePayload |
| 430 * @return {?CSSAgent.CSSRule} |
| 403 * @this {WebInspector.CSSStyleModel} | 431 * @this {WebInspector.CSSStyleModel} |
| 404 */ | 432 */ |
| 405 function callback(error, rulePayload) | 433 function parsePayload(error, rulePayload) |
| 406 { | 434 { |
| 407 this._pendingCommandsMajorState.pop(); | 435 this._pendingCommandsMajorState.pop(); |
| 408 if (error) { | 436 if (error || !rulePayload) |
| 409 // Invalid syntax for a selector | 437 return null; |
| 410 failureCallback(); | 438 this._domModel.markUndoableState(); |
| 411 } else { | 439 return rulePayload; |
| 412 this._domModel.markUndoableState(); | |
| 413 this._computeMatchingSelectors(rulePayload, node.id, successCall
back, failureCallback); | |
| 414 } | |
| 415 } | 440 } |
| 416 }, | 441 }, |
| 417 | 442 |
| 418 /** | 443 /** |
| 419 * @param {!WebInspector.DOMNode} node | 444 * @param {!WebInspector.DOMNode} node |
| 420 * @param {function(?WebInspector.CSSStyleSheetHeader)} callback | 445 * @param {function(?WebInspector.CSSStyleSheetHeader)} userCallback |
| 421 */ | 446 */ |
| 422 requestViaInspectorStylesheet: function(node, callback) | 447 requestViaInspectorStylesheet: function(node, userCallback) |
| 423 { | 448 { |
| 424 var frameId = node.frameId() || this.target().resourceTreeModel.mainFram
e.id; | 449 var frameId = node.frameId() || this.target().resourceTreeModel.mainFram
e.id; |
| 425 var headers = this._styleSheetIdToHeader.valuesArray(); | 450 var headers = this._styleSheetIdToHeader.valuesArray(); |
| 426 for (var i = 0; i < headers.length; ++i) { | 451 for (var i = 0; i < headers.length; ++i) { |
| 427 var styleSheetHeader = headers[i]; | 452 var styleSheetHeader = headers[i]; |
| 428 if (styleSheetHeader.frameId === frameId && styleSheetHeader.isViaIn
spector()) { | 453 if (styleSheetHeader.frameId === frameId && styleSheetHeader.isViaIn
spector()) { |
| 429 callback(styleSheetHeader); | 454 userCallback(styleSheetHeader); |
| 430 return; | 455 return; |
| 431 } | 456 } |
| 432 } | 457 } |
| 433 | 458 |
| 434 /** | 459 /** |
| 460 * @param {?Protocol.Error} error |
| 461 * @param {?CSSAgent.StyleSheetId} styleSheetId |
| 462 * @return {?WebInspector.CSSStyleSheetHeader} |
| 435 * @this {WebInspector.CSSStyleModel} | 463 * @this {WebInspector.CSSStyleModel} |
| 436 * @param {?Protocol.Error} error | |
| 437 * @param {!CSSAgent.StyleSheetId} styleSheetId | |
| 438 */ | 464 */ |
| 439 function innerCallback(error, styleSheetId) | 465 function innerCallback(error, styleSheetId) |
| 440 { | 466 { |
| 441 if (error) { | 467 return !error && styleSheetId ? this._styleSheetIdToHeader.get(style
SheetId) || null : null; |
| 442 console.error(error); | |
| 443 callback(null); | |
| 444 } | |
| 445 | |
| 446 callback(this._styleSheetIdToHeader.get(styleSheetId) || null); | |
| 447 } | 468 } |
| 448 | 469 |
| 449 this._agent.createStyleSheet(frameId, innerCallback.bind(this)); | 470 this._agent.createStyleSheet(frameId, innerCallback.bind(this)) |
| 471 .catchException(null) |
| 472 .then(userCallback) |
| 450 }, | 473 }, |
| 451 | 474 |
| 452 mediaQueryResultChanged: function() | 475 mediaQueryResultChanged: function() |
| 453 { | 476 { |
| 454 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue
ryResultChanged); | 477 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue
ryResultChanged); |
| 455 }, | 478 }, |
| 456 | 479 |
| 457 /** | 480 /** |
| 458 * @param {!CSSAgent.StyleSheetId} id | 481 * @param {!CSSAgent.StyleSheetId} id |
| 459 * @return {?WebInspector.CSSStyleSheetHeader} | 482 * @return {?WebInspector.CSSStyleSheetHeader} |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.Styl
eSheetRemoved, headers[i]); | 633 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.Styl
eSheetRemoved, headers[i]); |
| 611 }, | 634 }, |
| 612 | 635 |
| 613 _suspendStateChanged: function() | 636 _suspendStateChanged: function() |
| 614 { | 637 { |
| 615 if (WebInspector.targetManager.allTargetsSuspended()) { | 638 if (WebInspector.targetManager.allTargetsSuspended()) { |
| 616 this._agent.disable(); | 639 this._agent.disable(); |
| 617 this._isEnabled = false; | 640 this._isEnabled = false; |
| 618 } else { | 641 } else { |
| 619 this._resetStyleSheets(); | 642 this._resetStyleSheets(); |
| 620 this._agent.enable(this._wasEnabled.bind(this)); | 643 this._agent.enable().then(this._wasEnabled.bind(this)); |
| 621 } | 644 } |
| 622 }, | 645 }, |
| 623 | 646 |
| 624 __proto__: WebInspector.SDKModel.prototype | 647 __proto__: WebInspector.SDKModel.prototype |
| 625 } | 648 } |
| 626 | 649 |
| 627 /** | 650 /** |
| 628 * @constructor | 651 * @constructor |
| 629 * @extends {WebInspector.SDKObject} | 652 * @extends {WebInspector.SDKObject} |
| 630 * @param {!WebInspector.CSSStyleModel} cssModel | 653 * @param {!WebInspector.CSSStyleModel} cssModel |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 { | 918 { |
| 896 index = (typeof index === "undefined") ? this.pastLastSourcePropertyInde
x() : index; | 919 index = (typeof index === "undefined") ? this.pastLastSourcePropertyInde
x() : index; |
| 897 var property = new WebInspector.CSSProperty(this, index, "", "", false,
false, true, false, "", this._insertionRange(index)); | 920 var property = new WebInspector.CSSProperty(this, index, "", "", false,
false, true, false, "", this._insertionRange(index)); |
| 898 property._setActive(true); | 921 property._setActive(true); |
| 899 return property; | 922 return property; |
| 900 }, | 923 }, |
| 901 | 924 |
| 902 /** | 925 /** |
| 903 * @param {string} text | 926 * @param {string} text |
| 904 * @param {boolean} majorChange | 927 * @param {boolean} majorChange |
| 905 * @param {function(?WebInspector.CSSStyleDeclaration)} callback | 928 * @param {function(?WebInspector.CSSStyleDeclaration)} userCallback |
| 906 */ | 929 */ |
| 907 setText: function(text, majorChange, callback) | 930 setText: function(text, majorChange, userCallback) |
| 908 { | 931 { |
| 909 if (!this.styleSheetId) { | 932 if (!this.styleSheetId) { |
| 910 callback(null); | 933 userCallback(null); |
| 911 return; | 934 return; |
| 912 } | 935 } |
| 913 | 936 |
| 914 /** | 937 /** |
| 915 * @param {?Protocol.Error} error | 938 * @param {?Protocol.Error} error |
| 916 * @param {!CSSAgent.CSSStyle} stylePayload | 939 * @param {?CSSAgent.CSSStyle} stylePayload |
| 940 * @return {?WebInspector.CSSStyleDeclaration} |
| 917 * @this {WebInspector.CSSStyleDeclaration} | 941 * @this {WebInspector.CSSStyleDeclaration} |
| 918 */ | 942 */ |
| 919 function mycallback(error, stylePayload) | 943 function parsePayload(error, stylePayload) |
| 920 { | 944 { |
| 921 this._cssModel._pendingCommandsMajorState.pop(); | 945 this._cssModel._pendingCommandsMajorState.pop(); |
| 922 if (!error) { | 946 if (error || !stylePayload) |
| 923 if (majorChange) | 947 return null; |
| 924 this._cssModel._domModel.markUndoableState(); | 948 |
| 925 callback(WebInspector.CSSStyleDeclaration.parsePayload(this._css
Model, stylePayload)); | 949 if (majorChange) |
| 926 return; | 950 this._cssModel._domModel.markUndoableState(); |
| 927 } | 951 return WebInspector.CSSStyleDeclaration.parsePayload(this._cssModel,
stylePayload); |
| 928 callback(null); | |
| 929 } | 952 } |
| 930 | 953 |
| 931 this._cssModel._pendingCommandsMajorState.push(majorChange); | 954 this._cssModel._pendingCommandsMajorState.push(majorChange); |
| 932 this._cssModel._agent.setStyleText(this.styleSheetId, this.range.seriali
zeToObject(), text, mycallback.bind(this)); | 955 this._cssModel._agent.setStyleText(this.styleSheetId, this.range.seriali
zeToObject(), text, parsePayload.bind(this)) |
| 956 .catchException(null) |
| 957 .then(userCallback) |
| 933 }, | 958 }, |
| 934 | 959 |
| 935 /** | 960 /** |
| 936 * @param {number} index | 961 * @param {number} index |
| 937 * @param {string} name | 962 * @param {string} name |
| 938 * @param {string} value | 963 * @param {string} value |
| 939 * @param {function(?WebInspector.CSSStyleDeclaration)=} userCallback | 964 * @param {function(?WebInspector.CSSStyleDeclaration)=} userCallback |
| 940 */ | 965 */ |
| 941 insertPropertyAt: function(index, name, value, userCallback) | 966 insertPropertyAt: function(index, name, value, userCallback) |
| 942 { | 967 { |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1762 * @return {string} | 1787 * @return {string} |
| 1763 */ | 1788 */ |
| 1764 _trimSourceURL: function(text) | 1789 _trimSourceURL: function(text) |
| 1765 { | 1790 { |
| 1766 var sourceURLRegex = /\n[\040\t]*\/\*[#@][\040\t]sourceURL=[\040\t]*([^\
s]*)[\040\t]*\*\/[\040\t]*$/mg; | 1791 var sourceURLRegex = /\n[\040\t]*\/\*[#@][\040\t]sourceURL=[\040\t]*([^\
s]*)[\040\t]*\*\/[\040\t]*$/mg; |
| 1767 return text.replace(sourceURLRegex, ""); | 1792 return text.replace(sourceURLRegex, ""); |
| 1768 }, | 1793 }, |
| 1769 | 1794 |
| 1770 /** | 1795 /** |
| 1771 * @override | 1796 * @override |
| 1772 * @param {function(string)} callback | 1797 * @param {function(string)} userCallback |
| 1773 */ | 1798 */ |
| 1774 requestContent: function(callback) | 1799 requestContent: function(userCallback) |
| 1775 { | 1800 { |
| 1776 this._cssModel._agent.getStyleSheetText(this.id, textCallback.bind(this)
); | 1801 this._cssModel._agent.getStyleSheetText(this.id, textCallback.bind(this)
) |
| 1802 .catchException("") |
| 1803 .then(userCallback) |
| 1777 | 1804 |
| 1778 /** | 1805 /** |
| 1806 * @param {?Protocol.Error} error |
| 1807 * @param {?string} text |
| 1808 * @return {string} |
| 1779 * @this {WebInspector.CSSStyleSheetHeader} | 1809 * @this {WebInspector.CSSStyleSheetHeader} |
| 1780 */ | 1810 */ |
| 1781 function textCallback(error, text) | 1811 function textCallback(error, text) |
| 1782 { | 1812 { |
| 1783 if (error) { | 1813 if (error || !text) { |
| 1784 WebInspector.console.error("Failed to get text for stylesheet "
+ this.id + ": " + error); | 1814 WebInspector.console.error("Failed to get text for stylesheet "
+ this.id + ": " + error) |
| 1785 text = ""; | 1815 text = ""; |
| 1786 // Fall through. | 1816 // Fall through. |
| 1787 } | 1817 } |
| 1788 text = this._trimSourceURL(text); | 1818 return this._trimSourceURL(text); |
| 1789 callback(text); | |
| 1790 } | 1819 } |
| 1791 }, | 1820 }, |
| 1792 | 1821 |
| 1793 /** | 1822 /** |
| 1794 * @override | 1823 * @override |
| 1795 */ | 1824 */ |
| 1796 searchInContent: function(query, caseSensitive, isRegex, callback) | 1825 searchInContent: function(query, caseSensitive, isRegex, callback) |
| 1797 { | 1826 { |
| 1798 function performSearch(content) | 1827 function performSearch(content) |
| 1799 { | 1828 { |
| 1800 callback(WebInspector.ContentProvider.performSearchInContent(content
, query, caseSensitive, isRegex)); | 1829 callback(WebInspector.ContentProvider.performSearchInContent(content
, query, caseSensitive, isRegex)); |
| 1801 } | 1830 } |
| 1802 | 1831 |
| 1803 // searchInContent should call back later. | 1832 // searchInContent should call back later. |
| 1804 this.requestContent(performSearch); | 1833 this.requestContent(performSearch); |
| 1805 }, | 1834 }, |
| 1806 | 1835 |
| 1807 /** | 1836 /** |
| 1808 * @param {string} newText | 1837 * @param {string} newText |
| 1809 * @param {function(?Protocol.Error)} callback | 1838 * @param {function(?Protocol.Error)} callback |
| 1810 */ | 1839 */ |
| 1811 setContent: function(newText, callback) | 1840 setContent: function(newText, callback) |
| 1812 { | 1841 { |
| 1813 newText = this._trimSourceURL(newText); | 1842 newText = this._trimSourceURL(newText); |
| 1814 if (this.hasSourceURL) | 1843 if (this.hasSourceURL) |
| 1815 newText += "\n/*# sourceURL=" + this.sourceURL + " */"; | 1844 newText += "\n/*# sourceURL=" + this.sourceURL + " */"; |
| 1816 this._cssModel._agent.setStyleSheetText(this.id, newText, callback); | 1845 this._cssModel._agent.setStyleSheetText(this.id, newText, extractProtoco
lError) |
| 1846 .then(callback); |
| 1847 |
| 1848 /** |
| 1849 * @param {?Protocol.Error} error |
| 1850 */ |
| 1851 function extractProtocolError(error) |
| 1852 { |
| 1853 return error || null; |
| 1854 } |
| 1817 }, | 1855 }, |
| 1818 | 1856 |
| 1819 /** | 1857 /** |
| 1820 * @return {boolean} | 1858 * @return {boolean} |
| 1821 */ | 1859 */ |
| 1822 isViaInspector: function() | 1860 isViaInspector: function() |
| 1823 { | 1861 { |
| 1824 return this.origin === "inspector"; | 1862 return this.origin === "inspector"; |
| 1825 } | 1863 } |
| 1826 } | 1864 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1890 */ | 1928 */ |
| 1891 getComputedStyle: function(nodeId, userCallback) | 1929 getComputedStyle: function(nodeId, userCallback) |
| 1892 { | 1930 { |
| 1893 if (this._nodeIdToCallbackData[nodeId]) { | 1931 if (this._nodeIdToCallbackData[nodeId]) { |
| 1894 this._nodeIdToCallbackData[nodeId].push(userCallback); | 1932 this._nodeIdToCallbackData[nodeId].push(userCallback); |
| 1895 return; | 1933 return; |
| 1896 } | 1934 } |
| 1897 | 1935 |
| 1898 this._nodeIdToCallbackData[nodeId] = [userCallback]; | 1936 this._nodeIdToCallbackData[nodeId] = [userCallback]; |
| 1899 | 1937 |
| 1900 this._cssModel._agent.getComputedStyleForNode(nodeId, resultCallback.bin
d(this, nodeId)); | 1938 this._cssModel._agent.getComputedStyleForNode(nodeId, parsePayload.bind(
this)) |
| 1939 .catchException(null) |
| 1940 .then(broadcast.bind(this, nodeId)) |
| 1941 |
| 1942 /** |
| 1943 * @param {?Protocol.Error} error |
| 1944 * @param {!Array.<!CSSAgent.CSSComputedStyleProperty>} computedPayload |
| 1945 * @return {?WebInspector.CSSStyleDeclaration} |
| 1946 * @this {WebInspector.CSSStyleModel.ComputedStyleLoader} |
| 1947 */ |
| 1948 function parsePayload(error, computedPayload) |
| 1949 { |
| 1950 return !error && computedPayload ? WebInspector.CSSStyleDeclaration.
parseComputedStylePayload(this._cssModel, computedPayload) : null; |
| 1951 } |
| 1901 | 1952 |
| 1902 /** | 1953 /** |
| 1903 * @param {!DOMAgent.NodeId} nodeId | 1954 * @param {!DOMAgent.NodeId} nodeId |
| 1904 * @param {?Protocol.Error} error | 1955 * @param {?WebInspector.CSSStyleDeclaration} computedStyle |
| 1905 * @param {!Array.<!CSSAgent.CSSComputedStyleProperty>} computedPayload | |
| 1906 * @this {WebInspector.CSSStyleModel.ComputedStyleLoader} | 1956 * @this {WebInspector.CSSStyleModel.ComputedStyleLoader} |
| 1907 */ | 1957 */ |
| 1908 function resultCallback(nodeId, error, computedPayload) | 1958 function broadcast(nodeId, computedStyle) |
| 1909 { | 1959 { |
| 1910 var computedStyle = (error || !computedPayload) ? null : WebInspecto
r.CSSStyleDeclaration.parseComputedStylePayload(this._cssModel, computedPayload)
; | |
| 1911 var callbacks = this._nodeIdToCallbackData[nodeId]; | 1960 var callbacks = this._nodeIdToCallbackData[nodeId]; |
| 1912 | 1961 |
| 1913 // The loader has been reset. | 1962 // The loader has been reset. |
| 1914 if (!callbacks) | 1963 if (!callbacks) |
| 1915 return; | 1964 return; |
| 1916 | 1965 |
| 1917 delete this._nodeIdToCallbackData[nodeId]; | 1966 delete this._nodeIdToCallbackData[nodeId]; |
| 1918 for (var i = 0; i < callbacks.length; ++i) | 1967 for (var i = 0; i < callbacks.length; ++i) |
| 1919 callbacks[i](computedStyle); | 1968 callbacks[i](computedStyle); |
| 1920 } | 1969 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1980 * @constructor | 2029 * @constructor |
| 1981 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle | 2030 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle |
| 1982 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle | 2031 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle |
| 1983 */ | 2032 */ |
| 1984 WebInspector.CSSStyleModel.InlineStyleResult = function(inlineStyle, attributesS
tyle) | 2033 WebInspector.CSSStyleModel.InlineStyleResult = function(inlineStyle, attributesS
tyle) |
| 1985 { | 2034 { |
| 1986 this.inlineStyle = inlineStyle; | 2035 this.inlineStyle = inlineStyle; |
| 1987 this.attributesStyle = attributesStyle; | 2036 this.attributesStyle = attributesStyle; |
| 1988 } | 2037 } |
| 1989 | 2038 |
| OLD | NEW |