| 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 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * @unrestricted | 30 * @unrestricted |
| 31 */ | 31 */ |
| 32 WebInspector.MetricsSidebarPane = class extends WebInspector.ElementsSidebarPane
{ | 32 Elements.MetricsSidebarPane = class extends Elements.ElementsSidebarPane { |
| 33 constructor() { | 33 constructor() { |
| 34 super(); | 34 super(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * @override | 38 * @override |
| 39 * @protected | 39 * @protected |
| 40 * @return {!Promise.<?>} | 40 * @return {!Promise.<?>} |
| 41 */ | 41 */ |
| 42 doUpdate() { | 42 doUpdate() { |
| 43 // "style" attribute might have changed. Update metrics unless they are bein
g edited | 43 // "style" attribute might have changed. Update metrics unless they are bein
g edited |
| 44 // (if a CSS property is added, a StyleSheetChanged event is dispatched). | 44 // (if a CSS property is added, a StyleSheetChanged event is dispatched). |
| 45 if (this._isEditingMetrics) | 45 if (this._isEditingMetrics) |
| 46 return Promise.resolve(); | 46 return Promise.resolve(); |
| 47 | 47 |
| 48 // FIXME: avoid updates of a collapsed pane. | 48 // FIXME: avoid updates of a collapsed pane. |
| 49 var node = this.node(); | 49 var node = this.node(); |
| 50 var cssModel = this.cssModel(); | 50 var cssModel = this.cssModel(); |
| 51 if (!node || node.nodeType() !== Node.ELEMENT_NODE || !cssModel) { | 51 if (!node || node.nodeType() !== Node.ELEMENT_NODE || !cssModel) { |
| 52 this.element.removeChildren(); | 52 this.element.removeChildren(); |
| 53 return Promise.resolve(); | 53 return Promise.resolve(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * @param {?Map.<string, string>} style | 57 * @param {?Map.<string, string>} style |
| 58 * @this {WebInspector.MetricsSidebarPane} | 58 * @this {Elements.MetricsSidebarPane} |
| 59 */ | 59 */ |
| 60 function callback(style) { | 60 function callback(style) { |
| 61 if (!style || this.node() !== node) | 61 if (!style || this.node() !== node) |
| 62 return; | 62 return; |
| 63 this._updateMetrics(style); | 63 this._updateMetrics(style); |
| 64 } | 64 } |
| 65 /** | 65 /** |
| 66 * @param {?WebInspector.CSSModel.InlineStyleResult} inlineStyleResult | 66 * @param {?SDK.CSSModel.InlineStyleResult} inlineStyleResult |
| 67 * @this {WebInspector.MetricsSidebarPane} | 67 * @this {Elements.MetricsSidebarPane} |
| 68 */ | 68 */ |
| 69 function inlineStyleCallback(inlineStyleResult) { | 69 function inlineStyleCallback(inlineStyleResult) { |
| 70 if (inlineStyleResult && this.node() === node) | 70 if (inlineStyleResult && this.node() === node) |
| 71 this.inlineStyle = inlineStyleResult.inlineStyle; | 71 this.inlineStyle = inlineStyleResult.inlineStyle; |
| 72 } | 72 } |
| 73 | 73 |
| 74 var promises = [ | 74 var promises = [ |
| 75 cssModel.computedStylePromise(node.id).then(callback.bind(this)), | 75 cssModel.computedStylePromise(node.id).then(callback.bind(this)), |
| 76 cssModel.inlineStylesPromise(node.id).then(inlineStyleCallback.bind(this)) | 76 cssModel.inlineStylesPromise(node.id).then(inlineStyleCallback.bind(this)) |
| 77 ]; | 77 ]; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 */ | 114 */ |
| 115 _highlightDOMNode(showHighlight, mode, event) { | 115 _highlightDOMNode(showHighlight, mode, event) { |
| 116 event.consume(); | 116 event.consume(); |
| 117 if (showHighlight && this.node()) { | 117 if (showHighlight && this.node()) { |
| 118 if (this._highlightMode === mode) | 118 if (this._highlightMode === mode) |
| 119 return; | 119 return; |
| 120 this._highlightMode = mode; | 120 this._highlightMode = mode; |
| 121 this.node().highlight(mode); | 121 this.node().highlight(mode); |
| 122 } else { | 122 } else { |
| 123 delete this._highlightMode; | 123 delete this._highlightMode; |
| 124 WebInspector.DOMModel.hideDOMNodeHighlight(); | 124 SDK.DOMModel.hideDOMNodeHighlight(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 for (var i = 0; this._boxElements && i < this._boxElements.length; ++i) { | 127 for (var i = 0; this._boxElements && i < this._boxElements.length; ++i) { |
| 128 var element = this._boxElements[i]; | 128 var element = this._boxElements[i]; |
| 129 if (!this.node() || mode === 'all' || element._name === mode) | 129 if (!this.node() || mode === 'all' || element._name === mode) |
| 130 element.style.backgroundColor = element._backgroundColor; | 130 element.style.backgroundColor = element._backgroundColor; |
| 131 else | 131 else |
| 132 element.style.backgroundColor = ''; | 132 element.style.backgroundColor = ''; |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 /** | 136 /** |
| 137 * @param {!Map.<string, string>} style | 137 * @param {!Map.<string, string>} style |
| 138 */ | 138 */ |
| 139 _updateMetrics(style) { | 139 _updateMetrics(style) { |
| 140 // Updating with computed style. | 140 // Updating with computed style. |
| 141 var metricsElement = createElement('div'); | 141 var metricsElement = createElement('div'); |
| 142 metricsElement.className = 'metrics'; | 142 metricsElement.className = 'metrics'; |
| 143 var self = this; | 143 var self = this; |
| 144 | 144 |
| 145 /** | 145 /** |
| 146 * @param {!Map.<string, string>} style | 146 * @param {!Map.<string, string>} style |
| 147 * @param {string} name | 147 * @param {string} name |
| 148 * @param {string} side | 148 * @param {string} side |
| 149 * @param {string} suffix | 149 * @param {string} suffix |
| 150 * @this {WebInspector.MetricsSidebarPane} | 150 * @this {Elements.MetricsSidebarPane} |
| 151 */ | 151 */ |
| 152 function createBoxPartElement(style, name, side, suffix) { | 152 function createBoxPartElement(style, name, side, suffix) { |
| 153 var propertyName = (name !== 'position' ? name + '-' : '') + side + suffix
; | 153 var propertyName = (name !== 'position' ? name + '-' : '') + side + suffix
; |
| 154 var value = style.get(propertyName); | 154 var value = style.get(propertyName); |
| 155 if (value === '' || (name !== 'position' && value === '0px')) | 155 if (value === '' || (name !== 'position' && value === '0px')) |
| 156 value = '\u2012'; | 156 value = '\u2012'; |
| 157 else if (name === 'position' && value === 'auto') | 157 else if (name === 'position' && value === 'auto') |
| 158 value = '\u2012'; | 158 value = '\u2012'; |
| 159 value = value.replace(/px$/, ''); | 159 value = value.replace(/px$/, ''); |
| 160 value = Number.toFixedIfFloating(value); | 160 value = Number.toFixedIfFloating(value); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 'table-header-group': true, | 217 'table-header-group': true, |
| 218 'table-row': true, | 218 'table-row': true, |
| 219 'table-row-group': true | 219 'table-row-group': true |
| 220 }; | 220 }; |
| 221 | 221 |
| 222 // Position types for which top, left, bottom and right are ignored. | 222 // Position types for which top, left, bottom and right are ignored. |
| 223 var noPositionType = {'static': true}; | 223 var noPositionType = {'static': true}; |
| 224 | 224 |
| 225 var boxes = ['content', 'padding', 'border', 'margin', 'position']; | 225 var boxes = ['content', 'padding', 'border', 'margin', 'position']; |
| 226 var boxColors = [ | 226 var boxColors = [ |
| 227 WebInspector.Color.PageHighlight.Content, WebInspector.Color.PageHighlight
.Padding, | 227 Common.Color.PageHighlight.Content, Common.Color.PageHighlight.Padding, |
| 228 WebInspector.Color.PageHighlight.Border, WebInspector.Color.PageHighlight.
Margin, | 228 Common.Color.PageHighlight.Border, Common.Color.PageHighlight.Margin, |
| 229 WebInspector.Color.fromRGBA([0, 0, 0, 0]) | 229 Common.Color.fromRGBA([0, 0, 0, 0]) |
| 230 ]; | 230 ]; |
| 231 var boxLabels = [ | 231 var boxLabels = [ |
| 232 WebInspector.UIString('content'), WebInspector.UIString('padding'), WebIns
pector.UIString('border'), | 232 Common.UIString('content'), Common.UIString('padding'), Common.UIString('b
order'), |
| 233 WebInspector.UIString('margin'), WebInspector.UIString('position') | 233 Common.UIString('margin'), Common.UIString('position') |
| 234 ]; | 234 ]; |
| 235 var previousBox = null; | 235 var previousBox = null; |
| 236 this._boxElements = []; | 236 this._boxElements = []; |
| 237 for (var i = 0; i < boxes.length; ++i) { | 237 for (var i = 0; i < boxes.length; ++i) { |
| 238 var name = boxes[i]; | 238 var name = boxes[i]; |
| 239 | 239 |
| 240 if (name === 'margin' && noMarginDisplayType[style.get('display')]) | 240 if (name === 'margin' && noMarginDisplayType[style.get('display')]) |
| 241 continue; | 241 continue; |
| 242 if (name === 'padding' && noPaddingDisplayType[style.get('display')]) | 242 if (name === 'padding' && noPaddingDisplayType[style.get('display')]) |
| 243 continue; | 243 continue; |
| 244 if (name === 'position' && noPositionType[style.get('position')]) | 244 if (name === 'position' && noPositionType[style.get('position')]) |
| 245 continue; | 245 continue; |
| 246 | 246 |
| 247 var boxElement = createElement('div'); | 247 var boxElement = createElement('div'); |
| 248 boxElement.className = name; | 248 boxElement.className = name; |
| 249 boxElement._backgroundColor = boxColors[i].asString(WebInspector.Color.For
mat.RGBA); | 249 boxElement._backgroundColor = boxColors[i].asString(Common.Color.Format.RG
BA); |
| 250 boxElement._name = name; | 250 boxElement._name = name; |
| 251 boxElement.style.backgroundColor = boxElement._backgroundColor; | 251 boxElement.style.backgroundColor = boxElement._backgroundColor; |
| 252 boxElement.addEventListener( | 252 boxElement.addEventListener( |
| 253 'mouseover', this._highlightDOMNode.bind(this, true, name === 'positio
n' ? 'all' : name), false); | 253 'mouseover', this._highlightDOMNode.bind(this, true, name === 'positio
n' ? 'all' : name), false); |
| 254 this._boxElements.push(boxElement); | 254 this._boxElements.push(boxElement); |
| 255 | 255 |
| 256 if (name === 'content') { | 256 if (name === 'content') { |
| 257 var widthElement = createElement('span'); | 257 var widthElement = createElement('span'); |
| 258 widthElement.textContent = getContentAreaWidthPx(style); | 258 widthElement.textContent = getContentAreaWidthPx(style); |
| 259 widthElement.addEventListener( | 259 widthElement.addEventListener( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 this.element.appendChild(metricsElement); | 296 this.element.appendChild(metricsElement); |
| 297 } | 297 } |
| 298 | 298 |
| 299 /** | 299 /** |
| 300 * @param {!Element} targetElement | 300 * @param {!Element} targetElement |
| 301 * @param {string} box | 301 * @param {string} box |
| 302 * @param {string} styleProperty | 302 * @param {string} styleProperty |
| 303 * @param {!Map.<string, string>} computedStyle | 303 * @param {!Map.<string, string>} computedStyle |
| 304 */ | 304 */ |
| 305 startEditing(targetElement, box, styleProperty, computedStyle) { | 305 startEditing(targetElement, box, styleProperty, computedStyle) { |
| 306 if (WebInspector.isBeingEdited(targetElement)) | 306 if (UI.isBeingEdited(targetElement)) |
| 307 return; | 307 return; |
| 308 | 308 |
| 309 var context = {box: box, styleProperty: styleProperty, computedStyle: comput
edStyle}; | 309 var context = {box: box, styleProperty: styleProperty, computedStyle: comput
edStyle}; |
| 310 var boundKeyDown = this._handleKeyDown.bind(this, context, styleProperty); | 310 var boundKeyDown = this._handleKeyDown.bind(this, context, styleProperty); |
| 311 context.keyDownHandler = boundKeyDown; | 311 context.keyDownHandler = boundKeyDown; |
| 312 targetElement.addEventListener('keydown', boundKeyDown, false); | 312 targetElement.addEventListener('keydown', boundKeyDown, false); |
| 313 | 313 |
| 314 this._isEditingMetrics = true; | 314 this._isEditingMetrics = true; |
| 315 | 315 |
| 316 var config = new WebInspector.InplaceEditor.Config( | 316 var config = new UI.InplaceEditor.Config( |
| 317 this._editingCommitted.bind(this), this.editingCancelled.bind(this), con
text); | 317 this._editingCommitted.bind(this), this.editingCancelled.bind(this), con
text); |
| 318 WebInspector.InplaceEditor.startEditing(targetElement, config); | 318 UI.InplaceEditor.startEditing(targetElement, config); |
| 319 | 319 |
| 320 targetElement.getComponentSelection().setBaseAndExtent(targetElement, 0, tar
getElement, 1); | 320 targetElement.getComponentSelection().setBaseAndExtent(targetElement, 0, tar
getElement, 1); |
| 321 } | 321 } |
| 322 | 322 |
| 323 _handleKeyDown(context, styleProperty, event) { | 323 _handleKeyDown(context, styleProperty, event) { |
| 324 var element = event.currentTarget; | 324 var element = event.currentTarget; |
| 325 | 325 |
| 326 /** | 326 /** |
| 327 * @param {string} originalValue | 327 * @param {string} originalValue |
| 328 * @param {string} replacementString | 328 * @param {string} replacementString |
| 329 * @this {WebInspector.MetricsSidebarPane} | 329 * @this {Elements.MetricsSidebarPane} |
| 330 */ | 330 */ |
| 331 function finishHandler(originalValue, replacementString) { | 331 function finishHandler(originalValue, replacementString) { |
| 332 this._applyUserInput(element, replacementString, originalValue, context, f
alse); | 332 this._applyUserInput(element, replacementString, originalValue, context, f
alse); |
| 333 } | 333 } |
| 334 | 334 |
| 335 /** | 335 /** |
| 336 * @param {string} prefix | 336 * @param {string} prefix |
| 337 * @param {number} number | 337 * @param {number} number |
| 338 * @param {string} suffix | 338 * @param {string} suffix |
| 339 * @return {string} | 339 * @return {string} |
| 340 */ | 340 */ |
| 341 function customNumberHandler(prefix, number, suffix) { | 341 function customNumberHandler(prefix, number, suffix) { |
| 342 if (styleProperty !== 'margin' && number < 0) | 342 if (styleProperty !== 'margin' && number < 0) |
| 343 number = 0; | 343 number = 0; |
| 344 return prefix + number + suffix; | 344 return prefix + number + suffix; |
| 345 } | 345 } |
| 346 | 346 |
| 347 WebInspector.handleElementValueModifications( | 347 UI.handleElementValueModifications( |
| 348 event, element, finishHandler.bind(this), undefined, customNumberHandler
); | 348 event, element, finishHandler.bind(this), undefined, customNumberHandler
); |
| 349 } | 349 } |
| 350 | 350 |
| 351 editingEnded(element, context) { | 351 editingEnded(element, context) { |
| 352 delete this.originalPropertyData; | 352 delete this.originalPropertyData; |
| 353 delete this.previousPropertyDataCandidate; | 353 delete this.previousPropertyDataCandidate; |
| 354 element.removeEventListener('keydown', context.keyDownHandler, false); | 354 element.removeEventListener('keydown', context.keyDownHandler, false); |
| 355 delete this._isEditingMetrics; | 355 delete this._isEditingMetrics; |
| 356 } | 356 } |
| 357 | 357 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 387 userInput = userInput.toLowerCase(); | 387 userInput = userInput.toLowerCase(); |
| 388 // Append a "px" unit if the user input was just a number. | 388 // Append a "px" unit if the user input was just a number. |
| 389 if (/^\d+$/.test(userInput)) | 389 if (/^\d+$/.test(userInput)) |
| 390 userInput += 'px'; | 390 userInput += 'px'; |
| 391 | 391 |
| 392 var styleProperty = context.styleProperty; | 392 var styleProperty = context.styleProperty; |
| 393 var computedStyle = context.computedStyle; | 393 var computedStyle = context.computedStyle; |
| 394 | 394 |
| 395 if (computedStyle.get('box-sizing') === 'border-box' && (styleProperty === '
width' || styleProperty === 'height')) { | 395 if (computedStyle.get('box-sizing') === 'border-box' && (styleProperty === '
width' || styleProperty === 'height')) { |
| 396 if (!userInput.match(/px$/)) { | 396 if (!userInput.match(/px$/)) { |
| 397 WebInspector.console.error( | 397 Common.console.error( |
| 398 'For elements with box-sizing: border-box, only absolute content are
a dimensions can be applied'); | 398 'For elements with box-sizing: border-box, only absolute content are
a dimensions can be applied'); |
| 399 return; | 399 return; |
| 400 } | 400 } |
| 401 | 401 |
| 402 var borderBox = this._getBox(computedStyle, 'border'); | 402 var borderBox = this._getBox(computedStyle, 'border'); |
| 403 var paddingBox = this._getBox(computedStyle, 'padding'); | 403 var paddingBox = this._getBox(computedStyle, 'padding'); |
| 404 var userValuePx = Number(userInput.replace(/px$/, '')); | 404 var userValuePx = Number(userInput.replace(/px$/, '')); |
| 405 if (isNaN(userValuePx)) | 405 if (isNaN(userValuePx)) |
| 406 return; | 406 return; |
| 407 if (styleProperty === 'width') | 407 if (styleProperty === 'width') |
| (...skipping 14 matching lines...) Expand all Loading... |
| 422 | 422 |
| 423 this.previousPropertyDataCandidate = property; | 423 this.previousPropertyDataCandidate = property; |
| 424 property.setValue(userInput, commitEditor, true, callback.bind(this)); | 424 property.setValue(userInput, commitEditor, true, callback.bind(this)); |
| 425 return; | 425 return; |
| 426 } | 426 } |
| 427 | 427 |
| 428 this.inlineStyle.appendProperty(context.styleProperty, userInput, callback.b
ind(this)); | 428 this.inlineStyle.appendProperty(context.styleProperty, userInput, callback.b
ind(this)); |
| 429 | 429 |
| 430 /** | 430 /** |
| 431 * @param {boolean} success | 431 * @param {boolean} success |
| 432 * @this {WebInspector.MetricsSidebarPane} | 432 * @this {Elements.MetricsSidebarPane} |
| 433 */ | 433 */ |
| 434 function callback(success) { | 434 function callback(success) { |
| 435 if (!success) | 435 if (!success) |
| 436 return; | 436 return; |
| 437 if (!('originalPropertyData' in this)) | 437 if (!('originalPropertyData' in this)) |
| 438 this.originalPropertyData = this.previousPropertyDataCandidate; | 438 this.originalPropertyData = this.previousPropertyDataCandidate; |
| 439 | 439 |
| 440 if (typeof this._highlightMode !== 'undefined') | 440 if (typeof this._highlightMode !== 'undefined') |
| 441 this.node().highlight(this._highlightMode); | 441 this.node().highlight(this._highlightMode); |
| 442 | 442 |
| 443 if (commitEditor) | 443 if (commitEditor) |
| 444 this.update(); | 444 this.update(); |
| 445 } | 445 } |
| 446 } | 446 } |
| 447 | 447 |
| 448 _editingCommitted(element, userInput, previousContent, context) { | 448 _editingCommitted(element, userInput, previousContent, context) { |
| 449 this.editingEnded(element, context); | 449 this.editingEnded(element, context); |
| 450 this._applyUserInput(element, userInput, previousContent, context, true); | 450 this._applyUserInput(element, userInput, previousContent, context, true); |
| 451 } | 451 } |
| 452 }; | 452 }; |
| OLD | NEW |