blob: 7f2b03c5b838c91ecddad1b634812c735221f71d [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
2 * Copyright (C) 2007, 2008 Apple 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
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
Blink Reformat4c46d092018-04-07 15:32:3728
29/**
30 * @unrestricted
31 */
Tim van der Lippe0830b3d2019-10-03 13:20:0732export default class Panel extends UI.VBox {
Blink Reformat4c46d092018-04-07 15:32:3733 /**
34 * @param {string} name
35 */
36 constructor(name) {
37 super();
38
39 this.element.classList.add('panel');
40 this.element.setAttribute('aria-label', name);
41 this.element.classList.add(name);
42 this._panelName = name;
43
44 // For testing.
45 UI.panels[name] = this;
Blink Reformat4c46d092018-04-07 15:32:3746 }
47
48 get name() {
49 return this._panelName;
50 }
51
52 /**
53 * @return {?UI.SearchableView}
54 */
55 searchableView() {
56 return null;
57 }
58
59 /**
60 * @override
61 * @return {!Array.<!Element>}
62 */
63 elementsToRestoreScrollPositionsFor() {
64 return [];
65 }
66
67 /**
Blink Reformat4c46d092018-04-07 15:32:3768 * @param {!UI.Infobar} infobar
69 */
70 showInfobar(infobar) {
71 infobar.setCloseCallback(this._onInfobarClosed.bind(this, infobar));
Tim van der Lippe1d6e57a2019-09-30 11:55:3472 if (this.element.firstChild) {
Blink Reformat4c46d092018-04-07 15:32:3773 this.element.insertBefore(infobar.element, this.element.firstChild);
Tim van der Lippe1d6e57a2019-09-30 11:55:3474 } else {
Blink Reformat4c46d092018-04-07 15:32:3775 this.element.appendChild(infobar.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:3476 }
Blink Reformat4c46d092018-04-07 15:32:3777 infobar.setParentView(this);
78 this.doResize();
79 }
80
81 /**
82 * @param {!UI.Infobar} infobar
83 */
84 _onInfobarClosed(infobar) {
85 infobar.element.remove();
86 this.doResize();
87 }
Tim van der Lippe0830b3d2019-10-03 13:20:0788}
Blink Reformat4c46d092018-04-07 15:32:3789
90/**
91 * @unrestricted
92 */
Tim van der Lippe0830b3d2019-10-03 13:20:0793export class PanelWithSidebar extends Panel {
Blink Reformat4c46d092018-04-07 15:32:3794 /**
95 * @param {string} name
96 * @param {number=} defaultWidth
97 */
98 constructor(name, defaultWidth) {
99 super(name);
100
101 this._panelSplitWidget =
102 new UI.SplitWidget(true, false, this._panelName + 'PanelSplitViewState', defaultWidth || 200);
103 this._panelSplitWidget.show(this.element);
104
105 this._mainWidget = new UI.VBox();
106 this._panelSplitWidget.setMainWidget(this._mainWidget);
107
108 this._sidebarWidget = new UI.VBox();
109 this._sidebarWidget.setMinimumSize(100, 25);
110 this._panelSplitWidget.setSidebarWidget(this._sidebarWidget);
111
112 this._sidebarWidget.element.classList.add('panel-sidebar');
113 }
114
115 /**
116 * @return {!Element}
117 */
118 panelSidebarElement() {
119 return this._sidebarWidget.element;
120 }
121
122 /**
123 * @return {!Element}
124 */
125 mainElement() {
126 return this._mainWidget.element;
127 }
128
129 /**
130 * @return {!UI.SplitWidget}
131 */
132 splitWidget() {
133 return this._panelSplitWidget;
134 }
Tim van der Lippe0830b3d2019-10-03 13:20:07135}
136
137/* Legacy exported object*/
138self.UI = self.UI || {};
139
140/* Legacy exported object*/
141UI = UI || {};
142
143/** @constructor */
144UI.Panel = Panel;
145
146/** @constructor */
147UI.PanelWithSidebar = PanelWithSidebar;
148
149// For testing.
150UI.panels = {};