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
3 // found in the LICENSE file.
7 * @extends {WebInspector.View}
9 WebInspector.InspectedPagePlaceholder = function()
11 WebInspector.View.call(this);
12 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.ZoomChanged, this._onZoomChanged, this);
13 this._margins = { top: false, right: false, bottom: false, left: false };
14 this.setMinimumSize(WebInspector.InspectedPagePlaceholder.Constraints.Width, WebInspector.InspectedPagePlaceholder.Constraints.Height);
17 WebInspector.InspectedPagePlaceholder.Constraints = {
22 WebInspector.InspectedPagePlaceholder.MarginValue = 3;
24 WebInspector.InspectedPagePlaceholder.prototype = {
25 _findMargins: function()
27 var margins = { top: false, right: false, bottom: false, left: false };
28 var adjacent = { top: true, right: true, bottom: true, left: true};
30 while (view.parentView()) {
31 var parent = view.parentView();
32 // 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.
34 if (parent instanceof WebInspector.SplitView) {
35 var side = parent.sidebarSide();
36 if (adjacent[side] && !parent.hasCustomResizer())
38 adjacent[side] = false;
43 if (this._margins.top !== margins.top || this._margins.left !== margins.left || this._margins.right !== margins.right || this._margins.bottom !== margins.bottom) {
44 this._margins = margins;
45 this._updateMarginValue();
49 _updateMarginValue: function()
51 var marginValue = Math.round(WebInspector.InspectedPagePlaceholder.MarginValue / 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;
59 _onZoomChanged: function()
61 this._updateMarginValue();
62 this._scheduleUpdate();
68 this._scheduleUpdate();
71 _scheduleUpdate: function()
73 var dockSide = WebInspector.dockController.dockSide();
74 if (dockSide !== WebInspector.DockController.State.Undocked) {
76 window.cancelAnimationFrame(this._updateId);
77 this._updateId = window.requestAnimationFrame(this._update.bind(this));
83 delete this._updateId;
85 var zoomFactor = WebInspector.zoomManager.zoomFactor();
87 var marginValue = WebInspector.InspectedPagePlaceholder.MarginValue;
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};
95 width: WebInspector.InspectedPagePlaceholder.Constraints.Width - Math.round(insets.left * zoomFactor) - Math.round(insets.right * zoomFactor),
96 height: WebInspector.InspectedPagePlaceholder.Constraints.Height - Math.round(insets.top * zoomFactor) - Math.round(insets.bottom * zoomFactor)};
98 // This view assumes it's always inside the main split view element, not a sidebar.
101 if ((view instanceof WebInspector.SplitView) && view.sidebarSide())
102 insets[view.sidebarSide()] += view.preferredSidebarSize();
103 view = view.parentView();
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)};
112 InspectorFrontendHost.setContentsResizingStrategy(roundedInsets, minSize);
115 __proto__: WebInspector.View.prototype