| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 _wasEnabled: function() | 113 _wasEnabled: function() |
| 114 { | 114 { |
| 115 this._isEnabled = true; | 115 this._isEnabled = true; |
| 116 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.ModelWas
Enabled); | 116 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.ModelWas
Enabled); |
| 117 }, | 117 }, |
| 118 | 118 |
| 119 /** | 119 /** |
| 120 * @param {!DOMAgent.NodeId} nodeId | 120 * @param {!DOMAgent.NodeId} nodeId |
| 121 * @param {boolean} excludePseudo | 121 * @param {boolean} excludePseudo |
| 122 * @param {boolean} excludeInherited | 122 * @param {boolean} excludeInherited |
| 123 * @param {function(?*)} userCallback | 123 * @param {function(?WebInspector.CSSStyleModel.MatchedStyleResult)} userCal
lback |
| 124 */ | 124 */ |
| 125 getMatchedStylesAsync: function(nodeId, excludePseudo, excludeInherited, use
rCallback) | 125 getMatchedStylesAsync: function(nodeId, excludePseudo, excludeInherited, use
rCallback) |
| 126 { | 126 { |
| 127 /** | 127 /** |
| 128 * @param {function(?*)} userCallback | |
| 129 * @param {?Protocol.Error} error | 128 * @param {?Protocol.Error} error |
| 130 * @param {!Array.<!CSSAgent.RuleMatch>=} matchedPayload | 129 * @param {!Array.<!CSSAgent.RuleMatch>=} matchedPayload |
| 131 * @param {!Array.<!CSSAgent.PseudoIdMatches>=} pseudoPayload | 130 * @param {!Array.<!CSSAgent.PseudoIdMatches>=} pseudoPayload |
| 132 * @param {!Array.<!CSSAgent.InheritedStyleEntry>=} inheritedPayload | 131 * @param {!Array.<!CSSAgent.InheritedStyleEntry>=} inheritedPayload |
| 133 * @this {WebInspector.CSSStyleModel} | 132 * @this {WebInspector.CSSStyleModel} |
| 134 */ | 133 */ |
| 135 function callback(userCallback, error, matchedPayload, pseudoPayload, in
heritedPayload) | 134 function callback(error, matchedPayload, pseudoPayload, inheritedPayload
) |
| 136 { | 135 { |
| 137 if (error) { | 136 if (error) { |
| 138 if (userCallback) | 137 if (userCallback) |
| 139 userCallback(null); | 138 userCallback(null); |
| 140 return; | 139 return; |
| 141 } | 140 } |
| 142 | 141 |
| 143 var result = {}; | |
| 144 // Due to CSSOM inconsistencies, backend might send us illegal data.
@see crbug.com/178410 | 142 // Due to CSSOM inconsistencies, backend might send us illegal data.
@see crbug.com/178410 |
| 143 var result = null; |
| 145 try { | 144 try { |
| 146 result.matchedCSSRules = WebInspector.CSSStyleModel.parseRuleMat
chArrayPayload(this, matchedPayload); | 145 var matchedRules = WebInspector.CSSStyleModel.parseRuleMatchArra
yPayload(this, matchedPayload); |
| 147 | 146 |
| 148 result.pseudoElements = []; | 147 var pseudoElements = []; |
| 149 if (pseudoPayload) { | 148 if (pseudoPayload) { |
| 150 for (var i = 0; i < pseudoPayload.length; ++i) { | 149 for (var i = 0; i < pseudoPayload.length; ++i) { |
| 151 var entryPayload = pseudoPayload[i]; | 150 var entryPayload = pseudoPayload[i]; |
| 152 result.pseudoElements.push({ pseudoId: entryPayload.pseu
doId, rules: WebInspector.CSSStyleModel.parseRuleMatchArrayPayload(this, entryPa
yload.matches) }); | 151 pseudoElements.push(new WebInspector.CSSStyleModel.Pseud
oElementMatches(entryPayload.pseudoId, WebInspector.CSSStyleModel.parseRuleMatch
ArrayPayload(this, entryPayload.matches))); |
| 153 } | 152 } |
| 154 } | 153 } |
| 155 | 154 |
| 156 result.inherited = []; | 155 var inherited = []; |
| 157 if (inheritedPayload) { | 156 if (inheritedPayload) { |
| 158 for (var i = 0; i < inheritedPayload.length; ++i) { | 157 for (var i = 0; i < inheritedPayload.length; ++i) { |
| 159 var entryPayload = inheritedPayload[i]; | 158 var entryPayload = inheritedPayload[i]; |
| 160 var entry = {}; | 159 var inlineStyle = entryPayload.inlineStyle ? WebInspecto
r.CSSStyleDeclaration.parsePayload(this, entryPayload.inlineStyle) : null; |
| 161 if (entryPayload.inlineStyle) | 160 var matchedCSSRules = entryPayload.matchedCSSRules ? Web
Inspector.CSSStyleModel.parseRuleMatchArrayPayload(this, entryPayload.matchedCSS
Rules) : null; |
| 162 entry.inlineStyle = WebInspector.CSSStyleDeclaration
.parsePayload(this, entryPayload.inlineStyle); | 161 inherited.push(new WebInspector.CSSStyleModel.InheritedM
atches(inlineStyle, matchedCSSRules)); |
| 163 if (entryPayload.matchedCSSRules) | |
| 164 entry.matchedCSSRules = WebInspector.CSSStyleModel.p
arseRuleMatchArrayPayload(this, entryPayload.matchedCSSRules); | |
| 165 result.inherited.push(entry); | |
| 166 } | 162 } |
| 167 } | 163 } |
| 164 result = new WebInspector.CSSStyleModel.MatchedStyleResult(match
edRules, inherited, pseudoElements); |
| 168 } catch (e) { | 165 } catch (e) { |
| 169 console.error(e); | 166 console.error(e); |
| 170 result = null; | |
| 171 } | 167 } |
| 172 | 168 |
| 173 if (userCallback) | 169 if (userCallback) |
| 174 userCallback(result); | 170 userCallback(result); |
| 175 } | 171 } |
| 176 | 172 |
| 177 this._agent.getMatchedStylesForNode(nodeId, excludePseudo, excludeInheri
ted, callback.bind(this, userCallback)); | 173 this._agent.getMatchedStylesForNode(nodeId, excludePseudo, excludeInheri
ted, callback.bind(this)); |
| 178 }, | 174 }, |
| 179 | 175 |
| 180 /** | 176 /** |
| 181 * @param {!DOMAgent.NodeId} nodeId | 177 * @param {!DOMAgent.NodeId} nodeId |
| 182 * @param {function(?WebInspector.CSSStyleDeclaration)} userCallback | 178 * @param {function(?WebInspector.CSSStyleDeclaration)} userCallback |
| 183 */ | 179 */ |
| 184 getComputedStyleAsync: function(nodeId, userCallback) | 180 getComputedStyleAsync: function(nodeId, userCallback) |
| 185 { | 181 { |
| 186 this._styleLoader.getComputedStyle(nodeId, userCallback); | 182 this._styleLoader.getComputedStyle(nodeId, userCallback); |
| 187 }, | 183 }, |
| 188 | 184 |
| 189 /** | 185 /** |
| 190 * @param {number} nodeId | 186 * @param {number} nodeId |
| 191 * @param {function(?string, ?Array.<!CSSAgent.PlatformFontUsage>)} callback | 187 * @param {function(?Array.<!CSSAgent.PlatformFontUsage>)} callback |
| 192 */ | 188 */ |
| 193 getPlatformFontsForNode: function(nodeId, callback) | 189 getPlatformFontsForNode: function(nodeId, callback) |
| 194 { | 190 { |
| 195 function platformFontsCallback(error, cssFamilyName, fonts) | 191 function platformFontsCallback(error, fonts) |
| 196 { | 192 { |
| 197 if (error) | 193 if (error) |
| 198 callback(null, null); | 194 callback(null); |
| 199 else | 195 else |
| 200 callback(cssFamilyName, fonts); | 196 callback(fonts); |
| 201 } | 197 } |
| 202 this._agent.getPlatformFontsForNode(nodeId, platformFontsCallback); | 198 this._agent.getPlatformFontsForNode(nodeId, platformFontsCallback); |
| 203 }, | 199 }, |
| 204 | 200 |
| 205 /** | 201 /** |
| 206 * @return {!Array.<!WebInspector.CSSStyleSheetHeader>} | 202 * @return {!Array.<!WebInspector.CSSStyleSheetHeader>} |
| 207 */ | 203 */ |
| 208 allStyleSheets: function() | 204 allStyleSheets: function() |
| 209 { | 205 { |
| 210 var values = this._styleSheetIdToHeader.valuesArray(); | 206 var values = this._styleSheetIdToHeader.valuesArray(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 221 return 1; | 217 return 1; |
| 222 return a.startLine - b.startLine || a.startColumn - b.startColumn; | 218 return a.startLine - b.startLine || a.startColumn - b.startColumn; |
| 223 } | 219 } |
| 224 values.sort(styleSheetComparator); | 220 values.sort(styleSheetComparator); |
| 225 | 221 |
| 226 return values; | 222 return values; |
| 227 }, | 223 }, |
| 228 | 224 |
| 229 /** | 225 /** |
| 230 * @param {!DOMAgent.NodeId} nodeId | 226 * @param {!DOMAgent.NodeId} nodeId |
| 231 * @param {function(?WebInspector.CSSStyleDeclaration, ?WebInspector.CSSStyl
eDeclaration)} userCallback | 227 * @param {function(?WebInspector.CSSStyleModel.InlineStyleResult)} userCall
back |
| 232 */ | 228 */ |
| 233 getInlineStylesAsync: function(nodeId, userCallback) | 229 getInlineStylesAsync: function(nodeId, userCallback) |
| 234 { | 230 { |
| 235 /** | 231 /** |
| 236 * @param {function(?WebInspector.CSSStyleDeclaration, ?WebInspector.CSS
StyleDeclaration)} userCallback | |
| 237 * @param {?Protocol.Error} error | 232 * @param {?Protocol.Error} error |
| 238 * @param {?CSSAgent.CSSStyle=} inlinePayload | 233 * @param {?CSSAgent.CSSStyle=} inlinePayload |
| 239 * @param {?CSSAgent.CSSStyle=} attributesStylePayload | 234 * @param {?CSSAgent.CSSStyle=} attributesStylePayload |
| 240 * @this {WebInspector.CSSStyleModel} | 235 * @this {WebInspector.CSSStyleModel} |
| 241 */ | 236 */ |
| 242 function callback(userCallback, error, inlinePayload, attributesStylePay
load) | 237 function callback(error, inlinePayload, attributesStylePayload) |
| 243 { | 238 { |
| 244 if (error || !inlinePayload) | 239 if (error || !inlinePayload) { |
| 245 userCallback(null, null); | 240 userCallback(null); |
| 246 else | 241 return; |
| 247 userCallback(WebInspector.CSSStyleDeclaration.parsePayload(this,
inlinePayload), attributesStylePayload ? WebInspector.CSSStyleDeclaration.parse
Payload(this, attributesStylePayload) : null); | 242 } |
| 243 var inlineStyle = inlinePayload ? WebInspector.CSSStyleDeclaration.p
arsePayload(this, inlinePayload) : null; |
| 244 var attributesStyle = attributesStylePayload ? WebInspector.CSSStyle
Declaration.parsePayload(this, attributesStylePayload) : null; |
| 245 userCallback(new WebInspector.CSSStyleModel.InlineStyleResult(inline
Style, attributesStyle)); |
| 248 } | 246 } |
| 249 | 247 |
| 250 this._agent.getInlineStylesForNode(nodeId, callback.bind(this, userCallb
ack)); | 248 this._agent.getInlineStylesForNode(nodeId, callback.bind(this)); |
| 251 }, | 249 }, |
| 252 | 250 |
| 253 /** | 251 /** |
| 254 * @param {!WebInspector.DOMNode} node | 252 * @param {!WebInspector.DOMNode} node |
| 255 * @param {string} pseudoClass | 253 * @param {string} pseudoClass |
| 256 * @param {boolean} enable | 254 * @param {boolean} enable |
| 257 * @return {boolean} | 255 * @return {boolean} |
| 258 */ | 256 */ |
| 259 forcePseudoState: function(node, pseudoClass, enable) | 257 forcePseudoState: function(node, pseudoClass, enable) |
| 260 { | 258 { |
| (...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1935 } | 1933 } |
| 1936 | 1934 |
| 1937 /** | 1935 /** |
| 1938 * @param {!WebInspector.DOMNode} node | 1936 * @param {!WebInspector.DOMNode} node |
| 1939 * @return {!WebInspector.CSSStyleModel} | 1937 * @return {!WebInspector.CSSStyleModel} |
| 1940 */ | 1938 */ |
| 1941 WebInspector.CSSStyleModel.fromNode = function(node) | 1939 WebInspector.CSSStyleModel.fromNode = function(node) |
| 1942 { | 1940 { |
| 1943 return /** @type {!WebInspector.CSSStyleModel} */ (WebInspector.CSSStyleMode
l.fromTarget(node.target())); | 1941 return /** @type {!WebInspector.CSSStyleModel} */ (WebInspector.CSSStyleMode
l.fromTarget(node.target())); |
| 1944 } | 1942 } |
| 1943 |
| 1944 /** |
| 1945 * @constructor |
| 1946 * @param {?Array.<!WebInspector.CSSRule>} matchedRules |
| 1947 * @param {?Array.<!WebInspector.CSSStyleModel.InheritedMatches>} inherited |
| 1948 * @param {?Array.<!WebInspector.CSSStyleModel.PseudoElementMatches>} pseudoElem
ents |
| 1949 */ |
| 1950 WebInspector.CSSStyleModel.MatchedStyleResult = function(matchedRules, inherited
, pseudoElements) |
| 1951 { |
| 1952 this.matchedCSSRules = matchedRules; |
| 1953 this.inherited = inherited; |
| 1954 this.pseudoElements = pseudoElements; |
| 1955 } |
| 1956 |
| 1957 /** |
| 1958 * @constructor |
| 1959 * @param {number} pseudoId |
| 1960 * @param {?Array.<!WebInspector.CSSRule>} rules |
| 1961 */ |
| 1962 WebInspector.CSSStyleModel.PseudoElementMatches = function(pseudoId, rules) |
| 1963 { |
| 1964 this.pseudoId = pseudoId; |
| 1965 this.rules = rules; |
| 1966 } |
| 1967 |
| 1968 /** |
| 1969 * @constructor |
| 1970 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle |
| 1971 * @param {?Array.<!WebInspector.CSSRule>} matchedRules |
| 1972 */ |
| 1973 WebInspector.CSSStyleModel.InheritedMatches = function(inlineStyle, matchedRules
) |
| 1974 { |
| 1975 this.inlineStyle = inlineStyle; |
| 1976 this.matchedCSSRules = matchedRules; |
| 1977 } |
| 1978 |
| 1979 /** |
| 1980 * @constructor |
| 1981 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle |
| 1982 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle |
| 1983 */ |
| 1984 WebInspector.CSSStyleModel.InlineStyleResult = function(inlineStyle, attributesS
tyle) |
| 1985 { |
| 1986 this.inlineStyle = inlineStyle; |
| 1987 this.attributesStyle = attributesStyle; |
| 1988 } |
| 1989 |
| OLD | NEW |