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 /** | 5 /** |
6 * @constructor | 6 * @constructor |
7 * @extends {WebInspector.View} | 7 * @extends {WebInspector.View} |
8 */ | 8 */ |
9 WebInspector.InspectedPagePlaceholder = function() | 9 WebInspector.InspectedPagePlaceholder = function() |
10 { | 10 { |
11 WebInspector.View.call(this); | 11 WebInspector.View.call(this); |
12 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._onZoomChanged, this); | 12 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._onZoomChanged, this); |
13 this._margins = { top: false, right: false, bottom: false, left: false }; | 13 this._margins = { top: 0, right: 0, bottom: 0, left: 0 }; |
14 this.setMinimumSize(WebInspector.InspectedPagePlaceholder.Constraints.Width,
WebInspector.InspectedPagePlaceholder.Constraints.Height); | 14 this.setMinimumSize(50, 50); |
15 }; | |
16 | |
17 WebInspector.InspectedPagePlaceholder.Constraints = { | |
18 Width: 50, | |
19 Height: 50 | |
20 }; | 15 }; |
21 | 16 |
22 WebInspector.InspectedPagePlaceholder.MarginValue = 3; | 17 WebInspector.InspectedPagePlaceholder.MarginValue = 3; |
23 | 18 |
24 WebInspector.InspectedPagePlaceholder.prototype = { | 19 WebInspector.InspectedPagePlaceholder.prototype = { |
25 _findMargins: function() | 20 _findMargins: function() |
26 { | 21 { |
27 var margins = { top: false, right: false, bottom: false, left: false }; | 22 var margins = { top: 0, right: 0, bottom: 0, left: 0 }; |
28 var adjacent = { top: true, right: true, bottom: true, left: true}; | 23 var adjacent = { top: true, right: true, bottom: true, left: true }; |
29 var view = this; | 24 var view = this; |
30 while (view.parentView()) { | 25 while (view.parentView()) { |
31 var parent = view.parentView(); | 26 var parent = view.parentView(); |
32 // This view assumes it's always inside the main split view element,
not a sidebar. | 27 // This view assumes it's always inside the main split view element,
not a sidebar. |
33 // Every parent which is not a split view, must be of the same size
as this view. | 28 // Every parent which is not a split view, must be of the same size
as this view. |
34 if (parent instanceof WebInspector.SplitView) { | 29 if (parent instanceof WebInspector.SplitView) { |
35 var side = parent.sidebarSide(); | 30 var side = parent.sidebarSide(); |
36 if (adjacent[side] && !parent.hasCustomResizer()) | 31 if (adjacent[side] && !parent.hasCustomResizer()) |
37 margins[side] = true; | 32 margins[side] = WebInspector.InspectedPagePlaceholder.Margin
Value; |
38 adjacent[side] = false; | 33 adjacent[side] = false; |
39 } | 34 } |
40 view = parent; | 35 view = parent; |
41 } | 36 } |
42 | 37 |
43 if (this._margins.top !== margins.top || this._margins.left !== margins.
left || this._margins.right !== margins.right || this._margins.bottom !== margin
s.bottom) { | 38 if (this._margins.top !== margins.top || this._margins.left !== margins.
left || this._margins.right !== margins.right || this._margins.bottom !== margin
s.bottom) { |
44 this._margins = margins; | 39 this._margins = margins; |
45 this._updateMarginValue(); | 40 this._scheduleUpdate(); |
46 } | 41 } |
47 }, | 42 }, |
48 | 43 |
49 _updateMarginValue: function() | |
50 { | |
51 var marginValue = Math.round(WebInspector.InspectedPagePlaceholder.Margi
nValue / WebInspector.zoomManager.zoomFactor()) + "px "; | |
52 var margins = this._margins.top ? marginValue : "0 "; | |
53 margins += this._margins.right ? marginValue : "0 "; | |
54 margins += this._margins.bottom ? marginValue : "0 "; | |
55 margins += this._margins.left ? marginValue : "0 "; | |
56 this.element.style.margin = margins; | |
57 }, | |
58 | |
59 _onZoomChanged: function() | 44 _onZoomChanged: function() |
60 { | 45 { |
61 this._updateMarginValue(); | |
62 this._scheduleUpdate(); | 46 this._scheduleUpdate(); |
63 }, | 47 }, |
64 | 48 |
65 onResize: function() | 49 onResize: function() |
66 { | 50 { |
67 this._findMargins(); | 51 this._findMargins(); |
68 this._scheduleUpdate(); | 52 this._scheduleUpdate(); |
69 }, | 53 }, |
70 | 54 |
71 _scheduleUpdate: function() | 55 _scheduleUpdate: function() |
72 { | 56 { |
73 var dockSide = WebInspector.dockController.dockSide(); | 57 var dockSide = WebInspector.dockController.dockSide(); |
74 if (dockSide !== WebInspector.DockController.State.Undocked) { | 58 if (dockSide !== WebInspector.DockController.State.Undocked) { |
75 if (this._updateId) | 59 if (this._updateId) |
76 window.cancelAnimationFrame(this._updateId); | 60 window.cancelAnimationFrame(this._updateId); |
77 this._updateId = window.requestAnimationFrame(this._update.bind(this
)); | 61 this._updateId = window.requestAnimationFrame(this._update.bind(this
)); |
78 } | 62 } |
79 }, | 63 }, |
80 | 64 |
| 65 _dipPageRect: function() |
| 66 { |
| 67 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
| 68 var rect = this.element.getBoundingClientRect(); |
| 69 var bodyRect = document.body.getBoundingClientRect(); |
| 70 |
| 71 var left = Math.max(rect.left * zoomFactor + this._margins.left, bodyRec
t.left * zoomFactor); |
| 72 var top = Math.max(rect.top * zoomFactor + this._margins.top, bodyRect.t
op * zoomFactor); |
| 73 var bottom = Math.min(rect.bottom * zoomFactor - this._margins.bottom, b
odyRect.bottom * zoomFactor); |
| 74 var right = Math.min(rect.right * zoomFactor - this._margins.right, body
Rect.right * zoomFactor); |
| 75 |
| 76 return { x: left, y: top, width: right - left, height: bottom - top }; |
| 77 }, |
| 78 |
81 _update: function() | 79 _update: function() |
82 { | 80 { |
83 delete this._updateId; | 81 delete this._updateId; |
84 | 82 |
85 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 83 var rect = this._dipPageRect(); |
86 | 84 var bounds = { x: Math.round(rect.x), y: Math.round(rect.y), height: Mat
h.round(rect.height), width: Math.round(rect.width) }; |
87 var marginValue = WebInspector.InspectedPagePlaceholder.MarginValue; | 85 InspectorFrontendHost.setInspectedPageBounds(bounds); |
88 var insets = { | |
89 top: this._margins.top ? marginValue : 0, | |
90 left: this._margins.left ? marginValue : 0, | |
91 right: this._margins.right ? marginValue : 0, | |
92 bottom: this._margins.bottom ? marginValue : 0}; | |
93 | |
94 var minSize = { | |
95 width: WebInspector.InspectedPagePlaceholder.Constraints.Width - Mat
h.round(insets.left * zoomFactor) - Math.round(insets.right * zoomFactor), | |
96 height: WebInspector.InspectedPagePlaceholder.Constraints.Height - M
ath.round(insets.top * zoomFactor) - Math.round(insets.bottom * zoomFactor)}; | |
97 | |
98 // This view assumes it's always inside the main split view element, not
a sidebar. | |
99 var view = this; | |
100 while (view) { | |
101 if ((view instanceof WebInspector.SplitView) && view.sidebarSide()) | |
102 insets[view.sidebarSide()] += view.preferredSidebarSize(); | |
103 view = view.parentView(); | |
104 } | |
105 | |
106 var roundedInsets = { | |
107 top: Math.ceil(insets.top), | |
108 left: Math.ceil(insets.left), | |
109 right: Math.ceil(insets.right), | |
110 bottom: Math.ceil(insets.bottom)}; | |
111 | |
112 InspectorFrontendHost.setContentsResizingStrategy(roundedInsets, minSize
); | |
113 }, | 86 }, |
114 | 87 |
115 __proto__: WebInspector.View.prototype | 88 __proto__: WebInspector.View.prototype |
116 }; | 89 }; |
OLD | NEW |