blob: 6842a69af76ce0dbf0e476193240934571b18c08 [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
Paul Lewis9950e182019-12-16 16:06:0729import {SearchableView} from './SearchableView.js'; // eslint-disable-line no-unused-vars
30import {SplitWidget} from './SplitWidget.js';
31import {VBox} from './Widget.js';
32
Sigurd Schneider46da7db2020-05-20 13:45:1133
Paul Lewis9950e182019-12-16 16:06:0734export class Panel extends VBox {
Blink Reformat4c46d092018-04-07 15:32:3735 /**
36 * @param {string} name
37 */
38 constructor(name) {
39 super();
40
41 this.element.classList.add('panel');
42 this.element.setAttribute('aria-label', name);
43 this.element.classList.add(name);
44 this._panelName = name;
45
Simon Zünd57a98682020-08-13 06:24:1346 // @ts-ignore: Legacy global. Requires rewriting tests to get rid of.
Blink Reformat4c46d092018-04-07 15:32:3747 // For testing.
48 UI.panels[name] = this;
Blink Reformat4c46d092018-04-07 15:32:3749 }
50
51 get name() {
52 return this._panelName;
53 }
54
55 /**
Paul Lewis9950e182019-12-16 16:06:0756 * @return {?SearchableView}
Blink Reformat4c46d092018-04-07 15:32:3757 */
58 searchableView() {
59 return null;
60 }
61
62 /**
63 * @override
64 * @return {!Array.<!Element>}
65 */
66 elementsToRestoreScrollPositionsFor() {
67 return [];
68 }
Tim van der Lippe0830b3d2019-10-03 13:20:0769}
Blink Reformat4c46d092018-04-07 15:32:3770
71/**
72 * @unrestricted
73 */
Tim van der Lippe0830b3d2019-10-03 13:20:0774export class PanelWithSidebar extends Panel {
Blink Reformat4c46d092018-04-07 15:32:3775 /**
76 * @param {string} name
77 * @param {number=} defaultWidth
78 */
79 constructor(name, defaultWidth) {
80 super(name);
81
Paul Lewis9950e182019-12-16 16:06:0782 this._panelSplitWidget = new SplitWidget(true, false, this._panelName + 'PanelSplitViewState', defaultWidth || 200);
Blink Reformat4c46d092018-04-07 15:32:3783 this._panelSplitWidget.show(this.element);
84
Paul Lewis9950e182019-12-16 16:06:0785 this._mainWidget = new VBox();
Blink Reformat4c46d092018-04-07 15:32:3786 this._panelSplitWidget.setMainWidget(this._mainWidget);
87
Paul Lewis9950e182019-12-16 16:06:0788 this._sidebarWidget = new VBox();
Blink Reformat4c46d092018-04-07 15:32:3789 this._sidebarWidget.setMinimumSize(100, 25);
90 this._panelSplitWidget.setSidebarWidget(this._sidebarWidget);
91
92 this._sidebarWidget.element.classList.add('panel-sidebar');
93 }
94
95 /**
96 * @return {!Element}
97 */
98 panelSidebarElement() {
99 return this._sidebarWidget.element;
100 }
101
102 /**
103 * @return {!Element}
104 */
105 mainElement() {
106 return this._mainWidget.element;
107 }
108
109 /**
Paul Lewis9950e182019-12-16 16:06:07110 * @return {!SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37111 */
112 splitWidget() {
113 return this._panelSplitWidget;
114 }
Tim van der Lippe0830b3d2019-10-03 13:20:07115}