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 this.element.classList.add("white-background"); | 12 this.element.classList.add("white-background"); |
13 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._onZoomChanged, this); | 13 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._scheduleUpdate, this); |
14 this._margins = { top: 0, right: 0, bottom: 0, left: 0 }; | 14 this._margins = { top: 0, right: 0, bottom: 0, left: 0 }; |
15 this.restoreMinimumSizeAndMargins(); | 15 this.restoreMinimumSizeAndMargins(); |
16 WebInspector.dockController.addEventListener(WebInspector.DockController.Eve
nts.BeforeDockSideChanged, this._beforeDockSideChange, this); | |
17 WebInspector.dockController.addEventListener(WebInspector.DockController.Eve
nts.AfterDockSideChanged, this._afterDockSideChange, this); | |
18 }; | 16 }; |
19 | 17 |
20 WebInspector.InspectedPagePlaceholder.MarginValue = 3; | 18 WebInspector.InspectedPagePlaceholder.MarginValue = 3; |
21 | 19 |
| 20 WebInspector.InspectedPagePlaceholder.Events = { |
| 21 Update: "Update" |
| 22 }; |
| 23 |
22 WebInspector.InspectedPagePlaceholder.prototype = { | 24 WebInspector.InspectedPagePlaceholder.prototype = { |
23 _findMargins: function() | 25 _findMargins: function() |
24 { | 26 { |
25 var margins = { top: 0, right: 0, bottom: 0, left: 0 }; | 27 var margins = { top: 0, right: 0, bottom: 0, left: 0 }; |
26 | 28 |
27 if (this._useMargins) { | 29 if (this._useMargins) { |
28 var adjacent = { top: true, right: true, bottom: true, left: true }; | 30 var adjacent = { top: true, right: true, bottom: true, left: true }; |
29 var view = this; | 31 var view = this; |
30 while (view.parentView()) { | 32 while (view.parentView()) { |
31 var parent = view.parentView(); | 33 var parent = view.parentView(); |
32 // This view assumes it's always inside the main split view elem
ent, not a sidebar. | 34 // This view assumes it's always inside the main split view elem
ent, not a sidebar. |
33 // Every parent which is not a split view, must be of the same s
ize as this view. | 35 // Every parent which is not a split view, must be of the same s
ize as this view. |
34 if (parent instanceof WebInspector.SplitView) { | 36 if (parent instanceof WebInspector.SplitView) { |
35 var side = parent.sidebarSide(); | 37 var side = parent.sidebarSide(); |
36 if (adjacent[side] && !parent.hasCustomResizer() && parent.i
sResizable()) | 38 if (adjacent[side] && !parent.hasCustomResizer() && parent.i
sResizable()) |
37 margins[side] = WebInspector.InspectedPagePlaceholder.Ma
rginValue; | 39 margins[side] = WebInspector.InspectedPagePlaceholder.Ma
rginValue; |
38 adjacent[side] = false; | 40 adjacent[side] = false; |
39 } | 41 } |
40 view = parent; | 42 view = parent; |
41 } | 43 } |
42 } | 44 } |
43 | 45 |
44 if (this._margins.top !== margins.top || this._margins.left !== margins.
left || this._margins.right !== margins.right || this._margins.bottom !== margin
s.bottom) { | 46 if (this._margins.top !== margins.top || this._margins.left !== margins.
left || this._margins.right !== margins.right || this._margins.bottom !== margin
s.bottom) { |
45 this._margins = margins; | 47 this._margins = margins; |
46 this._scheduleUpdate(); | 48 this._scheduleUpdate(); |
47 } | 49 } |
48 }, | 50 }, |
49 | 51 |
50 _onZoomChanged: function() | |
51 { | |
52 this._scheduleUpdate(); | |
53 }, | |
54 | |
55 onResize: function() | 52 onResize: function() |
56 { | 53 { |
57 this._findMargins(); | 54 this._findMargins(); |
58 this._scheduleUpdate(); | 55 this._scheduleUpdate(); |
59 }, | 56 }, |
60 | 57 |
61 _scheduleUpdate: function() | 58 _scheduleUpdate: function() |
62 { | 59 { |
63 if (this._noUpdates) | 60 if (this._updateId) |
64 return; | 61 window.cancelAnimationFrame(this._updateId); |
65 | 62 this._updateId = window.requestAnimationFrame(this.update.bind(this)); |
66 var dockSide = WebInspector.dockController.dockSide(); | |
67 if (dockSide !== WebInspector.DockController.State.Undocked) { | |
68 if (this._updateId) | |
69 window.cancelAnimationFrame(this._updateId); | |
70 this._updateId = window.requestAnimationFrame(this._update.bind(this
)); | |
71 } | |
72 }, | 63 }, |
73 | 64 |
74 /** | 65 /** |
75 * @return {!Size} | 66 * @return {!Size} |
76 */ | 67 */ |
77 dipPageSize: function() | 68 dipPageSize: function() |
78 { | 69 { |
79 var rect = this._dipPageRect(); | 70 var rect = this._dipPageRect(); |
80 return new Size(Math.round(rect.width), Math.round(rect.height)); | 71 return new Size(Math.round(rect.width), Math.round(rect.height)); |
81 }, | 72 }, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 var bodyRect = document.body.getBoundingClientRect(); | 104 var bodyRect = document.body.getBoundingClientRect(); |
114 | 105 |
115 var left = Math.max(rect.left * zoomFactor + this._margins.left, bodyRec
t.left * zoomFactor); | 106 var left = Math.max(rect.left * zoomFactor + this._margins.left, bodyRec
t.left * zoomFactor); |
116 var top = Math.max(rect.top * zoomFactor + this._margins.top, bodyRect.t
op * zoomFactor); | 107 var top = Math.max(rect.top * zoomFactor + this._margins.top, bodyRect.t
op * zoomFactor); |
117 var bottom = Math.min(rect.bottom * zoomFactor - this._margins.bottom, b
odyRect.bottom * zoomFactor); | 108 var bottom = Math.min(rect.bottom * zoomFactor - this._margins.bottom, b
odyRect.bottom * zoomFactor); |
118 var right = Math.min(rect.right * zoomFactor - this._margins.right, body
Rect.right * zoomFactor); | 109 var right = Math.min(rect.right * zoomFactor - this._margins.right, body
Rect.right * zoomFactor); |
119 | 110 |
120 return { x: left, y: top, width: right - left, height: bottom - top }; | 111 return { x: left, y: top, width: right - left, height: bottom - top }; |
121 }, | 112 }, |
122 | 113 |
123 _update: function() | 114 update: function() |
124 { | 115 { |
125 delete this._updateId; | 116 delete this._updateId; |
126 if (this._noUpdates) | |
127 return; | |
128 | |
129 var rect = this._dipPageRect(); | 117 var rect = this._dipPageRect(); |
130 var bounds = { x: Math.round(rect.x), y: Math.round(rect.y), height: Mat
h.round(rect.height), width: Math.round(rect.width) }; | 118 var bounds = { x: Math.round(rect.x), y: Math.round(rect.y), height: Mat
h.round(rect.height), width: Math.round(rect.width) }; |
131 InspectorFrontendHost.setInspectedPageBounds(bounds); | 119 this.dispatchEventToListeners(WebInspector.InspectedPagePlaceholder.Even
ts.Update, bounds); |
132 }, | |
133 | |
134 _beforeDockSideChange: function() | |
135 { | |
136 this._noUpdates = true; | |
137 }, | |
138 | |
139 _afterDockSideChange: function() | |
140 { | |
141 this._noUpdates = false; | |
142 this._scheduleUpdate(); | |
143 }, | 120 }, |
144 | 121 |
145 __proto__: WebInspector.View.prototype | 122 __proto__: WebInspector.View.prototype |
146 }; | 123 }; |
OLD | NEW |