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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 callback(cssFamilyName, fonts); | 162 callback(cssFamilyName, fonts); |
163 } | 163 } |
164 CSSAgent.getPlatformFontsForNode(nodeId, platformFontsCallback); | 164 CSSAgent.getPlatformFontsForNode(nodeId, platformFontsCallback); |
165 }, | 165 }, |
166 | 166 |
167 /** | 167 /** |
168 * @return {!Array.<!WebInspector.CSSStyleSheetHeader>} | 168 * @return {!Array.<!WebInspector.CSSStyleSheetHeader>} |
169 */ | 169 */ |
170 allStyleSheets: function() | 170 allStyleSheets: function() |
171 { | 171 { |
172 return Object.values(this._styleSheetIdToHeader); | 172 var values = Object.values(this._styleSheetIdToHeader); |
| 173 /** |
| 174 * @param {!WebInspector.CSSStyleSheetHeader} a |
| 175 * @param {!WebInspector.CSSStyleSheetHeader} b |
| 176 * @return {number} |
| 177 */ |
| 178 function styleSheetComparator(a, b) |
| 179 { |
| 180 if (a.sourceURL < b.sourceURL) |
| 181 return -1; |
| 182 else if (a.sourceURL > b.sourceURL) |
| 183 return 1; |
| 184 return a.startLine - b.startLine || a.startColumn - b.startColumn; |
| 185 } |
| 186 values.sort(styleSheetComparator); |
| 187 |
| 188 return values; |
173 }, | 189 }, |
174 | 190 |
175 /** | 191 /** |
176 * @param {!DOMAgent.NodeId} nodeId | 192 * @param {!DOMAgent.NodeId} nodeId |
177 * @param {function(?WebInspector.CSSStyleDeclaration, ?WebInspector.CSSStyl
eDeclaration)} userCallback | 193 * @param {function(?WebInspector.CSSStyleDeclaration, ?WebInspector.CSSStyl
eDeclaration)} userCallback |
178 */ | 194 */ |
179 getInlineStylesAsync: function(nodeId, userCallback) | 195 getInlineStylesAsync: function(nodeId, userCallback) |
180 { | 196 { |
181 /** | 197 /** |
182 * @param {function(?WebInspector.CSSStyleDeclaration, ?WebInspector.CSS
StyleDeclaration)} userCallback | 198 * @param {function(?WebInspector.CSSStyleDeclaration, ?WebInspector.CSS
StyleDeclaration)} userCallback |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 354 } |
339 | 355 |
340 callback(this._styleSheetIdToHeader[styleSheetId]); | 356 callback(this._styleSheetIdToHeader[styleSheetId]); |
341 } | 357 } |
342 | 358 |
343 CSSAgent.createStyleSheet(frameId, innerCallback.bind(this)); | 359 CSSAgent.createStyleSheet(frameId, innerCallback.bind(this)); |
344 }, | 360 }, |
345 | 361 |
346 mediaQueryResultChanged: function() | 362 mediaQueryResultChanged: function() |
347 { | 363 { |
348 this._styleLoader.reset(); | |
349 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue
ryResultChanged); | 364 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue
ryResultChanged); |
350 }, | 365 }, |
351 | 366 |
352 /** | 367 /** |
353 * @param {!CSSAgent.StyleSheetId} id | 368 * @param {!CSSAgent.StyleSheetId} id |
354 * @return {!WebInspector.CSSStyleSheetHeader} | 369 * @return {!WebInspector.CSSStyleSheetHeader} |
355 */ | 370 */ |
356 styleSheetHeaderForId: function(id) | 371 styleSheetHeaderForId: function(id) |
357 { | 372 { |
358 return this._styleSheetIdToHeader[id]; | 373 return this._styleSheetIdToHeader[id]; |
(...skipping 17 matching lines...) Expand all Loading... |
376 if (!node) | 391 if (!node) |
377 return null; | 392 return null; |
378 return node.ownerDocument ? node.ownerDocument.id : null; | 393 return node.ownerDocument ? node.ownerDocument.id : null; |
379 }, | 394 }, |
380 | 395 |
381 /** | 396 /** |
382 * @param {!CSSAgent.StyleSheetId} styleSheetId | 397 * @param {!CSSAgent.StyleSheetId} styleSheetId |
383 */ | 398 */ |
384 _fireStyleSheetChanged: function(styleSheetId) | 399 _fireStyleSheetChanged: function(styleSheetId) |
385 { | 400 { |
386 this._styleLoader.reset(); | |
387 if (!this._pendingCommandsMajorState.length) | 401 if (!this._pendingCommandsMajorState.length) |
388 return; | 402 return; |
389 | 403 |
390 var majorChange = this._pendingCommandsMajorState[this._pendingCommandsM
ajorState.length - 1]; | 404 var majorChange = this._pendingCommandsMajorState[this._pendingCommandsM
ajorState.length - 1]; |
391 | 405 |
392 if (!styleSheetId || !this.hasEventListeners(WebInspector.CSSStyleModel.
Events.StyleSheetChanged)) | 406 if (!styleSheetId || !this.hasEventListeners(WebInspector.CSSStyleModel.
Events.StyleSheetChanged)) |
393 return; | 407 return; |
394 | 408 |
395 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe
etChanged, { styleSheetId: styleSheetId, majorChange: majorChange }); | 409 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe
etChanged, { styleSheetId: styleSheetId, majorChange: majorChange }); |
396 }, | 410 }, |
397 | 411 |
398 /** | 412 /** |
399 * @param {!CSSAgent.CSSStyleSheetHeader} header | 413 * @param {!CSSAgent.CSSStyleSheetHeader} header |
400 */ | 414 */ |
401 _styleSheetAdded: function(header) | 415 _styleSheetAdded: function(header) |
402 { | 416 { |
403 console.assert(!this._styleSheetIdToHeader[header.styleSheetId]); | 417 console.assert(!this._styleSheetIdToHeader[header.styleSheetId]); |
404 var styleSheetHeader = new WebInspector.CSSStyleSheetHeader(header); | 418 var styleSheetHeader = new WebInspector.CSSStyleSheetHeader(header); |
405 this._styleSheetIdToHeader[header.styleSheetId] = styleSheetHeader; | 419 this._styleSheetIdToHeader[header.styleSheetId] = styleSheetHeader; |
406 var url = styleSheetHeader.resourceURL(); | 420 var url = styleSheetHeader.resourceURL(); |
407 if (!this._styleSheetIdsForURL[url]) | 421 if (!this._styleSheetIdsForURL[url]) |
408 this._styleSheetIdsForURL[url] = {}; | 422 this._styleSheetIdsForURL[url] = {}; |
409 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url]; | 423 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url]; |
410 var styleSheetIds = frameIdToStyleSheetIds[styleSheetHeader.frameId]; | 424 var styleSheetIds = frameIdToStyleSheetIds[styleSheetHeader.frameId]; |
411 if (!styleSheetIds) { | 425 if (!styleSheetIds) { |
412 styleSheetIds = []; | 426 styleSheetIds = []; |
413 frameIdToStyleSheetIds[styleSheetHeader.frameId] = styleSheetIds; | 427 frameIdToStyleSheetIds[styleSheetHeader.frameId] = styleSheetIds; |
414 } | 428 } |
415 styleSheetIds.push(styleSheetHeader.id); | 429 styleSheetIds.push(styleSheetHeader.id); |
416 this._styleLoader.reset(); | |
417 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe
etAdded, styleSheetHeader); | 430 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe
etAdded, styleSheetHeader); |
418 }, | 431 }, |
419 | 432 |
420 /** | 433 /** |
421 * @param {!CSSAgent.StyleSheetId} id | 434 * @param {!CSSAgent.StyleSheetId} id |
422 */ | 435 */ |
423 _styleSheetRemoved: function(id) | 436 _styleSheetRemoved: function(id) |
424 { | 437 { |
425 var header = this._styleSheetIdToHeader[id]; | 438 var header = this._styleSheetIdToHeader[id]; |
426 console.assert(header); | 439 console.assert(header); |
427 delete this._styleSheetIdToHeader[id]; | 440 delete this._styleSheetIdToHeader[id]; |
428 var url = header.resourceURL(); | 441 var url = header.resourceURL(); |
429 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url]; | 442 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url]; |
430 frameIdToStyleSheetIds[header.frameId].remove(id); | 443 frameIdToStyleSheetIds[header.frameId].remove(id); |
431 if (!frameIdToStyleSheetIds[header.frameId].length) { | 444 if (!frameIdToStyleSheetIds[header.frameId].length) { |
432 delete frameIdToStyleSheetIds[header.frameId]; | 445 delete frameIdToStyleSheetIds[header.frameId]; |
433 if (!Object.keys(this._styleSheetIdsForURL[url]).length) | 446 if (!Object.keys(this._styleSheetIdsForURL[url]).length) |
434 delete this._styleSheetIdsForURL[url]; | 447 delete this._styleSheetIdsForURL[url]; |
435 } | 448 } |
436 this._styleLoader.reset(); | |
437 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe
etRemoved, header); | 449 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe
etRemoved, header); |
438 }, | 450 }, |
439 | 451 |
440 /** | 452 /** |
441 * @param {string} url | 453 * @param {string} url |
442 * @return {!Array.<!CSSAgent.StyleSheetId>} | 454 * @return {!Array.<!CSSAgent.StyleSheetId>} |
443 */ | 455 */ |
444 styleSheetIdsForURL: function(url) | 456 styleSheetIdsForURL: function(url) |
445 { | 457 { |
446 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url]; | 458 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url]; |
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 * @param {!WebInspector.CSSStyleModel} cssModel | 1528 * @param {!WebInspector.CSSStyleModel} cssModel |
1517 */ | 1529 */ |
1518 WebInspector.CSSStyleModel.ComputedStyleLoader = function(cssModel) | 1530 WebInspector.CSSStyleModel.ComputedStyleLoader = function(cssModel) |
1519 { | 1531 { |
1520 this._cssModel = cssModel; | 1532 this._cssModel = cssModel; |
1521 /** @type {!Object.<*, !Array.<function(?WebInspector.CSSStyleDeclaration)>>
} */ | 1533 /** @type {!Object.<*, !Array.<function(?WebInspector.CSSStyleDeclaration)>>
} */ |
1522 this._nodeIdToCallbackData = {}; | 1534 this._nodeIdToCallbackData = {}; |
1523 } | 1535 } |
1524 | 1536 |
1525 WebInspector.CSSStyleModel.ComputedStyleLoader.prototype = { | 1537 WebInspector.CSSStyleModel.ComputedStyleLoader.prototype = { |
1526 reset: function() | |
1527 { | |
1528 for (var nodeId in this._nodeIdToCallbackData) { | |
1529 var callbacks = this._nodeIdToCallbackData[nodeId]; | |
1530 for (var i = 0; i < callbacks.length; ++i) | |
1531 callbacks[i](null); | |
1532 } | |
1533 this._nodeIdToCallbackData = {}; | |
1534 }, | |
1535 | |
1536 /** | 1538 /** |
1537 * @param {!DOMAgent.NodeId} nodeId | 1539 * @param {!DOMAgent.NodeId} nodeId |
1538 * @param {function(?WebInspector.CSSStyleDeclaration)} userCallback | 1540 * @param {function(?WebInspector.CSSStyleDeclaration)} userCallback |
1539 */ | 1541 */ |
1540 getComputedStyle: function(nodeId, userCallback) | 1542 getComputedStyle: function(nodeId, userCallback) |
1541 { | 1543 { |
1542 if (this._nodeIdToCallbackData[nodeId]) { | 1544 if (this._nodeIdToCallbackData[nodeId]) { |
1543 this._nodeIdToCallbackData[nodeId].push(userCallback); | 1545 this._nodeIdToCallbackData[nodeId].push(userCallback); |
1544 return; | 1546 return; |
1545 } | 1547 } |
(...skipping 21 matching lines...) Expand all Loading... |
1567 for (var i = 0; i < callbacks.length; ++i) | 1569 for (var i = 0; i < callbacks.length; ++i) |
1568 callbacks[i](computedStyle); | 1570 callbacks[i](computedStyle); |
1569 } | 1571 } |
1570 } | 1572 } |
1571 } | 1573 } |
1572 | 1574 |
1573 /** | 1575 /** |
1574 * @type {!WebInspector.CSSStyleModel} | 1576 * @type {!WebInspector.CSSStyleModel} |
1575 */ | 1577 */ |
1576 WebInspector.cssModel; | 1578 WebInspector.cssModel; |
OLD | NEW |