Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/elements/ComputedStyleWidget.js

Issue 1430123003: DevTools: kill WebInspector.SectionCascade class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new-rule-out-of-cascade
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro 3 * Copyright (C) 2009 Joseph Pecoraro
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 var color = WebInspector.Color.parse(text); 117 var color = WebInspector.Color.parse(text);
118 if (!color) 118 if (!color)
119 return createTextNode(text); 119 return createTextNode(text);
120 var swatch = WebInspector.ColorSwatch.create(); 120 var swatch = WebInspector.ColorSwatch.create();
121 swatch.setColorText(text); 121 swatch.setColorText(text);
122 return swatch; 122 return swatch;
123 }, 123 },
124 124
125 /** 125 /**
126 * @param {?WebInspector.SharedSidebarModel.ComputedStyle} nodeStyle 126 * @param {?WebInspector.SharedSidebarModel.ComputedStyle} nodeStyle
127 * @param {?{matched: !WebInspector.SectionCascade, pseudo: !Map.<number, !W ebInspector.SectionCascade>}} cascades 127 * @param {?WebInspector.CSSStyleModel.MatchedStyleResult} matchedStyles
128 */ 128 */
129 _innerRebuildUpdate: function(nodeStyle, cascades) 129 _innerRebuildUpdate: function(nodeStyle, matchedStyles)
130 { 130 {
131 this._propertiesOutline.removeChildren(); 131 this._propertiesOutline.removeChildren();
132 this._linkifier.reset(); 132 this._linkifier.reset();
133 var cssModel = this._sharedModel.cssModel(); 133 var cssModel = this._sharedModel.cssModel();
134 if (!nodeStyle || !cascades || !cssModel) 134 if (!nodeStyle || !matchedStyles || !cssModel)
135 return; 135 return;
136 136
137 var uniqueProperties = nodeStyle.computedStyle.keysArray(); 137 var uniqueProperties = nodeStyle.computedStyle.keysArray();
138 uniqueProperties.sort(propertySorter); 138 uniqueProperties.sort(propertySorter);
139 139
140 var propertyTraces = this._computePropertyTraces(cascades.matched); 140 var propertyTraces = this._computePropertyTraces(matchedStyles);
141 var inhertiedProperties = this._computeInheritedProperties(cascades.matc hed); 141 var inhertiedProperties = this._computeInheritedProperties(matchedStyles );
142 var showInherited = this._showInheritedComputedStylePropertiesSetting.ge t(); 142 var showInherited = this._showInheritedComputedStylePropertiesSetting.ge t();
143 for (var i = 0; i < uniqueProperties.length; ++i) { 143 for (var i = 0; i < uniqueProperties.length; ++i) {
144 var propertyName = uniqueProperties[i]; 144 var propertyName = uniqueProperties[i];
145 var propertyValue = nodeStyle.computedStyle.get(propertyName); 145 var propertyValue = nodeStyle.computedStyle.get(propertyName);
146 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName(p ropertyName); 146 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName(p ropertyName);
147 var inherited = !inhertiedProperties.has(canonicalName); 147 var inherited = !inhertiedProperties.has(canonicalName);
148 if (!showInherited && inherited && !(propertyName in this._alwaysSho wComputedProperties)) 148 if (!showInherited && inherited && !(propertyName in this._alwaysSho wComputedProperties))
149 continue; 149 continue;
150 if (propertyName !== canonicalName && propertyValue === nodeStyle.co mputedStyle.get(canonicalName)) 150 if (propertyName !== canonicalName && propertyValue === nodeStyle.co mputedStyle.get(canonicalName))
151 continue; 151 continue;
(...skipping 16 matching lines...) Expand all
168 treeElement[WebInspector.ComputedStyleWidget._propertySymbol] = { 168 treeElement[WebInspector.ComputedStyleWidget._propertySymbol] = {
169 name: propertyName, 169 name: propertyName,
170 value: propertyValue 170 value: propertyValue
171 }; 171 };
172 var isOdd = this._propertiesOutline.rootElement().children().length % 2 === 0; 172 var isOdd = this._propertiesOutline.rootElement().children().length % 2 === 0;
173 treeElement.listItemElement.classList.toggle("odd-row", isOdd); 173 treeElement.listItemElement.classList.toggle("odd-row", isOdd);
174 this._propertiesOutline.appendChild(treeElement); 174 this._propertiesOutline.appendChild(treeElement);
175 175
176 var trace = propertyTraces.get(propertyName); 176 var trace = propertyTraces.get(propertyName);
177 if (trace) { 177 if (trace) {
178 this._renderPropertyTrace(cssModel, cascades.matched, nodeStyle. node, treeElement, trace); 178 this._renderPropertyTrace(cssModel, matchedStyles, nodeStyle.nod e, treeElement, trace);
179 treeElement.listItemElement.addEventListener("mousedown", consum eEvent, false); 179 treeElement.listItemElement.addEventListener("mousedown", consum eEvent, false);
180 treeElement.listItemElement.addEventListener("dblclick", consume Event, false); 180 treeElement.listItemElement.addEventListener("dblclick", consume Event, false);
181 treeElement.listItemElement.addEventListener("click", handleClic k.bind(null, treeElement), false); 181 treeElement.listItemElement.addEventListener("click", handleClic k.bind(null, treeElement), false);
182 } 182 }
183 } 183 }
184 184
185 this._updateFilter(this._filterRegex); 185 this._updateFilter(this._filterRegex);
186 186
187 /** 187 /**
188 * @param {string} a 188 * @param {string} a
(...skipping 17 matching lines...) Expand all
206 if (!treeElement.expanded) 206 if (!treeElement.expanded)
207 treeElement.expand(); 207 treeElement.expand();
208 else 208 else
209 treeElement.collapse(); 209 treeElement.collapse();
210 consumeEvent(event); 210 consumeEvent(event);
211 } 211 }
212 }, 212 },
213 213
214 /** 214 /**
215 * @param {!WebInspector.CSSStyleModel} cssModel 215 * @param {!WebInspector.CSSStyleModel} cssModel
216 * @param {!WebInspector.SectionCascade} matchedCascade 216 * @param {!WebInspector.CSSStyleModel.MatchedStyleResult} matchedStyles
217 * @param {!WebInspector.DOMNode} node 217 * @param {!WebInspector.DOMNode} node
218 * @param {!TreeElement} rootTreeElement 218 * @param {!TreeElement} rootTreeElement
219 * @param {!Array<!WebInspector.CSSProperty>} tracedProperties 219 * @param {!Array<!WebInspector.CSSProperty>} tracedProperties
220 */ 220 */
221 _renderPropertyTrace: function(cssModel, matchedCascade, node, rootTreeEleme nt, tracedProperties) 221 _renderPropertyTrace: function(cssModel, matchedStyles, node, rootTreeElemen t, tracedProperties)
222 { 222 {
223 for (var property of tracedProperties) { 223 for (var property of tracedProperties) {
224 var trace = createElement("div"); 224 var trace = createElement("div");
225 trace.classList.add("property-trace"); 225 trace.classList.add("property-trace");
226 if (matchedCascade.propertyState(property) === WebInspector.SectionC ascade.PropertyState.Overloaded) 226 if (matchedStyles.propertyState(property) === WebInspector.CSSStyleM odel.MatchedStyleResult.PropertyState.Overloaded)
227 trace.classList.add("property-trace-inactive"); 227 trace.classList.add("property-trace-inactive");
228 228
229 var renderer = new WebInspector.StylesSidebarPropertyRenderer(null, node, property.name, /** @type {string} */(property.value)); 229 var renderer = new WebInspector.StylesSidebarPropertyRenderer(null, node, property.name, /** @type {string} */(property.value));
230 renderer.setColorHandler(this._processColor.bind(this)); 230 renderer.setColorHandler(this._processColor.bind(this));
231 var valueElement = renderer.renderValue(); 231 var valueElement = renderer.renderValue();
232 valueElement.classList.add("property-trace-value"); 232 valueElement.classList.add("property-trace-value");
233 trace.appendChild(valueElement); 233 trace.appendChild(valueElement);
234 234
235 var rule = property.ownerStyle.parentRule; 235 var rule = property.ownerStyle.parentRule;
236 if (rule) { 236 if (rule) {
237 var linkSpan = trace.createChild("span", "trace-link"); 237 var linkSpan = trace.createChild("span", "trace-link");
238 linkSpan.appendChild(WebInspector.StylePropertiesSection.createR uleOriginNode(cssModel, this._linkifier, rule)); 238 linkSpan.appendChild(WebInspector.StylePropertiesSection.createR uleOriginNode(cssModel, this._linkifier, rule));
239 } 239 }
240 240
241 var selectorElement = trace.createChild("span", "property-trace-sele ctor"); 241 var selectorElement = trace.createChild("span", "property-trace-sele ctor");
242 selectorElement.textContent = rule ? rule.selectorText() : "element. style"; 242 selectorElement.textContent = rule ? rule.selectorText() : "element. style";
243 selectorElement.title = selectorElement.textContent; 243 selectorElement.title = selectorElement.textContent;
244 244
245 var traceTreeElement = new TreeElement(); 245 var traceTreeElement = new TreeElement();
246 traceTreeElement.title = trace; 246 traceTreeElement.title = trace;
247 traceTreeElement.selectable = false; 247 traceTreeElement.selectable = false;
248 rootTreeElement.appendChild(traceTreeElement); 248 rootTreeElement.appendChild(traceTreeElement);
249 } 249 }
250 }, 250 },
251 251
252 /** 252 /**
253 * @param {!WebInspector.SectionCascade} matchedCascade 253 * @param {!WebInspector.CSSStyleModel.MatchedStyleResult} matchedStyles
254 * @return {!Map<string, !Array<!WebInspector.CSSProperty>>} 254 * @return {!Map<string, !Array<!WebInspector.CSSProperty>>}
255 */ 255 */
256 _computePropertyTraces: function(matchedCascade) 256 _computePropertyTraces: function(matchedStyles)
257 { 257 {
258 var result = new Map(); 258 var result = new Map();
259 var styles = matchedCascade.styles(); 259 for (var style of matchedStyles.nodeStyles()) {
260 for (var style of styles) {
261 var allProperties = style.allProperties; 260 var allProperties = style.allProperties;
262 for (var property of allProperties) { 261 for (var property of allProperties) {
263 if (!property.activeInStyle() || !matchedCascade.propertyState(p roperty)) 262 if (!property.activeInStyle() || !matchedStyles.propertyState(pr operty))
264 continue; 263 continue;
265 if (!result.has(property.name)) 264 if (!result.has(property.name))
266 result.set(property.name, []); 265 result.set(property.name, []);
267 result.get(property.name).push(property); 266 result.get(property.name).push(property);
268 } 267 }
269 } 268 }
270 return result; 269 return result;
271 }, 270 },
272 271
273 /** 272 /**
274 * @param {!WebInspector.SectionCascade} matchedCascade 273 * @param {!WebInspector.CSSStyleModel.MatchedStyleResult} matchedStyles
275 * @return {!Set<string>} 274 * @return {!Set<string>}
276 */ 275 */
277 _computeInheritedProperties: function(matchedCascade) 276 _computeInheritedProperties: function(matchedStyles)
278 { 277 {
279 var result = new Set(); 278 var result = new Set();
280 for (var style of matchedCascade.styles()) { 279 for (var style of matchedStyles.nodeStyles()) {
281 for (var property of style.allProperties) { 280 for (var property of style.allProperties) {
282 if (!matchedCascade.propertyState(property)) 281 if (!matchedStyles.propertyState(property))
283 continue; 282 continue;
284 result.add(WebInspector.CSSMetadata.canonicalPropertyName(proper ty.name)); 283 result.add(WebInspector.CSSMetadata.canonicalPropertyName(proper ty.name));
285 } 284 }
286 } 285 }
287 return result; 286 return result;
288 }, 287 },
289 288
290 /** 289 /**
291 * @param {?RegExp} regex 290 * @param {?RegExp} regex
292 */ 291 */
293 _updateFilter: function(regex) 292 _updateFilter: function(regex)
294 { 293 {
295 var children = this._propertiesOutline.rootElement().children(); 294 var children = this._propertiesOutline.rootElement().children();
296 for (var child of children) { 295 for (var child of children) {
297 var property = child[WebInspector.ComputedStyleWidget._propertySymbo l]; 296 var property = child[WebInspector.ComputedStyleWidget._propertySymbo l];
298 var matched = !regex || regex.test(property.name) || regex.test(prop erty.value); 297 var matched = !regex || regex.test(property.name) || regex.test(prop erty.value);
299 child.hidden = !matched; 298 child.hidden = !matched;
300 } 299 }
301 }, 300 },
302 301
303 __proto__: WebInspector.ThrottledWidget.prototype 302 __proto__: WebInspector.ThrottledWidget.prototype
304 } 303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698