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 | |
| 29 | /** |
| 30 | * @unrestricted |
| 31 | */ |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 32 | export default class Panel extends UI.VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 33 | /** |
| 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 46 | } |
| 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 68 | * @param {!UI.Infobar} infobar |
| 69 | */ |
| 70 | showInfobar(infobar) { |
| 71 | infobar.setCloseCallback(this._onInfobarClosed.bind(this, infobar)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 72 | if (this.element.firstChild) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 73 | this.element.insertBefore(infobar.element, this.element.firstChild); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 74 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 75 | this.element.appendChild(infobar.element); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 76 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 77 | 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 Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 88 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * @unrestricted |
| 92 | */ |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 93 | export class PanelWithSidebar extends Panel { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 94 | /** |
| 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 Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 135 | } |
| 136 | |
| 137 | /* Legacy exported object*/ |
| 138 | self.UI = self.UI || {}; |
| 139 | |
| 140 | /* Legacy exported object*/ |
| 141 | UI = UI || {}; |
| 142 | |
| 143 | /** @constructor */ |
| 144 | UI.Panel = Panel; |
| 145 | |
| 146 | /** @constructor */ |
| 147 | UI.PanelWithSidebar = PanelWithSidebar; |
| 148 | |
| 149 | // For testing. |
| 150 | UI.panels = {}; |