Chromium Code Reviews| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 propertyElement.appendChild(renderer.renderName()); | |
| 160 propertyElement.appendChild(createTextNode(": ")); | |
|
pfeldman
2015/08/27 19:10:08
createTextChild
| |
| 161 propertyElement.appendChild(renderer.renderValue()); | |
| 162 propertyElement.appendChild(createTextNode(";")); | |
|
pfeldman
2015/08/27 19:10:08
ditto
| |
| 163 | |
| 164 var treeElement = new TreeElement(); | |
| 165 treeElement.selectable = false; | |
| 166 treeElement.title = propertyElement; | |
| 167 treeElement[WebInspector.ComputedStyleWidget._propertySymbol] = { | |
| 162 name: propertyName, | 168 name: propertyName, |
| 163 value: propertyValue | 169 value: propertyValue |
| 164 }; | 170 }; |
| 165 item.classList.toggle("computed-style-property-inherited", inherited ); | 171 this._propertiesOutline.appendChild(treeElement); |
| 166 var renderer = new WebInspector.StylesSidebarPropertyRenderer(null, nodeStyle.node, propertyName, /** @type {string} */(propertyValue)); | |
| 167 renderer.setColorHandler(this._processColor.bind(this)); | |
| 168 | 172 |
| 169 if (!inherited) { | 173 var trace = propertyTraces.get(propertyName); |
| 170 var traceButton = item.createChild("div", "computed-style-trace- button"); | 174 if (trace) { |
| 171 traceButton.createChild("div", "glyph"); | 175 this._renderPropertyTrace(treeElement, cssModel, trace); |
| 172 traceButton.addEventListener("click", this._onTracePropertyBound , false); | 176 propertyElement.addEventListener("mousedown", consumeEvent, fals e); |
| 177 propertyElement.addEventListener("dblclick", consumeEvent, false ); | |
| 178 propertyElement.addEventListener("click", handleClick.bind(null, treeElement), false); | |
| 173 } | 179 } |
| 174 item.appendChild(renderer.renderName()); | |
| 175 item.appendChild(createTextNode(": ")); | |
| 176 item.appendChild(renderer.renderValue()); | |
| 177 item.appendChild(createTextNode(";")); | |
| 178 this._propertiesContainer.appendChild(item); | |
| 179 } | 180 } |
| 180 | 181 |
| 181 this._updateFilter(this._filterRegex); | 182 this._updateFilter(this._filterRegex); |
| 182 | 183 |
| 183 /** | 184 /** |
| 184 * @param {string} a | 185 * @param {string} a |
| 185 * @param {string} b | 186 * @param {string} b |
| 186 */ | 187 */ |
| 187 function propertySorter(a, b) | 188 function propertySorter(a, b) |
| 188 { | 189 { |
| 189 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName; | 190 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName; |
| 190 return canonicalName(a).compareTo(canonicalName(b)); | 191 return canonicalName(a).compareTo(canonicalName(b)); |
| 191 } | 192 } |
| 193 | |
| 194 /** | |
| 195 * @param {!TreeElement} treeElement | |
| 196 * @param {!Event} event | |
| 197 */ | |
| 198 function handleClick(treeElement, event) | |
| 199 { | |
| 200 if (!treeElement.expanded) | |
| 201 treeElement.expand(); | |
| 202 else | |
| 203 treeElement.collapse(); | |
| 204 consumeEvent(event); | |
| 205 } | |
| 192 }, | 206 }, |
| 193 | 207 |
| 194 /** | 208 /** |
| 209 * @param {!TreeElement} rootTreeElement | |
| 210 * @param {!WebInspector.CSSStyleModel} cssModel | |
| 211 * @param {!Array.<!{property: !WebInspector.CSSProperty, overloaded: boolea n}>} tracedProperties | |
| 212 */ | |
| 213 _renderPropertyTrace: function(rootTreeElement, cssModel, tracedProperties) | |
| 214 { | |
| 215 for (var propertyInfo of tracedProperties) { | |
| 216 var trace = createElement("div"); | |
| 217 trace.classList.add("property-trace"); | |
| 218 if (propertyInfo.overloaded) | |
| 219 trace.classList.add("property-trace-inactive"); | |
| 220 | |
| 221 var valueElement = trace.createChild("span", "property-trace-value") ; | |
| 222 valueElement.textContent = propertyInfo.property.value; | |
| 223 trace.createTextChild(" - "); | |
| 224 | |
| 225 var rule = propertyInfo.property.ownerStyle.parentRule; | |
| 226 if (rule) { | |
| 227 var linkSpan = trace.createChild("span", "trace-link"); | |
| 228 linkSpan.appendChild(WebInspector.StylePropertiesSection.createR uleOriginNode(cssModel, this._linkifier, rule)); | |
| 229 } | |
| 230 | |
| 231 var selectorElement = trace.createChild("span", "property-trace-sele ctor"); | |
| 232 selectorElement.textContent = rule ? rule.selectorText : "element.st yle"; | |
| 233 selectorElement.title = selectorElement.textContent; | |
| 234 | |
| 235 var traceTreeElement = new TreeElement(); | |
| 236 traceTreeElement.title = trace; | |
| 237 traceTreeElement.selectable = false; | |
| 238 rootTreeElement.appendChild(traceTreeElement); | |
| 239 } | |
| 240 }, | |
| 241 | |
| 242 /** | |
| 243 * @param {!WebInspector.SectionCascade} matchedCascade | |
| 244 * @return {!Map.<string, !Array.<!{property: !WebInspector.CSSProperty, ove rloaded: boolean}>>} | |
| 245 */ | |
| 246 _computePropertyTraces: function(matchedCascade) | |
| 247 { | |
| 248 var result = new Map(); | |
| 249 var models = matchedCascade.sectionModels(); | |
| 250 for (var model of models) { | |
| 251 var allProperties = model.style().allProperties; | |
| 252 for (var property of allProperties) { | |
| 253 if (!property.activeInStyle() || !model.isPropertyInCascade(prop erty.name)) | |
| 254 continue; | |
| 255 if (!result.has(property.name)) | |
| 256 result.set(property.name, []); | |
| 257 result.get(property.name).push({ | |
| 258 property: property, | |
| 259 overloaded: model.isPropertyOverloaded(property.name) | |
| 260 }); | |
| 261 } | |
| 262 } | |
| 263 return result; | |
| 264 }, | |
| 265 | |
| 266 /** | |
| 195 * @param {!WebInspector.SectionCascade} matchedCascade | 267 * @param {!WebInspector.SectionCascade} matchedCascade |
| 196 * @param {string} propertyName | 268 * @param {string} propertyName |
| 197 */ | 269 */ |
| 198 _isPropertyInherited: function(matchedCascade, propertyName) | 270 _isPropertyInherited: function(matchedCascade, propertyName) |
| 199 { | 271 { |
| 200 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName(prope rtyName); | 272 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName(prope rtyName); |
| 201 return !matchedCascade.allUsedProperties().has(canonicalName); | 273 return !matchedCascade.allUsedProperties().has(canonicalName); |
| 202 }, | 274 }, |
| 203 | 275 |
| 204 /** | 276 /** |
| 205 * @param {?RegExp} regex | 277 * @param {?RegExp} regex |
| 206 */ | 278 */ |
| 207 _updateFilter: function(regex) | 279 _updateFilter: function(regex) |
| 208 { | 280 { |
| 209 for (var i = 0; i < this._propertiesContainer.children.length; ++i) { | 281 var children = this._propertiesOutline.rootElement().children(); |
| 210 var item = this._propertiesContainer.children[i]; | 282 for (var child of children) { |
| 211 var property = item[WebInspector.ComputedStyleWidget._propertySymbol ]; | 283 var property = child[WebInspector.ComputedStyleWidget._propertySymbo l]; |
| 212 var matched = !regex || regex.test(property.name) || regex.test(prop erty.value); | 284 var matched = !regex || regex.test(property.name) || regex.test(prop erty.value); |
| 213 item.classList.toggle("hidden", !matched); | 285 child.hidden = !matched; |
| 214 } | 286 } |
| 215 }, | 287 }, |
| 216 | 288 |
| 217 __proto__: WebInspector.ThrottledWidget.prototype | 289 __proto__: WebInspector.ThrottledWidget.prototype |
| 218 } | 290 } |
| OLD | NEW |