blob: c5780fdbb91bfbad497ce1475a315754bb6584cf [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
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 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
Paul Lewis17e384e2020-01-08 15:46:5129import * as Common from '../common/common.js';
Paul Lewis9950e182019-12-16 16:06:0730import {Constraints} from './Geometry.js';
31import {Events as ResizerWidgetEvents, SimpleResizerWidget} from './ResizerWidget.js';
32import {ToolbarButton} from './Toolbar.js';
33import {Widget} from './Widget.js';
34import {Events as ZoomManagerEvents} from './ZoomManager.js';
35
Blink Reformat4c46d092018-04-07 15:32:3736/**
37 * @unrestricted
38 */
Paul Lewis9950e182019-12-16 16:06:0739export class SplitWidget extends Widget {
Blink Reformat4c46d092018-04-07 15:32:3740 /**
41 * @param {boolean} isVertical
42 * @param {boolean} secondIsSidebar
43 * @param {string=} settingName
44 * @param {number=} defaultSidebarWidth
45 * @param {number=} defaultSidebarHeight
46 * @param {boolean=} constraintsInDip
47 */
48 constructor(isVertical, secondIsSidebar, settingName, defaultSidebarWidth, defaultSidebarHeight, constraintsInDip) {
49 super(true);
50 this.element.classList.add('split-widget');
51 this.registerRequiredCSS('ui/splitWidget.css');
52
53 this.contentElement.classList.add('shadow-split-widget');
Joel Einbinder27131b22019-03-14 09:29:5454 this._sidebarElement =
55 this.contentElement.createChild('div', 'shadow-split-widget-contents shadow-split-widget-sidebar vbox');
Blink Reformat4c46d092018-04-07 15:32:3756 this._mainElement =
57 this.contentElement.createChild('div', 'shadow-split-widget-contents shadow-split-widget-main vbox');
Joel Einbinder7fbe24c2019-01-24 05:19:0158 this._mainElement.createChild('slot').name = 'insertion-point-main';
Joel Einbinder7fbe24c2019-01-24 05:19:0159 this._sidebarElement.createChild('slot').name = 'insertion-point-sidebar';
Blink Reformat4c46d092018-04-07 15:32:3760 this._resizerElement = this.contentElement.createChild('div', 'shadow-split-widget-resizer');
61 this._resizerElementSize = null;
62
Paul Lewis9950e182019-12-16 16:06:0763 this._resizerWidget = new SimpleResizerWidget();
Blink Reformat4c46d092018-04-07 15:32:3764 this._resizerWidget.setEnabled(true);
Paul Lewis9950e182019-12-16 16:06:0765 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeStart, this._onResizeStart, this);
66 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeUpdate, this._onResizeUpdate, this);
67 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeEnd, this._onResizeEnd, this);
Blink Reformat4c46d092018-04-07 15:32:3768
69 this._defaultSidebarWidth = defaultSidebarWidth || 200;
70 this._defaultSidebarHeight = defaultSidebarHeight || this._defaultSidebarWidth;
71 this._constraintsInDip = !!constraintsInDip;
72 this._resizeStartSizeDIP = 0;
Paul Lewis17e384e2020-01-08 15:46:5173 // Note: go via self.Common for globally-namespaced singletons.
74 this._setting = settingName ? self.Common.settings.createSetting(settingName, {}) : null;
Blink Reformat4c46d092018-04-07 15:32:3775
76 this._totalSizeCSS = 0;
77 this._totalSizeOtherDimensionCSS = 0;
Paul Lewis9950e182019-12-16 16:06:0778 /** @type {?Widget} */
Blink Reformat4c46d092018-04-07 15:32:3779 this._mainWidget = null;
Paul Lewis9950e182019-12-16 16:06:0780 /** @type {?Widget} */
Blink Reformat4c46d092018-04-07 15:32:3781 this._sidebarWidget = null;
82 this._animationFrameHandle = 0;
83 /** @type {?function()} */
84 this._animationCallback = null;
85 this._showHideSidebarButtonTitle = '';
Paul Lewis9950e182019-12-16 16:06:0786 /** @type {?ToolbarButton} */
Blink Reformat4c46d092018-04-07 15:32:3787 this._showHideSidebarButton = null;
88 this._isVertical = false;
89 this._sidebarMinimized = false;
90 this._detaching = false;
91 this._sidebarSizeDIP = -1;
92 this._savedSidebarSizeDIP = this._sidebarSizeDIP;
93 this._secondIsSidebar = false;
94 this._shouldSaveShowMode = false;
95 /** @type {?number} */
96 this._savedVerticalMainSize = null;
97 /** @type {?number} */
98 this._savedHorizontalMainSize = null;
99
100 this.setSecondIsSidebar(secondIsSidebar);
101
102 this._innerSetVertical(isVertical);
Tim van der Lippe0830b3d2019-10-03 13:20:07103 this._showMode = ShowMode.Both;
Blink Reformat4c46d092018-04-07 15:32:37104 this._savedShowMode = this._showMode;
105
106 // Should be called after isVertical has the right value.
107 this.installResizer(this._resizerElement);
108 }
109
110 /**
111 * @return {boolean}
112 */
113 isVertical() {
114 return this._isVertical;
115 }
116
117 /**
118 * @param {boolean} isVertical
119 */
120 setVertical(isVertical) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34121 if (this._isVertical === isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37122 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34123 }
Blink Reformat4c46d092018-04-07 15:32:37124
125 this._innerSetVertical(isVertical);
126
Tim van der Lippe1d6e57a2019-09-30 11:55:34127 if (this.isShowing()) {
Blink Reformat4c46d092018-04-07 15:32:37128 this._updateLayout();
Tim van der Lippe1d6e57a2019-09-30 11:55:34129 }
Blink Reformat4c46d092018-04-07 15:32:37130 }
131
132 /**
133 * @param {boolean} isVertical
134 */
135 _innerSetVertical(isVertical) {
136 this.contentElement.classList.toggle('vbox', !isVertical);
137 this.contentElement.classList.toggle('hbox', isVertical);
138 this._isVertical = isVertical;
139
140 this._resizerElementSize = null;
141 this._sidebarSizeDIP = -1;
142 this._restoreSidebarSizeFromSettings();
Tim van der Lippe1d6e57a2019-09-30 11:55:34143 if (this._shouldSaveShowMode) {
Blink Reformat4c46d092018-04-07 15:32:37144 this._restoreAndApplyShowModeFromSettings();
Tim van der Lippe1d6e57a2019-09-30 11:55:34145 }
Blink Reformat4c46d092018-04-07 15:32:37146 this._updateShowHideSidebarButton();
147 // FIXME: reverse SplitWidget.isVertical meaning.
148 this._resizerWidget.setVertical(!isVertical);
149 this.invalidateConstraints();
150 }
151
152 /**
153 * @param {boolean=} animate
154 */
155 _updateLayout(animate) {
156 this._totalSizeCSS = 0; // Lazy update.
157 this._totalSizeOtherDimensionCSS = 0;
158
159 // Remove properties that might affect total size calculation.
160 this._mainElement.style.removeProperty('width');
161 this._mainElement.style.removeProperty('height');
162 this._sidebarElement.style.removeProperty('width');
163 this._sidebarElement.style.removeProperty('height');
164
165 this._innerSetSidebarSizeDIP(this._preferredSidebarSizeDIP(), !!animate);
166 }
167
168 /**
Paul Lewis9950e182019-12-16 16:06:07169 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37170 */
171 setMainWidget(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34172 if (this._mainWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37173 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34174 }
Blink Reformat4c46d092018-04-07 15:32:37175 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34176 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37177 this._mainWidget.detach();
Tim van der Lippe1d6e57a2019-09-30 11:55:34178 }
Blink Reformat4c46d092018-04-07 15:32:37179 this._mainWidget = widget;
180 if (widget) {
Joel Einbinder7fbe24c2019-01-24 05:19:01181 widget.element.slot = 'insertion-point-main';
Tim van der Lippe0830b3d2019-10-03 13:20:07182 if (this._showMode === ShowMode.OnlyMain || this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37183 widget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34184 }
Blink Reformat4c46d092018-04-07 15:32:37185 }
186 this.resumeInvalidations();
187 }
188
189 /**
Paul Lewis9950e182019-12-16 16:06:07190 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37191 */
192 setSidebarWidget(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34193 if (this._sidebarWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37194 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34195 }
Blink Reformat4c46d092018-04-07 15:32:37196 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34197 if (this._sidebarWidget) {
Blink Reformat4c46d092018-04-07 15:32:37198 this._sidebarWidget.detach();
Tim van der Lippe1d6e57a2019-09-30 11:55:34199 }
Blink Reformat4c46d092018-04-07 15:32:37200 this._sidebarWidget = widget;
201 if (widget) {
Joel Einbinder7fbe24c2019-01-24 05:19:01202 widget.element.slot = 'insertion-point-sidebar';
Tim van der Lippe0830b3d2019-10-03 13:20:07203 if (this._showMode === ShowMode.OnlySidebar || this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37204 widget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34205 }
Blink Reformat4c46d092018-04-07 15:32:37206 }
207 this.resumeInvalidations();
208 }
209
210 /**
Paul Lewis9950e182019-12-16 16:06:07211 * @return {?Widget}
Blink Reformat4c46d092018-04-07 15:32:37212 */
213 mainWidget() {
214 return this._mainWidget;
215 }
216
217 /**
Paul Lewis9950e182019-12-16 16:06:07218 * @return {?Widget}
Blink Reformat4c46d092018-04-07 15:32:37219 */
220 sidebarWidget() {
221 return this._sidebarWidget;
222 }
223
224 /**
225 * @override
Paul Lewis9950e182019-12-16 16:06:07226 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37227 */
228 childWasDetached(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34229 if (this._detaching) {
Blink Reformat4c46d092018-04-07 15:32:37230 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34231 }
232 if (this._mainWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37233 this._mainWidget = null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34234 }
235 if (this._sidebarWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37236 this._sidebarWidget = null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34237 }
Blink Reformat4c46d092018-04-07 15:32:37238 this.invalidateConstraints();
239 }
240
241 /**
242 * @return {boolean}
243 */
244 isSidebarSecond() {
245 return this._secondIsSidebar;
246 }
247
248 enableShowModeSaving() {
249 this._shouldSaveShowMode = true;
250 this._restoreAndApplyShowModeFromSettings();
251 }
252
253 /**
254 * @return {string}
255 */
256 showMode() {
257 return this._showMode;
258 }
259
260 /**
261 * @param {boolean} secondIsSidebar
262 */
263 setSecondIsSidebar(secondIsSidebar) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34264 if (secondIsSidebar === this._secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54265 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34266 }
Blink Reformat4c46d092018-04-07 15:32:37267 this._secondIsSidebar = secondIsSidebar;
Joel Einbinder27131b22019-03-14 09:29:54268 if (!this._mainWidget || !this._mainWidget.shouldHideOnDetach()) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34269 if (secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54270 this.contentElement.insertBefore(this._mainElement, this._sidebarElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34271 } else {
Joel Einbinder27131b22019-03-14 09:29:54272 this.contentElement.insertBefore(this._mainElement, this._resizerElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34273 }
Joel Einbinder27131b22019-03-14 09:29:54274 } else if (!this._sidebarWidget || !this._sidebarWidget.shouldHideOnDetach()) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34275 if (secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54276 this.contentElement.insertBefore(this._sidebarElement, this._resizerElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34277 } else {
Joel Einbinder27131b22019-03-14 09:29:54278 this.contentElement.insertBefore(this._sidebarElement, this._mainElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34279 }
Joel Einbinder27131b22019-03-14 09:29:54280 } else {
281 console.error('Could not swap split widget side. Both children widgets contain iframes.');
282 this._secondIsSidebar = !secondIsSidebar;
283 }
Blink Reformat4c46d092018-04-07 15:32:37284 }
285
286 /**
287 * @return {?string}
288 */
289 sidebarSide() {
Tim van der Lippe0830b3d2019-10-03 13:20:07290 if (this._showMode !== ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37291 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34292 }
Blink Reformat4c46d092018-04-07 15:32:37293 return this._isVertical ? (this._secondIsSidebar ? 'right' : 'left') : (this._secondIsSidebar ? 'bottom' : 'top');
294 }
295
296 /**
297 * @return {!Element}
298 */
299 resizerElement() {
300 return this._resizerElement;
301 }
302
303 /**
304 * @param {boolean=} animate
305 */
306 hideMain(animate) {
307 this._showOnly(this._sidebarWidget, this._mainWidget, this._sidebarElement, this._mainElement, animate);
Tim van der Lippe0830b3d2019-10-03 13:20:07308 this._updateShowMode(ShowMode.OnlySidebar);
Blink Reformat4c46d092018-04-07 15:32:37309 }
310
311 /**
312 * @param {boolean=} animate
313 */
314 hideSidebar(animate) {
315 this._showOnly(this._mainWidget, this._sidebarWidget, this._mainElement, this._sidebarElement, animate);
Tim van der Lippe0830b3d2019-10-03 13:20:07316 this._updateShowMode(ShowMode.OnlyMain);
Blink Reformat4c46d092018-04-07 15:32:37317 }
318
319 /**
320 * @param {boolean} minimized
321 */
322 setSidebarMinimized(minimized) {
323 this._sidebarMinimized = minimized;
324 this.invalidateConstraints();
325 }
326
327 /**
328 * @return {boolean}
329 */
330 isSidebarMinimized() {
331 return this._sidebarMinimized;
332 }
333
334 /**
Paul Lewis9950e182019-12-16 16:06:07335 * @param {?Widget} sideToShow
Blink Reformat4c46d092018-04-07 15:32:37336 * @param {?UI.Widget} sideToHide
337 * @param {!Element} shadowToShow
338 * @param {!Element} shadowToHide
339 * @param {boolean=} animate
340 */
341 _showOnly(sideToShow, sideToHide, shadowToShow, shadowToHide, animate) {
342 this._cancelAnimation();
343
344 /**
Tim van der Lippe0830b3d2019-10-03 13:20:07345 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37346 */
347 function callback() {
348 if (sideToShow) {
349 // Make sure main is first in the children list.
Tim van der Lippe1d6e57a2019-09-30 11:55:34350 if (sideToShow === this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37351 this._mainWidget.show(this.element, this._sidebarWidget ? this._sidebarWidget.element : null);
Tim van der Lippe1d6e57a2019-09-30 11:55:34352 } else {
Blink Reformat4c46d092018-04-07 15:32:37353 this._sidebarWidget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34354 }
Blink Reformat4c46d092018-04-07 15:32:37355 }
356 if (sideToHide) {
357 this._detaching = true;
358 sideToHide.detach();
359 this._detaching = false;
360 }
361
362 this._resizerElement.classList.add('hidden');
363 shadowToShow.classList.remove('hidden');
364 shadowToShow.classList.add('maximized');
365 shadowToHide.classList.add('hidden');
366 shadowToHide.classList.remove('maximized');
367 this._removeAllLayoutProperties();
368 this.doResize();
369 this._showFinishedForTest();
370 }
371
Tim van der Lippe1d6e57a2019-09-30 11:55:34372 if (animate) {
Blink Reformat4c46d092018-04-07 15:32:37373 this._animate(true, callback.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34374 } else {
Blink Reformat4c46d092018-04-07 15:32:37375 callback.call(this);
Tim van der Lippe1d6e57a2019-09-30 11:55:34376 }
Blink Reformat4c46d092018-04-07 15:32:37377
378 this._sidebarSizeDIP = -1;
379 this.setResizable(false);
380 }
381
382 _showFinishedForTest() {
383 // This method is sniffed in tests.
384 }
385
386 _removeAllLayoutProperties() {
387 this._sidebarElement.style.removeProperty('flexBasis');
388
389 this._mainElement.style.removeProperty('width');
390 this._mainElement.style.removeProperty('height');
391 this._sidebarElement.style.removeProperty('width');
392 this._sidebarElement.style.removeProperty('height');
393
394 this._resizerElement.style.removeProperty('left');
395 this._resizerElement.style.removeProperty('right');
396 this._resizerElement.style.removeProperty('top');
397 this._resizerElement.style.removeProperty('bottom');
398
399 this._resizerElement.style.removeProperty('margin-left');
400 this._resizerElement.style.removeProperty('margin-right');
401 this._resizerElement.style.removeProperty('margin-top');
402 this._resizerElement.style.removeProperty('margin-bottom');
403 }
404
405 /**
406 * @param {boolean=} animate
407 */
408 showBoth(animate) {
Tim van der Lippe0830b3d2019-10-03 13:20:07409 if (this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37410 animate = false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34411 }
Blink Reformat4c46d092018-04-07 15:32:37412
413 this._cancelAnimation();
414 this._mainElement.classList.remove('maximized', 'hidden');
415 this._sidebarElement.classList.remove('maximized', 'hidden');
416 this._resizerElement.classList.remove('hidden');
417 this.setResizable(true);
418
419 // Make sure main is the first in the children list.
420 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34421 if (this._sidebarWidget) {
Blink Reformat4c46d092018-04-07 15:32:37422 this._sidebarWidget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34423 }
424 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37425 this._mainWidget.show(this.element, this._sidebarWidget ? this._sidebarWidget.element : null);
Tim van der Lippe1d6e57a2019-09-30 11:55:34426 }
Blink Reformat4c46d092018-04-07 15:32:37427 this.resumeInvalidations();
428 // Order widgets in DOM properly.
429 this.setSecondIsSidebar(this._secondIsSidebar);
430
431 this._sidebarSizeDIP = -1;
Tim van der Lippe0830b3d2019-10-03 13:20:07432 this._updateShowMode(ShowMode.Both);
Blink Reformat4c46d092018-04-07 15:32:37433 this._updateLayout(animate);
434 }
435
436 /**
437 * @param {boolean} resizable
438 */
439 setResizable(resizable) {
440 this._resizerWidget.setEnabled(resizable);
441 }
442
443 /**
444 * @return {boolean}
445 */
446 isResizable() {
447 return this._resizerWidget.isEnabled();
448 }
449
450 /**
451 * @param {number} size
452 */
453 setSidebarSize(size) {
454 const sizeDIP = UI.zoomManager.cssToDIP(size);
455 this._savedSidebarSizeDIP = sizeDIP;
456 this._saveSetting();
457 this._innerSetSidebarSizeDIP(sizeDIP, false, true);
458 }
459
460 /**
461 * @return {number}
462 */
463 sidebarSize() {
464 const sizeDIP = Math.max(0, this._sidebarSizeDIP);
465 return UI.zoomManager.dipToCSS(sizeDIP);
466 }
467
468 /**
469 * Returns total size in DIP.
470 * @return {number}
471 */
472 _totalSizeDIP() {
473 if (!this._totalSizeCSS) {
474 this._totalSizeCSS = this._isVertical ? this.contentElement.offsetWidth : this.contentElement.offsetHeight;
475 this._totalSizeOtherDimensionCSS =
476 this._isVertical ? this.contentElement.offsetHeight : this.contentElement.offsetWidth;
477 }
478 return UI.zoomManager.cssToDIP(this._totalSizeCSS);
479 }
480
481 /**
482 * @param {string} showMode
483 */
484 _updateShowMode(showMode) {
485 this._showMode = showMode;
486 this._saveShowModeToSettings();
487 this._updateShowHideSidebarButton();
Tim van der Lippe0830b3d2019-10-03 13:20:07488 this.dispatchEventToListeners(SplitWidget.Events.ShowModeChanged, showMode);
Blink Reformat4c46d092018-04-07 15:32:37489 this.invalidateConstraints();
490 }
491
492 /**
493 * @param {number} sizeDIP
494 * @param {boolean} animate
495 * @param {boolean=} userAction
496 */
497 _innerSetSidebarSizeDIP(sizeDIP, animate, userAction) {
Tim van der Lippe0830b3d2019-10-03 13:20:07498 if (this._showMode !== ShowMode.Both || !this.isShowing()) {
Blink Reformat4c46d092018-04-07 15:32:37499 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34500 }
Blink Reformat4c46d092018-04-07 15:32:37501
502 sizeDIP = this._applyConstraints(sizeDIP, userAction);
Tim van der Lippe1d6e57a2019-09-30 11:55:34503 if (this._sidebarSizeDIP === sizeDIP) {
Blink Reformat4c46d092018-04-07 15:32:37504 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34505 }
Blink Reformat4c46d092018-04-07 15:32:37506
507 if (!this._resizerElementSize) {
508 this._resizerElementSize =
509 this._isVertical ? this._resizerElement.offsetWidth : this._resizerElement.offsetHeight;
510 }
511
512 // Invalidate layout below.
513
514 this._removeAllLayoutProperties();
515
516 // this._totalSizeDIP is available below since we successfully applied constraints.
517 const roundSizeCSS = Math.round(UI.zoomManager.dipToCSS(sizeDIP));
518 const sidebarSizeValue = roundSizeCSS + 'px';
519 const mainSizeValue = (this._totalSizeCSS - roundSizeCSS) + 'px';
520 this._sidebarElement.style.flexBasis = sidebarSizeValue;
521
522 // Make both sides relayout boundaries.
523 if (this._isVertical) {
524 this._sidebarElement.style.width = sidebarSizeValue;
525 this._mainElement.style.width = mainSizeValue;
526 this._sidebarElement.style.height = this._totalSizeOtherDimensionCSS + 'px';
527 this._mainElement.style.height = this._totalSizeOtherDimensionCSS + 'px';
528 } else {
529 this._sidebarElement.style.height = sidebarSizeValue;
530 this._mainElement.style.height = mainSizeValue;
531 this._sidebarElement.style.width = this._totalSizeOtherDimensionCSS + 'px';
532 this._mainElement.style.width = this._totalSizeOtherDimensionCSS + 'px';
533 }
534
535 // Position resizer.
536 if (this._isVertical) {
537 if (this._secondIsSidebar) {
538 this._resizerElement.style.right = sidebarSizeValue;
539 this._resizerElement.style.marginRight = -this._resizerElementSize / 2 + 'px';
540 } else {
541 this._resizerElement.style.left = sidebarSizeValue;
542 this._resizerElement.style.marginLeft = -this._resizerElementSize / 2 + 'px';
543 }
544 } else {
545 if (this._secondIsSidebar) {
546 this._resizerElement.style.bottom = sidebarSizeValue;
547 this._resizerElement.style.marginBottom = -this._resizerElementSize / 2 + 'px';
548 } else {
549 this._resizerElement.style.top = sidebarSizeValue;
550 this._resizerElement.style.marginTop = -this._resizerElementSize / 2 + 'px';
551 }
552 }
553
554 this._sidebarSizeDIP = sizeDIP;
555
556 // Force layout.
557
558 if (animate) {
559 this._animate(false);
560 } else {
561 // No need to recalculate this._sidebarSizeDIP and this._totalSizeDIP again.
562 this.doResize();
Tim van der Lippe0830b3d2019-10-03 13:20:07563 this.dispatchEventToListeners(SplitWidget.Events.SidebarSizeChanged, this.sidebarSize());
Blink Reformat4c46d092018-04-07 15:32:37564 }
565 }
566
567 /**
568 * @param {boolean} reverse
569 * @param {function()=} callback
570 */
571 _animate(reverse, callback) {
572 const animationTime = 50;
573 this._animationCallback = callback || null;
574
575 let animatedMarginPropertyName;
Tim van der Lippe1d6e57a2019-09-30 11:55:34576 if (this._isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37577 animatedMarginPropertyName = this._secondIsSidebar ? 'margin-right' : 'margin-left';
Tim van der Lippe1d6e57a2019-09-30 11:55:34578 } else {
Blink Reformat4c46d092018-04-07 15:32:37579 animatedMarginPropertyName = this._secondIsSidebar ? 'margin-bottom' : 'margin-top';
Tim van der Lippe1d6e57a2019-09-30 11:55:34580 }
Blink Reformat4c46d092018-04-07 15:32:37581
582 const marginFrom = reverse ? '0' : '-' + UI.zoomManager.dipToCSS(this._sidebarSizeDIP) + 'px';
583 const marginTo = reverse ? '-' + UI.zoomManager.dipToCSS(this._sidebarSizeDIP) + 'px' : '0';
584
585 // This order of things is important.
586 // 1. Resize main element early and force layout.
587 this.contentElement.style.setProperty(animatedMarginPropertyName, marginFrom);
588 if (!reverse) {
589 suppressUnused(this._mainElement.offsetWidth);
590 suppressUnused(this._sidebarElement.offsetWidth);
591 }
592
593 // 2. Issue onresize to the sidebar element, its size won't change.
Tim van der Lippe1d6e57a2019-09-30 11:55:34594 if (!reverse) {
Blink Reformat4c46d092018-04-07 15:32:37595 this._sidebarWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34596 }
Blink Reformat4c46d092018-04-07 15:32:37597
598 // 3. Configure and run animation
599 this.contentElement.style.setProperty('transition', animatedMarginPropertyName + ' ' + animationTime + 'ms linear');
600
601 const boundAnimationFrame = animationFrame.bind(this);
602 let startTime;
603 /**
Tim van der Lippe0830b3d2019-10-03 13:20:07604 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37605 */
606 function animationFrame() {
607 this._animationFrameHandle = 0;
608
609 if (!startTime) {
610 // Kick animation on first frame.
611 this.contentElement.style.setProperty(animatedMarginPropertyName, marginTo);
612 startTime = window.performance.now();
613 } else if (window.performance.now() < startTime + animationTime) {
614 // Process regular animation frame.
Tim van der Lippe1d6e57a2019-09-30 11:55:34615 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37616 this._mainWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34617 }
Blink Reformat4c46d092018-04-07 15:32:37618 } else {
619 // Complete animation.
620 this._cancelAnimation();
Tim van der Lippe1d6e57a2019-09-30 11:55:34621 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37622 this._mainWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34623 }
Tim van der Lippe0830b3d2019-10-03 13:20:07624 this.dispatchEventToListeners(SplitWidget.Events.SidebarSizeChanged, this.sidebarSize());
Blink Reformat4c46d092018-04-07 15:32:37625 return;
626 }
627 this._animationFrameHandle = this.contentElement.window().requestAnimationFrame(boundAnimationFrame);
628 }
629 this._animationFrameHandle = this.contentElement.window().requestAnimationFrame(boundAnimationFrame);
630 }
631
632 _cancelAnimation() {
633 this.contentElement.style.removeProperty('margin-top');
634 this.contentElement.style.removeProperty('margin-right');
635 this.contentElement.style.removeProperty('margin-bottom');
636 this.contentElement.style.removeProperty('margin-left');
637 this.contentElement.style.removeProperty('transition');
638
639 if (this._animationFrameHandle) {
640 this.contentElement.window().cancelAnimationFrame(this._animationFrameHandle);
641 this._animationFrameHandle = 0;
642 }
643 if (this._animationCallback) {
644 this._animationCallback();
645 this._animationCallback = null;
646 }
647 }
648
649 /**
650 * @param {number} sidebarSize
651 * @param {boolean=} userAction
652 * @return {number}
653 */
654 _applyConstraints(sidebarSize, userAction) {
655 const totalSize = this._totalSizeDIP();
656 const zoomFactor = this._constraintsInDip ? 1 : UI.zoomManager.zoomFactor();
657
Paul Lewis9950e182019-12-16 16:06:07658 let constraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Blink Reformat4c46d092018-04-07 15:32:37659 let minSidebarSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34660 if (!minSidebarSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07661 minSidebarSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34662 }
Blink Reformat4c46d092018-04-07 15:32:37663 minSidebarSize *= zoomFactor;
Tim van der Lippe1d6e57a2019-09-30 11:55:34664 if (this._sidebarMinimized) {
Blink Reformat4c46d092018-04-07 15:32:37665 sidebarSize = minSidebarSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34666 }
Blink Reformat4c46d092018-04-07 15:32:37667
668 let preferredSidebarSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34669 if (!preferredSidebarSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07670 preferredSidebarSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34671 }
Blink Reformat4c46d092018-04-07 15:32:37672 preferredSidebarSize *= zoomFactor;
673 // Allow sidebar to be less than preferred by explicit user action.
Tim van der Lippe1d6e57a2019-09-30 11:55:34674 if (sidebarSize < preferredSidebarSize) {
Blink Reformat4c46d092018-04-07 15:32:37675 preferredSidebarSize = Math.max(sidebarSize, minSidebarSize);
Tim van der Lippe1d6e57a2019-09-30 11:55:34676 }
Blink Reformat4c46d092018-04-07 15:32:37677 preferredSidebarSize += zoomFactor; // 1 css pixel for splitter border.
678
Paul Lewis9950e182019-12-16 16:06:07679 constraints = this._mainWidget ? this._mainWidget.constraints() : new Constraints();
Blink Reformat4c46d092018-04-07 15:32:37680 let minMainSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34681 if (!minMainSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07682 minMainSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34683 }
Blink Reformat4c46d092018-04-07 15:32:37684 minMainSize *= zoomFactor;
685
686 let preferredMainSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34687 if (!preferredMainSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07688 preferredMainSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34689 }
Blink Reformat4c46d092018-04-07 15:32:37690 preferredMainSize *= zoomFactor;
691 const savedMainSize = this.isVertical() ? this._savedVerticalMainSize : this._savedHorizontalMainSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34692 if (savedMainSize !== null) {
Blink Reformat4c46d092018-04-07 15:32:37693 preferredMainSize = Math.min(preferredMainSize, savedMainSize * zoomFactor);
Tim van der Lippe1d6e57a2019-09-30 11:55:34694 }
695 if (userAction) {
Blink Reformat4c46d092018-04-07 15:32:37696 preferredMainSize = minMainSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34697 }
Blink Reformat4c46d092018-04-07 15:32:37698
699 // Enough space for preferred.
700 const totalPreferred = preferredMainSize + preferredSidebarSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34701 if (totalPreferred <= totalSize) {
Blink Reformat4c46d092018-04-07 15:32:37702 return Number.constrain(sidebarSize, preferredSidebarSize, totalSize - preferredMainSize);
Tim van der Lippe1d6e57a2019-09-30 11:55:34703 }
Blink Reformat4c46d092018-04-07 15:32:37704
705 // Enough space for minimum.
706 if (minMainSize + minSidebarSize <= totalSize) {
707 const delta = totalPreferred - totalSize;
708 const sidebarDelta = delta * preferredSidebarSize / totalPreferred;
709 sidebarSize = preferredSidebarSize - sidebarDelta;
710 return Number.constrain(sidebarSize, minSidebarSize, totalSize - minMainSize);
711 }
712
713 // Not enough space even for minimum sizes.
714 return Math.max(0, totalSize - minMainSize);
715 }
716
717 /**
718 * @override
719 */
720 wasShown() {
721 this._forceUpdateLayout();
Paul Lewis9950e182019-12-16 16:06:07722 UI.zoomManager.addEventListener(ZoomManagerEvents.ZoomChanged, this._onZoomChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37723 }
724
725 /**
726 * @override
727 */
728 willHide() {
Paul Lewis9950e182019-12-16 16:06:07729 UI.zoomManager.removeEventListener(ZoomManagerEvents.ZoomChanged, this._onZoomChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37730 }
731
732 /**
733 * @override
734 */
735 onResize() {
736 this._updateLayout();
737 }
738
739 /**
740 * @override
741 */
742 onLayout() {
743 this._updateLayout();
744 }
745
746 /**
747 * @override
Paul Lewis9950e182019-12-16 16:06:07748 * @return {!Constraints}
Blink Reformat4c46d092018-04-07 15:32:37749 */
750 calculateConstraints() {
Tim van der Lippe0830b3d2019-10-03 13:20:07751 if (this._showMode === ShowMode.OnlyMain) {
Paul Lewis9950e182019-12-16 16:06:07752 return this._mainWidget ? this._mainWidget.constraints() : new Constraints();
Tim van der Lippe1d6e57a2019-09-30 11:55:34753 }
Tim van der Lippe0830b3d2019-10-03 13:20:07754 if (this._showMode === ShowMode.OnlySidebar) {
Paul Lewis9950e182019-12-16 16:06:07755 return this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Tim van der Lippe1d6e57a2019-09-30 11:55:34756 }
Blink Reformat4c46d092018-04-07 15:32:37757
Paul Lewis9950e182019-12-16 16:06:07758 let mainConstraints = this._mainWidget ? this._mainWidget.constraints() : new Constraints();
759 let sidebarConstraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Tim van der Lippe0830b3d2019-10-03 13:20:07760 const min = MinPadding;
Blink Reformat4c46d092018-04-07 15:32:37761 if (this._isVertical) {
762 mainConstraints = mainConstraints.widthToMax(min).addWidth(1); // 1 for splitter
763 sidebarConstraints = sidebarConstraints.widthToMax(min);
764 return mainConstraints.addWidth(sidebarConstraints).heightToMax(sidebarConstraints);
765 } else {
766 mainConstraints = mainConstraints.heightToMax(min).addHeight(1); // 1 for splitter
767 sidebarConstraints = sidebarConstraints.heightToMax(min);
768 return mainConstraints.widthToMax(sidebarConstraints).addHeight(sidebarConstraints);
769 }
770 }
771
772 /**
773 * @param {!Common.Event} event
774 */
775 _onResizeStart(event) {
776 this._resizeStartSizeDIP = this._sidebarSizeDIP;
777 }
778
779 /**
780 * @param {!Common.Event} event
781 */
782 _onResizeUpdate(event) {
783 const offset = event.data.currentPosition - event.data.startPosition;
784 const offsetDIP = UI.zoomManager.cssToDIP(offset);
785 const newSizeDIP =
786 this._secondIsSidebar ? this._resizeStartSizeDIP - offsetDIP : this._resizeStartSizeDIP + offsetDIP;
787 const constrainedSizeDIP = this._applyConstraints(newSizeDIP, true);
788 this._savedSidebarSizeDIP = constrainedSizeDIP;
789 this._saveSetting();
790 this._innerSetSidebarSizeDIP(constrainedSizeDIP, false, true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34791 if (this.isVertical()) {
Blink Reformat4c46d092018-04-07 15:32:37792 this._savedVerticalMainSize = this._totalSizeDIP() - this._sidebarSizeDIP;
Tim van der Lippe1d6e57a2019-09-30 11:55:34793 } else {
Blink Reformat4c46d092018-04-07 15:32:37794 this._savedHorizontalMainSize = this._totalSizeDIP() - this._sidebarSizeDIP;
Tim van der Lippe1d6e57a2019-09-30 11:55:34795 }
Blink Reformat4c46d092018-04-07 15:32:37796 }
797
798 /**
799 * @param {!Common.Event} event
800 */
801 _onResizeEnd(event) {
802 this._resizeStartSizeDIP = 0;
803 }
804
805 /**
806 * @param {boolean=} noSplitter
807 */
808 hideDefaultResizer(noSplitter) {
809 this.uninstallResizer(this._resizerElement);
Pavel Feldmanc9060ea2018-04-30 04:42:18810 this._sidebarElement.classList.toggle('no-default-splitter', !!noSplitter);
Blink Reformat4c46d092018-04-07 15:32:37811 }
812
813 /**
814 * @param {!Element} resizerElement
815 */
816 installResizer(resizerElement) {
817 this._resizerWidget.addElement(resizerElement);
818 }
819
820 /**
821 * @param {!Element} resizerElement
822 */
823 uninstallResizer(resizerElement) {
824 this._resizerWidget.removeElement(resizerElement);
825 }
826
827 /**
828 * @return {boolean}
829 */
830 hasCustomResizer() {
831 const elements = this._resizerWidget.elements();
832 return elements.length > 1 || (elements.length === 1 && elements[0] !== this._resizerElement);
833 }
834
835 /**
836 * @param {!Element} resizer
837 * @param {boolean} on
838 */
839 toggleResizer(resizer, on) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34840 if (on) {
Blink Reformat4c46d092018-04-07 15:32:37841 this.installResizer(resizer);
Tim van der Lippe1d6e57a2019-09-30 11:55:34842 } else {
Blink Reformat4c46d092018-04-07 15:32:37843 this.uninstallResizer(resizer);
Tim van der Lippe1d6e57a2019-09-30 11:55:34844 }
Blink Reformat4c46d092018-04-07 15:32:37845 }
846
847 /**
Tim van der Lippe0830b3d2019-10-03 13:20:07848 * @return {?SplitWidget.SettingForOrientation}
Blink Reformat4c46d092018-04-07 15:32:37849 */
850 _settingForOrientation() {
851 const state = this._setting ? this._setting.get() : {};
852 return this._isVertical ? state.vertical : state.horizontal;
853 }
854
855 /**
856 * @return {number}
857 */
858 _preferredSidebarSizeDIP() {
859 let size = this._savedSidebarSizeDIP;
860 if (!size) {
861 size = this._isVertical ? this._defaultSidebarWidth : this._defaultSidebarHeight;
862 // If we have default value in percents, calculate it on first use.
Tim van der Lippe1d6e57a2019-09-30 11:55:34863 if (0 < size && size < 1) {
Blink Reformat4c46d092018-04-07 15:32:37864 size *= this._totalSizeDIP();
Tim van der Lippe1d6e57a2019-09-30 11:55:34865 }
Blink Reformat4c46d092018-04-07 15:32:37866 }
867 return size;
868 }
869
870 _restoreSidebarSizeFromSettings() {
871 const settingForOrientation = this._settingForOrientation();
872 this._savedSidebarSizeDIP = settingForOrientation ? settingForOrientation.size : 0;
873 }
874
875 _restoreAndApplyShowModeFromSettings() {
876 const orientationState = this._settingForOrientation();
877 this._savedShowMode = orientationState && orientationState.showMode ? orientationState.showMode : this._showMode;
878 this._showMode = this._savedShowMode;
879
880 switch (this._savedShowMode) {
Tim van der Lippe0830b3d2019-10-03 13:20:07881 case ShowMode.Both:
Blink Reformat4c46d092018-04-07 15:32:37882 this.showBoth();
883 break;
Tim van der Lippe0830b3d2019-10-03 13:20:07884 case ShowMode.OnlyMain:
Blink Reformat4c46d092018-04-07 15:32:37885 this.hideSidebar();
886 break;
Tim van der Lippe0830b3d2019-10-03 13:20:07887 case ShowMode.OnlySidebar:
Blink Reformat4c46d092018-04-07 15:32:37888 this.hideMain();
889 break;
890 }
891 }
892
893 _saveShowModeToSettings() {
894 this._savedShowMode = this._showMode;
895 this._saveSetting();
896 }
897
898 _saveSetting() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34899 if (!this._setting) {
Blink Reformat4c46d092018-04-07 15:32:37900 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34901 }
Blink Reformat4c46d092018-04-07 15:32:37902 const state = this._setting.get();
903 const orientationState = (this._isVertical ? state.vertical : state.horizontal) || {};
904
905 orientationState.size = this._savedSidebarSizeDIP;
Tim van der Lippe1d6e57a2019-09-30 11:55:34906 if (this._shouldSaveShowMode) {
Blink Reformat4c46d092018-04-07 15:32:37907 orientationState.showMode = this._savedShowMode;
Tim van der Lippe1d6e57a2019-09-30 11:55:34908 }
Blink Reformat4c46d092018-04-07 15:32:37909
Tim van der Lippe1d6e57a2019-09-30 11:55:34910 if (this._isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37911 state.vertical = orientationState;
Tim van der Lippe1d6e57a2019-09-30 11:55:34912 } else {
Blink Reformat4c46d092018-04-07 15:32:37913 state.horizontal = orientationState;
Tim van der Lippe1d6e57a2019-09-30 11:55:34914 }
Blink Reformat4c46d092018-04-07 15:32:37915 this._setting.set(state);
916 }
917
918 _forceUpdateLayout() {
919 // Force layout even if sidebar size does not change.
920 this._sidebarSizeDIP = -1;
921 this._updateLayout();
922 }
923
924 /**
925 * @param {!Common.Event} event
926 */
927 _onZoomChanged(event) {
928 this._forceUpdateLayout();
929 }
930
931 /**
932 * @param {string} title
Paul Lewis9950e182019-12-16 16:06:07933 * @return {!ToolbarButton}
Blink Reformat4c46d092018-04-07 15:32:37934 */
935 createShowHideSidebarButton(title) {
Mandy Chen84d56b62019-09-03 18:21:18936 this._showHideSidebarButtonTitle = title;
Paul Lewis9950e182019-12-16 16:06:07937 this._showHideSidebarButton = new ToolbarButton('', '');
938 this._showHideSidebarButton.addEventListener(ToolbarButton.Events.Click, buttonClicked, this);
Blink Reformat4c46d092018-04-07 15:32:37939 this._updateShowHideSidebarButton();
940
941 /**
942 * @param {!Common.Event} event
Tim van der Lippe0830b3d2019-10-03 13:20:07943 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37944 */
945 function buttonClicked(event) {
Tim van der Lippe0830b3d2019-10-03 13:20:07946 if (this._showMode !== ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37947 this.showBoth(true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34948 } else {
Blink Reformat4c46d092018-04-07 15:32:37949 this.hideSidebar(true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34950 }
Blink Reformat4c46d092018-04-07 15:32:37951 }
952
953 return this._showHideSidebarButton;
954 }
955
956 _updateShowHideSidebarButton() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34957 if (!this._showHideSidebarButton) {
Blink Reformat4c46d092018-04-07 15:32:37958 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34959 }
Tim van der Lippe0830b3d2019-10-03 13:20:07960 const sidebarHidden = this._showMode === ShowMode.OnlyMain;
Blink Reformat4c46d092018-04-07 15:32:37961 let glyph = '';
962 if (sidebarHidden) {
963 glyph = this.isVertical() ?
964 (this.isSidebarSecond() ? 'largeicon-show-right-sidebar' : 'largeicon-show-left-sidebar') :
965 (this.isSidebarSecond() ? 'largeicon-show-bottom-sidebar' : 'largeicon-show-top-sidebar');
966 } else {
967 glyph = this.isVertical() ?
968 (this.isSidebarSecond() ? 'largeicon-hide-right-sidebar' : 'largeicon-hide-left-sidebar') :
969 (this.isSidebarSecond() ? 'largeicon-hide-bottom-sidebar' : 'largeicon-hide-top-sidebar');
970 }
971 this._showHideSidebarButton.setGlyph(glyph);
972 this._showHideSidebarButton.setTitle(
Paul Lewis17e384e2020-01-08 15:46:51973 sidebarHidden ? Common.UIString.UIString('Show %s', this._showHideSidebarButtonTitle) :
974 Common.UIString.UIString('Hide %s', this._showHideSidebarButtonTitle));
Blink Reformat4c46d092018-04-07 15:32:37975 }
Tim van der Lippe0830b3d2019-10-03 13:20:07976}
Blink Reformat4c46d092018-04-07 15:32:37977
Tim van der Lippe0830b3d2019-10-03 13:20:07978export const ShowMode = {
Blink Reformat4c46d092018-04-07 15:32:37979 Both: 'Both',
980 OnlyMain: 'OnlyMain',
981 OnlySidebar: 'OnlySidebar'
982};
983
984/** @enum {symbol} */
Tim van der Lippe0830b3d2019-10-03 13:20:07985export const Events = {
Blink Reformat4c46d092018-04-07 15:32:37986 SidebarSizeChanged: Symbol('SidebarSizeChanged'),
987 ShowModeChanged: Symbol('ShowModeChanged')
988};
989
Tim van der Lippec96ccd92019-11-29 16:23:54990const MinPadding = 20;