1/*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * @constructor
31 * @extends {WebInspector.SplitView}
32 * @param {string=} sidebarPosition
33 * @param {string=} sidebarWidthSettingName
34 * @param {number=} defaultSidebarWidth
35 * @param {number=} defaultSidebarHeight
36 */
37WebInspector.SidebarView = function(sidebarPosition, sidebarWidthSettingName, defaultSidebarWidth, defaultSidebarHeight)
38{
39    WebInspector.SplitView.call(this, true, sidebarWidthSettingName, defaultSidebarWidth, defaultSidebarHeight);
40
41    this._minimumSidebarWidth = Preferences.minSidebarWidth;
42    this._minimumMainWidthPercent = 50;
43
44    this._minimumSidebarHeight = Preferences.minSidebarHeight;
45    this._minimumMainHeightPercent = 50;
46
47    this._sidebarPosition = sidebarPosition || WebInspector.SidebarView.SidebarPosition.Start;
48    this.setSecondIsSidebar(this._sidebarPosition === WebInspector.SidebarView.SidebarPosition.End);
49}
50
51WebInspector.SidebarView.EventTypes = {
52    Resized: "Resized"
53}
54
55/**
56 * @enum {string}
57 */
58WebInspector.SidebarView.SidebarPosition = {
59    Start: "Start",
60    End: "End"
61}
62
63WebInspector.SidebarView.prototype = {
64    /**
65     * @param {number} width
66     */
67    setMinimumSidebarWidth: function(width)
68    {
69        this._minimumSidebarWidth = width;
70    },
71
72    /**
73     * @param {number} height
74     */
75    setMinimumSidebarHeight: function(height)
76    {
77        this._minimumSidebarHeight = height;
78    },
79
80    /**
81     * @param {number} widthPercent
82     */
83    setMinimumMainWidthPercent: function(widthPercent)
84    {
85        this._minimumMainWidthPercent = widthPercent;
86    },
87
88    /**
89     * @param {number} heightPercent
90     */
91    setMinimumMainHeightPercent: function(heightPercent)
92    {
93        this._minimumMainHeightPercent = heightPercent;
94    },
95
96    /**
97     * @param {number} width
98     */
99    setSidebarWidth: function(width)
100    {
101        this.setSidebarSize(width);
102    },
103
104    /**
105     * @return {number}
106     */
107    sidebarWidth: function()
108    {
109        return this.sidebarSize();
110    },
111
112    onResize: function()
113    {
114        WebInspector.SplitView.prototype.onResize.call(this);
115        this.dispatchEventToListeners(WebInspector.SidebarView.EventTypes.Resized, this.sidebarWidth());
116    },
117
118    /**
119     * @param {number} size
120     */
121    applyConstraints: function(size)
122    {
123        var minSidebarSize = this.isVertical() ? this._minimumSidebarWidth : this._minimumSidebarHeight;
124        var minMainSizePercent = this.isVertical() ? this._minimumMainWidthPercent : this._minimumMainHeightPercent;
125        return Number.constrain(size, minSidebarSize, this.totalSize() * (100 - minMainSizePercent) / 100);
126    },
127
128    hideMainElement: function()
129    {
130        if (this.isSidebarSecond())
131            this.showOnlySecond();
132        else
133            this.showOnlyFirst();
134    },
135
136    showMainElement: function()
137    {
138        this.showBoth();
139    },
140
141    hideSidebarElement: function()
142    {
143        if (this.isSidebarSecond())
144            this.showOnlyFirst();
145        else
146            this.showOnlySecond();
147    },
148
149    showSidebarElement: function()
150    {
151        this.showBoth();
152    },
153
154    /**
155     * @return {Array.<Element>}
156     */
157    elementsToRestoreScrollPositionsFor: function()
158    {
159        return [ this.mainElement, this.sidebarElement ];
160    },
161
162    __proto__: WebInspector.SplitView.prototype
163}
164