| 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 29 matching lines...) Expand all Loading... |
| 40 this._agent = target.cssAgent(); | 40 this._agent = target.cssAgent(); |
| 41 this._styleLoader = new WebInspector.CSSModel.ComputedStyleLoader(this); | 41 this._styleLoader = new WebInspector.CSSModel.ComputedStyleLoader(this); |
| 42 target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Eve
ntTypes.MainFrameNavigated, this._mainFrameNavigated, this); | 42 target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Eve
ntTypes.MainFrameNavigated, this._mainFrameNavigated, this); |
| 43 target.registerCSSDispatcher(new WebInspector.CSSDispatcher(this)); | 43 target.registerCSSDispatcher(new WebInspector.CSSDispatcher(this)); |
| 44 this._agent.enable().then(this._wasEnabled.bind(this)); | 44 this._agent.enable().then(this._wasEnabled.bind(this)); |
| 45 /** @type {!Map.<string, !WebInspector.CSSStyleSheetHeader>} */ | 45 /** @type {!Map.<string, !WebInspector.CSSStyleSheetHeader>} */ |
| 46 this._styleSheetIdToHeader = new Map(); | 46 this._styleSheetIdToHeader = new Map(); |
| 47 /** @type {!Map.<string, !Object.<!PageAgent.FrameId, !Array.<!CSSAgent.Styl
eSheetId>>>} */ | 47 /** @type {!Map.<string, !Object.<!PageAgent.FrameId, !Array.<!CSSAgent.Styl
eSheetId>>>} */ |
| 48 this._styleSheetIdsForURL = new Map(); | 48 this._styleSheetIdsForURL = new Map(); |
| 49 | 49 |
| 50 /** @type {!Map.<!WebInspector.CSSStyleSheetHeader, !Promise<string>>} */ |
| 51 this._originalStyleSheetText = new Map(); |
| 52 |
| 50 /** @type {!Multimap<string, !CSSAgent.StyleSheetId>} */ | 53 /** @type {!Multimap<string, !CSSAgent.StyleSheetId>} */ |
| 51 this._sourceMapLoadingStyleSheetsIds = new Multimap(); | 54 this._sourceMapLoadingStyleSheetsIds = new Multimap(); |
| 52 | 55 |
| 53 /** @type {!Map<string, !WebInspector.SourceMap>} */ | 56 /** @type {!Map<string, !WebInspector.SourceMap>} */ |
| 54 this._sourceMapByURL = new Map(); | 57 this._sourceMapByURL = new Map(); |
| 55 /** @type {!Multimap<string, !WebInspector.CSSStyleSheetHeader>} */ | 58 /** @type {!Multimap<string, !WebInspector.CSSStyleSheetHeader>} */ |
| 56 this._sourceMapURLToHeaders = new Multimap(); | 59 this._sourceMapURLToHeaders = new Multimap(); |
| 57 WebInspector.moduleSetting("cssSourceMapsEnabled").addChangeListener(this._t
oggleSourceMapSupport, this); | 60 WebInspector.moduleSetting("cssSourceMapsEnabled").addChangeListener(this._t
oggleSourceMapSupport, this); |
| 58 } | 61 } |
| 59 | 62 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 this._domModel.markUndoableState(); | 381 this._domModel.markUndoableState(); |
| 379 for (var i = 0; i < ranges.length; ++i) { | 382 for (var i = 0; i < ranges.length; ++i) { |
| 380 var edit = new WebInspector.CSSModel.Edit(styleSheetIds[i], rang
es[i], texts[i], stylePayloads[i]); | 383 var edit = new WebInspector.CSSModel.Edit(styleSheetIds[i], rang
es[i], texts[i], stylePayloads[i]); |
| 381 this._fireStyleSheetChanged(styleSheetIds[i], edit); | 384 this._fireStyleSheetChanged(styleSheetIds[i], edit); |
| 382 } | 385 } |
| 383 return true; | 386 return true; |
| 384 } | 387 } |
| 385 | 388 |
| 386 console.assert(styleSheetIds.length === ranges.length && ranges.length =
== texts.length, "Array lengths must be equal"); | 389 console.assert(styleSheetIds.length === ranges.length && ranges.length =
== texts.length, "Array lengths must be equal"); |
| 387 var edits = []; | 390 var edits = []; |
| 391 var ensureContentPromises = []; |
| 388 for (var i = 0; i < styleSheetIds.length; ++i) { | 392 for (var i = 0; i < styleSheetIds.length; ++i) { |
| 389 edits.push({ | 393 edits.push({ |
| 390 styleSheetId: styleSheetIds[i], | 394 styleSheetId: styleSheetIds[i], |
| 391 range: ranges[i].serializeToObject(), | 395 range: ranges[i].serializeToObject(), |
| 392 text: texts[i] | 396 text: texts[i] |
| 393 }); | 397 }); |
| 398 ensureContentPromises.push(this._ensureOriginalStyleSheetText(styleS
heetIds[i])); |
| 394 } | 399 } |
| 395 | 400 |
| 396 return this._agent.setStyleTexts(edits, parsePayload.bind(this)) | 401 return Promise.all(ensureContentPromises) |
| 402 .then(() => this._agent.setStyleTexts(edits, parsePayload.bind(this)
)) |
| 397 .catchException(false); | 403 .catchException(false); |
| 398 }, | 404 }, |
| 399 | 405 |
| 400 /** | 406 /** |
| 401 * @param {!CSSAgent.StyleSheetId} styleSheetId | 407 * @param {!CSSAgent.StyleSheetId} styleSheetId |
| 402 * @param {!WebInspector.TextRange} range | 408 * @param {!WebInspector.TextRange} range |
| 403 * @param {string} text | 409 * @param {string} text |
| 404 * @return {!Promise<boolean>} | 410 * @return {!Promise<boolean>} |
| 405 */ | 411 */ |
| 406 setSelectorText: function(styleSheetId, range, text) | 412 setSelectorText: function(styleSheetId, range, text) |
| 407 { | 413 { |
| 408 /** | 414 /** |
| 409 * @param {?Protocol.Error} error | 415 * @param {?Protocol.Error} error |
| 410 * @param {?CSSAgent.SelectorList} selectorPayload | 416 * @param {?CSSAgent.SelectorList} selectorPayload |
| 411 * @return {boolean} | 417 * @return {boolean} |
| 412 * @this {WebInspector.CSSModel} | 418 * @this {WebInspector.CSSModel} |
| 413 */ | 419 */ |
| 414 function callback(error, selectorPayload) | 420 function callback(error, selectorPayload) |
| 415 { | 421 { |
| 416 if (error || !selectorPayload) | 422 if (error || !selectorPayload) |
| 417 return false; | 423 return false; |
| 418 this._domModel.markUndoableState(); | 424 this._domModel.markUndoableState(); |
| 419 var edit = new WebInspector.CSSModel.Edit(styleSheetId, range, text,
selectorPayload); | 425 var edit = new WebInspector.CSSModel.Edit(styleSheetId, range, text,
selectorPayload); |
| 420 this._fireStyleSheetChangedAndDetach(styleSheetId, edit); | 426 this._fireStyleSheetChangedAndDetach(styleSheetId, edit); |
| 421 return true; | 427 return true; |
| 422 } | 428 } |
| 423 | 429 |
| 424 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Sty
leRuleEdited); | 430 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Sty
leRuleEdited); |
| 425 return this._agent.setRuleSelector(styleSheetId, range, text, callback.b
ind(this)) | 431 return this._ensureOriginalStyleSheetText(styleSheetId) |
| 432 .then(() => this._agent.setRuleSelector(styleSheetId, range, text, c
allback.bind(this))) |
| 426 .catchException(false); | 433 .catchException(false); |
| 427 }, | 434 }, |
| 428 | 435 |
| 429 /** | 436 /** |
| 430 * @param {!CSSAgent.StyleSheetId} styleSheetId | 437 * @param {!CSSAgent.StyleSheetId} styleSheetId |
| 431 * @param {!WebInspector.TextRange} range | 438 * @param {!WebInspector.TextRange} range |
| 432 * @param {string} text | 439 * @param {string} text |
| 433 * @return {!Promise<boolean>} | 440 * @return {!Promise<boolean>} |
| 434 */ | 441 */ |
| 435 setKeyframeKey: function(styleSheetId, range, text) | 442 setKeyframeKey: function(styleSheetId, range, text) |
| 436 { | 443 { |
| 437 /** | 444 /** |
| 438 * @param {?Protocol.Error} error | 445 * @param {?Protocol.Error} error |
| 439 * @param {!CSSAgent.Value} payload | 446 * @param {!CSSAgent.Value} payload |
| 440 * @return {boolean} | 447 * @return {boolean} |
| 441 * @this {WebInspector.CSSModel} | 448 * @this {WebInspector.CSSModel} |
| 442 */ | 449 */ |
| 443 function callback(error, payload) | 450 function callback(error, payload) |
| 444 { | 451 { |
| 445 if (error || !payload) | 452 if (error || !payload) |
| 446 return false; | 453 return false; |
| 447 this._domModel.markUndoableState(); | 454 this._domModel.markUndoableState(); |
| 448 var edit = new WebInspector.CSSModel.Edit(styleSheetId, range, text,
payload); | 455 var edit = new WebInspector.CSSModel.Edit(styleSheetId, range, text,
payload); |
| 449 this._fireStyleSheetChangedAndDetach(styleSheetId, edit); | 456 this._fireStyleSheetChangedAndDetach(styleSheetId, edit); |
| 450 return true; | 457 return true; |
| 451 } | 458 } |
| 452 | 459 |
| 453 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Sty
leRuleEdited); | 460 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Sty
leRuleEdited); |
| 454 return this._agent.setKeyframeKey(styleSheetId, range, text, callback.bi
nd(this)) | 461 return this._ensureOriginalStyleSheetText(styleSheetId) |
| 462 .then(() => this._agent.setKeyframeKey(styleSheetId, range, text, ca
llback.bind(this))) |
| 455 .catchException(false); | 463 .catchException(false); |
| 456 }, | 464 }, |
| 457 | 465 |
| 458 /** | 466 /** |
| 459 * @return {!Promise.<!Array.<!WebInspector.CSSMedia>>} | 467 * @return {!Promise.<!Array.<!WebInspector.CSSMedia>>} |
| 460 */ | 468 */ |
| 461 mediaQueriesPromise: function() | 469 mediaQueriesPromise: function() |
| 462 { | 470 { |
| 463 /** | 471 /** |
| 464 * @param {?Protocol.Error} error | 472 * @param {?Protocol.Error} error |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 { | 685 { |
| 678 if (!mediaPayload) | 686 if (!mediaPayload) |
| 679 return false; | 687 return false; |
| 680 this._domModel.markUndoableState(); | 688 this._domModel.markUndoableState(); |
| 681 var edit = new WebInspector.CSSModel.Edit(styleSheetId, range, newMe
diaText, mediaPayload); | 689 var edit = new WebInspector.CSSModel.Edit(styleSheetId, range, newMe
diaText, mediaPayload); |
| 682 this._fireStyleSheetChangedAndDetach(styleSheetId, edit); | 690 this._fireStyleSheetChangedAndDetach(styleSheetId, edit); |
| 683 return true; | 691 return true; |
| 684 } | 692 } |
| 685 | 693 |
| 686 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Sty
leRuleEdited); | 694 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Sty
leRuleEdited); |
| 687 return this._agent.setMediaText(styleSheetId, range, newMediaText, parse
Payload.bind(this)) | 695 return this._ensureOriginalStyleSheetText(styleSheetId) |
| 696 .then(() => this._agent.setMediaText(styleSheetId, range, newMediaTe
xt, parsePayload.bind(this))) |
| 688 .catchException(false); | 697 .catchException(false); |
| 689 }, | 698 }, |
| 690 | 699 |
| 691 /** | 700 /** |
| 692 * @param {!CSSAgent.StyleSheetId} styleSheetId | 701 * @param {!CSSAgent.StyleSheetId} styleSheetId |
| 693 * @param {string} ruleText | 702 * @param {string} ruleText |
| 694 * @param {!WebInspector.TextRange} ruleLocation | 703 * @param {!WebInspector.TextRange} ruleLocation |
| 695 * @return {!Promise<?WebInspector.CSSStyleRule>} | 704 * @return {!Promise<?WebInspector.CSSStyleRule>} |
| 696 */ | 705 */ |
| 697 addRule: function(styleSheetId, ruleText, ruleLocation) | 706 addRule: function(styleSheetId, ruleText, ruleLocation) |
| 698 { | 707 { |
| 699 return this._agent.addRule(styleSheetId, ruleText, ruleLocation, parsePa
yload.bind(this)) | 708 return this._ensureOriginalStyleSheetText(styleSheetId) |
| 709 .then(() => this._agent.addRule(styleSheetId, ruleText, ruleLocation
, parsePayload.bind(this))) |
| 700 .catchException(/** @type {?WebInspector.CSSStyleRule} */(null)) | 710 .catchException(/** @type {?WebInspector.CSSStyleRule} */(null)) |
| 701 | 711 |
| 702 /** | 712 /** |
| 703 * @param {?Protocol.Error} error | 713 * @param {?Protocol.Error} error |
| 704 * @param {?CSSAgent.CSSRule} rulePayload | 714 * @param {?CSSAgent.CSSRule} rulePayload |
| 705 * @return {?WebInspector.CSSStyleRule} | 715 * @return {?WebInspector.CSSStyleRule} |
| 706 * @this {WebInspector.CSSModel} | 716 * @this {WebInspector.CSSModel} |
| 707 */ | 717 */ |
| 708 function parsePayload(error, rulePayload) | 718 function parsePayload(error, rulePayload) |
| 709 { | 719 { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 */ | 795 */ |
| 786 _fireStyleSheetChangedAndDetach: function(styleSheetId, edit) | 796 _fireStyleSheetChangedAndDetach: function(styleSheetId, edit) |
| 787 { | 797 { |
| 788 this.dispatchEventToListeners(WebInspector.CSSModel.Events.StyleSheetCha
nged, { styleSheetId: styleSheetId, edit: edit }); | 798 this.dispatchEventToListeners(WebInspector.CSSModel.Events.StyleSheetCha
nged, { styleSheetId: styleSheetId, edit: edit }); |
| 789 var header = this.styleSheetHeaderForId(styleSheetId); | 799 var header = this.styleSheetHeaderForId(styleSheetId); |
| 790 if (header) | 800 if (header) |
| 791 this._detachSourceMap(header); | 801 this._detachSourceMap(header); |
| 792 }, | 802 }, |
| 793 | 803 |
| 794 /** | 804 /** |
| 805 * @param {!CSSAgent.StyleSheetId} styleSheetId |
| 806 * @return {!Promise<string>} |
| 807 */ |
| 808 _ensureOriginalStyleSheetText: function(styleSheetId) |
| 809 { |
| 810 var header = this.styleSheetHeaderForId(styleSheetId); |
| 811 if (!header) |
| 812 return Promise.resolve(""); |
| 813 var promise = this._originalStyleSheetText.get(header); |
| 814 if (!promise) { |
| 815 promise = this.getStyleSheetText(header.id); |
| 816 this._originalStyleSheetText.set(header, promise); |
| 817 } |
| 818 return promise; |
| 819 }, |
| 820 |
| 821 /** |
| 822 * @param {!WebInspector.CSSStyleSheetHeader} header |
| 823 * @return {!Promise<string>} |
| 824 */ |
| 825 originalStyleSheetText: function(header) |
| 826 { |
| 827 return this._ensureOriginalStyleSheetText(header.id); |
| 828 }, |
| 829 |
| 830 /** |
| 795 * @param {!CSSAgent.CSSStyleSheetHeader} header | 831 * @param {!CSSAgent.CSSStyleSheetHeader} header |
| 796 */ | 832 */ |
| 797 _styleSheetAdded: function(header) | 833 _styleSheetAdded: function(header) |
| 798 { | 834 { |
| 799 console.assert(!this._styleSheetIdToHeader.get(header.styleSheetId)); | 835 console.assert(!this._styleSheetIdToHeader.get(header.styleSheetId)); |
| 800 var styleSheetHeader = new WebInspector.CSSStyleSheetHeader(this, header
); | 836 var styleSheetHeader = new WebInspector.CSSStyleSheetHeader(this, header
); |
| 801 this._styleSheetIdToHeader.set(header.styleSheetId, styleSheetHeader); | 837 this._styleSheetIdToHeader.set(header.styleSheetId, styleSheetHeader); |
| 802 var url = styleSheetHeader.resourceURL(); | 838 var url = styleSheetHeader.resourceURL(); |
| 803 if (!this._styleSheetIdsForURL.get(url)) | 839 if (!this._styleSheetIdsForURL.get(url)) |
| 804 this._styleSheetIdsForURL.set(url, {}); | 840 this._styleSheetIdsForURL.set(url, {}); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 825 this._styleSheetIdToHeader.remove(id); | 861 this._styleSheetIdToHeader.remove(id); |
| 826 var url = header.resourceURL(); | 862 var url = header.resourceURL(); |
| 827 var frameIdToStyleSheetIds = /** @type {!Object.<!PageAgent.FrameId, !Ar
ray.<!CSSAgent.StyleSheetId>>} */ (this._styleSheetIdsForURL.get(url)); | 863 var frameIdToStyleSheetIds = /** @type {!Object.<!PageAgent.FrameId, !Ar
ray.<!CSSAgent.StyleSheetId>>} */ (this._styleSheetIdsForURL.get(url)); |
| 828 console.assert(frameIdToStyleSheetIds, "No frameId to styleSheetId map i
s available for given style sheet URL."); | 864 console.assert(frameIdToStyleSheetIds, "No frameId to styleSheetId map i
s available for given style sheet URL."); |
| 829 frameIdToStyleSheetIds[header.frameId].remove(id); | 865 frameIdToStyleSheetIds[header.frameId].remove(id); |
| 830 if (!frameIdToStyleSheetIds[header.frameId].length) { | 866 if (!frameIdToStyleSheetIds[header.frameId].length) { |
| 831 delete frameIdToStyleSheetIds[header.frameId]; | 867 delete frameIdToStyleSheetIds[header.frameId]; |
| 832 if (!Object.keys(frameIdToStyleSheetIds).length) | 868 if (!Object.keys(frameIdToStyleSheetIds).length) |
| 833 this._styleSheetIdsForURL.remove(url); | 869 this._styleSheetIdsForURL.remove(url); |
| 834 } | 870 } |
| 871 this._originalStyleSheetText.remove(header); |
| 835 this._detachSourceMap(header); | 872 this._detachSourceMap(header); |
| 836 this.dispatchEventToListeners(WebInspector.CSSModel.Events.StyleSheetRem
oved, header); | 873 this.dispatchEventToListeners(WebInspector.CSSModel.Events.StyleSheetRem
oved, header); |
| 837 }, | 874 }, |
| 838 | 875 |
| 839 /** | 876 /** |
| 840 * @param {string} url | 877 * @param {string} url |
| 841 * @return {!Array.<!CSSAgent.StyleSheetId>} | 878 * @return {!Array.<!CSSAgent.StyleSheetId>} |
| 842 */ | 879 */ |
| 843 styleSheetIdsForURL: function(url) | 880 styleSheetIdsForURL: function(url) |
| 844 { | 881 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 858 * @param {boolean} majorChange | 895 * @param {boolean} majorChange |
| 859 * @return {!Promise.<?Protocol.Error>} | 896 * @return {!Promise.<?Protocol.Error>} |
| 860 */ | 897 */ |
| 861 setStyleSheetText: function(styleSheetId, newText, majorChange) | 898 setStyleSheetText: function(styleSheetId, newText, majorChange) |
| 862 { | 899 { |
| 863 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */(this._styl
eSheetIdToHeader.get(styleSheetId)); | 900 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */(this._styl
eSheetIdToHeader.get(styleSheetId)); |
| 864 console.assert(header); | 901 console.assert(header); |
| 865 newText = WebInspector.CSSModel.trimSourceURL(newText); | 902 newText = WebInspector.CSSModel.trimSourceURL(newText); |
| 866 if (header.hasSourceURL) | 903 if (header.hasSourceURL) |
| 867 newText += "\n/*# sourceURL=" + header.sourceURL + " */"; | 904 newText += "\n/*# sourceURL=" + header.sourceURL + " */"; |
| 868 return this._agent.setStyleSheetText(header.id, newText, callback.bind(t
his)); | 905 return this._ensureOriginalStyleSheetText(styleSheetId) |
| 906 .then(() => this._agent.setStyleSheetText(header.id, newText, callba
ck.bind(this))); |
| 869 | 907 |
| 870 /** | 908 /** |
| 871 * @param {?Protocol.Error} error | 909 * @param {?Protocol.Error} error |
| 872 * @param {string=} sourceMapURL | 910 * @param {string=} sourceMapURL |
| 873 * @return {?Protocol.Error} | 911 * @return {?Protocol.Error} |
| 874 * @this {WebInspector.CSSModel} | 912 * @this {WebInspector.CSSModel} |
| 875 */ | 913 */ |
| 876 function callback(error, sourceMapURL) | 914 function callback(error, sourceMapURL) |
| 877 { | 915 { |
| 878 this._detachSourceMap(header); | 916 this._detachSourceMap(header); |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 /** | 1201 /** |
| 1164 * @constructor | 1202 * @constructor |
| 1165 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle | 1203 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle |
| 1166 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle | 1204 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle |
| 1167 */ | 1205 */ |
| 1168 WebInspector.CSSModel.InlineStyleResult = function(inlineStyle, attributesStyle) | 1206 WebInspector.CSSModel.InlineStyleResult = function(inlineStyle, attributesStyle) |
| 1169 { | 1207 { |
| 1170 this.inlineStyle = inlineStyle; | 1208 this.inlineStyle = inlineStyle; |
| 1171 this.attributesStyle = attributesStyle; | 1209 this.attributesStyle = attributesStyle; |
| 1172 } | 1210 } |
| OLD | NEW |