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

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

Issue 2144923002: DevTools: remove the ComputedStyles -> Styles pane dependency. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
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 12 matching lines...) Expand all
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30 /** 30 /**
31 * @constructor 31 * @constructor
32 * @extends {WebInspector.ThrottledWidget} 32 * @extends {WebInspector.ThrottledWidget}
33 * @param {!WebInspector.StylesSidebarPane} stylesSidebarPane
34 * @param {!WebInspector.SharedSidebarModel} sharedModel
35 * @param {function(!WebInspector.CSSProperty)} revealCallback
36 */ 33 */
37 WebInspector.ComputedStyleWidget = function(stylesSidebarPane, sharedModel, reve alCallback) 34 WebInspector.ComputedStyleWidget = function()
38 { 35 {
39 WebInspector.ThrottledWidget.call(this); 36 WebInspector.ThrottledWidget.call(this);
40 this.element.classList.add("computed-style-sidebar-pane"); 37 this.element.classList.add("computed-style-sidebar-pane");
41 38
42 this.registerRequiredCSS("elements/computedStyleSidebarPane.css"); 39 this.registerRequiredCSS("elements/computedStyleSidebarPane.css");
43 this._alwaysShowComputedProperties = { "display": true, "height": true, "wid th": true }; 40 this._alwaysShowComputedProperties = { "display": true, "height": true, "wid th": true };
44 41
45 this._sharedModel = sharedModel; 42 this._computedStyleModel = new WebInspector.ComputedStyleModel();
46 this._sharedModel.addEventListener(WebInspector.SharedSidebarModel.Events.Co mputedStyleChanged, this.update, this); 43 this._computedStyleModel.addEventListener(WebInspector.ComputedStyleModel.Ev ents.ComputedStyleChanged, this.update, this);
47 44
48 this._showInheritedComputedStylePropertiesSetting = WebInspector.settings.cr eateSetting("showInheritedComputedStyleProperties", false); 45 this._showInheritedComputedStylePropertiesSetting = WebInspector.settings.cr eateSetting("showInheritedComputedStyleProperties", false);
49 this._showInheritedComputedStylePropertiesSetting.addChangeListener(this._sh owInheritedComputedStyleChanged.bind(this)); 46 this._showInheritedComputedStylePropertiesSetting.addChangeListener(this._sh owInheritedComputedStyleChanged.bind(this));
50 47
51 var hbox = this.element.createChild("div", "hbox styles-sidebar-pane-toolbar "); 48 var hbox = this.element.createChild("div", "hbox styles-sidebar-pane-toolbar ");
52 var filterContainerElement = hbox.createChild("div", "styles-sidebar-pane-fi lter-box"); 49 var filterContainerElement = hbox.createChild("div", "styles-sidebar-pane-fi lter-box");
53 var filterInput = WebInspector.StylesSidebarPane.createPropertyFilterElement (WebInspector.UIString("Filter"), hbox, filterCallback.bind(this)); 50 var filterInput = WebInspector.StylesSidebarPane.createPropertyFilterElement (WebInspector.UIString("Filter"), hbox, filterCallback.bind(this));
54 filterContainerElement.appendChild(filterInput); 51 filterContainerElement.appendChild(filterInput);
55 52
56 var toolbar = new WebInspector.Toolbar("styles-pane-toolbar", hbox); 53 var toolbar = new WebInspector.Toolbar("styles-pane-toolbar", hbox);
57 toolbar.appendToolbarItem(new WebInspector.ToolbarCheckbox(WebInspector.UISt ring("Show all"), undefined, this._showInheritedComputedStylePropertiesSetting)) ; 54 toolbar.appendToolbarItem(new WebInspector.ToolbarCheckbox(WebInspector.UISt ring("Show all"), undefined, this._showInheritedComputedStylePropertiesSetting)) ;
58 55
59 this._propertiesOutline = new TreeOutlineInShadow(); 56 this._propertiesOutline = new TreeOutlineInShadow();
60 this._propertiesOutline.hideOverflow(); 57 this._propertiesOutline.hideOverflow();
61 this._propertiesOutline.registerRequiredCSS("elements/computedStyleSidebarPa ne.css"); 58 this._propertiesOutline.registerRequiredCSS("elements/computedStyleSidebarPa ne.css");
62 this._propertiesOutline.element.classList.add("monospace", "computed-propert ies"); 59 this._propertiesOutline.element.classList.add("monospace", "computed-propert ies");
63 this.element.appendChild(this._propertiesOutline.element); 60 this.element.appendChild(this._propertiesOutline.element);
64 61
65 this._stylesSidebarPane = stylesSidebarPane;
66 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa ultCSSFormatter()); 62 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa ultCSSFormatter());
67 this._revealCallback = revealCallback;
68 63
69 /** 64 /**
70 * @param {?RegExp} regex 65 * @param {?RegExp} regex
71 * @this {WebInspector.ComputedStyleWidget} 66 * @this {WebInspector.ComputedStyleWidget}
72 */ 67 */
73 function filterCallback(regex) 68 function filterCallback(regex)
74 { 69 {
75 this._filterRegex = regex; 70 this._filterRegex = regex;
76 this._updateFilter(regex); 71 this._updateFilter(regex);
77 } 72 }
73
74 var fontsWidget = new WebInspector.PlatformFontsWidget(this._computedStyleMo del);
75 fontsWidget.show(this.element);
78 } 76 }
79 77
80 /** 78 /**
81 * @param {!WebInspector.StylesSidebarPane} stylesSidebarPane
82 * @param {!WebInspector.SharedSidebarModel} sharedModel
83 * @param {function(!WebInspector.CSSProperty)} revealCallback
84 * @return {!WebInspector.ElementsSidebarViewWrapperPane} 79 * @return {!WebInspector.ElementsSidebarViewWrapperPane}
85 */ 80 */
86 WebInspector.ComputedStyleWidget.createSidebarWrapper = function(stylesSidebarPa ne, sharedModel, revealCallback) 81 WebInspector.ComputedStyleWidget.createSidebarWrapper = function()
87 { 82 {
88 var widget = new WebInspector.ComputedStyleWidget(stylesSidebarPane, sharedM odel, revealCallback); 83 var widget = new WebInspector.ComputedStyleWidget();
89 return new WebInspector.ElementsSidebarViewWrapperPane(WebInspector.UIString ("Computed Style"), widget) 84 return new WebInspector.ElementsSidebarViewWrapperPane(WebInspector.UIString ("Computed Style"), widget)
lushnikov 2016/07/13 13:33:58 while we're here: semicolon is missing
90 } 85 }
91 86
92 WebInspector.ComputedStyleWidget._propertySymbol = Symbol("property"); 87 WebInspector.ComputedStyleWidget._propertySymbol = Symbol("property");
93 88
94 WebInspector.ComputedStyleWidget.prototype = { 89 WebInspector.ComputedStyleWidget.prototype = {
95 _showInheritedComputedStyleChanged: function() 90 _showInheritedComputedStyleChanged: function()
96 { 91 {
97 this.update(); 92 this.update();
98 }, 93 },
99 94
100 /** 95 /**
101 * @override 96 * @override
102 * @return {!Promise.<?>} 97 * @return {!Promise.<?>}
103 */ 98 */
104 doUpdate: function() 99 doUpdate: function()
105 { 100 {
106 var promises = [ 101 var promises = [
107 this._sharedModel.fetchComputedStyle(), 102 this._computedStyleModel.fetchComputedStyle(),
108 this._stylesSidebarPane.fetchMatchedCascade() 103 this._fetchMatchedCascade()
109 ]; 104 ];
110 return Promise.all(promises) 105 return Promise.all(promises)
111 .spread(this._innerRebuildUpdate.bind(this)); 106 .spread(this._innerRebuildUpdate.bind(this));
112 }, 107 },
113 108
114 /** 109 /**
110 * @return {!Promise.<?WebInspector.CSSMatchedStyles>}
111 */
112 _fetchMatchedCascade: function()
113 {
114 var node = this._computedStyleModel.node();
115 if (!node || !this._computedStyleModel.cssModel())
116 return Promise.resolve(/** @type {?WebInspector.CSSMatchedStyles} */ (null));
117
118 return this._computedStyleModel.cssModel().cachedMatchedCascadeForNode(n ode).then(validateStyles.bind(this));
119
120 /**
121 * @param {?WebInspector.CSSMatchedStyles} matchedStyles
122 * @return {?WebInspector.CSSMatchedStyles}
123 * @this {WebInspector.ComputedStyleWidget}
124 */
125 function validateStyles(matchedStyles)
126 {
127 return matchedStyles && matchedStyles.node() === this._computedStyle Model.node() ? matchedStyles : null;
128 }
129 },
130
131 /**
115 * @param {string} text 132 * @param {string} text
116 * @return {!Node} 133 * @return {!Node}
117 */ 134 */
118 _processColor: function(text) 135 _processColor: function(text)
119 { 136 {
120 var color = WebInspector.Color.parse(text); 137 var color = WebInspector.Color.parse(text);
121 if (!color) 138 if (!color)
122 return createTextNode(text); 139 return createTextNode(text);
123 var swatch = WebInspector.ColorSwatch.create(); 140 var swatch = WebInspector.ColorSwatch.create();
124 swatch.setColorText(text); 141 swatch.setColorText(text);
125 swatch.setFormat(WebInspector.Color.detectColorFormat(color)); 142 swatch.setFormat(WebInspector.Color.detectColorFormat(color));
126 return swatch; 143 return swatch;
127 }, 144 },
128 145
129 /** 146 /**
130 * @param {?WebInspector.SharedSidebarModel.ComputedStyle} nodeStyle 147 * @param {?WebInspector.ComputedStyleModel.ComputedStyle} nodeStyle
131 * @param {?WebInspector.CSSMatchedStyles} matchedStyles 148 * @param {?WebInspector.CSSMatchedStyles} matchedStyles
132 */ 149 */
133 _innerRebuildUpdate: function(nodeStyle, matchedStyles) 150 _innerRebuildUpdate: function(nodeStyle, matchedStyles)
134 { 151 {
135 this._propertiesOutline.removeChildren(); 152 this._propertiesOutline.removeChildren();
136 this._linkifier.reset(); 153 this._linkifier.reset();
137 var cssModel = this._sharedModel.cssModel(); 154 var cssModel = this._computedStyleModel.cssModel();
138 if (!nodeStyle || !matchedStyles || !cssModel) 155 if (!nodeStyle || !matchedStyles || !cssModel)
139 return; 156 return;
140 157
141 var uniqueProperties = nodeStyle.computedStyle.keysArray(); 158 var uniqueProperties = nodeStyle.computedStyle.keysArray();
142 uniqueProperties.sort(propertySorter); 159 uniqueProperties.sort(propertySorter);
143 160
144 var propertyTraces = this._computePropertyTraces(matchedStyles); 161 var propertyTraces = this._computePropertyTraces(matchedStyles);
145 var inhertiedProperties = this._computeInheritedProperties(matchedStyles ); 162 var inhertiedProperties = this._computeInheritedProperties(matchedStyles );
146 var showInherited = this._showInheritedComputedStylePropertiesSetting.ge t(); 163 var showInherited = this._showInheritedComputedStylePropertiesSetting.ge t();
147 for (var i = 0; i < uniqueProperties.length; ++i) { 164 for (var i = 0; i < uniqueProperties.length; ++i) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 consumeEvent(event); 244 consumeEvent(event);
228 } 245 }
229 }, 246 },
230 247
231 /** 248 /**
232 * @param {!WebInspector.CSSProperty} cssProperty 249 * @param {!WebInspector.CSSProperty} cssProperty
233 * @param {!Event} event 250 * @param {!Event} event
234 */ 251 */
235 _navigateToSource: function(cssProperty, event) 252 _navigateToSource: function(cssProperty, event)
236 { 253 {
237 if (this._revealCallback) 254 WebInspector.Revealer.reveal(cssProperty);
238 this._revealCallback.call(null, cssProperty);
239 event.consume(true); 255 event.consume(true);
240 }, 256 },
241 257
242 /** 258 /**
243 * @param {!WebInspector.CSSModel} cssModel 259 * @param {!WebInspector.CSSModel} cssModel
244 * @param {!WebInspector.CSSMatchedStyles} matchedStyles 260 * @param {!WebInspector.CSSMatchedStyles} matchedStyles
245 * @param {!WebInspector.DOMNode} node 261 * @param {!WebInspector.DOMNode} node
246 * @param {!TreeElement} rootTreeElement 262 * @param {!TreeElement} rootTreeElement
247 * @param {!Array<!WebInspector.CSSProperty>} tracedProperties 263 * @param {!Array<!WebInspector.CSSProperty>} tracedProperties
248 * @return {!WebInspector.CSSProperty} 264 * @return {!WebInspector.CSSProperty}
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 var children = this._propertiesOutline.rootElement().children(); 349 var children = this._propertiesOutline.rootElement().children();
334 for (var child of children) { 350 for (var child of children) {
335 var property = child[WebInspector.ComputedStyleWidget._propertySymbo l]; 351 var property = child[WebInspector.ComputedStyleWidget._propertySymbo l];
336 var matched = !regex || regex.test(property.name) || regex.test(prop erty.value); 352 var matched = !regex || regex.test(property.name) || regex.test(prop erty.value);
337 child.hidden = !matched; 353 child.hidden = !matched;
338 } 354 }
339 }, 355 },
340 356
341 __proto__: WebInspector.ThrottledWidget.prototype 357 __proto__: WebInspector.ThrottledWidget.prototype
342 } 358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698