| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 /** | 4 /** |
| 5 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 Emulation.InspectedPagePlaceholder = class extends UI.Widget { | 7 Emulation.InspectedPagePlaceholder = class extends UI.Widget { |
| 8 constructor() { | 8 constructor() { |
| 9 super(true); | 9 super(true); |
| 10 this.registerRequiredCSS('emulation/inspectedPagePlaceholder.css'); | 10 this.registerRequiredCSS('emulation/inspectedPagePlaceholder.css'); |
| 11 UI.zoomManager.addEventListener(UI.ZoomManager.Events.ZoomChanged, this._sch
eduleUpdate, this); | 11 UI.zoomManager.addEventListener(UI.ZoomManager.Events.ZoomChanged, this.onRe
size, this); |
| 12 this._margins = {top: 0, right: 0, bottom: 0, left: 0}; | 12 this.restoreMinimumSize(); |
| 13 this.restoreMinimumSizeAndMargins(); | |
| 14 } | |
| 15 | |
| 16 _findMargins() { | |
| 17 var margins = {top: 0, right: 0, bottom: 0, left: 0}; | |
| 18 | |
| 19 if (this._useMargins) { | |
| 20 var adjacent = {top: true, right: true, bottom: true, left: true}; | |
| 21 var widget = this; | |
| 22 while (widget.parentWidget()) { | |
| 23 var parent = widget.parentWidget(); | |
| 24 // This view assumes it's always inside the main split widget element, n
ot a sidebar. | |
| 25 // Every parent which is not a split widget, must be of the same size as
this widget. | |
| 26 if (parent instanceof UI.SplitWidget) { | |
| 27 var side = parent.sidebarSide(); | |
| 28 if (adjacent[side] && !parent.hasCustomResizer() && parent.isResizable
()) | |
| 29 margins[side] = Emulation.InspectedPagePlaceholder.MarginValue; | |
| 30 adjacent[side] = false; | |
| 31 } | |
| 32 widget = parent; | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 if (this._margins.top !== margins.top || this._margins.left !== margins.left
|| | |
| 37 this._margins.right !== margins.right || this._margins.bottom !== margin
s.bottom) { | |
| 38 this._margins = margins; | |
| 39 this._scheduleUpdate(); | |
| 40 } | |
| 41 } | 13 } |
| 42 | 14 |
| 43 /** | 15 /** |
| 44 * @override | 16 * @override |
| 45 */ | 17 */ |
| 46 onResize() { | 18 onResize() { |
| 47 this._findMargins(); | |
| 48 this._scheduleUpdate(); | |
| 49 } | |
| 50 | |
| 51 _scheduleUpdate() { | |
| 52 if (this._updateId) | 19 if (this._updateId) |
| 53 this.element.window().cancelAnimationFrame(this._updateId); | 20 this.element.window().cancelAnimationFrame(this._updateId); |
| 54 this._updateId = this.element.window().requestAnimationFrame(this.update.bin
d(this)); | 21 this._updateId = this.element.window().requestAnimationFrame(this.update.bin
d(this)); |
| 55 } | 22 } |
| 56 | 23 |
| 57 restoreMinimumSizeAndMargins() { | 24 restoreMinimumSize() { |
| 58 this._useMargins = true; | |
| 59 this.setMinimumSize(150, 150); | 25 this.setMinimumSize(150, 150); |
| 60 this._findMargins(); | |
| 61 } | 26 } |
| 62 | 27 |
| 63 clearMinimumSizeAndMargins() { | 28 clearMinimumSize() { |
| 64 this._useMargins = false; | |
| 65 this.setMinimumSize(1, 1); | 29 this.setMinimumSize(1, 1); |
| 66 this._findMargins(); | |
| 67 } | 30 } |
| 68 | 31 |
| 69 _dipPageRect() { | 32 _dipPageRect() { |
| 70 var zoomFactor = UI.zoomManager.zoomFactor(); | 33 var zoomFactor = UI.zoomManager.zoomFactor(); |
| 71 var rect = this.element.getBoundingClientRect(); | 34 var rect = this.element.getBoundingClientRect(); |
| 72 var bodyRect = this.element.ownerDocument.body.getBoundingClientRect(); | 35 var bodyRect = this.element.ownerDocument.body.getBoundingClientRect(); |
| 73 | 36 |
| 74 var left = Math.max(rect.left * zoomFactor + this._margins.left, bodyRect.le
ft * zoomFactor); | 37 var left = Math.max(rect.left * zoomFactor, bodyRect.left * zoomFactor); |
| 75 var top = Math.max(rect.top * zoomFactor + this._margins.top, bodyRect.top *
zoomFactor); | 38 var top = Math.max(rect.top * zoomFactor, bodyRect.top * zoomFactor); |
| 76 var bottom = Math.min(rect.bottom * zoomFactor - this._margins.bottom, bodyR
ect.bottom * zoomFactor); | 39 var bottom = Math.min(rect.bottom * zoomFactor, bodyRect.bottom * zoomFactor
); |
| 77 var right = Math.min(rect.right * zoomFactor - this._margins.right, bodyRect
.right * zoomFactor); | 40 var right = Math.min(rect.right * zoomFactor, bodyRect.right * zoomFactor); |
| 78 | 41 |
| 79 return {x: left, y: top, width: right - left, height: bottom - top}; | 42 return {x: left, y: top, width: right - left, height: bottom - top}; |
| 80 } | 43 } |
| 81 | 44 |
| 82 update() { | 45 update() { |
| 83 delete this._updateId; | 46 delete this._updateId; |
| 84 var rect = this._dipPageRect(); | 47 var rect = this._dipPageRect(); |
| 85 var bounds = { | 48 var bounds = { |
| 86 x: Math.round(rect.x), | 49 x: Math.round(rect.x), |
| 87 y: Math.round(rect.y), | 50 y: Math.round(rect.y), |
| 88 height: Math.max(1, Math.round(rect.height)), | 51 height: Math.max(1, Math.round(rect.height)), |
| 89 width: Math.max(1, Math.round(rect.width)) | 52 width: Math.max(1, Math.round(rect.width)) |
| 90 }; | 53 }; |
| 91 this.dispatchEventToListeners(Emulation.InspectedPagePlaceholder.Events.Upda
te, bounds); | 54 this.dispatchEventToListeners(Emulation.InspectedPagePlaceholder.Events.Upda
te, bounds); |
| 92 } | 55 } |
| 93 }; | 56 }; |
| 94 | 57 |
| 95 /** @enum {symbol} */ | 58 /** @enum {symbol} */ |
| 96 Emulation.InspectedPagePlaceholder.Events = { | 59 Emulation.InspectedPagePlaceholder.Events = { |
| 97 Update: Symbol('Update') | 60 Update: Symbol('Update') |
| 98 }; | 61 }; |
| 99 | |
| 100 Emulation.InspectedPagePlaceholder.MarginValue = 3; | |
| OLD | NEW |