Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Google 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 are |
| 6 | * met: |
| 7 | * |
Tim van der Lippe | 83f02be | 2020-01-23 11:11:40 | [diff] [blame] | 8 | * * Redistributions of source code must retain the above copyright |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 9 | * notice, this list of conditions and the following disclaimer. |
Tim van der Lippe | 83f02be | 2020-01-23 11:11:40 | [diff] [blame] | 10 | * * Redistributions in binary form must reproduce the above |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 11 | * copyright notice, this list of conditions and the following disclaimer |
| 12 | * in the documentation and/or other materials provided with the |
| 13 | * distribution. |
Tim van der Lippe | 83f02be | 2020-01-23 11:11:40 | [diff] [blame] | 14 | * * Neither the name of Google Inc. nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived from |
| 16 | * this software without specific prior written permission. |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 17 | * |
Tim van der Lippe | 83f02be | 2020-01-23 11:11:40 | [diff] [blame] | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
Tim van der Lippe | 83f02be | 2020-01-23 11:11:40 | [diff] [blame] | 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Tim van der Lippe | ee97fa3 | 2020-04-23 15:20:56 | [diff] [blame] | 31 | // @ts-nocheck |
| 32 | // TODO(crbug.com/1011811): Enable TypeScript compiler checks |
| 33 | |
Paul Lewis | 17e384e | 2020-01-08 15:46:51 | [diff] [blame] | 34 | import * as Common from '../common/common.js'; |
Jack Franklin | 1be909c | 2020-03-04 08:57:41 | [diff] [blame] | 35 | import * as Platform from '../platform/platform.js'; |
Tim van der Lippe | aa76aa2 | 2020-02-14 14:38:24 | [diff] [blame] | 36 | |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 37 | import {Constraints} from './Geometry.js'; |
| 38 | import {Events as ResizerWidgetEvents, SimpleResizerWidget} from './ResizerWidget.js'; |
| 39 | import {ToolbarButton} from './Toolbar.js'; |
| 40 | import {Widget} from './Widget.js'; |
Paul Lewis | 6c914a1 | 2020-03-19 11:23:21 | [diff] [blame] | 41 | import {Events as ZoomManagerEvents, ZoomManager} from './ZoomManager.js'; |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 42 | |
Sigurd Schneider | 46da7db | 2020-05-20 13:45:11 | [diff] [blame] | 43 | |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 44 | export class SplitWidget extends Widget { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 45 | /** |
| 46 | * @param {boolean} isVertical |
| 47 | * @param {boolean} secondIsSidebar |
| 48 | * @param {string=} settingName |
| 49 | * @param {number=} defaultSidebarWidth |
| 50 | * @param {number=} defaultSidebarHeight |
| 51 | * @param {boolean=} constraintsInDip |
| 52 | */ |
| 53 | constructor(isVertical, secondIsSidebar, settingName, defaultSidebarWidth, defaultSidebarHeight, constraintsInDip) { |
| 54 | super(true); |
| 55 | this.element.classList.add('split-widget'); |
Jack Franklin | 71519f8 | 2020-11-03 12:08:59 | [diff] [blame^] | 56 | this.registerRequiredCSS('ui/splitWidget.css', {enableLegacyPatching: true}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 57 | |
| 58 | this.contentElement.classList.add('shadow-split-widget'); |
Joel Einbinder | 27131b2 | 2019-03-14 09:29:54 | [diff] [blame] | 59 | this._sidebarElement = |
| 60 | this.contentElement.createChild('div', 'shadow-split-widget-contents shadow-split-widget-sidebar vbox'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 61 | this._mainElement = |
| 62 | this.contentElement.createChild('div', 'shadow-split-widget-contents shadow-split-widget-main vbox'); |
Joel Einbinder | 7fbe24c | 2019-01-24 05:19:01 | [diff] [blame] | 63 | this._mainElement.createChild('slot').name = 'insertion-point-main'; |
Joel Einbinder | 7fbe24c | 2019-01-24 05:19:01 | [diff] [blame] | 64 | this._sidebarElement.createChild('slot').name = 'insertion-point-sidebar'; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 65 | this._resizerElement = this.contentElement.createChild('div', 'shadow-split-widget-resizer'); |
| 66 | this._resizerElementSize = null; |
| 67 | |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 68 | this._resizerWidget = new SimpleResizerWidget(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 69 | this._resizerWidget.setEnabled(true); |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 70 | this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeStart, this._onResizeStart, this); |
| 71 | this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeUpdate, this._onResizeUpdate, this); |
| 72 | this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeEnd, this._onResizeEnd, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 73 | |
| 74 | this._defaultSidebarWidth = defaultSidebarWidth || 200; |
| 75 | this._defaultSidebarHeight = defaultSidebarHeight || this._defaultSidebarWidth; |
| 76 | this._constraintsInDip = !!constraintsInDip; |
| 77 | this._resizeStartSizeDIP = 0; |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame] | 78 | this._setting = settingName ? Common.Settings.Settings.instance().createSetting(settingName, {}) : null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 79 | |
| 80 | this._totalSizeCSS = 0; |
| 81 | this._totalSizeOtherDimensionCSS = 0; |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 82 | /** @type {?Widget} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 83 | this._mainWidget = null; |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 84 | /** @type {?Widget} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 85 | this._sidebarWidget = null; |
| 86 | this._animationFrameHandle = 0; |
Tim van der Lippe | ee97fa3 | 2020-04-23 15:20:56 | [diff] [blame] | 87 | /** @type {?function():void} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 88 | this._animationCallback = null; |
| 89 | this._showHideSidebarButtonTitle = ''; |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 90 | /** @type {?ToolbarButton} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 91 | this._showHideSidebarButton = null; |
| 92 | this._isVertical = false; |
| 93 | this._sidebarMinimized = false; |
| 94 | this._detaching = false; |
| 95 | this._sidebarSizeDIP = -1; |
| 96 | this._savedSidebarSizeDIP = this._sidebarSizeDIP; |
| 97 | this._secondIsSidebar = false; |
| 98 | this._shouldSaveShowMode = false; |
| 99 | /** @type {?number} */ |
| 100 | this._savedVerticalMainSize = null; |
| 101 | /** @type {?number} */ |
| 102 | this._savedHorizontalMainSize = null; |
| 103 | |
| 104 | this.setSecondIsSidebar(secondIsSidebar); |
| 105 | |
| 106 | this._innerSetVertical(isVertical); |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 107 | this._showMode = ShowMode.Both; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 108 | this._savedShowMode = this._showMode; |
| 109 | |
| 110 | // Should be called after isVertical has the right value. |
| 111 | this.installResizer(this._resizerElement); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * @return {boolean} |
| 116 | */ |
| 117 | isVertical() { |
| 118 | return this._isVertical; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * @param {boolean} isVertical |
| 123 | */ |
| 124 | setVertical(isVertical) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 125 | if (this._isVertical === isVertical) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 126 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 127 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 128 | |
| 129 | this._innerSetVertical(isVertical); |
| 130 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 131 | if (this.isShowing()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 132 | this._updateLayout(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 133 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /** |
| 137 | * @param {boolean} isVertical |
| 138 | */ |
| 139 | _innerSetVertical(isVertical) { |
| 140 | this.contentElement.classList.toggle('vbox', !isVertical); |
| 141 | this.contentElement.classList.toggle('hbox', isVertical); |
| 142 | this._isVertical = isVertical; |
| 143 | |
| 144 | this._resizerElementSize = null; |
| 145 | this._sidebarSizeDIP = -1; |
| 146 | this._restoreSidebarSizeFromSettings(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 147 | if (this._shouldSaveShowMode) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 148 | this._restoreAndApplyShowModeFromSettings(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 149 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 150 | this._updateShowHideSidebarButton(); |
| 151 | // FIXME: reverse SplitWidget.isVertical meaning. |
| 152 | this._resizerWidget.setVertical(!isVertical); |
| 153 | this.invalidateConstraints(); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @param {boolean=} animate |
| 158 | */ |
| 159 | _updateLayout(animate) { |
| 160 | this._totalSizeCSS = 0; // Lazy update. |
| 161 | this._totalSizeOtherDimensionCSS = 0; |
| 162 | |
| 163 | // Remove properties that might affect total size calculation. |
| 164 | this._mainElement.style.removeProperty('width'); |
| 165 | this._mainElement.style.removeProperty('height'); |
| 166 | this._sidebarElement.style.removeProperty('width'); |
| 167 | this._sidebarElement.style.removeProperty('height'); |
| 168 | |
| 169 | this._innerSetSidebarSizeDIP(this._preferredSidebarSizeDIP(), !!animate); |
| 170 | } |
| 171 | |
| 172 | /** |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 173 | * @param {!Widget} widget |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 174 | */ |
| 175 | setMainWidget(widget) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 176 | if (this._mainWidget === widget) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 177 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 178 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 179 | this.suspendInvalidations(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 180 | if (this._mainWidget) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 181 | this._mainWidget.detach(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 182 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 183 | this._mainWidget = widget; |
| 184 | if (widget) { |
Joel Einbinder | 7fbe24c | 2019-01-24 05:19:01 | [diff] [blame] | 185 | widget.element.slot = 'insertion-point-main'; |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 186 | if (this._showMode === ShowMode.OnlyMain || this._showMode === ShowMode.Both) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 187 | widget.show(this.element); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 188 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 189 | } |
| 190 | this.resumeInvalidations(); |
| 191 | } |
| 192 | |
| 193 | /** |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 194 | * @param {!Widget} widget |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 195 | */ |
| 196 | setSidebarWidget(widget) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 197 | if (this._sidebarWidget === widget) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 198 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 199 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 200 | this.suspendInvalidations(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 201 | if (this._sidebarWidget) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 202 | this._sidebarWidget.detach(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 203 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 204 | this._sidebarWidget = widget; |
| 205 | if (widget) { |
Joel Einbinder | 7fbe24c | 2019-01-24 05:19:01 | [diff] [blame] | 206 | widget.element.slot = 'insertion-point-sidebar'; |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 207 | if (this._showMode === ShowMode.OnlySidebar || this._showMode === ShowMode.Both) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 208 | widget.show(this.element); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 209 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 210 | } |
| 211 | this.resumeInvalidations(); |
| 212 | } |
| 213 | |
| 214 | /** |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 215 | * @return {?Widget} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 216 | */ |
| 217 | mainWidget() { |
| 218 | return this._mainWidget; |
| 219 | } |
| 220 | |
| 221 | /** |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 222 | * @return {?Widget} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 223 | */ |
| 224 | sidebarWidget() { |
| 225 | return this._sidebarWidget; |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * @override |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 230 | * @param {!Widget} widget |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 231 | */ |
| 232 | childWasDetached(widget) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 233 | if (this._detaching) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 234 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 235 | } |
| 236 | if (this._mainWidget === widget) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 237 | this._mainWidget = null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 238 | } |
| 239 | if (this._sidebarWidget === widget) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 240 | this._sidebarWidget = null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 241 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 242 | this.invalidateConstraints(); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * @return {boolean} |
| 247 | */ |
| 248 | isSidebarSecond() { |
| 249 | return this._secondIsSidebar; |
| 250 | } |
| 251 | |
| 252 | enableShowModeSaving() { |
| 253 | this._shouldSaveShowMode = true; |
| 254 | this._restoreAndApplyShowModeFromSettings(); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * @return {string} |
| 259 | */ |
| 260 | showMode() { |
| 261 | return this._showMode; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * @param {boolean} secondIsSidebar |
| 266 | */ |
| 267 | setSecondIsSidebar(secondIsSidebar) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 268 | if (secondIsSidebar === this._secondIsSidebar) { |
Joel Einbinder | 27131b2 | 2019-03-14 09:29:54 | [diff] [blame] | 269 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 270 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 271 | this._secondIsSidebar = secondIsSidebar; |
Joel Einbinder | 27131b2 | 2019-03-14 09:29:54 | [diff] [blame] | 272 | if (!this._mainWidget || !this._mainWidget.shouldHideOnDetach()) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 273 | if (secondIsSidebar) { |
Joel Einbinder | 27131b2 | 2019-03-14 09:29:54 | [diff] [blame] | 274 | this.contentElement.insertBefore(this._mainElement, this._sidebarElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 275 | } else { |
Joel Einbinder | 27131b2 | 2019-03-14 09:29:54 | [diff] [blame] | 276 | this.contentElement.insertBefore(this._mainElement, this._resizerElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 277 | } |
Joel Einbinder | 27131b2 | 2019-03-14 09:29:54 | [diff] [blame] | 278 | } else if (!this._sidebarWidget || !this._sidebarWidget.shouldHideOnDetach()) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 279 | if (secondIsSidebar) { |
Joel Einbinder | 27131b2 | 2019-03-14 09:29:54 | [diff] [blame] | 280 | this.contentElement.insertBefore(this._sidebarElement, this._resizerElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 281 | } else { |
Joel Einbinder | 27131b2 | 2019-03-14 09:29:54 | [diff] [blame] | 282 | this.contentElement.insertBefore(this._sidebarElement, this._mainElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 283 | } |
Joel Einbinder | 27131b2 | 2019-03-14 09:29:54 | [diff] [blame] | 284 | } else { |
| 285 | console.error('Could not swap split widget side. Both children widgets contain iframes.'); |
| 286 | this._secondIsSidebar = !secondIsSidebar; |
| 287 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /** |
| 291 | * @return {?string} |
| 292 | */ |
| 293 | sidebarSide() { |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 294 | if (this._showMode !== ShowMode.Both) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 295 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 296 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 297 | return this._isVertical ? (this._secondIsSidebar ? 'right' : 'left') : (this._secondIsSidebar ? 'bottom' : 'top'); |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * @return {!Element} |
| 302 | */ |
| 303 | resizerElement() { |
| 304 | return this._resizerElement; |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * @param {boolean=} animate |
| 309 | */ |
| 310 | hideMain(animate) { |
| 311 | this._showOnly(this._sidebarWidget, this._mainWidget, this._sidebarElement, this._mainElement, animate); |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 312 | this._updateShowMode(ShowMode.OnlySidebar); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | /** |
| 316 | * @param {boolean=} animate |
| 317 | */ |
| 318 | hideSidebar(animate) { |
| 319 | this._showOnly(this._mainWidget, this._sidebarWidget, this._mainElement, this._sidebarElement, animate); |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 320 | this._updateShowMode(ShowMode.OnlyMain); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /** |
| 324 | * @param {boolean} minimized |
| 325 | */ |
| 326 | setSidebarMinimized(minimized) { |
| 327 | this._sidebarMinimized = minimized; |
| 328 | this.invalidateConstraints(); |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * @return {boolean} |
| 333 | */ |
| 334 | isSidebarMinimized() { |
| 335 | return this._sidebarMinimized; |
| 336 | } |
| 337 | |
| 338 | /** |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 339 | * @param {?Widget} sideToShow |
Tim van der Lippe | aa76aa2 | 2020-02-14 14:38:24 | [diff] [blame] | 340 | * @param {?Widget} sideToHide |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 341 | * @param {!Element} shadowToShow |
| 342 | * @param {!Element} shadowToHide |
| 343 | * @param {boolean=} animate |
| 344 | */ |
| 345 | _showOnly(sideToShow, sideToHide, shadowToShow, shadowToHide, animate) { |
| 346 | this._cancelAnimation(); |
| 347 | |
| 348 | /** |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 349 | * @this {SplitWidget} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 350 | */ |
| 351 | function callback() { |
| 352 | if (sideToShow) { |
| 353 | // Make sure main is first in the children list. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 354 | if (sideToShow === this._mainWidget) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 355 | this._mainWidget.show(this.element, this._sidebarWidget ? this._sidebarWidget.element : null); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 356 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 357 | this._sidebarWidget.show(this.element); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 358 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 359 | } |
| 360 | if (sideToHide) { |
| 361 | this._detaching = true; |
| 362 | sideToHide.detach(); |
| 363 | this._detaching = false; |
| 364 | } |
| 365 | |
| 366 | this._resizerElement.classList.add('hidden'); |
| 367 | shadowToShow.classList.remove('hidden'); |
| 368 | shadowToShow.classList.add('maximized'); |
| 369 | shadowToHide.classList.add('hidden'); |
| 370 | shadowToHide.classList.remove('maximized'); |
| 371 | this._removeAllLayoutProperties(); |
| 372 | this.doResize(); |
| 373 | this._showFinishedForTest(); |
| 374 | } |
| 375 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 376 | if (animate) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 377 | this._animate(true, callback.bind(this)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 378 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 379 | callback.call(this); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 380 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 381 | |
| 382 | this._sidebarSizeDIP = -1; |
| 383 | this.setResizable(false); |
| 384 | } |
| 385 | |
| 386 | _showFinishedForTest() { |
| 387 | // This method is sniffed in tests. |
| 388 | } |
| 389 | |
| 390 | _removeAllLayoutProperties() { |
| 391 | this._sidebarElement.style.removeProperty('flexBasis'); |
| 392 | |
| 393 | this._mainElement.style.removeProperty('width'); |
| 394 | this._mainElement.style.removeProperty('height'); |
| 395 | this._sidebarElement.style.removeProperty('width'); |
| 396 | this._sidebarElement.style.removeProperty('height'); |
| 397 | |
| 398 | this._resizerElement.style.removeProperty('left'); |
| 399 | this._resizerElement.style.removeProperty('right'); |
| 400 | this._resizerElement.style.removeProperty('top'); |
| 401 | this._resizerElement.style.removeProperty('bottom'); |
| 402 | |
| 403 | this._resizerElement.style.removeProperty('margin-left'); |
| 404 | this._resizerElement.style.removeProperty('margin-right'); |
| 405 | this._resizerElement.style.removeProperty('margin-top'); |
| 406 | this._resizerElement.style.removeProperty('margin-bottom'); |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * @param {boolean=} animate |
| 411 | */ |
| 412 | showBoth(animate) { |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 413 | if (this._showMode === ShowMode.Both) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 414 | animate = false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 415 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 416 | |
| 417 | this._cancelAnimation(); |
| 418 | this._mainElement.classList.remove('maximized', 'hidden'); |
| 419 | this._sidebarElement.classList.remove('maximized', 'hidden'); |
| 420 | this._resizerElement.classList.remove('hidden'); |
| 421 | this.setResizable(true); |
| 422 | |
| 423 | // Make sure main is the first in the children list. |
| 424 | this.suspendInvalidations(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 425 | if (this._sidebarWidget) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 426 | this._sidebarWidget.show(this.element); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 427 | } |
| 428 | if (this._mainWidget) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 429 | this._mainWidget.show(this.element, this._sidebarWidget ? this._sidebarWidget.element : null); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 430 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 431 | this.resumeInvalidations(); |
| 432 | // Order widgets in DOM properly. |
| 433 | this.setSecondIsSidebar(this._secondIsSidebar); |
| 434 | |
| 435 | this._sidebarSizeDIP = -1; |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 436 | this._updateShowMode(ShowMode.Both); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 437 | this._updateLayout(animate); |
| 438 | } |
| 439 | |
| 440 | /** |
| 441 | * @param {boolean} resizable |
| 442 | */ |
| 443 | setResizable(resizable) { |
| 444 | this._resizerWidget.setEnabled(resizable); |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * @return {boolean} |
| 449 | */ |
| 450 | isResizable() { |
| 451 | return this._resizerWidget.isEnabled(); |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * @param {number} size |
| 456 | */ |
| 457 | setSidebarSize(size) { |
Paul Lewis | 6c914a1 | 2020-03-19 11:23:21 | [diff] [blame] | 458 | const sizeDIP = ZoomManager.instance().cssToDIP(size); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 459 | this._savedSidebarSizeDIP = sizeDIP; |
| 460 | this._saveSetting(); |
| 461 | this._innerSetSidebarSizeDIP(sizeDIP, false, true); |
| 462 | } |
| 463 | |
| 464 | /** |
| 465 | * @return {number} |
| 466 | */ |
| 467 | sidebarSize() { |
| 468 | const sizeDIP = Math.max(0, this._sidebarSizeDIP); |
Paul Lewis | 6c914a1 | 2020-03-19 11:23:21 | [diff] [blame] | 469 | return ZoomManager.instance().dipToCSS(sizeDIP); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Returns total size in DIP. |
| 474 | * @return {number} |
| 475 | */ |
| 476 | _totalSizeDIP() { |
| 477 | if (!this._totalSizeCSS) { |
| 478 | this._totalSizeCSS = this._isVertical ? this.contentElement.offsetWidth : this.contentElement.offsetHeight; |
| 479 | this._totalSizeOtherDimensionCSS = |
| 480 | this._isVertical ? this.contentElement.offsetHeight : this.contentElement.offsetWidth; |
| 481 | } |
Paul Lewis | 6c914a1 | 2020-03-19 11:23:21 | [diff] [blame] | 482 | return ZoomManager.instance().cssToDIP(this._totalSizeCSS); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /** |
| 486 | * @param {string} showMode |
| 487 | */ |
| 488 | _updateShowMode(showMode) { |
| 489 | this._showMode = showMode; |
| 490 | this._saveShowModeToSettings(); |
| 491 | this._updateShowHideSidebarButton(); |
Tim van der Lippe | 3fffd0d | 2020-03-27 15:47:51 | [diff] [blame] | 492 | this.dispatchEventToListeners(Events.ShowModeChanged, showMode); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 493 | this.invalidateConstraints(); |
| 494 | } |
| 495 | |
| 496 | /** |
| 497 | * @param {number} sizeDIP |
| 498 | * @param {boolean} animate |
| 499 | * @param {boolean=} userAction |
| 500 | */ |
| 501 | _innerSetSidebarSizeDIP(sizeDIP, animate, userAction) { |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 502 | if (this._showMode !== ShowMode.Both || !this.isShowing()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 503 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 504 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 505 | |
| 506 | sizeDIP = this._applyConstraints(sizeDIP, userAction); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 507 | if (this._sidebarSizeDIP === sizeDIP) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 508 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 509 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 510 | |
| 511 | if (!this._resizerElementSize) { |
| 512 | this._resizerElementSize = |
| 513 | this._isVertical ? this._resizerElement.offsetWidth : this._resizerElement.offsetHeight; |
| 514 | } |
| 515 | |
| 516 | // Invalidate layout below. |
| 517 | |
| 518 | this._removeAllLayoutProperties(); |
| 519 | |
| 520 | // this._totalSizeDIP is available below since we successfully applied constraints. |
Paul Lewis | 6c914a1 | 2020-03-19 11:23:21 | [diff] [blame] | 521 | const roundSizeCSS = Math.round(ZoomManager.instance().dipToCSS(sizeDIP)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 522 | const sidebarSizeValue = roundSizeCSS + 'px'; |
| 523 | const mainSizeValue = (this._totalSizeCSS - roundSizeCSS) + 'px'; |
| 524 | this._sidebarElement.style.flexBasis = sidebarSizeValue; |
| 525 | |
| 526 | // Make both sides relayout boundaries. |
| 527 | if (this._isVertical) { |
| 528 | this._sidebarElement.style.width = sidebarSizeValue; |
| 529 | this._mainElement.style.width = mainSizeValue; |
| 530 | this._sidebarElement.style.height = this._totalSizeOtherDimensionCSS + 'px'; |
| 531 | this._mainElement.style.height = this._totalSizeOtherDimensionCSS + 'px'; |
| 532 | } else { |
| 533 | this._sidebarElement.style.height = sidebarSizeValue; |
| 534 | this._mainElement.style.height = mainSizeValue; |
| 535 | this._sidebarElement.style.width = this._totalSizeOtherDimensionCSS + 'px'; |
| 536 | this._mainElement.style.width = this._totalSizeOtherDimensionCSS + 'px'; |
| 537 | } |
| 538 | |
| 539 | // Position resizer. |
| 540 | if (this._isVertical) { |
| 541 | if (this._secondIsSidebar) { |
| 542 | this._resizerElement.style.right = sidebarSizeValue; |
| 543 | this._resizerElement.style.marginRight = -this._resizerElementSize / 2 + 'px'; |
| 544 | } else { |
| 545 | this._resizerElement.style.left = sidebarSizeValue; |
| 546 | this._resizerElement.style.marginLeft = -this._resizerElementSize / 2 + 'px'; |
| 547 | } |
| 548 | } else { |
| 549 | if (this._secondIsSidebar) { |
| 550 | this._resizerElement.style.bottom = sidebarSizeValue; |
| 551 | this._resizerElement.style.marginBottom = -this._resizerElementSize / 2 + 'px'; |
| 552 | } else { |
| 553 | this._resizerElement.style.top = sidebarSizeValue; |
| 554 | this._resizerElement.style.marginTop = -this._resizerElementSize / 2 + 'px'; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | this._sidebarSizeDIP = sizeDIP; |
| 559 | |
| 560 | // Force layout. |
| 561 | |
| 562 | if (animate) { |
| 563 | this._animate(false); |
| 564 | } else { |
| 565 | // No need to recalculate this._sidebarSizeDIP and this._totalSizeDIP again. |
| 566 | this.doResize(); |
Tim van der Lippe | 3fffd0d | 2020-03-27 15:47:51 | [diff] [blame] | 567 | this.dispatchEventToListeners(Events.SidebarSizeChanged, this.sidebarSize()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * @param {boolean} reverse |
Tim van der Lippe | 403a88d | 2020-05-13 11:51:32 | [diff] [blame] | 573 | * @param {function():void=} callback |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 574 | */ |
| 575 | _animate(reverse, callback) { |
| 576 | const animationTime = 50; |
| 577 | this._animationCallback = callback || null; |
| 578 | |
| 579 | let animatedMarginPropertyName; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 580 | if (this._isVertical) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 581 | animatedMarginPropertyName = this._secondIsSidebar ? 'margin-right' : 'margin-left'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 582 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 583 | animatedMarginPropertyName = this._secondIsSidebar ? 'margin-bottom' : 'margin-top'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 584 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 585 | |
Paul Lewis | 6c914a1 | 2020-03-19 11:23:21 | [diff] [blame] | 586 | const marginFrom = reverse ? '0' : '-' + ZoomManager.instance().dipToCSS(this._sidebarSizeDIP) + 'px'; |
| 587 | const marginTo = reverse ? '-' + ZoomManager.instance().dipToCSS(this._sidebarSizeDIP) + 'px' : '0'; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 588 | |
| 589 | // This order of things is important. |
| 590 | // 1. Resize main element early and force layout. |
| 591 | this.contentElement.style.setProperty(animatedMarginPropertyName, marginFrom); |
| 592 | if (!reverse) { |
| 593 | suppressUnused(this._mainElement.offsetWidth); |
| 594 | suppressUnused(this._sidebarElement.offsetWidth); |
| 595 | } |
| 596 | |
| 597 | // 2. Issue onresize to the sidebar element, its size won't change. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 598 | if (!reverse) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 599 | this._sidebarWidget.doResize(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 600 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 601 | |
| 602 | // 3. Configure and run animation |
| 603 | this.contentElement.style.setProperty('transition', animatedMarginPropertyName + ' ' + animationTime + 'ms linear'); |
| 604 | |
| 605 | const boundAnimationFrame = animationFrame.bind(this); |
| 606 | let startTime; |
| 607 | /** |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 608 | * @this {SplitWidget} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 609 | */ |
| 610 | function animationFrame() { |
| 611 | this._animationFrameHandle = 0; |
| 612 | |
| 613 | if (!startTime) { |
| 614 | // Kick animation on first frame. |
| 615 | this.contentElement.style.setProperty(animatedMarginPropertyName, marginTo); |
| 616 | startTime = window.performance.now(); |
| 617 | } else if (window.performance.now() < startTime + animationTime) { |
| 618 | // Process regular animation frame. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 619 | if (this._mainWidget) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 620 | this._mainWidget.doResize(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 621 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 622 | } else { |
| 623 | // Complete animation. |
| 624 | this._cancelAnimation(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 625 | if (this._mainWidget) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 626 | this._mainWidget.doResize(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 627 | } |
Tim van der Lippe | 3fffd0d | 2020-03-27 15:47:51 | [diff] [blame] | 628 | this.dispatchEventToListeners(Events.SidebarSizeChanged, this.sidebarSize()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 629 | return; |
| 630 | } |
| 631 | this._animationFrameHandle = this.contentElement.window().requestAnimationFrame(boundAnimationFrame); |
| 632 | } |
| 633 | this._animationFrameHandle = this.contentElement.window().requestAnimationFrame(boundAnimationFrame); |
| 634 | } |
| 635 | |
| 636 | _cancelAnimation() { |
| 637 | this.contentElement.style.removeProperty('margin-top'); |
| 638 | this.contentElement.style.removeProperty('margin-right'); |
| 639 | this.contentElement.style.removeProperty('margin-bottom'); |
| 640 | this.contentElement.style.removeProperty('margin-left'); |
| 641 | this.contentElement.style.removeProperty('transition'); |
| 642 | |
| 643 | if (this._animationFrameHandle) { |
| 644 | this.contentElement.window().cancelAnimationFrame(this._animationFrameHandle); |
| 645 | this._animationFrameHandle = 0; |
| 646 | } |
| 647 | if (this._animationCallback) { |
| 648 | this._animationCallback(); |
| 649 | this._animationCallback = null; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * @param {number} sidebarSize |
| 655 | * @param {boolean=} userAction |
| 656 | * @return {number} |
| 657 | */ |
| 658 | _applyConstraints(sidebarSize, userAction) { |
| 659 | const totalSize = this._totalSizeDIP(); |
Paul Lewis | 6c914a1 | 2020-03-19 11:23:21 | [diff] [blame] | 660 | const zoomFactor = this._constraintsInDip ? 1 : ZoomManager.instance().zoomFactor(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 661 | |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 662 | let constraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 663 | let minSidebarSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 664 | if (!minSidebarSize) { |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 665 | minSidebarSize = MinPadding; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 666 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 667 | minSidebarSize *= zoomFactor; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 668 | if (this._sidebarMinimized) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 669 | sidebarSize = minSidebarSize; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 670 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 671 | |
| 672 | let preferredSidebarSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 673 | if (!preferredSidebarSize) { |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 674 | preferredSidebarSize = MinPadding; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 675 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 676 | preferredSidebarSize *= zoomFactor; |
| 677 | // Allow sidebar to be less than preferred by explicit user action. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 678 | if (sidebarSize < preferredSidebarSize) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 679 | preferredSidebarSize = Math.max(sidebarSize, minSidebarSize); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 680 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 681 | preferredSidebarSize += zoomFactor; // 1 css pixel for splitter border. |
| 682 | |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 683 | constraints = this._mainWidget ? this._mainWidget.constraints() : new Constraints(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 684 | let minMainSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 685 | if (!minMainSize) { |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 686 | minMainSize = MinPadding; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 687 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 688 | minMainSize *= zoomFactor; |
| 689 | |
| 690 | let preferredMainSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 691 | if (!preferredMainSize) { |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 692 | preferredMainSize = MinPadding; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 693 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 694 | preferredMainSize *= zoomFactor; |
| 695 | const savedMainSize = this.isVertical() ? this._savedVerticalMainSize : this._savedHorizontalMainSize; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 696 | if (savedMainSize !== null) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 697 | preferredMainSize = Math.min(preferredMainSize, savedMainSize * zoomFactor); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 698 | } |
| 699 | if (userAction) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 700 | preferredMainSize = minMainSize; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 701 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 702 | |
| 703 | // Enough space for preferred. |
| 704 | const totalPreferred = preferredMainSize + preferredSidebarSize; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 705 | if (totalPreferred <= totalSize) { |
Jack Franklin | 1be909c | 2020-03-04 08:57:41 | [diff] [blame] | 706 | return Platform.NumberUtilities.clamp(sidebarSize, preferredSidebarSize, totalSize - preferredMainSize); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 707 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 708 | |
| 709 | // Enough space for minimum. |
| 710 | if (minMainSize + minSidebarSize <= totalSize) { |
| 711 | const delta = totalPreferred - totalSize; |
| 712 | const sidebarDelta = delta * preferredSidebarSize / totalPreferred; |
| 713 | sidebarSize = preferredSidebarSize - sidebarDelta; |
Jack Franklin | 1be909c | 2020-03-04 08:57:41 | [diff] [blame] | 714 | return Platform.NumberUtilities.clamp(sidebarSize, minSidebarSize, totalSize - minMainSize); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | // Not enough space even for minimum sizes. |
| 718 | return Math.max(0, totalSize - minMainSize); |
| 719 | } |
| 720 | |
| 721 | /** |
| 722 | * @override |
| 723 | */ |
| 724 | wasShown() { |
| 725 | this._forceUpdateLayout(); |
Paul Lewis | 6c914a1 | 2020-03-19 11:23:21 | [diff] [blame] | 726 | ZoomManager.instance().addEventListener(ZoomManagerEvents.ZoomChanged, this._onZoomChanged, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | /** |
| 730 | * @override |
| 731 | */ |
| 732 | willHide() { |
Paul Lewis | 6c914a1 | 2020-03-19 11:23:21 | [diff] [blame] | 733 | ZoomManager.instance().removeEventListener(ZoomManagerEvents.ZoomChanged, this._onZoomChanged, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | /** |
| 737 | * @override |
| 738 | */ |
| 739 | onResize() { |
| 740 | this._updateLayout(); |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * @override |
| 745 | */ |
| 746 | onLayout() { |
| 747 | this._updateLayout(); |
| 748 | } |
| 749 | |
| 750 | /** |
| 751 | * @override |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 752 | * @return {!Constraints} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 753 | */ |
| 754 | calculateConstraints() { |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 755 | if (this._showMode === ShowMode.OnlyMain) { |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 756 | return this._mainWidget ? this._mainWidget.constraints() : new Constraints(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 757 | } |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 758 | if (this._showMode === ShowMode.OnlySidebar) { |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 759 | return this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 760 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 761 | |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 762 | let mainConstraints = this._mainWidget ? this._mainWidget.constraints() : new Constraints(); |
| 763 | let sidebarConstraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints(); |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 764 | const min = MinPadding; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 765 | if (this._isVertical) { |
| 766 | mainConstraints = mainConstraints.widthToMax(min).addWidth(1); // 1 for splitter |
| 767 | sidebarConstraints = sidebarConstraints.widthToMax(min); |
| 768 | return mainConstraints.addWidth(sidebarConstraints).heightToMax(sidebarConstraints); |
Mathias Bynens | f06e8c0 | 2020-02-28 13:58:28 | [diff] [blame] | 769 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 770 | mainConstraints = mainConstraints.heightToMax(min).addHeight(1); // 1 for splitter |
| 771 | sidebarConstraints = sidebarConstraints.heightToMax(min); |
| 772 | return mainConstraints.widthToMax(sidebarConstraints).addHeight(sidebarConstraints); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 776 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 777 | */ |
| 778 | _onResizeStart(event) { |
| 779 | this._resizeStartSizeDIP = this._sidebarSizeDIP; |
| 780 | } |
| 781 | |
| 782 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 783 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 784 | */ |
| 785 | _onResizeUpdate(event) { |
| 786 | const offset = event.data.currentPosition - event.data.startPosition; |
Paul Lewis | 6c914a1 | 2020-03-19 11:23:21 | [diff] [blame] | 787 | const offsetDIP = ZoomManager.instance().cssToDIP(offset); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 788 | const newSizeDIP = |
| 789 | this._secondIsSidebar ? this._resizeStartSizeDIP - offsetDIP : this._resizeStartSizeDIP + offsetDIP; |
| 790 | const constrainedSizeDIP = this._applyConstraints(newSizeDIP, true); |
| 791 | this._savedSidebarSizeDIP = constrainedSizeDIP; |
| 792 | this._saveSetting(); |
| 793 | this._innerSetSidebarSizeDIP(constrainedSizeDIP, false, true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 794 | if (this.isVertical()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 795 | this._savedVerticalMainSize = this._totalSizeDIP() - this._sidebarSizeDIP; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 796 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 797 | this._savedHorizontalMainSize = this._totalSizeDIP() - this._sidebarSizeDIP; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 798 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 802 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 803 | */ |
| 804 | _onResizeEnd(event) { |
| 805 | this._resizeStartSizeDIP = 0; |
| 806 | } |
| 807 | |
| 808 | /** |
| 809 | * @param {boolean=} noSplitter |
| 810 | */ |
| 811 | hideDefaultResizer(noSplitter) { |
| 812 | this.uninstallResizer(this._resizerElement); |
Pavel Feldman | c9060ea | 2018-04-30 04:42:18 | [diff] [blame] | 813 | this._sidebarElement.classList.toggle('no-default-splitter', !!noSplitter); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | /** |
| 817 | * @param {!Element} resizerElement |
| 818 | */ |
| 819 | installResizer(resizerElement) { |
Simon Zünd | 3141f41 | 2020-08-12 09:52:51 | [diff] [blame] | 820 | this._resizerWidget.addElement(/** @type {!HTMLElement} */ (resizerElement)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | /** |
| 824 | * @param {!Element} resizerElement |
| 825 | */ |
| 826 | uninstallResizer(resizerElement) { |
Simon Zünd | 3141f41 | 2020-08-12 09:52:51 | [diff] [blame] | 827 | this._resizerWidget.removeElement(/** @type {!HTMLElement} */ (resizerElement)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | /** |
| 831 | * @return {boolean} |
| 832 | */ |
| 833 | hasCustomResizer() { |
| 834 | const elements = this._resizerWidget.elements(); |
| 835 | return elements.length > 1 || (elements.length === 1 && elements[0] !== this._resizerElement); |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * @param {!Element} resizer |
| 840 | * @param {boolean} on |
| 841 | */ |
| 842 | toggleResizer(resizer, on) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 843 | if (on) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 844 | this.installResizer(resizer); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 845 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 846 | this.uninstallResizer(resizer); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 847 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | /** |
Tim van der Lippe | aa76aa2 | 2020-02-14 14:38:24 | [diff] [blame] | 851 | * @return {?SettingForOrientation} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 852 | */ |
| 853 | _settingForOrientation() { |
| 854 | const state = this._setting ? this._setting.get() : {}; |
| 855 | return this._isVertical ? state.vertical : state.horizontal; |
| 856 | } |
| 857 | |
| 858 | /** |
| 859 | * @return {number} |
| 860 | */ |
| 861 | _preferredSidebarSizeDIP() { |
| 862 | let size = this._savedSidebarSizeDIP; |
| 863 | if (!size) { |
| 864 | size = this._isVertical ? this._defaultSidebarWidth : this._defaultSidebarHeight; |
| 865 | // If we have default value in percents, calculate it on first use. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 866 | if (0 < size && size < 1) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 867 | size *= this._totalSizeDIP(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 868 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 869 | } |
| 870 | return size; |
| 871 | } |
| 872 | |
| 873 | _restoreSidebarSizeFromSettings() { |
| 874 | const settingForOrientation = this._settingForOrientation(); |
| 875 | this._savedSidebarSizeDIP = settingForOrientation ? settingForOrientation.size : 0; |
| 876 | } |
| 877 | |
| 878 | _restoreAndApplyShowModeFromSettings() { |
| 879 | const orientationState = this._settingForOrientation(); |
| 880 | this._savedShowMode = orientationState && orientationState.showMode ? orientationState.showMode : this._showMode; |
| 881 | this._showMode = this._savedShowMode; |
| 882 | |
| 883 | switch (this._savedShowMode) { |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 884 | case ShowMode.Both: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 885 | this.showBoth(); |
| 886 | break; |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 887 | case ShowMode.OnlyMain: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 888 | this.hideSidebar(); |
| 889 | break; |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 890 | case ShowMode.OnlySidebar: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 891 | this.hideMain(); |
| 892 | break; |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | _saveShowModeToSettings() { |
| 897 | this._savedShowMode = this._showMode; |
| 898 | this._saveSetting(); |
| 899 | } |
| 900 | |
| 901 | _saveSetting() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 902 | if (!this._setting) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 903 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 904 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 905 | const state = this._setting.get(); |
| 906 | const orientationState = (this._isVertical ? state.vertical : state.horizontal) || {}; |
| 907 | |
| 908 | orientationState.size = this._savedSidebarSizeDIP; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 909 | if (this._shouldSaveShowMode) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 910 | orientationState.showMode = this._savedShowMode; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 911 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 912 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 913 | if (this._isVertical) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 914 | state.vertical = orientationState; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 915 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 916 | state.horizontal = orientationState; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 917 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 918 | this._setting.set(state); |
| 919 | } |
| 920 | |
| 921 | _forceUpdateLayout() { |
| 922 | // Force layout even if sidebar size does not change. |
| 923 | this._sidebarSizeDIP = -1; |
| 924 | this._updateLayout(); |
| 925 | } |
| 926 | |
| 927 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 928 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 929 | */ |
| 930 | _onZoomChanged(event) { |
| 931 | this._forceUpdateLayout(); |
| 932 | } |
| 933 | |
| 934 | /** |
| 935 | * @param {string} title |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 936 | * @return {!ToolbarButton} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 937 | */ |
| 938 | createShowHideSidebarButton(title) { |
Mandy Chen | 84d56b6 | 2019-09-03 18:21:18 | [diff] [blame] | 939 | this._showHideSidebarButtonTitle = title; |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 940 | this._showHideSidebarButton = new ToolbarButton('', ''); |
| 941 | this._showHideSidebarButton.addEventListener(ToolbarButton.Events.Click, buttonClicked, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 942 | this._updateShowHideSidebarButton(); |
| 943 | |
| 944 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 945 | * @param {!Common.EventTarget.EventTargetEvent} event |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 946 | * @this {SplitWidget} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 947 | */ |
| 948 | function buttonClicked(event) { |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 949 | if (this._showMode !== ShowMode.Both) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 950 | this.showBoth(true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 951 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 952 | this.hideSidebar(true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 953 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | return this._showHideSidebarButton; |
| 957 | } |
| 958 | |
| 959 | _updateShowHideSidebarButton() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 960 | if (!this._showHideSidebarButton) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 961 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 962 | } |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 963 | const sidebarHidden = this._showMode === ShowMode.OnlyMain; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 964 | let glyph = ''; |
| 965 | if (sidebarHidden) { |
| 966 | glyph = this.isVertical() ? |
| 967 | (this.isSidebarSecond() ? 'largeicon-show-right-sidebar' : 'largeicon-show-left-sidebar') : |
| 968 | (this.isSidebarSecond() ? 'largeicon-show-bottom-sidebar' : 'largeicon-show-top-sidebar'); |
| 969 | } else { |
| 970 | glyph = this.isVertical() ? |
| 971 | (this.isSidebarSecond() ? 'largeicon-hide-right-sidebar' : 'largeicon-hide-left-sidebar') : |
| 972 | (this.isSidebarSecond() ? 'largeicon-hide-bottom-sidebar' : 'largeicon-hide-top-sidebar'); |
| 973 | } |
| 974 | this._showHideSidebarButton.setGlyph(glyph); |
| 975 | this._showHideSidebarButton.setTitle( |
Paul Lewis | 17e384e | 2020-01-08 15:46:51 | [diff] [blame] | 976 | sidebarHidden ? Common.UIString.UIString('Show %s', this._showHideSidebarButtonTitle) : |
| 977 | Common.UIString.UIString('Hide %s', this._showHideSidebarButtonTitle)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 978 | } |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 979 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 980 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 981 | export const ShowMode = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 982 | Both: 'Both', |
| 983 | OnlyMain: 'OnlyMain', |
| 984 | OnlySidebar: 'OnlySidebar' |
| 985 | }; |
| 986 | |
| 987 | /** @enum {symbol} */ |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame] | 988 | export const Events = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 989 | SidebarSizeChanged: Symbol('SidebarSizeChanged'), |
| 990 | ShowModeChanged: Symbol('ShowModeChanged') |
| 991 | }; |
| 992 | |
Tim van der Lippe | c96ccd9 | 2019-11-29 16:23:54 | [diff] [blame] | 993 | const MinPadding = 20; |
Tim van der Lippe | aa76aa2 | 2020-02-14 14:38:24 | [diff] [blame] | 994 | |
| 995 | /** @typedef {{showMode: string, size: number}} */ |
| 996 | export let SettingForOrientation; |