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 23 matching lines...) Expand all Loading... |
34 * @param {!WebInspector.Workspace} workspace | 34 * @param {!WebInspector.Workspace} workspace |
35 */ | 35 */ |
36 WebInspector.CSSStyleModel = function(workspace) | 36 WebInspector.CSSStyleModel = function(workspace) |
37 { | 37 { |
38 this._workspace = workspace; | 38 this._workspace = workspace; |
39 this._pendingCommandsMajorState = []; | 39 this._pendingCommandsMajorState = []; |
40 this._styleLoader = new WebInspector.CSSStyleModel.ComputedStyleLoader(this)
; | 40 this._styleLoader = new WebInspector.CSSStyleModel.ComputedStyleLoader(this)
; |
41 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.UndoRedo
Requested, this._undoRedoRequested, this); | 41 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.UndoRedo
Requested, this._undoRedoRequested, this); |
42 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.UndoRedo
Completed, this._undoRedoCompleted, this); | 42 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.UndoRedo
Completed, this._undoRedoCompleted, this); |
43 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod
el.EventTypes.MainFrameCreatedOrNavigated, this._mainFrameCreatedOrNavigated, th
is); | 43 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod
el.EventTypes.MainFrameCreatedOrNavigated, this._mainFrameCreatedOrNavigated, th
is); |
44 this._namedFlowCollections = {}; | |
45 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.Document
Updated, this._resetNamedFlowCollections, this); | |
46 InspectorBackend.registerCSSDispatcher(new WebInspector.CSSDispatcher(this))
; | 44 InspectorBackend.registerCSSDispatcher(new WebInspector.CSSDispatcher(this))
; |
47 CSSAgent.enable(this._wasEnabled.bind(this)); | 45 CSSAgent.enable(this._wasEnabled.bind(this)); |
48 this._resetStyleSheets(); | 46 this._resetStyleSheets(); |
49 } | 47 } |
50 | 48 |
51 /** | 49 /** |
52 * @param {!Array.<!CSSAgent.RuleMatch>|undefined} matchArray | 50 * @param {!Array.<!CSSAgent.RuleMatch>|undefined} matchArray |
53 */ | 51 */ |
54 WebInspector.CSSStyleModel.parseRuleMatchArrayPayload = function(matchArray) | 52 WebInspector.CSSStyleModel.parseRuleMatchArrayPayload = function(matchArray) |
55 { | 53 { |
56 if (!matchArray) | 54 if (!matchArray) |
57 return []; | 55 return []; |
58 | 56 |
59 var result = []; | 57 var result = []; |
60 for (var i = 0; i < matchArray.length; ++i) | 58 for (var i = 0; i < matchArray.length; ++i) |
61 result.push(WebInspector.CSSRule.parsePayload(matchArray[i].rule, matchA
rray[i].matchingSelectors)); | 59 result.push(WebInspector.CSSRule.parsePayload(matchArray[i].rule, matchA
rray[i].matchingSelectors)); |
62 return result; | 60 return result; |
63 } | 61 } |
64 | 62 |
65 WebInspector.CSSStyleModel.Events = { | 63 WebInspector.CSSStyleModel.Events = { |
66 ModelWasEnabled: "ModelWasEnabled", | 64 ModelWasEnabled: "ModelWasEnabled", |
67 StyleSheetAdded: "StyleSheetAdded", | 65 StyleSheetAdded: "StyleSheetAdded", |
68 StyleSheetChanged: "StyleSheetChanged", | 66 StyleSheetChanged: "StyleSheetChanged", |
69 StyleSheetRemoved: "StyleSheetRemoved", | 67 StyleSheetRemoved: "StyleSheetRemoved", |
70 MediaQueryResultChanged: "MediaQueryResultChanged", | 68 MediaQueryResultChanged: "MediaQueryResultChanged", |
71 NamedFlowCreated: "NamedFlowCreated", | |
72 NamedFlowRemoved: "NamedFlowRemoved", | |
73 RegionLayoutUpdated: "RegionLayoutUpdated", | |
74 RegionOversetChanged: "RegionOversetChanged" | |
75 } | 69 } |
76 | 70 |
77 WebInspector.CSSStyleModel.MediaTypes = ["all", "braille", "embossed", "handheld
", "print", "projection", "screen", "speech", "tty", "tv"]; | 71 WebInspector.CSSStyleModel.MediaTypes = ["all", "braille", "embossed", "handheld
", "print", "projection", "screen", "speech", "tty", "tv"]; |
78 | 72 |
79 WebInspector.CSSStyleModel.prototype = { | 73 WebInspector.CSSStyleModel.prototype = { |
80 /** | 74 /** |
81 * @return {boolean} | 75 * @return {boolean} |
82 */ | 76 */ |
83 isEnabled: function() | 77 isEnabled: function() |
84 { | 78 { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 * @param {!DOMAgent.NodeId} nodeId | 191 * @param {!DOMAgent.NodeId} nodeId |
198 * @param {?Array.<string>|undefined} forcedPseudoClasses | 192 * @param {?Array.<string>|undefined} forcedPseudoClasses |
199 * @param {function()=} userCallback | 193 * @param {function()=} userCallback |
200 */ | 194 */ |
201 forcePseudoState: function(nodeId, forcedPseudoClasses, userCallback) | 195 forcePseudoState: function(nodeId, forcedPseudoClasses, userCallback) |
202 { | 196 { |
203 CSSAgent.forcePseudoState(nodeId, forcedPseudoClasses || [], userCallbac
k); | 197 CSSAgent.forcePseudoState(nodeId, forcedPseudoClasses || [], userCallbac
k); |
204 }, | 198 }, |
205 | 199 |
206 /** | 200 /** |
207 * @param {!DOMAgent.NodeId} documentNodeId | |
208 * @param {function(?WebInspector.NamedFlowCollection)} userCallback | |
209 */ | |
210 getNamedFlowCollectionAsync: function(documentNodeId, userCallback) | |
211 { | |
212 var namedFlowCollection = this._namedFlowCollections[documentNodeId]; | |
213 if (namedFlowCollection) { | |
214 userCallback(namedFlowCollection); | |
215 return; | |
216 } | |
217 | |
218 /** | |
219 * @param {function(?WebInspector.NamedFlowCollection)} userCallback | |
220 * @param {?Protocol.Error} error | |
221 * @param {?Array.<!CSSAgent.NamedFlow>} namedFlowPayload | |
222 * @this {WebInspector.CSSStyleModel} | |
223 */ | |
224 function callback(userCallback, error, namedFlowPayload) | |
225 { | |
226 if (error || !namedFlowPayload) | |
227 userCallback(null); | |
228 else { | |
229 var namedFlowCollection = new WebInspector.NamedFlowCollection(n
amedFlowPayload); | |
230 this._namedFlowCollections[documentNodeId] = namedFlowCollection
; | |
231 userCallback(namedFlowCollection); | |
232 } | |
233 } | |
234 | |
235 CSSAgent.getNamedFlowCollection(documentNodeId, callback.bind(this, user
Callback)); | |
236 }, | |
237 | |
238 /** | |
239 * @param {!DOMAgent.NodeId} documentNodeId | |
240 * @param {string} flowName | |
241 * @param {function(?WebInspector.NamedFlow)} userCallback | |
242 */ | |
243 getFlowByNameAsync: function(documentNodeId, flowName, userCallback) | |
244 { | |
245 var namedFlowCollection = this._namedFlowCollections[documentNodeId]; | |
246 if (namedFlowCollection) { | |
247 userCallback(namedFlowCollection.flowByName(flowName)); | |
248 return; | |
249 } | |
250 | |
251 /** | |
252 * @param {function(?WebInspector.NamedFlow)} userCallback | |
253 * @param {?WebInspector.NamedFlowCollection} namedFlowCollection | |
254 */ | |
255 function callback(userCallback, namedFlowCollection) | |
256 { | |
257 if (!namedFlowCollection) | |
258 userCallback(null); | |
259 else | |
260 userCallback(namedFlowCollection.flowByName(flowName)); | |
261 } | |
262 | |
263 this.getNamedFlowCollectionAsync(documentNodeId, callback.bind(this, use
rCallback)); | |
264 }, | |
265 | |
266 /** | |
267 * @param {!CSSAgent.CSSRuleId} ruleId | 201 * @param {!CSSAgent.CSSRuleId} ruleId |
268 * @param {!DOMAgent.NodeId} nodeId | 202 * @param {!DOMAgent.NodeId} nodeId |
269 * @param {string} newSelector | 203 * @param {string} newSelector |
270 * @param {function(!WebInspector.CSSRule)} successCallback | 204 * @param {function(!WebInspector.CSSRule)} successCallback |
271 * @param {function()} failureCallback | 205 * @param {function()} failureCallback |
272 */ | 206 */ |
273 setRuleSelector: function(ruleId, nodeId, newSelector, successCallback, fail
ureCallback) | 207 setRuleSelector: function(ruleId, nodeId, newSelector, successCallback, fail
ureCallback) |
274 { | 208 { |
275 /** | 209 /** |
276 * @param {!DOMAgent.NodeId} nodeId | 210 * @param {!DOMAgent.NodeId} nodeId |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 */ | 417 */ |
484 styleSheetIdsByFrameIdForURL: function(url) | 418 styleSheetIdsByFrameIdForURL: function(url) |
485 { | 419 { |
486 var styleSheetIdsForFrame = this._styleSheetIdsForURL[url]; | 420 var styleSheetIdsForFrame = this._styleSheetIdsForURL[url]; |
487 if (!styleSheetIdsForFrame) | 421 if (!styleSheetIdsForFrame) |
488 return {}; | 422 return {}; |
489 return styleSheetIdsForFrame; | 423 return styleSheetIdsForFrame; |
490 }, | 424 }, |
491 | 425 |
492 /** | 426 /** |
493 * @param {!CSSAgent.NamedFlow} namedFlowPayload | |
494 */ | |
495 _namedFlowCreated: function(namedFlowPayload) | |
496 { | |
497 var namedFlow = WebInspector.NamedFlow.parsePayload(namedFlowPayload); | |
498 var namedFlowCollection = this._namedFlowCollections[namedFlow.documentN
odeId]; | |
499 | |
500 if (!namedFlowCollection) | |
501 return; | |
502 | |
503 namedFlowCollection._appendNamedFlow(namedFlow); | |
504 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.NamedFlo
wCreated, namedFlow); | |
505 }, | |
506 | |
507 /** | |
508 * @param {!DOMAgent.NodeId} documentNodeId | |
509 * @param {string} flowName | |
510 */ | |
511 _namedFlowRemoved: function(documentNodeId, flowName) | |
512 { | |
513 var namedFlowCollection = this._namedFlowCollections[documentNodeId]; | |
514 | |
515 if (!namedFlowCollection) | |
516 return; | |
517 | |
518 namedFlowCollection._removeNamedFlow(flowName); | |
519 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.NamedFlo
wRemoved, { documentNodeId: documentNodeId, flowName: flowName }); | |
520 }, | |
521 | |
522 /** | |
523 * @param {!CSSAgent.NamedFlow} namedFlowPayload | |
524 */ | |
525 _regionLayoutUpdated: function(namedFlowPayload) | |
526 { | |
527 var namedFlow = WebInspector.NamedFlow.parsePayload(namedFlowPayload); | |
528 var namedFlowCollection = this._namedFlowCollections[namedFlow.documentN
odeId]; | |
529 | |
530 if (!namedFlowCollection) | |
531 return; | |
532 | |
533 namedFlowCollection._appendNamedFlow(namedFlow); | |
534 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.RegionLa
youtUpdated, namedFlow); | |
535 }, | |
536 | |
537 /** | |
538 * @param {!CSSAgent.NamedFlow} namedFlowPayload | |
539 */ | |
540 _regionOversetChanged: function(namedFlowPayload) | |
541 { | |
542 var namedFlow = WebInspector.NamedFlow.parsePayload(namedFlowPayload); | |
543 var namedFlowCollection = this._namedFlowCollections[namedFlow.documentN
odeId]; | |
544 | |
545 if (!namedFlowCollection) | |
546 return; | |
547 | |
548 namedFlowCollection._appendNamedFlow(namedFlow); | |
549 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.RegionOv
ersetChanged, namedFlow); | |
550 }, | |
551 | |
552 /** | |
553 * @param {!CSSAgent.StyleSheetId} styleSheetId | 427 * @param {!CSSAgent.StyleSheetId} styleSheetId |
554 * @param {string} newText | 428 * @param {string} newText |
555 * @param {boolean} majorChange | 429 * @param {boolean} majorChange |
556 * @param {function(?Protocol.Error)} userCallback | 430 * @param {function(?Protocol.Error)} userCallback |
557 */ | 431 */ |
558 setStyleSheetText: function(styleSheetId, newText, majorChange, userCallback
) | 432 setStyleSheetText: function(styleSheetId, newText, majorChange, userCallback
) |
559 { | 433 { |
560 var header = this._styleSheetIdToHeader[styleSheetId]; | 434 var header = this._styleSheetIdToHeader[styleSheetId]; |
561 console.assert(header); | 435 console.assert(header); |
562 this._pendingCommandsMajorState.push(majorChange); | 436 this._pendingCommandsMajorState.push(majorChange); |
563 header.setContent(newText, callback.bind(this)); | 437 header.setContent(newText, callback.bind(this)); |
564 | 438 |
565 /** | 439 /** |
566 * @param {?Protocol.Error} error | 440 * @param {?Protocol.Error} error |
567 * @this {WebInspector.CSSStyleModel} | 441 * @this {WebInspector.CSSStyleModel} |
568 */ | 442 */ |
569 function callback(error) | 443 function callback(error) |
570 { | 444 { |
571 this._pendingCommandsMajorState.pop(); | 445 this._pendingCommandsMajorState.pop(); |
572 if (!error && majorChange) | 446 if (!error && majorChange) |
573 WebInspector.domAgent.markUndoableState(); | 447 WebInspector.domAgent.markUndoableState(); |
574 | 448 |
575 if (!error && userCallback) | 449 if (!error && userCallback) |
576 userCallback(error); | 450 userCallback(error); |
577 } | 451 } |
578 }, | 452 }, |
579 | 453 |
580 _undoRedoRequested: function() | 454 _undoRedoRequested: function() |
581 { | 455 { |
582 this._pendingCommandsMajorState.push(true); | 456 this._pendingCommandsMajorState.push(true); |
583 }, | 457 }, |
584 | 458 |
585 _undoRedoCompleted: function() | 459 _undoRedoCompleted: function() |
586 { | 460 { |
587 this._pendingCommandsMajorState.pop(); | 461 this._pendingCommandsMajorState.pop(); |
588 }, | 462 }, |
589 | 463 |
590 _mainFrameCreatedOrNavigated: function() | 464 _mainFrameCreatedOrNavigated: function() |
591 { | 465 { |
592 this._resetStyleSheets(); | 466 this._resetStyleSheets(); |
593 }, | 467 }, |
594 | 468 |
595 _resetStyleSheets: function() | 469 _resetStyleSheets: function() |
596 { | 470 { |
597 /** @type {!Object.<string, !Object.<!PageAgent.FrameId, !Array.<!CSSAge
nt.StyleSheetId>>>} */ | 471 /** @type {!Object.<string, !Object.<!PageAgent.FrameId, !Array.<!CSSAge
nt.StyleSheetId>>>} */ |
598 this._styleSheetIdsForURL = {}; | 472 this._styleSheetIdsForURL = {}; |
599 /** @type {!Object.<!CSSAgent.StyleSheetId, !WebInspector.CSSStyleSheetH
eader>} */ | 473 /** @type {!Object.<!CSSAgent.StyleSheetId, !WebInspector.CSSStyleSheetH
eader>} */ |
600 this._styleSheetIdToHeader = {}; | 474 this._styleSheetIdToHeader = {}; |
601 }, | 475 }, |
602 | 476 |
603 _resetNamedFlowCollections: function() | |
604 { | |
605 this._namedFlowCollections = {}; | |
606 }, | |
607 | |
608 updateLocations: function() | 477 updateLocations: function() |
609 { | 478 { |
610 var headers = Object.values(this._styleSheetIdToHeader); | 479 var headers = Object.values(this._styleSheetIdToHeader); |
611 for (var i = 0; i < headers.length; ++i) | 480 for (var i = 0; i < headers.length; ++i) |
612 headers[i].updateLocations(); | 481 headers[i].updateLocations(); |
613 }, | 482 }, |
614 | 483 |
615 /** | 484 /** |
616 * @param {?CSSAgent.StyleSheetId} styleSheetId | 485 * @param {?CSSAgent.StyleSheetId} styleSheetId |
617 * @param {!WebInspector.CSSLocation} rawLocation | 486 * @param {!WebInspector.CSSLocation} rawLocation |
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1663 this._cssModel._styleSheetAdded(header); | 1532 this._cssModel._styleSheetAdded(header); |
1664 }, | 1533 }, |
1665 | 1534 |
1666 /** | 1535 /** |
1667 * @param {!CSSAgent.StyleSheetId} id | 1536 * @param {!CSSAgent.StyleSheetId} id |
1668 */ | 1537 */ |
1669 styleSheetRemoved: function(id) | 1538 styleSheetRemoved: function(id) |
1670 { | 1539 { |
1671 this._cssModel._styleSheetRemoved(id); | 1540 this._cssModel._styleSheetRemoved(id); |
1672 }, | 1541 }, |
1673 | |
1674 /** | |
1675 * @param {!CSSAgent.NamedFlow} namedFlowPayload | |
1676 */ | |
1677 namedFlowCreated: function(namedFlowPayload) | |
1678 { | |
1679 this._cssModel._namedFlowCreated(namedFlowPayload); | |
1680 }, | |
1681 | |
1682 /** | |
1683 * @param {!DOMAgent.NodeId} documentNodeId | |
1684 * @param {string} flowName | |
1685 */ | |
1686 namedFlowRemoved: function(documentNodeId, flowName) | |
1687 { | |
1688 this._cssModel._namedFlowRemoved(documentNodeId, flowName); | |
1689 }, | |
1690 | |
1691 /** | |
1692 * @param {!CSSAgent.NamedFlow} namedFlowPayload | |
1693 */ | |
1694 regionLayoutUpdated: function(namedFlowPayload) | |
1695 { | |
1696 this._cssModel._regionLayoutUpdated(namedFlowPayload); | |
1697 }, | |
1698 | |
1699 /** | |
1700 * @param {!CSSAgent.NamedFlow} namedFlowPayload | |
1701 */ | |
1702 regionOversetChanged: function(namedFlowPayload) | |
1703 { | |
1704 this._cssModel._regionOversetChanged(namedFlowPayload); | |
1705 } | |
1706 } | 1542 } |
1707 | 1543 |
1708 /** | 1544 /** |
1709 * @constructor | |
1710 * @param {!CSSAgent.NamedFlow} payload | |
1711 */ | |
1712 WebInspector.NamedFlow = function(payload) | |
1713 { | |
1714 this.documentNodeId = payload.documentNodeId; | |
1715 this.name = payload.name; | |
1716 this.overset = payload.overset; | |
1717 this.content = payload.content; | |
1718 this.regions = payload.regions; | |
1719 } | |
1720 | |
1721 /** | |
1722 * @param {!CSSAgent.NamedFlow} payload | |
1723 * @return {!WebInspector.NamedFlow} | |
1724 */ | |
1725 WebInspector.NamedFlow.parsePayload = function(payload) | |
1726 { | |
1727 return new WebInspector.NamedFlow(payload); | |
1728 } | |
1729 | |
1730 /** | |
1731 * @constructor | |
1732 * @param {!Array.<!CSSAgent.NamedFlow>} payload | |
1733 */ | |
1734 WebInspector.NamedFlowCollection = function(payload) | |
1735 { | |
1736 /** @type {!Object.<string, !WebInspector.NamedFlow>} */ | |
1737 this.namedFlowMap = {}; | |
1738 | |
1739 for (var i = 0; i < payload.length; ++i) { | |
1740 var namedFlow = WebInspector.NamedFlow.parsePayload(payload[i]); | |
1741 this.namedFlowMap[namedFlow.name] = namedFlow; | |
1742 } | |
1743 } | |
1744 | |
1745 WebInspector.NamedFlowCollection.prototype = { | |
1746 /** | |
1747 * @param {!WebInspector.NamedFlow} namedFlow | |
1748 */ | |
1749 _appendNamedFlow: function(namedFlow) | |
1750 { | |
1751 this.namedFlowMap[namedFlow.name] = namedFlow; | |
1752 }, | |
1753 | |
1754 /** | |
1755 * @param {string} flowName | |
1756 */ | |
1757 _removeNamedFlow: function(flowName) | |
1758 { | |
1759 delete this.namedFlowMap[flowName]; | |
1760 }, | |
1761 | |
1762 /** | |
1763 * @param {string} flowName | |
1764 * @return {?WebInspector.NamedFlow} | |
1765 */ | |
1766 flowByName: function(flowName) | |
1767 { | |
1768 var namedFlow = this.namedFlowMap[flowName]; | |
1769 | |
1770 if (!namedFlow) | |
1771 return null; | |
1772 return namedFlow; | |
1773 } | |
1774 } | |
1775 | |
1776 /** | |
1777 * @constructor | 1545 * @constructor |
1778 * @param {!WebInspector.CSSStyleModel} cssModel | 1546 * @param {!WebInspector.CSSStyleModel} cssModel |
1779 */ | 1547 */ |
1780 WebInspector.CSSStyleModel.ComputedStyleLoader = function(cssModel) | 1548 WebInspector.CSSStyleModel.ComputedStyleLoader = function(cssModel) |
1781 { | 1549 { |
1782 this._cssModel = cssModel; | 1550 this._cssModel = cssModel; |
1783 /** @type {!Object.<*, !Array.<function(?WebInspector.CSSStyleDeclaration)>>
} */ | 1551 /** @type {!Object.<*, !Array.<function(?WebInspector.CSSStyleDeclaration)>>
} */ |
1784 this._nodeIdToCallbackData = {}; | 1552 this._nodeIdToCallbackData = {}; |
1785 } | 1553 } |
1786 | 1554 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1829 for (var i = 0; i < callbacks.length; ++i) | 1597 for (var i = 0; i < callbacks.length; ++i) |
1830 callbacks[i](computedStyle); | 1598 callbacks[i](computedStyle); |
1831 } | 1599 } |
1832 } | 1600 } |
1833 } | 1601 } |
1834 | 1602 |
1835 /** | 1603 /** |
1836 * @type {!WebInspector.CSSStyleModel} | 1604 * @type {!WebInspector.CSSStyleModel} |
1837 */ | 1605 */ |
1838 WebInspector.cssModel; | 1606 WebInspector.cssModel; |
OLD | NEW |