blob: 103f78172c384de9c2facf15dcd5e0c67500ed75 [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
Blink Reformat4c46d092018-04-07 15:32:3733/**
34 * @unrestricted
35 */
Paul Lewis9950e182019-12-16 16:06:0736export class Panel extends VBox {
Blink Reformat4c46d092018-04-07 15:32:3737 /**
38 * @param {string} name
39 */
40 constructor(name) {
41 super();
42
43 this.element.classList.add('panel');
44 this.element.setAttribute('aria-label', name);
45 this.element.classList.add(name);
46 this._panelName = name;
47
48 // For testing.
49 UI.panels[name] = this;
Blink Reformat4c46d092018-04-07 15:32:3750 }
51
52 get name() {
53 return this._panelName;
54 }
55
56 /**
Paul Lewis9950e182019-12-16 16:06:0757 * @return {?SearchableView}
Blink Reformat4c46d092018-04-07 15:32:3758 */
59 searchableView() {
60 return null;
61 }
62
63 /**
64 * @override
65 * @return {!Array.<!Element>}
66 */
67 elementsToRestoreScrollPositionsFor() {
68 return [];
69 }
Tim van der Lippe0830b3d2019-10-03 13:20:0770}
Blink Reformat4c46d092018-04-07 15:32:3771
72/**
73 * @unrestricted
74 */
Tim van der Lippe0830b3d2019-10-03 13:20:0775export class PanelWithSidebar extends Panel {
Blink Reformat4c46d092018-04-07 15:32:3776 /**
77 * @param {string} name
78 * @param {number=} defaultWidth
79 */
80 constructor(name, defaultWidth) {
81 super(name);
82
Paul Lewis9950e182019-12-16 16:06:0783 this._panelSplitWidget = new SplitWidget(true, false, this._panelName + 'PanelSplitViewState', defaultWidth || 200);
Blink Reformat4c46d092018-04-07 15:32:3784 this._panelSplitWidget.show(this.element);
85
Paul Lewis9950e182019-12-16 16:06:0786 this._mainWidget = new VBox();
Blink Reformat4c46d092018-04-07 15:32:3787 this._panelSplitWidget.setMainWidget(this._mainWidget);
88
Paul Lewis9950e182019-12-16 16:06:0789 this._sidebarWidget = new VBox();
Blink Reformat4c46d092018-04-07 15:32:3790 this._sidebarWidget.setMinimumSize(100, 25);
91 this._panelSplitWidget.setSidebarWidget(this._sidebarWidget);
92
93 this._sidebarWidget.element.classList.add('panel-sidebar');
94 }
95
96 /**
97 * @return {!Element}
98 */
99 panelSidebarElement() {
100 return this._sidebarWidget.element;
101 }
102
103 /**
104 * @return {!Element}
105 */
106 mainElement() {
107 return this._mainWidget.element;
108 }
109
110 /**
Paul Lewis9950e182019-12-16 16:06:07111 * @return {!SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37112 */
113 splitWidget() {
114 return this._panelSplitWidget;
115 }
Tim van der Lippe0830b3d2019-10-03 13:20:07116}