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

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

Issue 1312893006: DevTools: revert back ComputedStylesSidebar (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: brand new design Created 5 years, 3 months 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 | Annotate | Revision Log
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 var filterContainerElement = hbox.createChild("div", "styles-sidebar-pane-fi lter-box"); 51 var filterContainerElement = hbox.createChild("div", "styles-sidebar-pane-fi lter-box");
52 var filterInput = WebInspector.StylesSidebarPane.createPropertyFilterElement (WebInspector.UIString("Filter"), hbox, filterCallback.bind(this)); 52 var filterInput = WebInspector.StylesSidebarPane.createPropertyFilterElement (WebInspector.UIString("Filter"), hbox, filterCallback.bind(this));
53 filterContainerElement.appendChild(filterInput); 53 filterContainerElement.appendChild(filterInput);
54 54
55 var toolbar = new WebInspector.Toolbar(hbox); 55 var toolbar = new WebInspector.Toolbar(hbox);
56 toolbar.element.classList.add("styles-pane-toolbar"); 56 toolbar.element.classList.add("styles-pane-toolbar");
57 toolbar.appendToolbarItem(new WebInspector.ToolbarCheckbox(WebInspector.UISt ring("Show inherited"), 57 toolbar.appendToolbarItem(new WebInspector.ToolbarCheckbox(WebInspector.UISt ring("Show inherited"),
58 WebInspector.UISt ring("Show inherited properties"), 58 WebInspector.UISt ring("Show inherited properties"),
59 this._showInherit edComputedStylePropertiesSetting)); 59 this._showInherit edComputedStylePropertiesSetting));
60 60
61 this._propertiesContainer = this.element.createChild("div", "monospace"); 61 this._propertiesOutline = new TreeOutlineInShadow();
62 this._propertiesContainer.classList.add("computed-properties"); 62 this._propertiesOutline.registerRequiredCSS("elements/computedStyleSidebarPa ne.css");
63 this._onTracePropertyBound = this._onTraceProperty.bind(this); 63 this._propertiesOutline.element.classList.add("monospace", "computed-propert ies");
64 this.element.appendChild(this._propertiesOutline.element);
64 65
65 this._stylesSidebarPane = stylesSidebarPane; 66 this._stylesSidebarPane = stylesSidebarPane;
67 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa ultCSSFormatter());
66 68
67 /** 69 /**
68 * @param {?RegExp} regex 70 * @param {?RegExp} regex
69 * @this {WebInspector.ComputedStyleWidget} 71 * @this {WebInspector.ComputedStyleWidget}
70 */ 72 */
71 function filterCallback(regex) 73 function filterCallback(regex)
72 { 74 {
73 this._filterRegex = regex; 75 this._filterRegex = regex;
74 this._updateFilter(regex); 76 this._updateFilter(regex);
75 } 77 }
76 } 78 }
77 79
78 /** 80 /**
79 * @param {!WebInspector.StylesSidebarPane} stylesSidebarPane 81 * @param {!WebInspector.StylesSidebarPane} stylesSidebarPane
80 * @param {!WebInspector.SharedSidebarModel} sharedModel 82 * @param {!WebInspector.SharedSidebarModel} sharedModel
81 * @return {!WebInspector.ElementsSidebarViewWrapperPane} 83 * @return {!WebInspector.ElementsSidebarViewWrapperPane}
82 */ 84 */
83 WebInspector.ComputedStyleWidget.createSidebarWrapper = function(stylesSidebarPa ne, sharedModel) 85 WebInspector.ComputedStyleWidget.createSidebarWrapper = function(stylesSidebarPa ne, sharedModel)
84 { 86 {
85 var widget = new WebInspector.ComputedStyleWidget(stylesSidebarPane, sharedM odel); 87 var widget = new WebInspector.ComputedStyleWidget(stylesSidebarPane, sharedM odel);
86 return new WebInspector.ElementsSidebarViewWrapperPane(WebInspector.UIString ("Computed Style"), widget) 88 return new WebInspector.ElementsSidebarViewWrapperPane(WebInspector.UIString ("Computed Style"), widget)
87 } 89 }
88 90
89 WebInspector.ComputedStyleWidget._propertySymbol = Symbol("property"); 91 WebInspector.ComputedStyleWidget._propertySymbol = Symbol("property");
90 92
91 WebInspector.ComputedStyleWidget.prototype = { 93 WebInspector.ComputedStyleWidget.prototype = {
92 /**
93 * @param {!Event} event
94 */
95 _onTraceProperty: function(event)
96 {
97 var item = event.target.enclosingNodeOrSelfWithClass("computed-style-pro perty");
98 var property = item && item[WebInspector.ComputedStyleWidget._propertySy mbol];
99 if (!property)
100 return;
101 this._stylesSidebarPane.tracePropertyName(property.name);
102 },
103
104 _showInheritedComputedStyleChanged: function() 94 _showInheritedComputedStyleChanged: function()
105 { 95 {
106 this.update(); 96 this.update();
107 }, 97 },
108 98
109 /** 99 /**
110 * @override 100 * @override
111 * @return {!Promise.<?>} 101 * @return {!Promise.<?>}
112 */ 102 */
113 doUpdate: function() 103 doUpdate: function()
(...skipping 19 matching lines...) Expand all
133 swatch.setColorText(text); 123 swatch.setColorText(text);
134 return swatch; 124 return swatch;
135 }, 125 },
136 126
137 /** 127 /**
138 * @param {?WebInspector.SharedSidebarModel.ComputedStyle} nodeStyle 128 * @param {?WebInspector.SharedSidebarModel.ComputedStyle} nodeStyle
139 * @param {?{matched: !WebInspector.SectionCascade, pseudo: !Map.<number, !W ebInspector.SectionCascade>}} cascades 129 * @param {?{matched: !WebInspector.SectionCascade, pseudo: !Map.<number, !W ebInspector.SectionCascade>}} cascades
140 */ 130 */
141 _innerRebuildUpdate: function(nodeStyle, cascades) 131 _innerRebuildUpdate: function(nodeStyle, cascades)
142 { 132 {
143 this._propertiesContainer.removeChildren(); 133 this._propertiesOutline.removeChildren();
144 if (!nodeStyle || !cascades) 134 this._linkifier.reset();
135 var cssModel = this._sharedModel.cssModel();
136 if (!nodeStyle || !cascades || !cssModel)
145 return; 137 return;
146 138
147 var uniqueProperties = nodeStyle.computedStyle.keysArray(); 139 var uniqueProperties = nodeStyle.computedStyle.keysArray();
148 uniqueProperties.sort(propertySorter); 140 uniqueProperties.sort(propertySorter);
149 141
142 var propertyTraces = this._computePropertyTraces(cascades.matched);
150 var showInherited = this._showInheritedComputedStylePropertiesSetting.ge t(); 143 var showInherited = this._showInheritedComputedStylePropertiesSetting.ge t();
151 for (var i = 0; i < uniqueProperties.length; ++i) { 144 for (var i = 0; i < uniqueProperties.length; ++i) {
152 var propertyName = uniqueProperties[i]; 145 var propertyName = uniqueProperties[i];
153 var propertyValue = nodeStyle.computedStyle.get(propertyName); 146 var propertyValue = nodeStyle.computedStyle.get(propertyName);
154 var inherited = this._isPropertyInherited(cascades.matched, property Name); 147 var inherited = this._isPropertyInherited(cascades.matched, property Name);
155 if (!showInherited && inherited && !(propertyName in this._alwaysSho wComputedProperties)) 148 if (!showInherited && inherited && !(propertyName in this._alwaysSho wComputedProperties))
156 continue; 149 continue;
157 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName(p ropertyName); 150 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName(p ropertyName);
158 if (propertyName !== canonicalName && propertyValue === nodeStyle.co mputedStyle.get(canonicalName)) 151 if (propertyName !== canonicalName && propertyValue === nodeStyle.co mputedStyle.get(canonicalName))
159 continue; 152 continue;
160 var item = this._propertiesContainer.createChild("div", "computed-st yle-property"); 153
161 item[WebInspector.ComputedStyleWidget._propertySymbol] = { 154 var propertyElement = createElement("div");
155 propertyElement.classList.add("computed-style-property");
156 propertyElement.classList.toggle("computed-style-property-inherited" , inherited);
157 var renderer = new WebInspector.StylesSidebarPropertyRenderer(null, nodeStyle.node, propertyName, /** @type {string} */(propertyValue));
158 renderer.setColorHandler(this._processColor.bind(this));
159 var propertyNameElement = renderer.renderName();
160 propertyNameElement.classList.add("property-name");
161 propertyElement.appendChild(propertyNameElement);
162 var propertyValueElement = renderer.renderValue();
163 propertyValueElement.classList.add("property-value");
164 propertyElement.appendChild(propertyValueElement);
165
166 var treeElement = new TreeElement();
167 treeElement.selectable = false;
168 treeElement.title = propertyElement;
169 treeElement[WebInspector.ComputedStyleWidget._propertySymbol] = {
162 name: propertyName, 170 name: propertyName,
163 value: propertyValue 171 value: propertyValue
164 }; 172 };
165 item.classList.toggle("computed-style-property-inherited", inherited ); 173 var isOdd = this._propertiesOutline.rootElement().children().length % 2 === 0;
166 var renderer = new WebInspector.StylesSidebarPropertyRenderer(null, nodeStyle.node, propertyName, /** @type {string} */(propertyValue)); 174 treeElement.listItemElement.classList.toggle("odd-row", isOdd);
167 renderer.setColorHandler(this._processColor.bind(this)); 175 this._propertiesOutline.appendChild(treeElement);
168 176
169 if (!inherited) { 177 var trace = propertyTraces.get(propertyName);
170 var traceButton = item.createChild("div", "computed-style-trace- button"); 178 if (trace) {
171 traceButton.createChild("div", "glyph"); 179 this._renderPropertyTrace(cssModel, nodeStyle.node, treeElement, trace);
172 traceButton.addEventListener("click", this._onTracePropertyBound , false); 180 treeElement.listItemElement.addEventListener("mousedown", consum eEvent, false);
181 treeElement.listItemElement.addEventListener("dblclick", consume Event, false);
182 treeElement.listItemElement.addEventListener("click", handleClic k.bind(null, treeElement), false);
173 } 183 }
174 item.appendChild(renderer.renderName());
175 item.appendChild(createTextNode(": "));
176 item.appendChild(renderer.renderValue());
177 item.appendChild(createTextNode(";"));
178 this._propertiesContainer.appendChild(item);
179 } 184 }
180 185
181 this._updateFilter(this._filterRegex); 186 this._updateFilter(this._filterRegex);
182 187
183 /** 188 /**
184 * @param {string} a 189 * @param {string} a
185 * @param {string} b 190 * @param {string} b
186 */ 191 */
187 function propertySorter(a, b) 192 function propertySorter(a, b)
188 { 193 {
189 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName; 194 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName;
190 return canonicalName(a).compareTo(canonicalName(b)); 195 return canonicalName(a).compareTo(canonicalName(b));
191 } 196 }
197
198 /**
199 * @param {!TreeElement} treeElement
200 * @param {!Event} event
201 */
202 function handleClick(treeElement, event)
203 {
204 if (!treeElement.expanded)
205 treeElement.expand();
206 else
207 treeElement.collapse();
208 consumeEvent(event);
209 }
192 }, 210 },
193 211
194 /** 212 /**
213 * @param {!WebInspector.CSSStyleModel} cssModel
214 * @param {!WebInspector.DOMNode} node
215 * @param {!TreeElement} rootTreeElement
216 * @param {!Array.<!{property: !WebInspector.CSSProperty, overloaded: boolea n}>} tracedProperties
217 */
218 _renderPropertyTrace: function(cssModel, node, rootTreeElement, tracedProper ties)
219 {
220 for (var propertyInfo of tracedProperties) {
221 var trace = createElement("div");
222 trace.classList.add("property-trace");
223 if (propertyInfo.overloaded)
224 trace.classList.add("property-trace-inactive");
225
226 var renderer = new WebInspector.StylesSidebarPropertyRenderer(null, node, propertyInfo.property.name, /** @type {string} */(propertyInfo.property.va lue));
227 renderer.setColorHandler(this._processColor.bind(this));
228 var valueElement = renderer.renderValue();
229 valueElement.classList.add("property-trace-value");
230 trace.appendChild(valueElement);
231
232 var rule = propertyInfo.property.ownerStyle.parentRule;
233 if (rule) {
234 var linkSpan = trace.createChild("span", "trace-link");
235 linkSpan.appendChild(WebInspector.StylePropertiesSection.createR uleOriginNode(cssModel, this._linkifier, rule));
236 }
237
238 var selectorElement = trace.createChild("span", "property-trace-sele ctor");
239 selectorElement.textContent = rule ? rule.selectorText : "element.st yle";
240 selectorElement.title = selectorElement.textContent;
241
242 var traceTreeElement = new TreeElement();
243 traceTreeElement.title = trace;
244 traceTreeElement.selectable = false;
245 rootTreeElement.appendChild(traceTreeElement);
246 }
247 },
248
249 /**
250 * @param {!WebInspector.SectionCascade} matchedCascade
251 * @return {!Map.<string, !Array.<!{property: !WebInspector.CSSProperty, ove rloaded: boolean}>>}
252 */
253 _computePropertyTraces: function(matchedCascade)
254 {
255 var result = new Map();
256 var models = matchedCascade.sectionModels();
257 for (var model of models) {
258 var allProperties = model.style().allProperties;
259 for (var property of allProperties) {
260 if (!property.activeInStyle() || !model.isPropertyInCascade(prop erty.name))
261 continue;
262 if (!result.has(property.name))
263 result.set(property.name, []);
264 result.get(property.name).push({
265 property: property,
266 overloaded: model.isPropertyOverloaded(property.name)
267 });
268 }
269 }
270 return result;
271 },
272
273 /**
195 * @param {!WebInspector.SectionCascade} matchedCascade 274 * @param {!WebInspector.SectionCascade} matchedCascade
196 * @param {string} propertyName 275 * @param {string} propertyName
197 */ 276 */
198 _isPropertyInherited: function(matchedCascade, propertyName) 277 _isPropertyInherited: function(matchedCascade, propertyName)
199 { 278 {
200 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName(prope rtyName); 279 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName(prope rtyName);
201 return !matchedCascade.allUsedProperties().has(canonicalName); 280 return !matchedCascade.allUsedProperties().has(canonicalName);
202 }, 281 },
203 282
204 /** 283 /**
205 * @param {?RegExp} regex 284 * @param {?RegExp} regex
206 */ 285 */
207 _updateFilter: function(regex) 286 _updateFilter: function(regex)
208 { 287 {
209 for (var i = 0; i < this._propertiesContainer.children.length; ++i) { 288 var children = this._propertiesOutline.rootElement().children();
210 var item = this._propertiesContainer.children[i]; 289 for (var child of children) {
211 var property = item[WebInspector.ComputedStyleWidget._propertySymbol ]; 290 var property = child[WebInspector.ComputedStyleWidget._propertySymbo l];
212 var matched = !regex || regex.test(property.name) || regex.test(prop erty.value); 291 var matched = !regex || regex.test(property.name) || regex.test(prop erty.value);
213 item.classList.toggle("hidden", !matched); 292 child.hidden = !matched;
214 } 293 }
215 }, 294 },
216 295
217 __proto__: WebInspector.ThrottledWidget.prototype 296 __proto__: WebInspector.ThrottledWidget.prototype
218 } 297 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698