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