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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 this._originalStyleSheetText = new Map(); | 52 this._originalStyleSheetText = new Map(); |
53 | 53 |
54 /** @type {!Multimap<string, !CSSAgent.StyleSheetId>} */ | 54 /** @type {!Multimap<string, !CSSAgent.StyleSheetId>} */ |
55 this._sourceMapLoadingStyleSheetsIds = new Multimap(); | 55 this._sourceMapLoadingStyleSheetsIds = new Multimap(); |
56 | 56 |
57 /** @type {!Map<string, !WebInspector.SourceMap>} */ | 57 /** @type {!Map<string, !WebInspector.SourceMap>} */ |
58 this._sourceMapByURL = new Map(); | 58 this._sourceMapByURL = new Map(); |
59 /** @type {!Multimap<string, !WebInspector.CSSStyleSheetHeader>} */ | 59 /** @type {!Multimap<string, !WebInspector.CSSStyleSheetHeader>} */ |
60 this._sourceMapURLToHeaders = new Multimap(); | 60 this._sourceMapURLToHeaders = new Multimap(); |
61 WebInspector.moduleSetting("cssSourceMapsEnabled").addChangeListener(this._t
oggleSourceMapSupport, this); | 61 WebInspector.moduleSetting("cssSourceMapsEnabled").addChangeListener(this._t
oggleSourceMapSupport, this); |
62 } | 62 }; |
63 | 63 |
64 /** @enum {symbol} */ | 64 /** @enum {symbol} */ |
65 WebInspector.CSSModel.Events = { | 65 WebInspector.CSSModel.Events = { |
66 LayoutEditorChange: Symbol("LayoutEditorChange"), | 66 LayoutEditorChange: Symbol("LayoutEditorChange"), |
67 FontsUpdated: Symbol("FontsUpdated"), | 67 FontsUpdated: Symbol("FontsUpdated"), |
68 MediaQueryResultChanged: Symbol("MediaQueryResultChanged"), | 68 MediaQueryResultChanged: Symbol("MediaQueryResultChanged"), |
69 ModelWasEnabled: Symbol("ModelWasEnabled"), | 69 ModelWasEnabled: Symbol("ModelWasEnabled"), |
70 PseudoStateForced: Symbol("PseudoStateForced"), | 70 PseudoStateForced: Symbol("PseudoStateForced"), |
71 StyleSheetAdded: Symbol("StyleSheetAdded"), | 71 StyleSheetAdded: Symbol("StyleSheetAdded"), |
72 StyleSheetChanged: Symbol("StyleSheetChanged"), | 72 StyleSheetChanged: Symbol("StyleSheetChanged"), |
73 StyleSheetRemoved: Symbol("StyleSheetRemoved"), | 73 StyleSheetRemoved: Symbol("StyleSheetRemoved"), |
74 SourceMapAttached: Symbol("SourceMapAttached"), | 74 SourceMapAttached: Symbol("SourceMapAttached"), |
75 SourceMapDetached: Symbol("SourceMapDetached"), | 75 SourceMapDetached: Symbol("SourceMapDetached"), |
76 SourceMapChanged: Symbol("SourceMapChanged") | 76 SourceMapChanged: Symbol("SourceMapChanged") |
77 } | 77 }; |
78 | 78 |
79 WebInspector.CSSModel.MediaTypes = ["all", "braille", "embossed", "handheld", "p
rint", "projection", "screen", "speech", "tty", "tv"]; | 79 WebInspector.CSSModel.MediaTypes = ["all", "braille", "embossed", "handheld", "p
rint", "projection", "screen", "speech", "tty", "tv"]; |
80 | 80 |
81 WebInspector.CSSModel.PseudoStateMarker = "pseudo-state-marker"; | 81 WebInspector.CSSModel.PseudoStateMarker = "pseudo-state-marker"; |
82 | 82 |
83 /** | 83 /** |
84 * @constructor | 84 * @constructor |
85 * @param {!CSSAgent.StyleSheetId} styleSheetId | 85 * @param {!CSSAgent.StyleSheetId} styleSheetId |
86 * @param {!WebInspector.TextRange} oldRange | 86 * @param {!WebInspector.TextRange} oldRange |
87 * @param {string} newText | 87 * @param {string} newText |
88 * @param {?Object} payload | 88 * @param {?Object} payload |
89 */ | 89 */ |
90 WebInspector.CSSModel.Edit = function(styleSheetId, oldRange, newText, payload) | 90 WebInspector.CSSModel.Edit = function(styleSheetId, oldRange, newText, payload) |
91 { | 91 { |
92 this.styleSheetId = styleSheetId; | 92 this.styleSheetId = styleSheetId; |
93 this.oldRange = oldRange; | 93 this.oldRange = oldRange; |
94 this.newRange = WebInspector.TextRange.fromEdit(oldRange, newText); | 94 this.newRange = WebInspector.TextRange.fromEdit(oldRange, newText); |
95 this.payload = payload; | 95 this.payload = payload; |
96 } | 96 }; |
97 | 97 |
98 WebInspector.CSSModel.prototype = { | 98 WebInspector.CSSModel.prototype = { |
99 /** | 99 /** |
100 * @param {!WebInspector.Event} event | 100 * @param {!WebInspector.Event} event |
101 */ | 101 */ |
102 _toggleSourceMapSupport: function(event) | 102 _toggleSourceMapSupport: function(event) |
103 { | 103 { |
104 var enabled = /** @type {boolean} */ (event.data); | 104 var enabled = /** @type {boolean} */ (event.data); |
105 var headers = this.styleSheetHeaders(); | 105 var headers = this.styleSheetHeaders(); |
106 for (var header of headers) { | 106 for (var header of headers) { |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 /** | 718 /** |
719 * @param {!CSSAgent.StyleSheetId} styleSheetId | 719 * @param {!CSSAgent.StyleSheetId} styleSheetId |
720 * @param {string} ruleText | 720 * @param {string} ruleText |
721 * @param {!WebInspector.TextRange} ruleLocation | 721 * @param {!WebInspector.TextRange} ruleLocation |
722 * @return {!Promise<?WebInspector.CSSStyleRule>} | 722 * @return {!Promise<?WebInspector.CSSStyleRule>} |
723 */ | 723 */ |
724 addRule: function(styleSheetId, ruleText, ruleLocation) | 724 addRule: function(styleSheetId, ruleText, ruleLocation) |
725 { | 725 { |
726 return this._ensureOriginalStyleSheetText(styleSheetId) | 726 return this._ensureOriginalStyleSheetText(styleSheetId) |
727 .then(() => this._agent.addRule(styleSheetId, ruleText, ruleLocation
, parsePayload.bind(this))) | 727 .then(() => this._agent.addRule(styleSheetId, ruleText, ruleLocation
, parsePayload.bind(this))) |
728 .catchException(/** @type {?WebInspector.CSSStyleRule} */(null)) | 728 .catchException(/** @type {?WebInspector.CSSStyleRule} */(null)); |
729 | 729 |
730 /** | 730 /** |
731 * @param {?Protocol.Error} error | 731 * @param {?Protocol.Error} error |
732 * @param {?CSSAgent.CSSRule} rulePayload | 732 * @param {?CSSAgent.CSSRule} rulePayload |
733 * @return {?WebInspector.CSSStyleRule} | 733 * @return {?WebInspector.CSSStyleRule} |
734 * @this {WebInspector.CSSModel} | 734 * @this {WebInspector.CSSModel} |
735 */ | 735 */ |
736 function parsePayload(error, rulePayload) | 736 function parsePayload(error, rulePayload) |
737 { | 737 { |
738 if (error || !rulePayload) | 738 if (error || !rulePayload) |
(...skipping 27 matching lines...) Expand all Loading... |
766 * @return {?WebInspector.CSSStyleSheetHeader} | 766 * @return {?WebInspector.CSSStyleSheetHeader} |
767 * @this {WebInspector.CSSModel} | 767 * @this {WebInspector.CSSModel} |
768 */ | 768 */ |
769 function innerCallback(error, styleSheetId) | 769 function innerCallback(error, styleSheetId) |
770 { | 770 { |
771 return !error && styleSheetId ? this._styleSheetIdToHeader.get(style
SheetId) || null : null; | 771 return !error && styleSheetId ? this._styleSheetIdToHeader.get(style
SheetId) || null : null; |
772 } | 772 } |
773 | 773 |
774 this._agent.createStyleSheet(frameId, innerCallback.bind(this)) | 774 this._agent.createStyleSheet(frameId, innerCallback.bind(this)) |
775 .catchException(null) | 775 .catchException(null) |
776 .then(userCallback) | 776 .then(userCallback); |
777 }, | 777 }, |
778 | 778 |
779 mediaQueryResultChanged: function() | 779 mediaQueryResultChanged: function() |
780 { | 780 { |
781 this.dispatchEventToListeners(WebInspector.CSSModel.Events.MediaQueryRes
ultChanged); | 781 this.dispatchEventToListeners(WebInspector.CSSModel.Events.MediaQueryRes
ultChanged); |
782 }, | 782 }, |
783 | 783 |
784 fontsUpdated: function() | 784 fontsUpdated: function() |
785 { | 785 { |
786 this.dispatchEventToListeners(WebInspector.CSSModel.Events.FontsUpdated)
; | 786 this.dispatchEventToListeners(WebInspector.CSSModel.Events.FontsUpdated)
; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 getStyleSheetText: function(styleSheetId) | 949 getStyleSheetText: function(styleSheetId) |
950 { | 950 { |
951 /** | 951 /** |
952 * @param {?Protocol.Error} error | 952 * @param {?Protocol.Error} error |
953 * @param {?string} text | 953 * @param {?string} text |
954 * @return {string} | 954 * @return {string} |
955 */ | 955 */ |
956 function textCallback(error, text) | 956 function textCallback(error, text) |
957 { | 957 { |
958 if (error || text === null) { | 958 if (error || text === null) { |
959 console.error("Failed to get text for stylesheet " + styleSheetI
d + ": " + error) | 959 console.error("Failed to get text for stylesheet " + styleSheetI
d + ": " + error); |
960 text = ""; | 960 text = ""; |
961 // Fall through. | 961 // Fall through. |
962 } | 962 } |
963 return WebInspector.CSSModel.trimSourceURL(text); | 963 return WebInspector.CSSModel.trimSourceURL(text); |
964 } | 964 } |
965 | 965 |
966 return this._agent.getStyleSheetText(styleSheetId, textCallback) | 966 return this._agent.getStyleSheetText(styleSheetId, textCallback) |
967 .catchException(/** @type {string} */("")); | 967 .catchException(/** @type {string} */("")); |
968 }, | 968 }, |
969 | 969 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 return this._cachedMatchedCascadePromise; | 1043 return this._cachedMatchedCascadePromise; |
1044 }, | 1044 }, |
1045 | 1045 |
1046 discardCachedMatchedCascade: function() | 1046 discardCachedMatchedCascade: function() |
1047 { | 1047 { |
1048 delete this._cachedMatchedCascadeNode; | 1048 delete this._cachedMatchedCascadeNode; |
1049 delete this._cachedMatchedCascadePromise; | 1049 delete this._cachedMatchedCascadePromise; |
1050 }, | 1050 }, |
1051 | 1051 |
1052 __proto__: WebInspector.SDKModel.prototype | 1052 __proto__: WebInspector.SDKModel.prototype |
1053 } | 1053 }; |
1054 | 1054 |
1055 /** | 1055 /** |
1056 * @param {string} text | 1056 * @param {string} text |
1057 * @return {string} | 1057 * @return {string} |
1058 */ | 1058 */ |
1059 WebInspector.CSSModel.trimSourceURL = function(text) | 1059 WebInspector.CSSModel.trimSourceURL = function(text) |
1060 { | 1060 { |
1061 var sourceURLIndex = text.lastIndexOf("/*# sourceURL="); | 1061 var sourceURLIndex = text.lastIndexOf("/*# sourceURL="); |
1062 if (sourceURLIndex === -1) { | 1062 if (sourceURLIndex === -1) { |
1063 sourceURLIndex = text.lastIndexOf("/*@ sourceURL="); | 1063 sourceURLIndex = text.lastIndexOf("/*@ sourceURL="); |
1064 if (sourceURLIndex === -1) | 1064 if (sourceURLIndex === -1) |
1065 return text; | 1065 return text; |
1066 } | 1066 } |
1067 var sourceURLLineIndex = text.lastIndexOf("\n", sourceURLIndex); | 1067 var sourceURLLineIndex = text.lastIndexOf("\n", sourceURLIndex); |
1068 if (sourceURLLineIndex === -1) | 1068 if (sourceURLLineIndex === -1) |
1069 return text; | 1069 return text; |
1070 var sourceURLLine = text.substr(sourceURLLineIndex + 1).split("\n", 1)[0]; | 1070 var sourceURLLine = text.substr(sourceURLLineIndex + 1).split("\n", 1)[0]; |
1071 var sourceURLRegex = /[\040\t]*\/\*[#@] sourceURL=[\040\t]*([^\s]*)[\040\t]*
\*\/[\040\t]*$/; | 1071 var sourceURLRegex = /[\040\t]*\/\*[#@] sourceURL=[\040\t]*([^\s]*)[\040\t]*
\*\/[\040\t]*$/; |
1072 if (sourceURLLine.search(sourceURLRegex) === -1) | 1072 if (sourceURLLine.search(sourceURLRegex) === -1) |
1073 return text; | 1073 return text; |
1074 return text.substr(0, sourceURLLineIndex) + text.substr(sourceURLLineIndex +
sourceURLLine.length + 1); | 1074 return text.substr(0, sourceURLLineIndex) + text.substr(sourceURLLineIndex +
sourceURLLine.length + 1); |
1075 } | 1075 }; |
1076 | 1076 |
1077 | 1077 |
1078 /** | 1078 /** |
1079 * @constructor | 1079 * @constructor |
1080 * @extends {WebInspector.SDKObject} | 1080 * @extends {WebInspector.SDKObject} |
1081 * @param {!WebInspector.CSSStyleSheetHeader} header | 1081 * @param {!WebInspector.CSSStyleSheetHeader} header |
1082 * @param {number} lineNumber | 1082 * @param {number} lineNumber |
1083 * @param {number=} columnNumber | 1083 * @param {number=} columnNumber |
1084 */ | 1084 */ |
1085 WebInspector.CSSLocation = function(header, lineNumber, columnNumber) | 1085 WebInspector.CSSLocation = function(header, lineNumber, columnNumber) |
1086 { | 1086 { |
1087 WebInspector.SDKObject.call(this, header.target()); | 1087 WebInspector.SDKObject.call(this, header.target()); |
1088 this._header = header; | 1088 this._header = header; |
1089 this.styleSheetId = header.id; | 1089 this.styleSheetId = header.id; |
1090 this.url = header.resourceURL(); | 1090 this.url = header.resourceURL(); |
1091 this.lineNumber = lineNumber; | 1091 this.lineNumber = lineNumber; |
1092 this.columnNumber = columnNumber || 0; | 1092 this.columnNumber = columnNumber || 0; |
1093 } | 1093 }; |
1094 | 1094 |
1095 WebInspector.CSSLocation.prototype = { | 1095 WebInspector.CSSLocation.prototype = { |
1096 /** | 1096 /** |
1097 * @return {!WebInspector.CSSModel} | 1097 * @return {!WebInspector.CSSModel} |
1098 */ | 1098 */ |
1099 cssModel: function() | 1099 cssModel: function() |
1100 { | 1100 { |
1101 return this._header.cssModel(); | 1101 return this._header.cssModel(); |
1102 }, | 1102 }, |
1103 | 1103 |
1104 /** | 1104 /** |
1105 * @return {!WebInspector.CSSStyleSheetHeader} | 1105 * @return {!WebInspector.CSSStyleSheetHeader} |
1106 */ | 1106 */ |
1107 header: function() | 1107 header: function() |
1108 { | 1108 { |
1109 return this._header; | 1109 return this._header; |
1110 }, | 1110 }, |
1111 | 1111 |
1112 __proto__: WebInspector.SDKObject.prototype | 1112 __proto__: WebInspector.SDKObject.prototype |
1113 } | 1113 }; |
1114 | 1114 |
1115 /** | 1115 /** |
1116 * @constructor | 1116 * @constructor |
1117 * @implements {CSSAgent.Dispatcher} | 1117 * @implements {CSSAgent.Dispatcher} |
1118 * @param {!WebInspector.CSSModel} cssModel | 1118 * @param {!WebInspector.CSSModel} cssModel |
1119 */ | 1119 */ |
1120 WebInspector.CSSDispatcher = function(cssModel) | 1120 WebInspector.CSSDispatcher = function(cssModel) |
1121 { | 1121 { |
1122 this._cssModel = cssModel; | 1122 this._cssModel = cssModel; |
1123 } | 1123 }; |
1124 | 1124 |
1125 WebInspector.CSSDispatcher.prototype = { | 1125 WebInspector.CSSDispatcher.prototype = { |
1126 /** | 1126 /** |
1127 * @override | 1127 * @override |
1128 */ | 1128 */ |
1129 mediaQueryResultChanged: function() | 1129 mediaQueryResultChanged: function() |
1130 { | 1130 { |
1131 this._cssModel.mediaQueryResultChanged(); | 1131 this._cssModel.mediaQueryResultChanged(); |
1132 }, | 1132 }, |
1133 | 1133 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 | 1168 |
1169 /** | 1169 /** |
1170 * @override | 1170 * @override |
1171 * @param {!CSSAgent.StyleSheetId} id | 1171 * @param {!CSSAgent.StyleSheetId} id |
1172 * @param {!CSSAgent.SourceRange} range | 1172 * @param {!CSSAgent.SourceRange} range |
1173 */ | 1173 */ |
1174 layoutEditorChange: function(id, range) | 1174 layoutEditorChange: function(id, range) |
1175 { | 1175 { |
1176 this._cssModel._layoutEditorChange(id, range); | 1176 this._cssModel._layoutEditorChange(id, range); |
1177 }, | 1177 }, |
1178 } | 1178 }; |
1179 | 1179 |
1180 /** | 1180 /** |
1181 * @constructor | 1181 * @constructor |
1182 * @param {!WebInspector.CSSModel} cssModel | 1182 * @param {!WebInspector.CSSModel} cssModel |
1183 */ | 1183 */ |
1184 WebInspector.CSSModel.ComputedStyleLoader = function(cssModel) | 1184 WebInspector.CSSModel.ComputedStyleLoader = function(cssModel) |
1185 { | 1185 { |
1186 this._cssModel = cssModel; | 1186 this._cssModel = cssModel; |
1187 /** @type {!Map<!DOMAgent.NodeId, !Promise<?Map<string, string>>>} */ | 1187 /** @type {!Map<!DOMAgent.NodeId, !Promise<?Map<string, string>>>} */ |
1188 this._nodeIdToPromise = new Map(); | 1188 this._nodeIdToPromise = new Map(); |
1189 } | 1189 }; |
1190 | 1190 |
1191 WebInspector.CSSModel.ComputedStyleLoader.prototype = { | 1191 WebInspector.CSSModel.ComputedStyleLoader.prototype = { |
1192 /** | 1192 /** |
1193 * @param {!DOMAgent.NodeId} nodeId | 1193 * @param {!DOMAgent.NodeId} nodeId |
1194 * @return {!Promise<?Map<string, string>>} | 1194 * @return {!Promise<?Map<string, string>>} |
1195 */ | 1195 */ |
1196 computedStylePromise: function(nodeId) | 1196 computedStylePromise: function(nodeId) |
1197 { | 1197 { |
1198 if (!this._nodeIdToPromise.has(nodeId)) | 1198 if (!this._nodeIdToPromise.has(nodeId)) |
1199 this._nodeIdToPromise.set(nodeId, this._cssModel._agent.getComputedS
tyleForNode(nodeId, parsePayload).then(cleanUp.bind(this))); | 1199 this._nodeIdToPromise.set(nodeId, this._cssModel._agent.getComputedS
tyleForNode(nodeId, parsePayload).then(cleanUp.bind(this))); |
(...skipping 19 matching lines...) Expand all Loading... |
1219 * @param {?Map.<string, string>} computedStyle | 1219 * @param {?Map.<string, string>} computedStyle |
1220 * @return {?Map.<string, string>} | 1220 * @return {?Map.<string, string>} |
1221 * @this {WebInspector.CSSModel.ComputedStyleLoader} | 1221 * @this {WebInspector.CSSModel.ComputedStyleLoader} |
1222 */ | 1222 */ |
1223 function cleanUp(computedStyle) | 1223 function cleanUp(computedStyle) |
1224 { | 1224 { |
1225 this._nodeIdToPromise.delete(nodeId); | 1225 this._nodeIdToPromise.delete(nodeId); |
1226 return computedStyle; | 1226 return computedStyle; |
1227 } | 1227 } |
1228 } | 1228 } |
1229 } | 1229 }; |
1230 | 1230 |
1231 /** | 1231 /** |
1232 * @param {!WebInspector.Target} target | 1232 * @param {!WebInspector.Target} target |
1233 * @return {?WebInspector.CSSModel} | 1233 * @return {?WebInspector.CSSModel} |
1234 */ | 1234 */ |
1235 WebInspector.CSSModel.fromTarget = function(target) | 1235 WebInspector.CSSModel.fromTarget = function(target) |
1236 { | 1236 { |
1237 return /** @type {?WebInspector.CSSModel} */ (target.model(WebInspector.CSSM
odel)); | 1237 return /** @type {?WebInspector.CSSModel} */ (target.model(WebInspector.CSSM
odel)); |
1238 } | 1238 }; |
1239 | 1239 |
1240 /** | 1240 /** |
1241 * @param {!WebInspector.DOMNode} node | 1241 * @param {!WebInspector.DOMNode} node |
1242 * @return {!WebInspector.CSSModel} | 1242 * @return {!WebInspector.CSSModel} |
1243 */ | 1243 */ |
1244 WebInspector.CSSModel.fromNode = function(node) | 1244 WebInspector.CSSModel.fromNode = function(node) |
1245 { | 1245 { |
1246 return /** @type {!WebInspector.CSSModel} */ (WebInspector.CSSModel.fromTarg
et(node.target())); | 1246 return /** @type {!WebInspector.CSSModel} */ (WebInspector.CSSModel.fromTarg
et(node.target())); |
1247 } | 1247 }; |
1248 | 1248 |
1249 /** | 1249 /** |
1250 * @constructor | 1250 * @constructor |
1251 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle | 1251 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle |
1252 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle | 1252 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle |
1253 */ | 1253 */ |
1254 WebInspector.CSSModel.InlineStyleResult = function(inlineStyle, attributesStyle) | 1254 WebInspector.CSSModel.InlineStyleResult = function(inlineStyle, attributesStyle) |
1255 { | 1255 { |
1256 this.inlineStyle = inlineStyle; | 1256 this.inlineStyle = inlineStyle; |
1257 this.attributesStyle = attributesStyle; | 1257 this.attributesStyle = attributesStyle; |
1258 } | 1258 }; |
OLD | NEW |