Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 28 | |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 29 | import {SearchableView} from './SearchableView.js'; // eslint-disable-line no-unused-vars |
| 30 | import {SplitWidget} from './SplitWidget.js'; |
| 31 | import {VBox} from './Widget.js'; |
| 32 | |
Sigurd Schneider | 46da7db | 2020-05-20 13:45:11 | [diff] [blame] | 33 | |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 34 | export class Panel extends VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 35 | /** |
| 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ünd | 57a9868 | 2020-08-13 06:24:13 | [diff] [blame] | 46 | // @ts-ignore: Legacy global. Requires rewriting tests to get rid of. |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 47 | // For testing. |
| 48 | UI.panels[name] = this; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | get name() { |
| 52 | return this._panelName; |
| 53 | } |
| 54 | |
| 55 | /** |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 56 | * @return {?SearchableView} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 57 | */ |
| 58 | searchableView() { |
| 59 | return null; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @override |
| 64 | * @return {!Array.<!Element>} |
| 65 | */ |
| 66 | elementsToRestoreScrollPositionsFor() { |
| 67 | return []; |
| 68 | } |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 69 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * @unrestricted |
| 73 | */ |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 74 | export class PanelWithSidebar extends Panel { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 75 | /** |
| 76 | * @param {string} name |
| 77 | * @param {number=} defaultWidth |
| 78 | */ |
| 79 | constructor(name, defaultWidth) { |
| 80 | super(name); |
| 81 | |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 82 | this._panelSplitWidget = new SplitWidget(true, false, this._panelName + 'PanelSplitViewState', defaultWidth || 200); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 83 | this._panelSplitWidget.show(this.element); |
| 84 | |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 85 | this._mainWidget = new VBox(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 86 | this._panelSplitWidget.setMainWidget(this._mainWidget); |
| 87 | |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 88 | this._sidebarWidget = new VBox(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 89 | 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 Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 110 | * @return {!SplitWidget} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 111 | */ |
| 112 | splitWidget() { |
| 113 | return this._panelSplitWidget; |
| 114 | } |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 115 | } |