OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 // FIXME: avoid updates of a collapsed pane. | 51 // FIXME: avoid updates of a collapsed pane. |
52 var node = this.node(); | 52 var node = this.node(); |
53 var cssModel = this.cssModel(); | 53 var cssModel = this.cssModel(); |
54 if (!node || node.nodeType() !== Node.ELEMENT_NODE || !cssModel) { | 54 if (!node || node.nodeType() !== Node.ELEMENT_NODE || !cssModel) { |
55 this.element.removeChildren(); | 55 this.element.removeChildren(); |
56 return Promise.resolve(); | 56 return Promise.resolve(); |
57 } | 57 } |
58 | 58 |
59 /** | 59 /** |
60 * @param {?WebInspector.CSSStyleDeclaration} style | 60 * @param {?Map.<string, string>} style |
61 * @this {WebInspector.MetricsSidebarPane} | 61 * @this {WebInspector.MetricsSidebarPane} |
62 */ | 62 */ |
63 function callback(style) | 63 function callback(style) |
64 { | 64 { |
65 if (!style || this.node() !== node) | 65 if (!style || this.node() !== node) |
66 return; | 66 return; |
67 this._updateMetrics(style); | 67 this._updateMetrics(style); |
68 } | 68 } |
69 /** | 69 /** |
70 * @param {?WebInspector.CSSStyleModel.InlineStyleResult} inlineStyleRes
ult | 70 * @param {?WebInspector.CSSStyleModel.InlineStyleResult} inlineStyleRes
ult |
(...skipping 29 matching lines...) Expand all Loading... |
100 }, | 100 }, |
101 | 101 |
102 /** | 102 /** |
103 * @override | 103 * @override |
104 */ | 104 */ |
105 onFrameResizedThrottled: function() | 105 onFrameResizedThrottled: function() |
106 { | 106 { |
107 this.update(); | 107 this.update(); |
108 }, | 108 }, |
109 | 109 |
| 110 /** |
| 111 * @param {!Map.<string, string>} style |
| 112 * @param {string} propertyName |
| 113 * @return {number} |
| 114 */ |
110 _getPropertyValueAsPx: function(style, propertyName) | 115 _getPropertyValueAsPx: function(style, propertyName) |
111 { | 116 { |
112 return Number(style.getPropertyValue(propertyName).replace(/px$/, "") ||
0); | 117 return Number(style.get(propertyName).replace(/px$/, "") || 0); |
113 }, | 118 }, |
114 | 119 |
| 120 /** |
| 121 * @param {!Map.<string, string>} computedStyle |
| 122 * @param {string} componentName |
| 123 */ |
115 _getBox: function(computedStyle, componentName) | 124 _getBox: function(computedStyle, componentName) |
116 { | 125 { |
117 var suffix = componentName === "border" ? "-width" : ""; | 126 var suffix = componentName === "border" ? "-width" : ""; |
118 var left = this._getPropertyValueAsPx(computedStyle, componentName + "-l
eft" + suffix); | 127 var left = this._getPropertyValueAsPx(computedStyle, componentName + "-l
eft" + suffix); |
119 var top = this._getPropertyValueAsPx(computedStyle, componentName + "-to
p" + suffix); | 128 var top = this._getPropertyValueAsPx(computedStyle, componentName + "-to
p" + suffix); |
120 var right = this._getPropertyValueAsPx(computedStyle, componentName + "-
right" + suffix); | 129 var right = this._getPropertyValueAsPx(computedStyle, componentName + "-
right" + suffix); |
121 var bottom = this._getPropertyValueAsPx(computedStyle, componentName + "
-bottom" + suffix); | 130 var bottom = this._getPropertyValueAsPx(computedStyle, componentName + "
-bottom" + suffix); |
122 return { left: left, top: top, right: right, bottom: bottom }; | 131 return { left: left, top: top, right: right, bottom: bottom }; |
123 }, | 132 }, |
124 | 133 |
(...skipping 18 matching lines...) Expand all Loading... |
143 for (var i = 0; this._boxElements && i < this._boxElements.length; ++i)
{ | 152 for (var i = 0; this._boxElements && i < this._boxElements.length; ++i)
{ |
144 var element = this._boxElements[i]; | 153 var element = this._boxElements[i]; |
145 if (!this.node() || mode === "all" || element._name === mode) | 154 if (!this.node() || mode === "all" || element._name === mode) |
146 element.style.backgroundColor = element._backgroundColor; | 155 element.style.backgroundColor = element._backgroundColor; |
147 else | 156 else |
148 element.style.backgroundColor = ""; | 157 element.style.backgroundColor = ""; |
149 } | 158 } |
150 }, | 159 }, |
151 | 160 |
152 /** | 161 /** |
153 * @param {!WebInspector.CSSStyleDeclaration} style | 162 * @param {!Map.<string, string>} style |
154 */ | 163 */ |
155 _updateMetrics: function(style) | 164 _updateMetrics: function(style) |
156 { | 165 { |
157 // Updating with computed style. | 166 // Updating with computed style. |
158 var metricsElement = createElement("div"); | 167 var metricsElement = createElement("div"); |
159 metricsElement.className = "metrics"; | 168 metricsElement.className = "metrics"; |
160 var self = this; | 169 var self = this; |
161 | 170 |
162 /** | 171 /** |
163 * @param {!WebInspector.CSSStyleDeclaration} style | 172 * @param {!Map.<string, string>} style |
164 * @param {string} name | 173 * @param {string} name |
165 * @param {string} side | 174 * @param {string} side |
166 * @param {string} suffix | 175 * @param {string} suffix |
167 * @this {WebInspector.MetricsSidebarPane} | 176 * @this {WebInspector.MetricsSidebarPane} |
168 */ | 177 */ |
169 function createBoxPartElement(style, name, side, suffix) | 178 function createBoxPartElement(style, name, side, suffix) |
170 { | 179 { |
171 var propertyName = (name !== "position" ? name + "-" : "") + side +
suffix; | 180 var propertyName = (name !== "position" ? name + "-" : "") + side +
suffix; |
172 var value = style.getPropertyValue(propertyName); | 181 var value = style.get(propertyName); |
173 if (value === "" || (name !== "position" && value === "0px")) | 182 if (value === "" || (name !== "position" && value === "0px")) |
174 value = "\u2012"; | 183 value = "\u2012"; |
175 else if (name === "position" && value === "auto") | 184 else if (name === "position" && value === "auto") |
176 value = "\u2012"; | 185 value = "\u2012"; |
177 value = value.replace(/px$/, ""); | 186 value = value.replace(/px$/, ""); |
178 value = Number.toFixedIfFloating(value); | 187 value = Number.toFixedIfFloating(value); |
179 | 188 |
180 var element = createElement("div"); | 189 var element = createElement("div"); |
181 element.className = side; | 190 element.className = side; |
182 element.textContent = value; | 191 element.textContent = value; |
183 element.addEventListener("dblclick", this.startEditing.bind(this, el
ement, name, propertyName, style), false); | 192 element.addEventListener("dblclick", this.startEditing.bind(this, el
ement, name, propertyName, style), false); |
184 return element; | 193 return element; |
185 } | 194 } |
186 | 195 |
| 196 /** |
| 197 * @param {!Map.<string, string>} style |
| 198 * @return {string} |
| 199 */ |
187 function getContentAreaWidthPx(style) | 200 function getContentAreaWidthPx(style) |
188 { | 201 { |
189 var width = style.getPropertyValue("width").replace(/px$/, ""); | 202 var width = style.get("width").replace(/px$/, ""); |
190 if (!isNaN(width) && style.getPropertyValue("box-sizing") === "borde
r-box") { | 203 if (!isNaN(width) && style.get("box-sizing") === "border-box") { |
191 var borderBox = self._getBox(style, "border"); | 204 var borderBox = self._getBox(style, "border"); |
192 var paddingBox = self._getBox(style, "padding"); | 205 var paddingBox = self._getBox(style, "padding"); |
193 | 206 |
194 width = width - borderBox.left - borderBox.right - paddingBox.le
ft - paddingBox.right; | 207 width = width - borderBox.left - borderBox.right - paddingBox.le
ft - paddingBox.right; |
195 } | 208 } |
196 | 209 |
197 return Number.toFixedIfFloating(width); | 210 return Number.toFixedIfFloating(width.toString()); |
198 } | 211 } |
199 | 212 |
| 213 /** |
| 214 * @param {!Map.<string, string>} style |
| 215 * @return {string} |
| 216 */ |
200 function getContentAreaHeightPx(style) | 217 function getContentAreaHeightPx(style) |
201 { | 218 { |
202 var height = style.getPropertyValue("height").replace(/px$/, ""); | 219 var height = style.get("height").replace(/px$/, ""); |
203 if (!isNaN(height) && style.getPropertyValue("box-sizing") === "bord
er-box") { | 220 if (!isNaN(height) && style.get("box-sizing") === "border-box") { |
204 var borderBox = self._getBox(style, "border"); | 221 var borderBox = self._getBox(style, "border"); |
205 var paddingBox = self._getBox(style, "padding"); | 222 var paddingBox = self._getBox(style, "padding"); |
206 | 223 |
207 height = height - borderBox.top - borderBox.bottom - paddingBox.
top - paddingBox.bottom; | 224 height = height - borderBox.top - borderBox.bottom - paddingBox.
top - paddingBox.bottom; |
208 } | 225 } |
209 | 226 |
210 return Number.toFixedIfFloating(height); | 227 return Number.toFixedIfFloating(height.toString()); |
211 } | 228 } |
212 | 229 |
213 // Display types for which margin is ignored. | 230 // Display types for which margin is ignored. |
214 var noMarginDisplayType = { | 231 var noMarginDisplayType = { |
215 "table-cell": true, | 232 "table-cell": true, |
216 "table-column": true, | 233 "table-column": true, |
217 "table-column-group": true, | 234 "table-column-group": true, |
218 "table-footer-group": true, | 235 "table-footer-group": true, |
219 "table-header-group": true, | 236 "table-header-group": true, |
220 "table-row": true, | 237 "table-row": true, |
(...skipping 22 matching lines...) Expand all Loading... |
243 WebInspector.Color.PageHighlight.Border, | 260 WebInspector.Color.PageHighlight.Border, |
244 WebInspector.Color.PageHighlight.Margin, | 261 WebInspector.Color.PageHighlight.Margin, |
245 WebInspector.Color.fromRGBA([0, 0, 0, 0]) | 262 WebInspector.Color.fromRGBA([0, 0, 0, 0]) |
246 ]; | 263 ]; |
247 var boxLabels = [WebInspector.UIString("content"), WebInspector.UIString
("padding"), WebInspector.UIString("border"), WebInspector.UIString("margin"), W
ebInspector.UIString("position")]; | 264 var boxLabels = [WebInspector.UIString("content"), WebInspector.UIString
("padding"), WebInspector.UIString("border"), WebInspector.UIString("margin"), W
ebInspector.UIString("position")]; |
248 var previousBox = null; | 265 var previousBox = null; |
249 this._boxElements = []; | 266 this._boxElements = []; |
250 for (var i = 0; i < boxes.length; ++i) { | 267 for (var i = 0; i < boxes.length; ++i) { |
251 var name = boxes[i]; | 268 var name = boxes[i]; |
252 | 269 |
253 if (name === "margin" && noMarginDisplayType[style.getPropertyValue(
"display")]) | 270 if (name === "margin" && noMarginDisplayType[style.get("display")]) |
254 continue; | 271 continue; |
255 if (name === "padding" && noPaddingDisplayType[style.getPropertyValu
e("display")]) | 272 if (name === "padding" && noPaddingDisplayType[style.get("display")]
) |
256 continue; | 273 continue; |
257 if (name === "position" && noPositionType[style.getPropertyValue("po
sition")]) | 274 if (name === "position" && noPositionType[style.get("position")]) |
258 continue; | 275 continue; |
259 | 276 |
260 var boxElement = createElement("div"); | 277 var boxElement = createElement("div"); |
261 boxElement.className = name; | 278 boxElement.className = name; |
262 boxElement._backgroundColor = boxColors[i].asString(WebInspector.Col
or.Format.RGBA); | 279 boxElement._backgroundColor = boxColors[i].asString(WebInspector.Col
or.Format.RGBA); |
263 boxElement._name = name; | 280 boxElement._name = name; |
264 boxElement.style.backgroundColor = boxElement._backgroundColor; | 281 boxElement.style.backgroundColor = boxElement._backgroundColor; |
265 boxElement.addEventListener("mouseover", this._highlightDOMNode.bind
(this, true, name === "position" ? "all" : name), false); | 282 boxElement.addEventListener("mouseover", this._highlightDOMNode.bind
(this, true, name === "position" ? "all" : name), false); |
266 this._boxElements.push(boxElement); | 283 this._boxElements.push(boxElement); |
267 | 284 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 | 316 |
300 previousBox = boxElement; | 317 previousBox = boxElement; |
301 } | 318 } |
302 | 319 |
303 metricsElement.appendChild(previousBox); | 320 metricsElement.appendChild(previousBox); |
304 metricsElement.addEventListener("mouseover", this._highlightDOMNode.bind
(this, false, "all"), false); | 321 metricsElement.addEventListener("mouseover", this._highlightDOMNode.bind
(this, false, "all"), false); |
305 this.element.removeChildren(); | 322 this.element.removeChildren(); |
306 this.element.appendChild(metricsElement); | 323 this.element.appendChild(metricsElement); |
307 }, | 324 }, |
308 | 325 |
| 326 /** |
| 327 * @param {!Element} targetElement |
| 328 * @param {string} box |
| 329 * @param {string} styleProperty |
| 330 * @param {!Map.<string, string>} computedStyle |
| 331 */ |
309 startEditing: function(targetElement, box, styleProperty, computedStyle) | 332 startEditing: function(targetElement, box, styleProperty, computedStyle) |
310 { | 333 { |
311 if (WebInspector.isBeingEdited(targetElement)) | 334 if (WebInspector.isBeingEdited(targetElement)) |
312 return; | 335 return; |
313 | 336 |
314 var context = { box: box, styleProperty: styleProperty, computedStyle: c
omputedStyle }; | 337 var context = { box: box, styleProperty: styleProperty, computedStyle: c
omputedStyle }; |
315 var boundKeyDown = this._handleKeyDown.bind(this, context, styleProperty
); | 338 var boundKeyDown = this._handleKeyDown.bind(this, context, styleProperty
); |
316 context.keyDownHandler = boundKeyDown; | 339 context.keyDownHandler = boundKeyDown; |
317 targetElement.addEventListener("keydown", boundKeyDown, false); | 340 targetElement.addEventListener("keydown", boundKeyDown, false); |
318 | 341 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 userInput = "auto"; | 416 userInput = "auto"; |
394 | 417 |
395 userInput = userInput.toLowerCase(); | 418 userInput = userInput.toLowerCase(); |
396 // Append a "px" unit if the user input was just a number. | 419 // Append a "px" unit if the user input was just a number. |
397 if (/^\d+$/.test(userInput)) | 420 if (/^\d+$/.test(userInput)) |
398 userInput += "px"; | 421 userInput += "px"; |
399 | 422 |
400 var styleProperty = context.styleProperty; | 423 var styleProperty = context.styleProperty; |
401 var computedStyle = context.computedStyle; | 424 var computedStyle = context.computedStyle; |
402 | 425 |
403 if (computedStyle.getPropertyValue("box-sizing") === "border-box" && (st
yleProperty === "width" || styleProperty === "height")) { | 426 if (computedStyle.get("box-sizing") === "border-box" && (styleProperty =
== "width" || styleProperty === "height")) { |
404 if (!userInput.match(/px$/)) { | 427 if (!userInput.match(/px$/)) { |
405 WebInspector.console.error("For elements with box-sizing: border
-box, only absolute content area dimensions can be applied"); | 428 WebInspector.console.error("For elements with box-sizing: border
-box, only absolute content area dimensions can be applied"); |
406 return; | 429 return; |
407 } | 430 } |
408 | 431 |
409 var borderBox = this._getBox(computedStyle, "border"); | 432 var borderBox = this._getBox(computedStyle, "border"); |
410 var paddingBox = this._getBox(computedStyle, "padding"); | 433 var paddingBox = this._getBox(computedStyle, "padding"); |
411 var userValuePx = Number(userInput.replace(/px$/, "")); | 434 var userValuePx = Number(userInput.replace(/px$/, "")); |
412 if (isNaN(userValuePx)) | 435 if (isNaN(userValuePx)) |
413 return; | 436 return; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 }, | 478 }, |
456 | 479 |
457 editingCommitted: function(element, userInput, previousContent, context) | 480 editingCommitted: function(element, userInput, previousContent, context) |
458 { | 481 { |
459 this.editingEnded(element, context); | 482 this.editingEnded(element, context); |
460 this._applyUserInput(element, userInput, previousContent, context, true)
; | 483 this._applyUserInput(element, userInput, previousContent, context, true)
; |
461 }, | 484 }, |
462 | 485 |
463 __proto__: WebInspector.ElementsSidebarPane.prototype | 486 __proto__: WebInspector.ElementsSidebarPane.prototype |
464 } | 487 } |
OLD | NEW |