| OLD | NEW |
| 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 11 matching lines...) Expand all Loading... |
| 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 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 * @param {!WebInspector.StylesSidebarPane} stylesSidebarPane | 33 * @param {!WebInspector.StylesSidebarPane} stylesSidebarPane |
| 33 * @param {!WebInspector.SharedSidebarModel} sharedModel | 34 * @param {!WebInspector.SharedSidebarModel} sharedModel |
| 34 * @extends {WebInspector.ThrottledWidget} | 35 * @param {function(!WebInspector.CSSProperty)} revealCallback |
| 35 */ | 36 */ |
| 36 WebInspector.ComputedStyleWidget = function(stylesSidebarPane, sharedModel) | 37 WebInspector.ComputedStyleWidget = function(stylesSidebarPane, sharedModel, reve
alCallback) |
| 37 { | 38 { |
| 38 WebInspector.ThrottledWidget.call(this); | 39 WebInspector.ThrottledWidget.call(this); |
| 39 this.element.classList.add("computed-style-sidebar-pane"); | 40 this.element.classList.add("computed-style-sidebar-pane"); |
| 40 | 41 |
| 41 this.registerRequiredCSS("elements/computedStyleSidebarPane.css"); | 42 this.registerRequiredCSS("elements/computedStyleSidebarPane.css"); |
| 42 this._alwaysShowComputedProperties = { "display": true, "height": true, "wid
th": true }; | 43 this._alwaysShowComputedProperties = { "display": true, "height": true, "wid
th": true }; |
| 43 | 44 |
| 44 this._sharedModel = sharedModel; | 45 this._sharedModel = sharedModel; |
| 45 this._sharedModel.addEventListener(WebInspector.SharedSidebarModel.Events.Co
mputedStyleChanged, this.update, this); | 46 this._sharedModel.addEventListener(WebInspector.SharedSidebarModel.Events.Co
mputedStyleChanged, this.update, this); |
| 46 | 47 |
| 47 this._showInheritedComputedStylePropertiesSetting = WebInspector.settings.cr
eateSetting("showInheritedComputedStyleProperties", false); | 48 this._showInheritedComputedStylePropertiesSetting = WebInspector.settings.cr
eateSetting("showInheritedComputedStyleProperties", false); |
| 48 this._showInheritedComputedStylePropertiesSetting.addChangeListener(this._sh
owInheritedComputedStyleChanged.bind(this)); | 49 this._showInheritedComputedStylePropertiesSetting.addChangeListener(this._sh
owInheritedComputedStyleChanged.bind(this)); |
| 49 | 50 |
| 50 var hbox = this.element.createChild("div", "hbox styles-sidebar-pane-toolbar
"); | 51 var hbox = this.element.createChild("div", "hbox styles-sidebar-pane-toolbar
"); |
| 51 var filterContainerElement = hbox.createChild("div", "styles-sidebar-pane-fi
lter-box"); | 52 var filterContainerElement = hbox.createChild("div", "styles-sidebar-pane-fi
lter-box"); |
| 52 var filterInput = WebInspector.StylesSidebarPane.createPropertyFilterElement
(WebInspector.UIString("Filter"), hbox, filterCallback.bind(this)); | 53 var filterInput = WebInspector.StylesSidebarPane.createPropertyFilterElement
(WebInspector.UIString("Filter"), hbox, filterCallback.bind(this)); |
| 53 filterContainerElement.appendChild(filterInput); | 54 filterContainerElement.appendChild(filterInput); |
| 54 | 55 |
| 55 var toolbar = new WebInspector.Toolbar("styles-pane-toolbar", hbox); | 56 var toolbar = new WebInspector.Toolbar("styles-pane-toolbar", hbox); |
| 56 toolbar.appendToolbarItem(new WebInspector.ToolbarCheckbox(WebInspector.UISt
ring("Show all"), undefined, this._showInheritedComputedStylePropertiesSetting))
; | 57 toolbar.appendToolbarItem(new WebInspector.ToolbarCheckbox(WebInspector.UISt
ring("Show all"), undefined, this._showInheritedComputedStylePropertiesSetting))
; |
| 57 | 58 |
| 58 this._propertiesOutline = new TreeOutlineInShadow(); | 59 this._propertiesOutline = new TreeOutlineInShadow(); |
| 59 this._propertiesOutline.hideOverflow(); | 60 this._propertiesOutline.hideOverflow(); |
| 60 this._propertiesOutline.registerRequiredCSS("elements/computedStyleSidebarPa
ne.css"); | 61 this._propertiesOutline.registerRequiredCSS("elements/computedStyleSidebarPa
ne.css"); |
| 61 this._propertiesOutline.element.classList.add("monospace", "computed-propert
ies"); | 62 this._propertiesOutline.element.classList.add("monospace", "computed-propert
ies"); |
| 62 this.element.appendChild(this._propertiesOutline.element); | 63 this.element.appendChild(this._propertiesOutline.element); |
| 63 | 64 |
| 64 this._stylesSidebarPane = stylesSidebarPane; | 65 this._stylesSidebarPane = stylesSidebarPane; |
| 65 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa
ultCSSFormatter()); | 66 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa
ultCSSFormatter()); |
| 67 this._revealCallback = revealCallback; |
| 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 |
| 83 * @param {function(!WebInspector.CSSProperty)} revealCallback |
| 81 * @return {!WebInspector.ElementsSidebarViewWrapperPane} | 84 * @return {!WebInspector.ElementsSidebarViewWrapperPane} |
| 82 */ | 85 */ |
| 83 WebInspector.ComputedStyleWidget.createSidebarWrapper = function(stylesSidebarPa
ne, sharedModel) | 86 WebInspector.ComputedStyleWidget.createSidebarWrapper = function(stylesSidebarPa
ne, sharedModel, revealCallback) |
| 84 { | 87 { |
| 85 var widget = new WebInspector.ComputedStyleWidget(stylesSidebarPane, sharedM
odel); | 88 var widget = new WebInspector.ComputedStyleWidget(stylesSidebarPane, sharedM
odel, revealCallback); |
| 86 return new WebInspector.ElementsSidebarViewWrapperPane(WebInspector.UIString
("Computed Style"), widget) | 89 return new WebInspector.ElementsSidebarViewWrapperPane(WebInspector.UIString
("Computed Style"), widget) |
| 87 } | 90 } |
| 88 | 91 |
| 89 WebInspector.ComputedStyleWidget._propertySymbol = Symbol("property"); | 92 WebInspector.ComputedStyleWidget._propertySymbol = Symbol("property"); |
| 90 | 93 |
| 91 WebInspector.ComputedStyleWidget.prototype = { | 94 WebInspector.ComputedStyleWidget.prototype = { |
| 92 _showInheritedComputedStyleChanged: function() | 95 _showInheritedComputedStyleChanged: function() |
| 93 { | 96 { |
| 94 this.update(); | 97 this.update(); |
| 95 }, | 98 }, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 treeElement[WebInspector.ComputedStyleWidget._propertySymbol] = { | 172 treeElement[WebInspector.ComputedStyleWidget._propertySymbol] = { |
| 170 name: propertyName, | 173 name: propertyName, |
| 171 value: propertyValue | 174 value: propertyValue |
| 172 }; | 175 }; |
| 173 var isOdd = this._propertiesOutline.rootElement().children().length
% 2 === 0; | 176 var isOdd = this._propertiesOutline.rootElement().children().length
% 2 === 0; |
| 174 treeElement.listItemElement.classList.toggle("odd-row", isOdd); | 177 treeElement.listItemElement.classList.toggle("odd-row", isOdd); |
| 175 this._propertiesOutline.appendChild(treeElement); | 178 this._propertiesOutline.appendChild(treeElement); |
| 176 | 179 |
| 177 var trace = propertyTraces.get(propertyName); | 180 var trace = propertyTraces.get(propertyName); |
| 178 if (trace) { | 181 if (trace) { |
| 179 this._renderPropertyTrace(cssModel, matchedStyles, nodeStyle.nod
e, treeElement, trace); | 182 var activeProperty = this._renderPropertyTrace(cssModel, matched
Styles, nodeStyle.node, treeElement, trace); |
| 180 treeElement.listItemElement.addEventListener("mousedown", consum
eEvent, false); | 183 treeElement.listItemElement.addEventListener("mousedown", consum
eEvent, false); |
| 181 treeElement.listItemElement.addEventListener("dblclick", consume
Event, false); | 184 treeElement.listItemElement.addEventListener("dblclick", consume
Event, false); |
| 182 treeElement.listItemElement.addEventListener("click", handleClic
k.bind(null, treeElement), false); | 185 treeElement.listItemElement.addEventListener("click", handleClic
k.bind(null, treeElement), false); |
| 186 var gotoSourceElement = propertyValueElement.createChild("div",
"goto-source-icon"); |
| 187 gotoSourceElement.addEventListener("click", this._navigateToSour
ce.bind(this, activeProperty)); |
| 183 } | 188 } |
| 184 } | 189 } |
| 185 | 190 |
| 186 this._updateFilter(this._filterRegex); | 191 this._updateFilter(this._filterRegex); |
| 187 | 192 |
| 188 /** | 193 /** |
| 189 * @param {string} a | 194 * @param {string} a |
| 190 * @param {string} b | 195 * @param {string} b |
| 191 * @return {number} | 196 * @return {number} |
| 192 */ | 197 */ |
| (...skipping 13 matching lines...) Expand all Loading... |
| 206 { | 211 { |
| 207 if (!treeElement.expanded) | 212 if (!treeElement.expanded) |
| 208 treeElement.expand(); | 213 treeElement.expand(); |
| 209 else | 214 else |
| 210 treeElement.collapse(); | 215 treeElement.collapse(); |
| 211 consumeEvent(event); | 216 consumeEvent(event); |
| 212 } | 217 } |
| 213 }, | 218 }, |
| 214 | 219 |
| 215 /** | 220 /** |
| 221 * @param {!WebInspector.CSSProperty} cssProperty |
| 222 * @param {!Event} event |
| 223 */ |
| 224 _navigateToSource: function(cssProperty, event) |
| 225 { |
| 226 if (this._revealCallback) |
| 227 this._revealCallback.call(null, cssProperty); |
| 228 event.consume(true); |
| 229 }, |
| 230 |
| 231 /** |
| 216 * @param {!WebInspector.CSSStyleModel} cssModel | 232 * @param {!WebInspector.CSSStyleModel} cssModel |
| 217 * @param {!WebInspector.CSSStyleModel.MatchedStyleResult} matchedStyles | 233 * @param {!WebInspector.CSSStyleModel.MatchedStyleResult} matchedStyles |
| 218 * @param {!WebInspector.DOMNode} node | 234 * @param {!WebInspector.DOMNode} node |
| 219 * @param {!TreeElement} rootTreeElement | 235 * @param {!TreeElement} rootTreeElement |
| 220 * @param {!Array<!WebInspector.CSSProperty>} tracedProperties | 236 * @param {!Array<!WebInspector.CSSProperty>} tracedProperties |
| 237 * @return {!WebInspector.CSSProperty} |
| 221 */ | 238 */ |
| 222 _renderPropertyTrace: function(cssModel, matchedStyles, node, rootTreeElemen
t, tracedProperties) | 239 _renderPropertyTrace: function(cssModel, matchedStyles, node, rootTreeElemen
t, tracedProperties) |
| 223 { | 240 { |
| 241 var activeProperty = null; |
| 224 for (var property of tracedProperties) { | 242 for (var property of tracedProperties) { |
| 225 var trace = createElement("div"); | 243 var trace = createElement("div"); |
| 226 trace.classList.add("property-trace"); | 244 trace.classList.add("property-trace"); |
| 227 if (matchedStyles.propertyState(property) === WebInspector.CSSStyleM
odel.MatchedStyleResult.PropertyState.Overloaded) | 245 if (matchedStyles.propertyState(property) === WebInspector.CSSStyleM
odel.MatchedStyleResult.PropertyState.Overloaded) |
| 228 trace.classList.add("property-trace-inactive"); | 246 trace.classList.add("property-trace-inactive"); |
| 247 else |
| 248 activeProperty = property; |
| 229 | 249 |
| 230 var renderer = new WebInspector.StylesSidebarPropertyRenderer(null,
node, property.name, /** @type {string} */(property.value)); | 250 var renderer = new WebInspector.StylesSidebarPropertyRenderer(null,
node, property.name, /** @type {string} */(property.value)); |
| 231 renderer.setColorHandler(this._processColor.bind(this)); | 251 renderer.setColorHandler(this._processColor.bind(this)); |
| 232 var valueElement = renderer.renderValue(); | 252 var valueElement = renderer.renderValue(); |
| 233 valueElement.classList.add("property-trace-value"); | 253 valueElement.classList.add("property-trace-value"); |
| 254 valueElement.addEventListener("click", this._navigateToSource.bind(t
his, property), false); |
| 255 var gotoSourceElement = createElement("div"); |
| 256 gotoSourceElement.classList.add("goto-source-icon"); |
| 257 gotoSourceElement.addEventListener("click", this._navigateToSource.b
ind(this, property)); |
| 258 valueElement.insertBefore(gotoSourceElement, valueElement.firstChild
); |
| 259 |
| 234 trace.appendChild(valueElement); | 260 trace.appendChild(valueElement); |
| 235 | 261 |
| 236 var rule = property.ownerStyle.parentRule; | 262 var rule = property.ownerStyle.parentRule; |
| 237 if (rule) { | 263 if (rule) { |
| 238 var linkSpan = trace.createChild("span", "trace-link"); | 264 var linkSpan = trace.createChild("span", "trace-link"); |
| 239 linkSpan.appendChild(WebInspector.StylePropertiesSection.createR
uleOriginNode(cssModel, this._linkifier, rule)); | 265 linkSpan.appendChild(WebInspector.StylePropertiesSection.createR
uleOriginNode(cssModel, this._linkifier, rule)); |
| 240 } | 266 } |
| 241 | 267 |
| 242 var selectorElement = trace.createChild("span", "property-trace-sele
ctor"); | 268 var selectorElement = trace.createChild("span", "property-trace-sele
ctor"); |
| 243 selectorElement.textContent = rule ? rule.selectorText() : "element.
style"; | 269 selectorElement.textContent = rule ? rule.selectorText() : "element.
style"; |
| 244 selectorElement.title = selectorElement.textContent; | 270 selectorElement.title = selectorElement.textContent; |
| 245 | 271 |
| 246 var traceTreeElement = new TreeElement(); | 272 var traceTreeElement = new TreeElement(); |
| 247 traceTreeElement.title = trace; | 273 traceTreeElement.title = trace; |
| 248 traceTreeElement.selectable = false; | 274 traceTreeElement.selectable = false; |
| 249 rootTreeElement.appendChild(traceTreeElement); | 275 rootTreeElement.appendChild(traceTreeElement); |
| 250 } | 276 } |
| 277 return /** @type {!WebInspector.CSSProperty} */(activeProperty); |
| 251 }, | 278 }, |
| 252 | 279 |
| 253 /** | 280 /** |
| 254 * @param {!WebInspector.CSSStyleModel.MatchedStyleResult} matchedStyles | 281 * @param {!WebInspector.CSSStyleModel.MatchedStyleResult} matchedStyles |
| 255 * @return {!Map<string, !Array<!WebInspector.CSSProperty>>} | 282 * @return {!Map<string, !Array<!WebInspector.CSSProperty>>} |
| 256 */ | 283 */ |
| 257 _computePropertyTraces: function(matchedStyles) | 284 _computePropertyTraces: function(matchedStyles) |
| 258 { | 285 { |
| 259 var result = new Map(); | 286 var result = new Map(); |
| 260 for (var style of matchedStyles.nodeStyles()) { | 287 for (var style of matchedStyles.nodeStyles()) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 var children = this._propertiesOutline.rootElement().children(); | 322 var children = this._propertiesOutline.rootElement().children(); |
| 296 for (var child of children) { | 323 for (var child of children) { |
| 297 var property = child[WebInspector.ComputedStyleWidget._propertySymbo
l]; | 324 var property = child[WebInspector.ComputedStyleWidget._propertySymbo
l]; |
| 298 var matched = !regex || regex.test(property.name) || regex.test(prop
erty.value); | 325 var matched = !regex || regex.test(property.name) || regex.test(prop
erty.value); |
| 299 child.hidden = !matched; | 326 child.hidden = !matched; |
| 300 } | 327 } |
| 301 }, | 328 }, |
| 302 | 329 |
| 303 __proto__: WebInspector.ThrottledWidget.prototype | 330 __proto__: WebInspector.ThrottledWidget.prototype |
| 304 } | 331 } |
| OLD | NEW |