Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / InspectedPagePlaceholder.js
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.
4
5 /**
6  * @constructor
7  * @extends {WebInspector.View}
8  */
9 WebInspector.InspectedPagePlaceholder = function()
10 {
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);
15 };
16
17 WebInspector.InspectedPagePlaceholder.Constraints = {
18     Width: 50,
19     Height: 50
20 };
21
22 WebInspector.InspectedPagePlaceholder.MarginValue = 3;
23
24 WebInspector.InspectedPagePlaceholder.prototype = {
25     _findMargins: function()
26     {
27         var margins = { top: false, right: false, bottom: false, left: false };
28         var adjacent = { top: true, right: true, bottom: true, left: true};
29         var view = this;
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())
37                     margins[side] = true;
38                 adjacent[side] = false;
39             }
40             view = parent;
41         }
42
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();
46         }
47     },
48
49     _updateMarginValue: function()
50     {
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;
57     },
58
59     _onZoomChanged: function()
60     {
61         this._updateMarginValue();
62         this._scheduleUpdate();
63     },
64
65     onResize: function()
66     {
67         this._findMargins();
68         this._scheduleUpdate();
69     },
70
71     _scheduleUpdate: function()
72     {
73         var dockSide = WebInspector.dockController.dockSide();
74         if (dockSide !== WebInspector.DockController.State.Undocked) {
75             if (this._updateId)
76                 window.cancelAnimationFrame(this._updateId);
77             this._updateId = window.requestAnimationFrame(this._update.bind(this));
78         }
79     },
80
81     _update: function()
82     {
83         delete this._updateId;
84
85         var zoomFactor = WebInspector.zoomManager.zoomFactor();
86
87         var marginValue = WebInspector.InspectedPagePlaceholder.MarginValue;
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 - 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)};
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     },
114
115     __proto__: WebInspector.View.prototype
116 };