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