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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 this._resourceTreeModel.addEventListener( | 47 this._resourceTreeModel.addEventListener( |
48 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._resetStyleSheet
s, this); | 48 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._resetStyleSheet
s, this); |
49 } | 49 } |
50 target.registerCSSDispatcher(new SDK.CSSDispatcher(this)); | 50 target.registerCSSDispatcher(new SDK.CSSDispatcher(this)); |
51 this._enable(); | 51 this._enable(); |
52 /** @type {!Map.<string, !SDK.CSSStyleSheetHeader>} */ | 52 /** @type {!Map.<string, !SDK.CSSStyleSheetHeader>} */ |
53 this._styleSheetIdToHeader = new Map(); | 53 this._styleSheetIdToHeader = new Map(); |
54 /** @type {!Map.<string, !Object.<!Protocol.Page.FrameId, !Array.<!Protocol.
CSS.StyleSheetId>>>} */ | 54 /** @type {!Map.<string, !Object.<!Protocol.Page.FrameId, !Array.<!Protocol.
CSS.StyleSheetId>>>} */ |
55 this._styleSheetIdsForURL = new Map(); | 55 this._styleSheetIdsForURL = new Map(); |
56 | 56 |
| 57 /** @type {!Multimap<string, function(!SDK.CSSStyleSheetHeader)>} */ |
| 58 this._styleSheetChangeSubscribers = new Multimap(); |
| 59 |
57 /** @type {!Map.<!SDK.CSSStyleSheetHeader, !Promise<?string>>} */ | 60 /** @type {!Map.<!SDK.CSSStyleSheetHeader, !Promise<?string>>} */ |
58 this._originalStyleSheetText = new Map(); | 61 this._originalStyleSheetText = new Map(); |
59 | 62 |
60 this._sourceMapManager.setEnabled(Common.moduleSetting('cssSourceMapsEnabled
').get()); | 63 this._sourceMapManager.setEnabled(Common.moduleSetting('cssSourceMapsEnabled
').get()); |
61 Common.moduleSetting('cssSourceMapsEnabled') | 64 Common.moduleSetting('cssSourceMapsEnabled') |
62 .addChangeListener(event => this._sourceMapManager.setEnabled(/** @type
{boolean} */ (event.data))); | 65 .addChangeListener(event => this._sourceMapManager.setEnabled(/** @type
{boolean} */ (event.data))); |
63 } | 66 } |
64 | 67 |
65 /** | 68 /** |
66 * @return {!SDK.SourceMapManager<!SDK.CSSStyleSheetHeader>} | 69 * @return {!SDK.SourceMapManager<!SDK.CSSStyleSheetHeader>} |
(...skipping 17 matching lines...) Expand all Loading... |
84 if (sourceURLLineIndex === -1) | 87 if (sourceURLLineIndex === -1) |
85 return text; | 88 return text; |
86 var sourceURLLine = text.substr(sourceURLLineIndex + 1).split('\n', 1)[0]; | 89 var sourceURLLine = text.substr(sourceURLLineIndex + 1).split('\n', 1)[0]; |
87 var sourceURLRegex = /[\040\t]*\/\*[#@] sourceURL=[\040\t]*([^\s]*)[\040\t]*
\*\/[\040\t]*$/; | 90 var sourceURLRegex = /[\040\t]*\/\*[#@] sourceURL=[\040\t]*([^\s]*)[\040\t]*
\*\/[\040\t]*$/; |
88 if (sourceURLLine.search(sourceURLRegex) === -1) | 91 if (sourceURLLine.search(sourceURLRegex) === -1) |
89 return text; | 92 return text; |
90 return text.substr(0, sourceURLLineIndex) + text.substr(sourceURLLineIndex +
sourceURLLine.length + 1); | 93 return text.substr(0, sourceURLLineIndex) + text.substr(sourceURLLineIndex +
sourceURLLine.length + 1); |
91 } | 94 } |
92 | 95 |
93 /** | 96 /** |
| 97 * @param {string} headerId |
| 98 * @param {function(!SDK.CSSStyleSheetHeader)} callback |
| 99 */ |
| 100 subscribeToStyleSheetChanged(headerId, callback) { |
| 101 this._styleSheetChangeSubscribers.set(headerId, callback); |
| 102 } |
| 103 |
| 104 /** |
| 105 * @param {string} headerId |
| 106 * @param {function(!SDK.CSSStyleSheetHeader)} callback |
| 107 */ |
| 108 unsubscribeFromStyleSheetChanged(headerId, callback) { |
| 109 this._styleSheetChangeSubscribers.delete(headerId, callback); |
| 110 } |
| 111 |
| 112 /** |
94 * @return {!SDK.DOMModel} | 113 * @return {!SDK.DOMModel} |
95 */ | 114 */ |
96 domModel() { | 115 domModel() { |
97 return this._domModel; | 116 return this._domModel; |
98 } | 117 } |
99 | 118 |
100 /** | 119 /** |
101 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | 120 * @param {!Protocol.CSS.StyleSheetId} styleSheetId |
102 * @param {!TextUtils.TextRange} range | 121 * @param {!TextUtils.TextRange} range |
103 * @param {string} text | 122 * @param {string} text |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 */ | 557 */ |
539 styleSheetHeaders() { | 558 styleSheetHeaders() { |
540 return this._styleSheetIdToHeader.valuesArray(); | 559 return this._styleSheetIdToHeader.valuesArray(); |
541 } | 560 } |
542 | 561 |
543 /** | 562 /** |
544 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | 563 * @param {!Protocol.CSS.StyleSheetId} styleSheetId |
545 * @param {!SDK.CSSModel.Edit=} edit | 564 * @param {!SDK.CSSModel.Edit=} edit |
546 */ | 565 */ |
547 _fireStyleSheetChanged(styleSheetId, edit) { | 566 _fireStyleSheetChanged(styleSheetId, edit) { |
| 567 if (this._styleSheetChangeSubscribers.has(styleSheetId)) { |
| 568 var header = this._styleSheetIdToHeader.get(styleSheetId); |
| 569 var subscribers = Array.from(this._styleSheetChangeSubscribers.get(styleSh
eetId)); |
| 570 if (header && subscribers) |
| 571 subscribers.forEach(subscriber => subscriber.call(null, header)); |
| 572 } |
548 this.dispatchEventToListeners(SDK.CSSModel.Events.StyleSheetChanged, {styleS
heetId: styleSheetId, edit: edit}); | 573 this.dispatchEventToListeners(SDK.CSSModel.Events.StyleSheetChanged, {styleS
heetId: styleSheetId, edit: edit}); |
549 } | 574 } |
550 | 575 |
551 /** | 576 /** |
552 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | 577 * @param {!Protocol.CSS.StyleSheetId} styleSheetId |
553 * @return {!Promise<?string>} | 578 * @return {!Promise<?string>} |
554 */ | 579 */ |
555 _ensureOriginalStyleSheetText(styleSheetId) { | 580 _ensureOriginalStyleSheetText(styleSheetId) { |
556 var header = this.styleSheetHeaderForId(styleSheetId); | 581 var header = this.styleSheetHeaderForId(styleSheetId); |
557 if (!header) | 582 if (!header) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 | 627 |
603 /** | 628 /** |
604 * @param {!Protocol.CSS.StyleSheetId} id | 629 * @param {!Protocol.CSS.StyleSheetId} id |
605 */ | 630 */ |
606 _styleSheetRemoved(id) { | 631 _styleSheetRemoved(id) { |
607 var header = this._styleSheetIdToHeader.get(id); | 632 var header = this._styleSheetIdToHeader.get(id); |
608 console.assert(header); | 633 console.assert(header); |
609 if (!header) | 634 if (!header) |
610 return; | 635 return; |
611 this._styleSheetIdToHeader.remove(id); | 636 this._styleSheetIdToHeader.remove(id); |
| 637 this._styleSheetChangeSubscribers.deleteAll(id); |
612 var url = header.resourceURL(); | 638 var url = header.resourceURL(); |
613 var frameIdToStyleSheetIds = /** @type {!Object.<!Protocol.Page.FrameId, !Ar
ray.<!Protocol.CSS.StyleSheetId>>} */ ( | 639 var frameIdToStyleSheetIds = /** @type {!Object.<!Protocol.Page.FrameId, !Ar
ray.<!Protocol.CSS.StyleSheetId>>} */ ( |
614 this._styleSheetIdsForURL.get(url)); | 640 this._styleSheetIdsForURL.get(url)); |
615 console.assert(frameIdToStyleSheetIds, 'No frameId to styleSheetId map is av
ailable for given style sheet URL.'); | 641 console.assert(frameIdToStyleSheetIds, 'No frameId to styleSheetId map is av
ailable for given style sheet URL.'); |
616 frameIdToStyleSheetIds[header.frameId].remove(id); | 642 frameIdToStyleSheetIds[header.frameId].remove(id); |
617 if (!frameIdToStyleSheetIds[header.frameId].length) { | 643 if (!frameIdToStyleSheetIds[header.frameId].length) { |
618 delete frameIdToStyleSheetIds[header.frameId]; | 644 delete frameIdToStyleSheetIds[header.frameId]; |
619 if (!Object.keys(frameIdToStyleSheetIds).length) | 645 if (!Object.keys(frameIdToStyleSheetIds).length) |
620 this._styleSheetIdsForURL.remove(url); | 646 this._styleSheetIdsForURL.remove(url); |
621 } | 647 } |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 SDK.CSSModel.InlineStyleResult = class { | 936 SDK.CSSModel.InlineStyleResult = class { |
911 /** | 937 /** |
912 * @param {?SDK.CSSStyleDeclaration} inlineStyle | 938 * @param {?SDK.CSSStyleDeclaration} inlineStyle |
913 * @param {?SDK.CSSStyleDeclaration} attributesStyle | 939 * @param {?SDK.CSSStyleDeclaration} attributesStyle |
914 */ | 940 */ |
915 constructor(inlineStyle, attributesStyle) { | 941 constructor(inlineStyle, attributesStyle) { |
916 this.inlineStyle = inlineStyle; | 942 this.inlineStyle = inlineStyle; |
917 this.attributesStyle = attributesStyle; | 943 this.attributesStyle = attributesStyle; |
918 } | 944 } |
919 }; | 945 }; |
OLD | NEW |