blob: 24a7bdcaba5c6e6765ab91f7c80ceab228152277 [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 Lewis9950e182019-12-16 16:06:0729import {Constraints} from './Geometry.js';
30import {Events as ResizerWidgetEvents, SimpleResizerWidget} from './ResizerWidget.js';
31import {ToolbarButton} from './Toolbar.js';
32import {Widget} from './Widget.js';
33import {Events as ZoomManagerEvents} from './ZoomManager.js';
34
Blink Reformat4c46d092018-04-07 15:32:3735/**
36 * @unrestricted
37 */
Paul Lewis9950e182019-12-16 16:06:0738export class SplitWidget extends Widget {
Blink Reformat4c46d092018-04-07 15:32:3739 /**
40 * @param {boolean} isVertical
41 * @param {boolean} secondIsSidebar
42 * @param {string=} settingName
43 * @param {number=} defaultSidebarWidth
44 * @param {number=} defaultSidebarHeight
45 * @param {boolean=} constraintsInDip
46 */
47 constructor(isVertical, secondIsSidebar, settingName, defaultSidebarWidth, defaultSidebarHeight, constraintsInDip) {
48 super(true);
49 this.element.classList.add('split-widget');
50 this.registerRequiredCSS('ui/splitWidget.css');
51
52 this.contentElement.classList.add('shadow-split-widget');
Joel Einbinder27131b22019-03-14 09:29:5453 this._sidebarElement =
54 this.contentElement.createChild('div', 'shadow-split-widget-contents shadow-split-widget-sidebar vbox');
Blink Reformat4c46d092018-04-07 15:32:3755 this._mainElement =
56 this.contentElement.createChild('div', 'shadow-split-widget-contents shadow-split-widget-main vbox');
Joel Einbinder7fbe24c2019-01-24 05:19:0157 this._mainElement.createChild('slot').name = 'insertion-point-main';
Joel Einbinder7fbe24c2019-01-24 05:19:0158 this._sidebarElement.createChild('slot').name = 'insertion-point-sidebar';
Blink Reformat4c46d092018-04-07 15:32:3759 this._resizerElement = this.contentElement.createChild('div', 'shadow-split-widget-resizer');
60 this._resizerElementSize = null;
61
Paul Lewis9950e182019-12-16 16:06:0762 this._resizerWidget = new SimpleResizerWidget();
Blink Reformat4c46d092018-04-07 15:32:3763 this._resizerWidget.setEnabled(true);
Paul Lewis9950e182019-12-16 16:06:0764 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeStart, this._onResizeStart, this);
65 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeUpdate, this._onResizeUpdate, this);
66 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeEnd, this._onResizeEnd, this);
Blink Reformat4c46d092018-04-07 15:32:3767
68 this._defaultSidebarWidth = defaultSidebarWidth || 200;
69 this._defaultSidebarHeight = defaultSidebarHeight || this._defaultSidebarWidth;
70 this._constraintsInDip = !!constraintsInDip;
71 this._resizeStartSizeDIP = 0;
72 this._setting = settingName ? Common.settings.createSetting(settingName, {}) : null;
73
74 this._totalSizeCSS = 0;
75 this._totalSizeOtherDimensionCSS = 0;
Paul Lewis9950e182019-12-16 16:06:0776 /** @type {?Widget} */
Blink Reformat4c46d092018-04-07 15:32:3777 this._mainWidget = null;
Paul Lewis9950e182019-12-16 16:06:0778 /** @type {?Widget} */
Blink Reformat4c46d092018-04-07 15:32:3779 this._sidebarWidget = null;
80 this._animationFrameHandle = 0;
81 /** @type {?function()} */
82 this._animationCallback = null;
83 this._showHideSidebarButtonTitle = '';
Paul Lewis9950e182019-12-16 16:06:0784 /** @type {?ToolbarButton} */
Blink Reformat4c46d092018-04-07 15:32:3785 this._showHideSidebarButton = null;
86 this._isVertical = false;
87 this._sidebarMinimized = false;
88 this._detaching = false;
89 this._sidebarSizeDIP = -1;
90 this._savedSidebarSizeDIP = this._sidebarSizeDIP;
91 this._secondIsSidebar = false;
92 this._shouldSaveShowMode = false;
93 /** @type {?number} */
94 this._savedVerticalMainSize = null;
95 /** @type {?number} */
96 this._savedHorizontalMainSize = null;
97
98 this.setSecondIsSidebar(secondIsSidebar);
99
100 this._innerSetVertical(isVertical);
Tim van der Lippe0830b3d2019-10-03 13:20:07101 this._showMode = ShowMode.Both;
Blink Reformat4c46d092018-04-07 15:32:37102 this._savedShowMode = this._showMode;
103
104 // Should be called after isVertical has the right value.
105 this.installResizer(this._resizerElement);
106 }
107
108 /**
109 * @return {boolean}
110 */
111 isVertical() {
112 return this._isVertical;
113 }
114
115 /**
116 * @param {boolean} isVertical
117 */
118 setVertical(isVertical) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34119 if (this._isVertical === isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37120 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34121 }
Blink Reformat4c46d092018-04-07 15:32:37122
123 this._innerSetVertical(isVertical);
124
Tim van der Lippe1d6e57a2019-09-30 11:55:34125 if (this.isShowing()) {
Blink Reformat4c46d092018-04-07 15:32:37126 this._updateLayout();
Tim van der Lippe1d6e57a2019-09-30 11:55:34127 }
Blink Reformat4c46d092018-04-07 15:32:37128 }
129
130 /**
131 * @param {boolean} isVertical
132 */
133 _innerSetVertical(isVertical) {
134 this.contentElement.classList.toggle('vbox', !isVertical);
135 this.contentElement.classList.toggle('hbox', isVertical);
136 this._isVertical = isVertical;
137
138 this._resizerElementSize = null;
139 this._sidebarSizeDIP = -1;
140 this._restoreSidebarSizeFromSettings();
Tim van der Lippe1d6e57a2019-09-30 11:55:34141 if (this._shouldSaveShowMode) {
Blink Reformat4c46d092018-04-07 15:32:37142 this._restoreAndApplyShowModeFromSettings();
Tim van der Lippe1d6e57a2019-09-30 11:55:34143 }
Blink Reformat4c46d092018-04-07 15:32:37144 this._updateShowHideSidebarButton();
145 // FIXME: reverse SplitWidget.isVertical meaning.
146 this._resizerWidget.setVertical(!isVertical);
147 this.invalidateConstraints();
148 }
149
150 /**
151 * @param {boolean=} animate
152 */
153 _updateLayout(animate) {
154 this._totalSizeCSS = 0; // Lazy update.
155 this._totalSizeOtherDimensionCSS = 0;
156
157 // Remove properties that might affect total size calculation.
158 this._mainElement.style.removeProperty('width');
159 this._mainElement.style.removeProperty('height');
160 this._sidebarElement.style.removeProperty('width');
161 this._sidebarElement.style.removeProperty('height');
162
163 this._innerSetSidebarSizeDIP(this._preferredSidebarSizeDIP(), !!animate);
164 }
165
166 /**
Paul Lewis9950e182019-12-16 16:06:07167 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37168 */
169 setMainWidget(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34170 if (this._mainWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37171 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34172 }
Blink Reformat4c46d092018-04-07 15:32:37173 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34174 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37175 this._mainWidget.detach();
Tim van der Lippe1d6e57a2019-09-30 11:55:34176 }
Blink Reformat4c46d092018-04-07 15:32:37177 this._mainWidget = widget;
178 if (widget) {
Joel Einbinder7fbe24c2019-01-24 05:19:01179 widget.element.slot = 'insertion-point-main';
Tim van der Lippe0830b3d2019-10-03 13:20:07180 if (this._showMode === ShowMode.OnlyMain || this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37181 widget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34182 }
Blink Reformat4c46d092018-04-07 15:32:37183 }
184 this.resumeInvalidations();
185 }
186
187 /**
Paul Lewis9950e182019-12-16 16:06:07188 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37189 */
190 setSidebarWidget(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34191 if (this._sidebarWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37192 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34193 }
Blink Reformat4c46d092018-04-07 15:32:37194 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34195 if (this._sidebarWidget) {
Blink Reformat4c46d092018-04-07 15:32:37196 this._sidebarWidget.detach();
Tim van der Lippe1d6e57a2019-09-30 11:55:34197 }
Blink Reformat4c46d092018-04-07 15:32:37198 this._sidebarWidget = widget;
199 if (widget) {
Joel Einbinder7fbe24c2019-01-24 05:19:01200 widget.element.slot = 'insertion-point-sidebar';
Tim van der Lippe0830b3d2019-10-03 13:20:07201 if (this._showMode === ShowMode.OnlySidebar || this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37202 widget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34203 }
Blink Reformat4c46d092018-04-07 15:32:37204 }
205 this.resumeInvalidations();
206 }
207
208 /**
Paul Lewis9950e182019-12-16 16:06:07209 * @return {?Widget}
Blink Reformat4c46d092018-04-07 15:32:37210 */
211 mainWidget() {
212 return this._mainWidget;
213 }
214
215 /**
Paul Lewis9950e182019-12-16 16:06:07216 * @return {?Widget}
Blink Reformat4c46d092018-04-07 15:32:37217 */
218 sidebarWidget() {
219 return this._sidebarWidget;
220 }
221
222 /**
223 * @override
Paul Lewis9950e182019-12-16 16:06:07224 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37225 */
226 childWasDetached(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34227 if (this._detaching) {
Blink Reformat4c46d092018-04-07 15:32:37228 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34229 }
230 if (this._mainWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37231 this._mainWidget = null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34232 }
233 if (this._sidebarWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37234 this._sidebarWidget = null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34235 }
Blink Reformat4c46d092018-04-07 15:32:37236 this.invalidateConstraints();
237 }
238
239 /**
240 * @return {boolean}
241 */
242 isSidebarSecond() {
243 return this._secondIsSidebar;
244 }
245
246 enableShowModeSaving() {
247 this._shouldSaveShowMode = true;
248 this._restoreAndApplyShowModeFromSettings();
249 }
250
251 /**
252 * @return {string}
253 */
254 showMode() {
255 return this._showMode;
256 }
257
258 /**
259 * @param {boolean} secondIsSidebar
260 */
261 setSecondIsSidebar(secondIsSidebar) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34262 if (secondIsSidebar === this._secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54263 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34264 }
Blink Reformat4c46d092018-04-07 15:32:37265 this._secondIsSidebar = secondIsSidebar;
Joel Einbinder27131b22019-03-14 09:29:54266 if (!this._mainWidget || !this._mainWidget.shouldHideOnDetach()) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34267 if (secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54268 this.contentElement.insertBefore(this._mainElement, this._sidebarElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34269 } else {
Joel Einbinder27131b22019-03-14 09:29:54270 this.contentElement.insertBefore(this._mainElement, this._resizerElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34271 }
Joel Einbinder27131b22019-03-14 09:29:54272 } else if (!this._sidebarWidget || !this._sidebarWidget.shouldHideOnDetach()) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34273 if (secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54274 this.contentElement.insertBefore(this._sidebarElement, this._resizerElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34275 } else {
Joel Einbinder27131b22019-03-14 09:29:54276 this.contentElement.insertBefore(this._sidebarElement, this._mainElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34277 }
Joel Einbinder27131b22019-03-14 09:29:54278 } else {
279 console.error('Could not swap split widget side. Both children widgets contain iframes.');
280 this._secondIsSidebar = !secondIsSidebar;
281 }
Blink Reformat4c46d092018-04-07 15:32:37282 }
283
284 /**
285 * @return {?string}
286 */
287 sidebarSide() {
Tim van der Lippe0830b3d2019-10-03 13:20:07288 if (this._showMode !== ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37289 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34290 }
Blink Reformat4c46d092018-04-07 15:32:37291 return this._isVertical ? (this._secondIsSidebar ? 'right' : 'left') : (this._secondIsSidebar ? 'bottom' : 'top');
292 }
293
294 /**
295 * @return {!Element}
296 */
297 resizerElement() {
298 return this._resizerElement;
299 }
300
301 /**
302 * @param {boolean=} animate
303 */
304 hideMain(animate) {
305 this._showOnly(this._sidebarWidget, this._mainWidget, this._sidebarElement, this._mainElement, animate);
Tim van der Lippe0830b3d2019-10-03 13:20:07306 this._updateShowMode(ShowMode.OnlySidebar);
Blink Reformat4c46d092018-04-07 15:32:37307 }
308
309 /**
310 * @param {boolean=} animate
311 */
312 hideSidebar(animate) {
313 this._showOnly(this._mainWidget, this._sidebarWidget, this._mainElement, this._sidebarElement, animate);
Tim van der Lippe0830b3d2019-10-03 13:20:07314 this._updateShowMode(ShowMode.OnlyMain);
Blink Reformat4c46d092018-04-07 15:32:37315 }
316
317 /**
318 * @param {boolean} minimized
319 */
320 setSidebarMinimized(minimized) {
321 this._sidebarMinimized = minimized;
322 this.invalidateConstraints();
323 }
324
325 /**
326 * @return {boolean}
327 */
328 isSidebarMinimized() {
329 return this._sidebarMinimized;
330 }
331
332 /**
Paul Lewis9950e182019-12-16 16:06:07333 * @param {?Widget} sideToShow
Blink Reformat4c46d092018-04-07 15:32:37334 * @param {?UI.Widget} sideToHide
335 * @param {!Element} shadowToShow
336 * @param {!Element} shadowToHide
337 * @param {boolean=} animate
338 */
339 _showOnly(sideToShow, sideToHide, shadowToShow, shadowToHide, animate) {
340 this._cancelAnimation();
341
342 /**
Tim van der Lippe0830b3d2019-10-03 13:20:07343 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37344 */
345 function callback() {
346 if (sideToShow) {
347 // Make sure main is first in the children list.
Tim van der Lippe1d6e57a2019-09-30 11:55:34348 if (sideToShow === this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37349 this._mainWidget.show(this.element, this._sidebarWidget ? this._sidebarWidget.element : null);
Tim van der Lippe1d6e57a2019-09-30 11:55:34350 } else {
Blink Reformat4c46d092018-04-07 15:32:37351 this._sidebarWidget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34352 }
Blink Reformat4c46d092018-04-07 15:32:37353 }
354 if (sideToHide) {
355 this._detaching = true;
356 sideToHide.detach();
357 this._detaching = false;
358 }
359
360 this._resizerElement.classList.add('hidden');
361 shadowToShow.classList.remove('hidden');
362 shadowToShow.classList.add('maximized');
363 shadowToHide.classList.add('hidden');
364 shadowToHide.classList.remove('maximized');
365 this._removeAllLayoutProperties();
366 this.doResize();
367 this._showFinishedForTest();
368 }
369
Tim van der Lippe1d6e57a2019-09-30 11:55:34370 if (animate) {
Blink Reformat4c46d092018-04-07 15:32:37371 this._animate(true, callback.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34372 } else {
Blink Reformat4c46d092018-04-07 15:32:37373 callback.call(this);
Tim van der Lippe1d6e57a2019-09-30 11:55:34374 }
Blink Reformat4c46d092018-04-07 15:32:37375
376 this._sidebarSizeDIP = -1;
377 this.setResizable(false);
378 }
379
380 _showFinishedForTest() {
381 // This method is sniffed in tests.
382 }
383
384 _removeAllLayoutProperties() {
385 this._sidebarElement.style.removeProperty('flexBasis');
386
387 this._mainElement.style.removeProperty('width');
388 this._mainElement.style.removeProperty('height');
389 this._sidebarElement.style.removeProperty('width');
390 this._sidebarElement.style.removeProperty('height');
391
392 this._resizerElement.style.removeProperty('left');
393 this._resizerElement.style.removeProperty('right');
394 this._resizerElement.style.removeProperty('top');
395 this._resizerElement.style.removeProperty('bottom');
396
397 this._resizerElement.style.removeProperty('margin-left');
398 this._resizerElement.style.removeProperty('margin-right');
399 this._resizerElement.style.removeProperty('margin-top');
400 this._resizerElement.style.removeProperty('margin-bottom');
401 }
402
403 /**
404 * @param {boolean=} animate
405 */
406 showBoth(animate) {
Tim van der Lippe0830b3d2019-10-03 13:20:07407 if (this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37408 animate = false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34409 }
Blink Reformat4c46d092018-04-07 15:32:37410
411 this._cancelAnimation();
412 this._mainElement.classList.remove('maximized', 'hidden');
413 this._sidebarElement.classList.remove('maximized', 'hidden');
414 this._resizerElement.classList.remove('hidden');
415 this.setResizable(true);
416
417 // Make sure main is the first in the children list.
418 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34419 if (this._sidebarWidget) {
Blink Reformat4c46d092018-04-07 15:32:37420 this._sidebarWidget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34421 }
422 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37423 this._mainWidget.show(this.element, this._sidebarWidget ? this._sidebarWidget.element : null);
Tim van der Lippe1d6e57a2019-09-30 11:55:34424 }
Blink Reformat4c46d092018-04-07 15:32:37425 this.resumeInvalidations();
426 // Order widgets in DOM properly.
427 this.setSecondIsSidebar(this._secondIsSidebar);
428
429 this._sidebarSizeDIP = -1;
Tim van der Lippe0830b3d2019-10-03 13:20:07430 this._updateShowMode(ShowMode.Both);
Blink Reformat4c46d092018-04-07 15:32:37431 this._updateLayout(animate);
432 }
433
434 /**
435 * @param {boolean} resizable
436 */
437 setResizable(resizable) {
438 this._resizerWidget.setEnabled(resizable);
439 }
440
441 /**
442 * @return {boolean}
443 */
444 isResizable() {
445 return this._resizerWidget.isEnabled();
446 }
447
448 /**
449 * @param {number} size
450 */
451 setSidebarSize(size) {
452 const sizeDIP = UI.zoomManager.cssToDIP(size);
453 this._savedSidebarSizeDIP = sizeDIP;
454 this._saveSetting();
455 this._innerSetSidebarSizeDIP(sizeDIP, false, true);
456 }
457
458 /**
459 * @return {number}
460 */
461 sidebarSize() {
462 const sizeDIP = Math.max(0, this._sidebarSizeDIP);
463 return UI.zoomManager.dipToCSS(sizeDIP);
464 }
465
466 /**
467 * Returns total size in DIP.
468 * @return {number}
469 */
470 _totalSizeDIP() {
471 if (!this._totalSizeCSS) {
472 this._totalSizeCSS = this._isVertical ? this.contentElement.offsetWidth : this.contentElement.offsetHeight;
473 this._totalSizeOtherDimensionCSS =
474 this._isVertical ? this.contentElement.offsetHeight : this.contentElement.offsetWidth;
475 }
476 return UI.zoomManager.cssToDIP(this._totalSizeCSS);
477 }
478
479 /**
480 * @param {string} showMode
481 */
482 _updateShowMode(showMode) {
483 this._showMode = showMode;
484 this._saveShowModeToSettings();
485 this._updateShowHideSidebarButton();
Tim van der Lippe0830b3d2019-10-03 13:20:07486 this.dispatchEventToListeners(SplitWidget.Events.ShowModeChanged, showMode);
Blink Reformat4c46d092018-04-07 15:32:37487 this.invalidateConstraints();
488 }
489
490 /**
491 * @param {number} sizeDIP
492 * @param {boolean} animate
493 * @param {boolean=} userAction
494 */
495 _innerSetSidebarSizeDIP(sizeDIP, animate, userAction) {
Tim van der Lippe0830b3d2019-10-03 13:20:07496 if (this._showMode !== ShowMode.Both || !this.isShowing()) {
Blink Reformat4c46d092018-04-07 15:32:37497 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34498 }
Blink Reformat4c46d092018-04-07 15:32:37499
500 sizeDIP = this._applyConstraints(sizeDIP, userAction);
Tim van der Lippe1d6e57a2019-09-30 11:55:34501 if (this._sidebarSizeDIP === sizeDIP) {
Blink Reformat4c46d092018-04-07 15:32:37502 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34503 }
Blink Reformat4c46d092018-04-07 15:32:37504
505 if (!this._resizerElementSize) {
506 this._resizerElementSize =
507 this._isVertical ? this._resizerElement.offsetWidth : this._resizerElement.offsetHeight;
508 }
509
510 // Invalidate layout below.
511
512 this._removeAllLayoutProperties();
513
514 // this._totalSizeDIP is available below since we successfully applied constraints.
515 const roundSizeCSS = Math.round(UI.zoomManager.dipToCSS(sizeDIP));
516 const sidebarSizeValue = roundSizeCSS + 'px';
517 const mainSizeValue = (this._totalSizeCSS - roundSizeCSS) + 'px';
518 this._sidebarElement.style.flexBasis = sidebarSizeValue;
519
520 // Make both sides relayout boundaries.
521 if (this._isVertical) {
522 this._sidebarElement.style.width = sidebarSizeValue;
523 this._mainElement.style.width = mainSizeValue;
524 this._sidebarElement.style.height = this._totalSizeOtherDimensionCSS + 'px';
525 this._mainElement.style.height = this._totalSizeOtherDimensionCSS + 'px';
526 } else {
527 this._sidebarElement.style.height = sidebarSizeValue;
528 this._mainElement.style.height = mainSizeValue;
529 this._sidebarElement.style.width = this._totalSizeOtherDimensionCSS + 'px';
530 this._mainElement.style.width = this._totalSizeOtherDimensionCSS + 'px';
531 }
532
533 // Position resizer.
534 if (this._isVertical) {
535 if (this._secondIsSidebar) {
536 this._resizerElement.style.right = sidebarSizeValue;
537 this._resizerElement.style.marginRight = -this._resizerElementSize / 2 + 'px';
538 } else {
539 this._resizerElement.style.left = sidebarSizeValue;
540 this._resizerElement.style.marginLeft = -this._resizerElementSize / 2 + 'px';
541 }
542 } else {
543 if (this._secondIsSidebar) {
544 this._resizerElement.style.bottom = sidebarSizeValue;
545 this._resizerElement.style.marginBottom = -this._resizerElementSize / 2 + 'px';
546 } else {
547 this._resizerElement.style.top = sidebarSizeValue;
548 this._resizerElement.style.marginTop = -this._resizerElementSize / 2 + 'px';
549 }
550 }
551
552 this._sidebarSizeDIP = sizeDIP;
553
554 // Force layout.
555
556 if (animate) {
557 this._animate(false);
558 } else {
559 // No need to recalculate this._sidebarSizeDIP and this._totalSizeDIP again.
560 this.doResize();
Tim van der Lippe0830b3d2019-10-03 13:20:07561 this.dispatchEventToListeners(SplitWidget.Events.SidebarSizeChanged, this.sidebarSize());
Blink Reformat4c46d092018-04-07 15:32:37562 }
563 }
564
565 /**
566 * @param {boolean} reverse
567 * @param {function()=} callback
568 */
569 _animate(reverse, callback) {
570 const animationTime = 50;
571 this._animationCallback = callback || null;
572
573 let animatedMarginPropertyName;
Tim van der Lippe1d6e57a2019-09-30 11:55:34574 if (this._isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37575 animatedMarginPropertyName = this._secondIsSidebar ? 'margin-right' : 'margin-left';
Tim van der Lippe1d6e57a2019-09-30 11:55:34576 } else {
Blink Reformat4c46d092018-04-07 15:32:37577 animatedMarginPropertyName = this._secondIsSidebar ? 'margin-bottom' : 'margin-top';
Tim van der Lippe1d6e57a2019-09-30 11:55:34578 }
Blink Reformat4c46d092018-04-07 15:32:37579
580 const marginFrom = reverse ? '0' : '-' + UI.zoomManager.dipToCSS(this._sidebarSizeDIP) + 'px';
581 const marginTo = reverse ? '-' + UI.zoomManager.dipToCSS(this._sidebarSizeDIP) + 'px' : '0';
582
583 // This order of things is important.
584 // 1. Resize main element early and force layout.
585 this.contentElement.style.setProperty(animatedMarginPropertyName, marginFrom);
586 if (!reverse) {
587 suppressUnused(this._mainElement.offsetWidth);
588 suppressUnused(this._sidebarElement.offsetWidth);
589 }
590
591 // 2. Issue onresize to the sidebar element, its size won't change.
Tim van der Lippe1d6e57a2019-09-30 11:55:34592 if (!reverse) {
Blink Reformat4c46d092018-04-07 15:32:37593 this._sidebarWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34594 }
Blink Reformat4c46d092018-04-07 15:32:37595
596 // 3. Configure and run animation
597 this.contentElement.style.setProperty('transition', animatedMarginPropertyName + ' ' + animationTime + 'ms linear');
598
599 const boundAnimationFrame = animationFrame.bind(this);
600 let startTime;
601 /**
Tim van der Lippe0830b3d2019-10-03 13:20:07602 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37603 */
604 function animationFrame() {
605 this._animationFrameHandle = 0;
606
607 if (!startTime) {
608 // Kick animation on first frame.
609 this.contentElement.style.setProperty(animatedMarginPropertyName, marginTo);
610 startTime = window.performance.now();
611 } else if (window.performance.now() < startTime + animationTime) {
612 // Process regular animation frame.
Tim van der Lippe1d6e57a2019-09-30 11:55:34613 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37614 this._mainWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34615 }
Blink Reformat4c46d092018-04-07 15:32:37616 } else {
617 // Complete animation.
618 this._cancelAnimation();
Tim van der Lippe1d6e57a2019-09-30 11:55:34619 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37620 this._mainWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34621 }
Tim van der Lippe0830b3d2019-10-03 13:20:07622 this.dispatchEventToListeners(SplitWidget.Events.SidebarSizeChanged, this.sidebarSize());
Blink Reformat4c46d092018-04-07 15:32:37623 return;
624 }
625 this._animationFrameHandle = this.contentElement.window().requestAnimationFrame(boundAnimationFrame);
626 }
627 this._animationFrameHandle = this.contentElement.window().requestAnimationFrame(boundAnimationFrame);
628 }
629
630 _cancelAnimation() {
631 this.contentElement.style.removeProperty('margin-top');
632 this.contentElement.style.removeProperty('margin-right');
633 this.contentElement.style.removeProperty('margin-bottom');
634 this.contentElement.style.removeProperty('margin-left');
635 this.contentElement.style.removeProperty('transition');
636
637 if (this._animationFrameHandle) {
638 this.contentElement.window().cancelAnimationFrame(this._animationFrameHandle);
639 this._animationFrameHandle = 0;
640 }
641 if (this._animationCallback) {
642 this._animationCallback();
643 this._animationCallback = null;
644 }
645 }
646
647 /**
648 * @param {number} sidebarSize
649 * @param {boolean=} userAction
650 * @return {number}
651 */
652 _applyConstraints(sidebarSize, userAction) {
653 const totalSize = this._totalSizeDIP();
654 const zoomFactor = this._constraintsInDip ? 1 : UI.zoomManager.zoomFactor();
655
Paul Lewis9950e182019-12-16 16:06:07656 let constraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Blink Reformat4c46d092018-04-07 15:32:37657 let minSidebarSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34658 if (!minSidebarSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07659 minSidebarSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34660 }
Blink Reformat4c46d092018-04-07 15:32:37661 minSidebarSize *= zoomFactor;
Tim van der Lippe1d6e57a2019-09-30 11:55:34662 if (this._sidebarMinimized) {
Blink Reformat4c46d092018-04-07 15:32:37663 sidebarSize = minSidebarSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34664 }
Blink Reformat4c46d092018-04-07 15:32:37665
666 let preferredSidebarSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34667 if (!preferredSidebarSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07668 preferredSidebarSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34669 }
Blink Reformat4c46d092018-04-07 15:32:37670 preferredSidebarSize *= zoomFactor;
671 // Allow sidebar to be less than preferred by explicit user action.
Tim van der Lippe1d6e57a2019-09-30 11:55:34672 if (sidebarSize < preferredSidebarSize) {
Blink Reformat4c46d092018-04-07 15:32:37673 preferredSidebarSize = Math.max(sidebarSize, minSidebarSize);
Tim van der Lippe1d6e57a2019-09-30 11:55:34674 }
Blink Reformat4c46d092018-04-07 15:32:37675 preferredSidebarSize += zoomFactor; // 1 css pixel for splitter border.
676
Paul Lewis9950e182019-12-16 16:06:07677 constraints = this._mainWidget ? this._mainWidget.constraints() : new Constraints();
Blink Reformat4c46d092018-04-07 15:32:37678 let minMainSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34679 if (!minMainSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07680 minMainSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34681 }
Blink Reformat4c46d092018-04-07 15:32:37682 minMainSize *= zoomFactor;
683
684 let preferredMainSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34685 if (!preferredMainSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07686 preferredMainSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34687 }
Blink Reformat4c46d092018-04-07 15:32:37688 preferredMainSize *= zoomFactor;
689 const savedMainSize = this.isVertical() ? this._savedVerticalMainSize : this._savedHorizontalMainSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34690 if (savedMainSize !== null) {
Blink Reformat4c46d092018-04-07 15:32:37691 preferredMainSize = Math.min(preferredMainSize, savedMainSize * zoomFactor);
Tim van der Lippe1d6e57a2019-09-30 11:55:34692 }
693 if (userAction) {
Blink Reformat4c46d092018-04-07 15:32:37694 preferredMainSize = minMainSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34695 }
Blink Reformat4c46d092018-04-07 15:32:37696
697 // Enough space for preferred.
698 const totalPreferred = preferredMainSize + preferredSidebarSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34699 if (totalPreferred <= totalSize) {
Blink Reformat4c46d092018-04-07 15:32:37700 return Number.constrain(sidebarSize, preferredSidebarSize, totalSize - preferredMainSize);
Tim van der Lippe1d6e57a2019-09-30 11:55:34701 }
Blink Reformat4c46d092018-04-07 15:32:37702
703 // Enough space for minimum.
704 if (minMainSize + minSidebarSize <= totalSize) {
705 const delta = totalPreferred - totalSize;
706 const sidebarDelta = delta * preferredSidebarSize / totalPreferred;
707 sidebarSize = preferredSidebarSize - sidebarDelta;
708 return Number.constrain(sidebarSize, minSidebarSize, totalSize - minMainSize);
709 }
710
711 // Not enough space even for minimum sizes.
712 return Math.max(0, totalSize - minMainSize);
713 }
714
715 /**
716 * @override
717 */
718 wasShown() {
719 this._forceUpdateLayout();
Paul Lewis9950e182019-12-16 16:06:07720 UI.zoomManager.addEventListener(ZoomManagerEvents.ZoomChanged, this._onZoomChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37721 }
722
723 /**
724 * @override
725 */
726 willHide() {
Paul Lewis9950e182019-12-16 16:06:07727 UI.zoomManager.removeEventListener(ZoomManagerEvents.ZoomChanged, this._onZoomChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37728 }
729
730 /**
731 * @override
732 */
733 onResize() {
734 this._updateLayout();
735 }
736
737 /**
738 * @override
739 */
740 onLayout() {
741 this._updateLayout();
742 }
743
744 /**
745 * @override
Paul Lewis9950e182019-12-16 16:06:07746 * @return {!Constraints}
Blink Reformat4c46d092018-04-07 15:32:37747 */
748 calculateConstraints() {
Tim van der Lippe0830b3d2019-10-03 13:20:07749 if (this._showMode === ShowMode.OnlyMain) {
Paul Lewis9950e182019-12-16 16:06:07750 return this._mainWidget ? this._mainWidget.constraints() : new Constraints();
Tim van der Lippe1d6e57a2019-09-30 11:55:34751 }
Tim van der Lippe0830b3d2019-10-03 13:20:07752 if (this._showMode === ShowMode.OnlySidebar) {
Paul Lewis9950e182019-12-16 16:06:07753 return this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Tim van der Lippe1d6e57a2019-09-30 11:55:34754 }
Blink Reformat4c46d092018-04-07 15:32:37755
Paul Lewis9950e182019-12-16 16:06:07756 let mainConstraints = this._mainWidget ? this._mainWidget.constraints() : new Constraints();
757 let sidebarConstraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Tim van der Lippe0830b3d2019-10-03 13:20:07758 const min = MinPadding;
Blink Reformat4c46d092018-04-07 15:32:37759 if (this._isVertical) {
760 mainConstraints = mainConstraints.widthToMax(min).addWidth(1); // 1 for splitter
761 sidebarConstraints = sidebarConstraints.widthToMax(min);
762 return mainConstraints.addWidth(sidebarConstraints).heightToMax(sidebarConstraints);
763 } else {
764 mainConstraints = mainConstraints.heightToMax(min).addHeight(1); // 1 for splitter
765 sidebarConstraints = sidebarConstraints.heightToMax(min);
766 return mainConstraints.widthToMax(sidebarConstraints).addHeight(sidebarConstraints);
767 }
768 }
769
770 /**
771 * @param {!Common.Event} event
772 */
773 _onResizeStart(event) {
774 this._resizeStartSizeDIP = this._sidebarSizeDIP;
775 }
776
777 /**
778 * @param {!Common.Event} event
779 */
780 _onResizeUpdate(event) {
781 const offset = event.data.currentPosition - event.data.startPosition;
782 const offsetDIP = UI.zoomManager.cssToDIP(offset);
783 const newSizeDIP =
784 this._secondIsSidebar ? this._resizeStartSizeDIP - offsetDIP : this._resizeStartSizeDIP + offsetDIP;
785 const constrainedSizeDIP = this._applyConstraints(newSizeDIP, true);
786 this._savedSidebarSizeDIP = constrainedSizeDIP;
787 this._saveSetting();
788 this._innerSetSidebarSizeDIP(constrainedSizeDIP, false, true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34789 if (this.isVertical()) {
Blink Reformat4c46d092018-04-07 15:32:37790 this._savedVerticalMainSize = this._totalSizeDIP() - this._sidebarSizeDIP;
Tim van der Lippe1d6e57a2019-09-30 11:55:34791 } else {
Blink Reformat4c46d092018-04-07 15:32:37792 this._savedHorizontalMainSize = this._totalSizeDIP() - this._sidebarSizeDIP;
Tim van der Lippe1d6e57a2019-09-30 11:55:34793 }
Blink Reformat4c46d092018-04-07 15:32:37794 }
795
796 /**
797 * @param {!Common.Event} event
798 */
799 _onResizeEnd(event) {
800 this._resizeStartSizeDIP = 0;
801 }
802
803 /**
804 * @param {boolean=} noSplitter
805 */
806 hideDefaultResizer(noSplitter) {
807 this.uninstallResizer(this._resizerElement);
Pavel Feldmanc9060ea2018-04-30 04:42:18808 this._sidebarElement.classList.toggle('no-default-splitter', !!noSplitter);
Blink Reformat4c46d092018-04-07 15:32:37809 }
810
811 /**
812 * @param {!Element} resizerElement
813 */
814 installResizer(resizerElement) {
815 this._resizerWidget.addElement(resizerElement);
816 }
817
818 /**
819 * @param {!Element} resizerElement
820 */
821 uninstallResizer(resizerElement) {
822 this._resizerWidget.removeElement(resizerElement);
823 }
824
825 /**
826 * @return {boolean}
827 */
828 hasCustomResizer() {
829 const elements = this._resizerWidget.elements();
830 return elements.length > 1 || (elements.length === 1 && elements[0] !== this._resizerElement);
831 }
832
833 /**
834 * @param {!Element} resizer
835 * @param {boolean} on
836 */
837 toggleResizer(resizer, on) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34838 if (on) {
Blink Reformat4c46d092018-04-07 15:32:37839 this.installResizer(resizer);
Tim van der Lippe1d6e57a2019-09-30 11:55:34840 } else {
Blink Reformat4c46d092018-04-07 15:32:37841 this.uninstallResizer(resizer);
Tim van der Lippe1d6e57a2019-09-30 11:55:34842 }
Blink Reformat4c46d092018-04-07 15:32:37843 }
844
845 /**
Tim van der Lippe0830b3d2019-10-03 13:20:07846 * @return {?SplitWidget.SettingForOrientation}
Blink Reformat4c46d092018-04-07 15:32:37847 */
848 _settingForOrientation() {
849 const state = this._setting ? this._setting.get() : {};
850 return this._isVertical ? state.vertical : state.horizontal;
851 }
852
853 /**
854 * @return {number}
855 */
856 _preferredSidebarSizeDIP() {
857 let size = this._savedSidebarSizeDIP;
858 if (!size) {
859 size = this._isVertical ? this._defaultSidebarWidth : this._defaultSidebarHeight;
860 // If we have default value in percents, calculate it on first use.
Tim van der Lippe1d6e57a2019-09-30 11:55:34861 if (0 < size && size < 1) {
Blink Reformat4c46d092018-04-07 15:32:37862 size *= this._totalSizeDIP();
Tim van der Lippe1d6e57a2019-09-30 11:55:34863 }
Blink Reformat4c46d092018-04-07 15:32:37864 }
865 return size;
866 }
867
868 _restoreSidebarSizeFromSettings() {
869 const settingForOrientation = this._settingForOrientation();
870 this._savedSidebarSizeDIP = settingForOrientation ? settingForOrientation.size : 0;
871 }
872
873 _restoreAndApplyShowModeFromSettings() {
874 const orientationState = this._settingForOrientation();
875 this._savedShowMode = orientationState && orientationState.showMode ? orientationState.showMode : this._showMode;
876 this._showMode = this._savedShowMode;
877
878 switch (this._savedShowMode) {
Tim van der Lippe0830b3d2019-10-03 13:20:07879 case ShowMode.Both:
Blink Reformat4c46d092018-04-07 15:32:37880 this.showBoth();
881 break;
Tim van der Lippe0830b3d2019-10-03 13:20:07882 case ShowMode.OnlyMain:
Blink Reformat4c46d092018-04-07 15:32:37883 this.hideSidebar();
884 break;
Tim van der Lippe0830b3d2019-10-03 13:20:07885 case ShowMode.OnlySidebar:
Blink Reformat4c46d092018-04-07 15:32:37886 this.hideMain();
887 break;
888 }
889 }
890
891 _saveShowModeToSettings() {
892 this._savedShowMode = this._showMode;
893 this._saveSetting();
894 }
895
896 _saveSetting() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34897 if (!this._setting) {
Blink Reformat4c46d092018-04-07 15:32:37898 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34899 }
Blink Reformat4c46d092018-04-07 15:32:37900 const state = this._setting.get();
901 const orientationState = (this._isVertical ? state.vertical : state.horizontal) || {};
902
903 orientationState.size = this._savedSidebarSizeDIP;
Tim van der Lippe1d6e57a2019-09-30 11:55:34904 if (this._shouldSaveShowMode) {
Blink Reformat4c46d092018-04-07 15:32:37905 orientationState.showMode = this._savedShowMode;
Tim van der Lippe1d6e57a2019-09-30 11:55:34906 }
Blink Reformat4c46d092018-04-07 15:32:37907
Tim van der Lippe1d6e57a2019-09-30 11:55:34908 if (this._isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37909 state.vertical = orientationState;
Tim van der Lippe1d6e57a2019-09-30 11:55:34910 } else {
Blink Reformat4c46d092018-04-07 15:32:37911 state.horizontal = orientationState;
Tim van der Lippe1d6e57a2019-09-30 11:55:34912 }
Blink Reformat4c46d092018-04-07 15:32:37913 this._setting.set(state);
914 }
915
916 _forceUpdateLayout() {
917 // Force layout even if sidebar size does not change.
918 this._sidebarSizeDIP = -1;
919 this._updateLayout();
920 }
921
922 /**
923 * @param {!Common.Event} event
924 */
925 _onZoomChanged(event) {
926 this._forceUpdateLayout();
927 }
928
929 /**
930 * @param {string} title
Paul Lewis9950e182019-12-16 16:06:07931 * @return {!ToolbarButton}
Blink Reformat4c46d092018-04-07 15:32:37932 */
933 createShowHideSidebarButton(title) {
Mandy Chen84d56b62019-09-03 18:21:18934 this._showHideSidebarButtonTitle = title;
Paul Lewis9950e182019-12-16 16:06:07935 this._showHideSidebarButton = new ToolbarButton('', '');
936 this._showHideSidebarButton.addEventListener(ToolbarButton.Events.Click, buttonClicked, this);
Blink Reformat4c46d092018-04-07 15:32:37937 this._updateShowHideSidebarButton();
938
939 /**
940 * @param {!Common.Event} event
Tim van der Lippe0830b3d2019-10-03 13:20:07941 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37942 */
943 function buttonClicked(event) {
Tim van der Lippe0830b3d2019-10-03 13:20:07944 if (this._showMode !== ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37945 this.showBoth(true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34946 } else {
Blink Reformat4c46d092018-04-07 15:32:37947 this.hideSidebar(true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34948 }
Blink Reformat4c46d092018-04-07 15:32:37949 }
950
951 return this._showHideSidebarButton;
952 }
953
954 _updateShowHideSidebarButton() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34955 if (!this._showHideSidebarButton) {
Blink Reformat4c46d092018-04-07 15:32:37956 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34957 }
Tim van der Lippe0830b3d2019-10-03 13:20:07958 const sidebarHidden = this._showMode === ShowMode.OnlyMain;
Blink Reformat4c46d092018-04-07 15:32:37959 let glyph = '';
960 if (sidebarHidden) {
961 glyph = this.isVertical() ?
962 (this.isSidebarSecond() ? 'largeicon-show-right-sidebar' : 'largeicon-show-left-sidebar') :
963 (this.isSidebarSecond() ? 'largeicon-show-bottom-sidebar' : 'largeicon-show-top-sidebar');
964 } else {
965 glyph = this.isVertical() ?
966 (this.isSidebarSecond() ? 'largeicon-hide-right-sidebar' : 'largeicon-hide-left-sidebar') :
967 (this.isSidebarSecond() ? 'largeicon-hide-bottom-sidebar' : 'largeicon-hide-top-sidebar');
968 }
969 this._showHideSidebarButton.setGlyph(glyph);
970 this._showHideSidebarButton.setTitle(
971 sidebarHidden ? Common.UIString('Show %s', this._showHideSidebarButtonTitle) :
972 Common.UIString('Hide %s', this._showHideSidebarButtonTitle));
973 }
Tim van der Lippe0830b3d2019-10-03 13:20:07974}
Blink Reformat4c46d092018-04-07 15:32:37975
Tim van der Lippe0830b3d2019-10-03 13:20:07976export const ShowMode = {
Blink Reformat4c46d092018-04-07 15:32:37977 Both: 'Both',
978 OnlyMain: 'OnlyMain',
979 OnlySidebar: 'OnlySidebar'
980};
981
982/** @enum {symbol} */
Tim van der Lippe0830b3d2019-10-03 13:20:07983export const Events = {
Blink Reformat4c46d092018-04-07 15:32:37984 SidebarSizeChanged: Symbol('SidebarSizeChanged'),
985 ShowModeChanged: Symbol('ShowModeChanged')
986};
987
Tim van der Lippec96ccd92019-11-29 16:23:54988const MinPadding = 20;