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.Widget}
9 WebInspector.InspectedPagePlaceholder = function()
11 WebInspector.Widget.call(this);
12 this.element.classList.add("inspected-page-placeholder");
13 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.ZoomChanged, this._scheduleUpdate, this);
14 this._margins = { top: 0, right: 0, bottom: 0, left: 0 };
15 this.restoreMinimumSizeAndMargins();
18 WebInspector.InspectedPagePlaceholder.Events = {
22 WebInspector.InspectedPagePlaceholder.MarginValue = 3;
24 WebInspector.InspectedPagePlaceholder.prototype = {
25 _findMargins: function()
27 var margins = { top: 0, right: 0, bottom: 0, left: 0 };
29 if (this._useMargins) {
30 var adjacent = { top: true, right: true, bottom: true, left: true };
32 while (widget.parentWidget()) {
33 var parent = widget.parentWidget();
34 // This view assumes it's always inside the main split widget element, not a sidebar.
35 // Every parent which is not a split widget, must be of the same size as this widget.
36 if (parent instanceof WebInspector.SplitWidget) {
37 var side = parent.sidebarSide();
38 if (adjacent[side] && !parent.hasCustomResizer() && parent.isResizable())
39 margins[side] = WebInspector.InspectedPagePlaceholder.MarginValue;
40 adjacent[side] = false;
46 if (this._margins.top !== margins.top || this._margins.left !== margins.left || this._margins.right !== margins.right || this._margins.bottom !== margins.bottom) {
47 this._margins = margins;
48 this._scheduleUpdate();
55 this._scheduleUpdate();
58 _scheduleUpdate: function()
61 this.element.window().cancelAnimationFrame(this._updateId);
62 this._updateId = this.element.window().requestAnimationFrame(this.update.bind(this));
65 restoreMinimumSizeAndMargins: function()
67 this._useMargins = true;
68 this.setMinimumSize(50, 50);
72 clearMinimumSizeAndMargins: function()
74 this._useMargins = false;
75 this.setMinimumSize(1, 1);
79 _dipPageRect: function()
81 var zoomFactor = WebInspector.zoomManager.zoomFactor();
82 var rect = this.element.getBoundingClientRect();
83 var bodyRect = this.element.ownerDocument.body.getBoundingClientRect();
85 var left = Math.max(rect.left * zoomFactor + this._margins.left, bodyRect.left * zoomFactor);
86 var top = Math.max(rect.top * zoomFactor + this._margins.top, bodyRect.top * zoomFactor);
87 var bottom = Math.min(rect.bottom * zoomFactor - this._margins.bottom, bodyRect.bottom * zoomFactor);
88 var right = Math.min(rect.right * zoomFactor - this._margins.right, bodyRect.right * zoomFactor);
90 return { x: left, y: top, width: right - left, height: bottom - top };
95 delete this._updateId;
96 var rect = this._dipPageRect();
97 var bounds = { x: Math.round(rect.x), y: Math.round(rect.y), height: Math.max(1, Math.round(rect.height)), width: Math.max(1, Math.round(rect.width)) };
98 this.dispatchEventToListeners(WebInspector.InspectedPagePlaceholder.Events.Update, bounds);
101 __proto__: WebInspector.Widget.prototype