blob: 7ab8f5d30b3cbb3c85ee109f9a18071251858ebe [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 *
Tim van der Lippe83f02be2020-01-23 11:11:408 * * Redistributions of source code must retain the above copyright
Blink Reformat4c46d092018-04-07 15:32:379 * notice, this list of conditions and the following disclaimer.
Tim van der Lippe83f02be2020-01-23 11:11:4010 * * Redistributions in binary form must reproduce the above
Blink Reformat4c46d092018-04-07 15:32:3711 * 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 Lippe83f02be2020-01-23 11:11:4014 * * 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 Reformat4c46d092018-04-07 15:32:3717 *
Tim van der Lippe83f02be2020-01-23 11:11:4018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Blink Reformat4c46d092018-04-07 15:32:3719 * "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 Lippe83f02be2020-01-23 11:11:4021 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Blink Reformat4c46d092018-04-07 15:32:3723 * 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 Lewis17e384e2020-01-08 15:46:5131import * as Common from '../common/common.js';
Tim van der Lippeaa76aa22020-02-14 14:38:2432
Paul Lewis9950e182019-12-16 16:06:0733import {Constraints} from './Geometry.js';
34import {Events as ResizerWidgetEvents, SimpleResizerWidget} from './ResizerWidget.js';
35import {ToolbarButton} from './Toolbar.js';
36import {Widget} from './Widget.js';
37import {Events as ZoomManagerEvents} from './ZoomManager.js';
38
Blink Reformat4c46d092018-04-07 15:32:3739/**
40 * @unrestricted
41 */
Paul Lewis9950e182019-12-16 16:06:0742export class SplitWidget extends Widget {
Blink Reformat4c46d092018-04-07 15:32:3743 /**
44 * @param {boolean} isVertical
45 * @param {boolean} secondIsSidebar
46 * @param {string=} settingName
47 * @param {number=} defaultSidebarWidth
48 * @param {number=} defaultSidebarHeight
49 * @param {boolean=} constraintsInDip
50 */
51 constructor(isVertical, secondIsSidebar, settingName, defaultSidebarWidth, defaultSidebarHeight, constraintsInDip) {
52 super(true);
53 this.element.classList.add('split-widget');
54 this.registerRequiredCSS('ui/splitWidget.css');
55
56 this.contentElement.classList.add('shadow-split-widget');
Joel Einbinder27131b22019-03-14 09:29:5457 this._sidebarElement =
58 this.contentElement.createChild('div', 'shadow-split-widget-contents shadow-split-widget-sidebar vbox');
Blink Reformat4c46d092018-04-07 15:32:3759 this._mainElement =
60 this.contentElement.createChild('div', 'shadow-split-widget-contents shadow-split-widget-main vbox');
Joel Einbinder7fbe24c2019-01-24 05:19:0161 this._mainElement.createChild('slot').name = 'insertion-point-main';
Joel Einbinder7fbe24c2019-01-24 05:19:0162 this._sidebarElement.createChild('slot').name = 'insertion-point-sidebar';
Blink Reformat4c46d092018-04-07 15:32:3763 this._resizerElement = this.contentElement.createChild('div', 'shadow-split-widget-resizer');
64 this._resizerElementSize = null;
65
Paul Lewis9950e182019-12-16 16:06:0766 this._resizerWidget = new SimpleResizerWidget();
Blink Reformat4c46d092018-04-07 15:32:3767 this._resizerWidget.setEnabled(true);
Paul Lewis9950e182019-12-16 16:06:0768 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeStart, this._onResizeStart, this);
69 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeUpdate, this._onResizeUpdate, this);
70 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeEnd, this._onResizeEnd, this);
Blink Reformat4c46d092018-04-07 15:32:3771
72 this._defaultSidebarWidth = defaultSidebarWidth || 200;
73 this._defaultSidebarHeight = defaultSidebarHeight || this._defaultSidebarWidth;
74 this._constraintsInDip = !!constraintsInDip;
75 this._resizeStartSizeDIP = 0;
Paul Lewis17e384e2020-01-08 15:46:5176 // Note: go via self.Common for globally-namespaced singletons.
Paul Lewis6bcdb182020-01-23 11:08:0577 this._setting = settingName ? self.self.Common.settings.createSetting(settingName, {}) : null;
Blink Reformat4c46d092018-04-07 15:32:3778
79 this._totalSizeCSS = 0;
80 this._totalSizeOtherDimensionCSS = 0;
Paul Lewis9950e182019-12-16 16:06:0781 /** @type {?Widget} */
Blink Reformat4c46d092018-04-07 15:32:3782 this._mainWidget = null;
Paul Lewis9950e182019-12-16 16:06:0783 /** @type {?Widget} */
Blink Reformat4c46d092018-04-07 15:32:3784 this._sidebarWidget = null;
85 this._animationFrameHandle = 0;
86 /** @type {?function()} */
87 this._animationCallback = null;
88 this._showHideSidebarButtonTitle = '';
Paul Lewis9950e182019-12-16 16:06:0789 /** @type {?ToolbarButton} */
Blink Reformat4c46d092018-04-07 15:32:3790 this._showHideSidebarButton = null;
91 this._isVertical = false;
92 this._sidebarMinimized = false;
93 this._detaching = false;
94 this._sidebarSizeDIP = -1;
95 this._savedSidebarSizeDIP = this._sidebarSizeDIP;
96 this._secondIsSidebar = false;
97 this._shouldSaveShowMode = false;
98 /** @type {?number} */
99 this._savedVerticalMainSize = null;
100 /** @type {?number} */
101 this._savedHorizontalMainSize = null;
102
103 this.setSecondIsSidebar(secondIsSidebar);
104
105 this._innerSetVertical(isVertical);
Tim van der Lippe0830b3d2019-10-03 13:20:07106 this._showMode = ShowMode.Both;
Blink Reformat4c46d092018-04-07 15:32:37107 this._savedShowMode = this._showMode;
108
109 // Should be called after isVertical has the right value.
110 this.installResizer(this._resizerElement);
111 }
112
113 /**
114 * @return {boolean}
115 */
116 isVertical() {
117 return this._isVertical;
118 }
119
120 /**
121 * @param {boolean} isVertical
122 */
123 setVertical(isVertical) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34124 if (this._isVertical === isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37125 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34126 }
Blink Reformat4c46d092018-04-07 15:32:37127
128 this._innerSetVertical(isVertical);
129
Tim van der Lippe1d6e57a2019-09-30 11:55:34130 if (this.isShowing()) {
Blink Reformat4c46d092018-04-07 15:32:37131 this._updateLayout();
Tim van der Lippe1d6e57a2019-09-30 11:55:34132 }
Blink Reformat4c46d092018-04-07 15:32:37133 }
134
135 /**
136 * @param {boolean} isVertical
137 */
138 _innerSetVertical(isVertical) {
139 this.contentElement.classList.toggle('vbox', !isVertical);
140 this.contentElement.classList.toggle('hbox', isVertical);
141 this._isVertical = isVertical;
142
143 this._resizerElementSize = null;
144 this._sidebarSizeDIP = -1;
145 this._restoreSidebarSizeFromSettings();
Tim van der Lippe1d6e57a2019-09-30 11:55:34146 if (this._shouldSaveShowMode) {
Blink Reformat4c46d092018-04-07 15:32:37147 this._restoreAndApplyShowModeFromSettings();
Tim van der Lippe1d6e57a2019-09-30 11:55:34148 }
Blink Reformat4c46d092018-04-07 15:32:37149 this._updateShowHideSidebarButton();
150 // FIXME: reverse SplitWidget.isVertical meaning.
151 this._resizerWidget.setVertical(!isVertical);
152 this.invalidateConstraints();
153 }
154
155 /**
156 * @param {boolean=} animate
157 */
158 _updateLayout(animate) {
159 this._totalSizeCSS = 0; // Lazy update.
160 this._totalSizeOtherDimensionCSS = 0;
161
162 // Remove properties that might affect total size calculation.
163 this._mainElement.style.removeProperty('width');
164 this._mainElement.style.removeProperty('height');
165 this._sidebarElement.style.removeProperty('width');
166 this._sidebarElement.style.removeProperty('height');
167
168 this._innerSetSidebarSizeDIP(this._preferredSidebarSizeDIP(), !!animate);
169 }
170
171 /**
Paul Lewis9950e182019-12-16 16:06:07172 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37173 */
174 setMainWidget(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34175 if (this._mainWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37176 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34177 }
Blink Reformat4c46d092018-04-07 15:32:37178 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34179 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37180 this._mainWidget.detach();
Tim van der Lippe1d6e57a2019-09-30 11:55:34181 }
Blink Reformat4c46d092018-04-07 15:32:37182 this._mainWidget = widget;
183 if (widget) {
Joel Einbinder7fbe24c2019-01-24 05:19:01184 widget.element.slot = 'insertion-point-main';
Tim van der Lippe0830b3d2019-10-03 13:20:07185 if (this._showMode === ShowMode.OnlyMain || this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37186 widget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34187 }
Blink Reformat4c46d092018-04-07 15:32:37188 }
189 this.resumeInvalidations();
190 }
191
192 /**
Paul Lewis9950e182019-12-16 16:06:07193 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37194 */
195 setSidebarWidget(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34196 if (this._sidebarWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37197 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34198 }
Blink Reformat4c46d092018-04-07 15:32:37199 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34200 if (this._sidebarWidget) {
Blink Reformat4c46d092018-04-07 15:32:37201 this._sidebarWidget.detach();
Tim van der Lippe1d6e57a2019-09-30 11:55:34202 }
Blink Reformat4c46d092018-04-07 15:32:37203 this._sidebarWidget = widget;
204 if (widget) {
Joel Einbinder7fbe24c2019-01-24 05:19:01205 widget.element.slot = 'insertion-point-sidebar';
Tim van der Lippe0830b3d2019-10-03 13:20:07206 if (this._showMode === ShowMode.OnlySidebar || this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37207 widget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34208 }
Blink Reformat4c46d092018-04-07 15:32:37209 }
210 this.resumeInvalidations();
211 }
212
213 /**
Paul Lewis9950e182019-12-16 16:06:07214 * @return {?Widget}
Blink Reformat4c46d092018-04-07 15:32:37215 */
216 mainWidget() {
217 return this._mainWidget;
218 }
219
220 /**
Paul Lewis9950e182019-12-16 16:06:07221 * @return {?Widget}
Blink Reformat4c46d092018-04-07 15:32:37222 */
223 sidebarWidget() {
224 return this._sidebarWidget;
225 }
226
227 /**
228 * @override
Paul Lewis9950e182019-12-16 16:06:07229 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37230 */
231 childWasDetached(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34232 if (this._detaching) {
Blink Reformat4c46d092018-04-07 15:32:37233 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34234 }
235 if (this._mainWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37236 this._mainWidget = null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34237 }
238 if (this._sidebarWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37239 this._sidebarWidget = null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34240 }
Blink Reformat4c46d092018-04-07 15:32:37241 this.invalidateConstraints();
242 }
243
244 /**
245 * @return {boolean}
246 */
247 isSidebarSecond() {
248 return this._secondIsSidebar;
249 }
250
251 enableShowModeSaving() {
252 this._shouldSaveShowMode = true;
253 this._restoreAndApplyShowModeFromSettings();
254 }
255
256 /**
257 * @return {string}
258 */
259 showMode() {
260 return this._showMode;
261 }
262
263 /**
264 * @param {boolean} secondIsSidebar
265 */
266 setSecondIsSidebar(secondIsSidebar) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34267 if (secondIsSidebar === this._secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54268 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34269 }
Blink Reformat4c46d092018-04-07 15:32:37270 this._secondIsSidebar = secondIsSidebar;
Joel Einbinder27131b22019-03-14 09:29:54271 if (!this._mainWidget || !this._mainWidget.shouldHideOnDetach()) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34272 if (secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54273 this.contentElement.insertBefore(this._mainElement, this._sidebarElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34274 } else {
Joel Einbinder27131b22019-03-14 09:29:54275 this.contentElement.insertBefore(this._mainElement, this._resizerElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34276 }
Joel Einbinder27131b22019-03-14 09:29:54277 } else if (!this._sidebarWidget || !this._sidebarWidget.shouldHideOnDetach()) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34278 if (secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54279 this.contentElement.insertBefore(this._sidebarElement, this._resizerElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34280 } else {
Joel Einbinder27131b22019-03-14 09:29:54281 this.contentElement.insertBefore(this._sidebarElement, this._mainElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34282 }
Joel Einbinder27131b22019-03-14 09:29:54283 } else {
284 console.error('Could not swap split widget side. Both children widgets contain iframes.');
285 this._secondIsSidebar = !secondIsSidebar;
286 }
Blink Reformat4c46d092018-04-07 15:32:37287 }
288
289 /**
290 * @return {?string}
291 */
292 sidebarSide() {
Tim van der Lippe0830b3d2019-10-03 13:20:07293 if (this._showMode !== ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37294 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34295 }
Blink Reformat4c46d092018-04-07 15:32:37296 return this._isVertical ? (this._secondIsSidebar ? 'right' : 'left') : (this._secondIsSidebar ? 'bottom' : 'top');
297 }
298
299 /**
300 * @return {!Element}
301 */
302 resizerElement() {
303 return this._resizerElement;
304 }
305
306 /**
307 * @param {boolean=} animate
308 */
309 hideMain(animate) {
310 this._showOnly(this._sidebarWidget, this._mainWidget, this._sidebarElement, this._mainElement, animate);
Tim van der Lippe0830b3d2019-10-03 13:20:07311 this._updateShowMode(ShowMode.OnlySidebar);
Blink Reformat4c46d092018-04-07 15:32:37312 }
313
314 /**
315 * @param {boolean=} animate
316 */
317 hideSidebar(animate) {
318 this._showOnly(this._mainWidget, this._sidebarWidget, this._mainElement, this._sidebarElement, animate);
Tim van der Lippe0830b3d2019-10-03 13:20:07319 this._updateShowMode(ShowMode.OnlyMain);
Blink Reformat4c46d092018-04-07 15:32:37320 }
321
322 /**
323 * @param {boolean} minimized
324 */
325 setSidebarMinimized(minimized) {
326 this._sidebarMinimized = minimized;
327 this.invalidateConstraints();
328 }
329
330 /**
331 * @return {boolean}
332 */
333 isSidebarMinimized() {
334 return this._sidebarMinimized;
335 }
336
337 /**
Paul Lewis9950e182019-12-16 16:06:07338 * @param {?Widget} sideToShow
Tim van der Lippeaa76aa22020-02-14 14:38:24339 * @param {?Widget} sideToHide
Blink Reformat4c46d092018-04-07 15:32:37340 * @param {!Element} shadowToShow
341 * @param {!Element} shadowToHide
342 * @param {boolean=} animate
343 */
344 _showOnly(sideToShow, sideToHide, shadowToShow, shadowToHide, animate) {
345 this._cancelAnimation();
346
347 /**
Tim van der Lippe0830b3d2019-10-03 13:20:07348 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37349 */
350 function callback() {
351 if (sideToShow) {
352 // Make sure main is first in the children list.
Tim van der Lippe1d6e57a2019-09-30 11:55:34353 if (sideToShow === this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37354 this._mainWidget.show(this.element, this._sidebarWidget ? this._sidebarWidget.element : null);
Tim van der Lippe1d6e57a2019-09-30 11:55:34355 } else {
Blink Reformat4c46d092018-04-07 15:32:37356 this._sidebarWidget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34357 }
Blink Reformat4c46d092018-04-07 15:32:37358 }
359 if (sideToHide) {
360 this._detaching = true;
361 sideToHide.detach();
362 this._detaching = false;
363 }
364
365 this._resizerElement.classList.add('hidden');
366 shadowToShow.classList.remove('hidden');
367 shadowToShow.classList.add('maximized');
368 shadowToHide.classList.add('hidden');
369 shadowToHide.classList.remove('maximized');
370 this._removeAllLayoutProperties();
371 this.doResize();
372 this._showFinishedForTest();
373 }
374
Tim van der Lippe1d6e57a2019-09-30 11:55:34375 if (animate) {
Blink Reformat4c46d092018-04-07 15:32:37376 this._animate(true, callback.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34377 } else {
Blink Reformat4c46d092018-04-07 15:32:37378 callback.call(this);
Tim van der Lippe1d6e57a2019-09-30 11:55:34379 }
Blink Reformat4c46d092018-04-07 15:32:37380
381 this._sidebarSizeDIP = -1;
382 this.setResizable(false);
383 }
384
385 _showFinishedForTest() {
386 // This method is sniffed in tests.
387 }
388
389 _removeAllLayoutProperties() {
390 this._sidebarElement.style.removeProperty('flexBasis');
391
392 this._mainElement.style.removeProperty('width');
393 this._mainElement.style.removeProperty('height');
394 this._sidebarElement.style.removeProperty('width');
395 this._sidebarElement.style.removeProperty('height');
396
397 this._resizerElement.style.removeProperty('left');
398 this._resizerElement.style.removeProperty('right');
399 this._resizerElement.style.removeProperty('top');
400 this._resizerElement.style.removeProperty('bottom');
401
402 this._resizerElement.style.removeProperty('margin-left');
403 this._resizerElement.style.removeProperty('margin-right');
404 this._resizerElement.style.removeProperty('margin-top');
405 this._resizerElement.style.removeProperty('margin-bottom');
406 }
407
408 /**
409 * @param {boolean=} animate
410 */
411 showBoth(animate) {
Tim van der Lippe0830b3d2019-10-03 13:20:07412 if (this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37413 animate = false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34414 }
Blink Reformat4c46d092018-04-07 15:32:37415
416 this._cancelAnimation();
417 this._mainElement.classList.remove('maximized', 'hidden');
418 this._sidebarElement.classList.remove('maximized', 'hidden');
419 this._resizerElement.classList.remove('hidden');
420 this.setResizable(true);
421
422 // Make sure main is the first in the children list.
423 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34424 if (this._sidebarWidget) {
Blink Reformat4c46d092018-04-07 15:32:37425 this._sidebarWidget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34426 }
427 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37428 this._mainWidget.show(this.element, this._sidebarWidget ? this._sidebarWidget.element : null);
Tim van der Lippe1d6e57a2019-09-30 11:55:34429 }
Blink Reformat4c46d092018-04-07 15:32:37430 this.resumeInvalidations();
431 // Order widgets in DOM properly.
432 this.setSecondIsSidebar(this._secondIsSidebar);
433
434 this._sidebarSizeDIP = -1;
Tim van der Lippe0830b3d2019-10-03 13:20:07435 this._updateShowMode(ShowMode.Both);
Blink Reformat4c46d092018-04-07 15:32:37436 this._updateLayout(animate);
437 }
438
439 /**
440 * @param {boolean} resizable
441 */
442 setResizable(resizable) {
443 this._resizerWidget.setEnabled(resizable);
444 }
445
446 /**
447 * @return {boolean}
448 */
449 isResizable() {
450 return this._resizerWidget.isEnabled();
451 }
452
453 /**
454 * @param {number} size
455 */
456 setSidebarSize(size) {
Paul Lewis50993692020-01-23 15:22:26457 const sizeDIP = self.UI.zoomManager.cssToDIP(size);
Blink Reformat4c46d092018-04-07 15:32:37458 this._savedSidebarSizeDIP = sizeDIP;
459 this._saveSetting();
460 this._innerSetSidebarSizeDIP(sizeDIP, false, true);
461 }
462
463 /**
464 * @return {number}
465 */
466 sidebarSize() {
467 const sizeDIP = Math.max(0, this._sidebarSizeDIP);
Paul Lewis50993692020-01-23 15:22:26468 return self.UI.zoomManager.dipToCSS(sizeDIP);
Blink Reformat4c46d092018-04-07 15:32:37469 }
470
471 /**
472 * Returns total size in DIP.
473 * @return {number}
474 */
475 _totalSizeDIP() {
476 if (!this._totalSizeCSS) {
477 this._totalSizeCSS = this._isVertical ? this.contentElement.offsetWidth : this.contentElement.offsetHeight;
478 this._totalSizeOtherDimensionCSS =
479 this._isVertical ? this.contentElement.offsetHeight : this.contentElement.offsetWidth;
480 }
Paul Lewis50993692020-01-23 15:22:26481 return self.UI.zoomManager.cssToDIP(this._totalSizeCSS);
Blink Reformat4c46d092018-04-07 15:32:37482 }
483
484 /**
485 * @param {string} showMode
486 */
487 _updateShowMode(showMode) {
488 this._showMode = showMode;
489 this._saveShowModeToSettings();
490 this._updateShowHideSidebarButton();
Tim van der Lippe0830b3d2019-10-03 13:20:07491 this.dispatchEventToListeners(SplitWidget.Events.ShowModeChanged, showMode);
Blink Reformat4c46d092018-04-07 15:32:37492 this.invalidateConstraints();
493 }
494
495 /**
496 * @param {number} sizeDIP
497 * @param {boolean} animate
498 * @param {boolean=} userAction
499 */
500 _innerSetSidebarSizeDIP(sizeDIP, animate, userAction) {
Tim van der Lippe0830b3d2019-10-03 13:20:07501 if (this._showMode !== ShowMode.Both || !this.isShowing()) {
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 sizeDIP = this._applyConstraints(sizeDIP, userAction);
Tim van der Lippe1d6e57a2019-09-30 11:55:34506 if (this._sidebarSizeDIP === sizeDIP) {
Blink Reformat4c46d092018-04-07 15:32:37507 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34508 }
Blink Reformat4c46d092018-04-07 15:32:37509
510 if (!this._resizerElementSize) {
511 this._resizerElementSize =
512 this._isVertical ? this._resizerElement.offsetWidth : this._resizerElement.offsetHeight;
513 }
514
515 // Invalidate layout below.
516
517 this._removeAllLayoutProperties();
518
519 // this._totalSizeDIP is available below since we successfully applied constraints.
Paul Lewis50993692020-01-23 15:22:26520 const roundSizeCSS = Math.round(self.UI.zoomManager.dipToCSS(sizeDIP));
Blink Reformat4c46d092018-04-07 15:32:37521 const sidebarSizeValue = roundSizeCSS + 'px';
522 const mainSizeValue = (this._totalSizeCSS - roundSizeCSS) + 'px';
523 this._sidebarElement.style.flexBasis = sidebarSizeValue;
524
525 // Make both sides relayout boundaries.
526 if (this._isVertical) {
527 this._sidebarElement.style.width = sidebarSizeValue;
528 this._mainElement.style.width = mainSizeValue;
529 this._sidebarElement.style.height = this._totalSizeOtherDimensionCSS + 'px';
530 this._mainElement.style.height = this._totalSizeOtherDimensionCSS + 'px';
531 } else {
532 this._sidebarElement.style.height = sidebarSizeValue;
533 this._mainElement.style.height = mainSizeValue;
534 this._sidebarElement.style.width = this._totalSizeOtherDimensionCSS + 'px';
535 this._mainElement.style.width = this._totalSizeOtherDimensionCSS + 'px';
536 }
537
538 // Position resizer.
539 if (this._isVertical) {
540 if (this._secondIsSidebar) {
541 this._resizerElement.style.right = sidebarSizeValue;
542 this._resizerElement.style.marginRight = -this._resizerElementSize / 2 + 'px';
543 } else {
544 this._resizerElement.style.left = sidebarSizeValue;
545 this._resizerElement.style.marginLeft = -this._resizerElementSize / 2 + 'px';
546 }
547 } else {
548 if (this._secondIsSidebar) {
549 this._resizerElement.style.bottom = sidebarSizeValue;
550 this._resizerElement.style.marginBottom = -this._resizerElementSize / 2 + 'px';
551 } else {
552 this._resizerElement.style.top = sidebarSizeValue;
553 this._resizerElement.style.marginTop = -this._resizerElementSize / 2 + 'px';
554 }
555 }
556
557 this._sidebarSizeDIP = sizeDIP;
558
559 // Force layout.
560
561 if (animate) {
562 this._animate(false);
563 } else {
564 // No need to recalculate this._sidebarSizeDIP and this._totalSizeDIP again.
565 this.doResize();
Tim van der Lippe0830b3d2019-10-03 13:20:07566 this.dispatchEventToListeners(SplitWidget.Events.SidebarSizeChanged, this.sidebarSize());
Blink Reformat4c46d092018-04-07 15:32:37567 }
568 }
569
570 /**
571 * @param {boolean} reverse
572 * @param {function()=} callback
573 */
574 _animate(reverse, callback) {
575 const animationTime = 50;
576 this._animationCallback = callback || null;
577
578 let animatedMarginPropertyName;
Tim van der Lippe1d6e57a2019-09-30 11:55:34579 if (this._isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37580 animatedMarginPropertyName = this._secondIsSidebar ? 'margin-right' : 'margin-left';
Tim van der Lippe1d6e57a2019-09-30 11:55:34581 } else {
Blink Reformat4c46d092018-04-07 15:32:37582 animatedMarginPropertyName = this._secondIsSidebar ? 'margin-bottom' : 'margin-top';
Tim van der Lippe1d6e57a2019-09-30 11:55:34583 }
Blink Reformat4c46d092018-04-07 15:32:37584
Paul Lewis50993692020-01-23 15:22:26585 const marginFrom = reverse ? '0' : '-' + self.UI.zoomManager.dipToCSS(this._sidebarSizeDIP) + 'px';
586 const marginTo = reverse ? '-' + self.UI.zoomManager.dipToCSS(this._sidebarSizeDIP) + 'px' : '0';
Blink Reformat4c46d092018-04-07 15:32:37587
588 // This order of things is important.
589 // 1. Resize main element early and force layout.
590 this.contentElement.style.setProperty(animatedMarginPropertyName, marginFrom);
591 if (!reverse) {
592 suppressUnused(this._mainElement.offsetWidth);
593 suppressUnused(this._sidebarElement.offsetWidth);
594 }
595
596 // 2. Issue onresize to the sidebar element, its size won't change.
Tim van der Lippe1d6e57a2019-09-30 11:55:34597 if (!reverse) {
Blink Reformat4c46d092018-04-07 15:32:37598 this._sidebarWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34599 }
Blink Reformat4c46d092018-04-07 15:32:37600
601 // 3. Configure and run animation
602 this.contentElement.style.setProperty('transition', animatedMarginPropertyName + ' ' + animationTime + 'ms linear');
603
604 const boundAnimationFrame = animationFrame.bind(this);
605 let startTime;
606 /**
Tim van der Lippe0830b3d2019-10-03 13:20:07607 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37608 */
609 function animationFrame() {
610 this._animationFrameHandle = 0;
611
612 if (!startTime) {
613 // Kick animation on first frame.
614 this.contentElement.style.setProperty(animatedMarginPropertyName, marginTo);
615 startTime = window.performance.now();
616 } else if (window.performance.now() < startTime + animationTime) {
617 // Process regular animation frame.
Tim van der Lippe1d6e57a2019-09-30 11:55:34618 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37619 this._mainWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34620 }
Blink Reformat4c46d092018-04-07 15:32:37621 } else {
622 // Complete animation.
623 this._cancelAnimation();
Tim van der Lippe1d6e57a2019-09-30 11:55:34624 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37625 this._mainWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34626 }
Tim van der Lippe0830b3d2019-10-03 13:20:07627 this.dispatchEventToListeners(SplitWidget.Events.SidebarSizeChanged, this.sidebarSize());
Blink Reformat4c46d092018-04-07 15:32:37628 return;
629 }
630 this._animationFrameHandle = this.contentElement.window().requestAnimationFrame(boundAnimationFrame);
631 }
632 this._animationFrameHandle = this.contentElement.window().requestAnimationFrame(boundAnimationFrame);
633 }
634
635 _cancelAnimation() {
636 this.contentElement.style.removeProperty('margin-top');
637 this.contentElement.style.removeProperty('margin-right');
638 this.contentElement.style.removeProperty('margin-bottom');
639 this.contentElement.style.removeProperty('margin-left');
640 this.contentElement.style.removeProperty('transition');
641
642 if (this._animationFrameHandle) {
643 this.contentElement.window().cancelAnimationFrame(this._animationFrameHandle);
644 this._animationFrameHandle = 0;
645 }
646 if (this._animationCallback) {
647 this._animationCallback();
648 this._animationCallback = null;
649 }
650 }
651
652 /**
653 * @param {number} sidebarSize
654 * @param {boolean=} userAction
655 * @return {number}
656 */
657 _applyConstraints(sidebarSize, userAction) {
658 const totalSize = this._totalSizeDIP();
Paul Lewis50993692020-01-23 15:22:26659 const zoomFactor = this._constraintsInDip ? 1 : self.UI.zoomManager.zoomFactor();
Blink Reformat4c46d092018-04-07 15:32:37660
Paul Lewis9950e182019-12-16 16:06:07661 let constraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Blink Reformat4c46d092018-04-07 15:32:37662 let minSidebarSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34663 if (!minSidebarSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07664 minSidebarSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34665 }
Blink Reformat4c46d092018-04-07 15:32:37666 minSidebarSize *= zoomFactor;
Tim van der Lippe1d6e57a2019-09-30 11:55:34667 if (this._sidebarMinimized) {
Blink Reformat4c46d092018-04-07 15:32:37668 sidebarSize = minSidebarSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34669 }
Blink Reformat4c46d092018-04-07 15:32:37670
671 let preferredSidebarSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34672 if (!preferredSidebarSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07673 preferredSidebarSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34674 }
Blink Reformat4c46d092018-04-07 15:32:37675 preferredSidebarSize *= zoomFactor;
676 // Allow sidebar to be less than preferred by explicit user action.
Tim van der Lippe1d6e57a2019-09-30 11:55:34677 if (sidebarSize < preferredSidebarSize) {
Blink Reformat4c46d092018-04-07 15:32:37678 preferredSidebarSize = Math.max(sidebarSize, minSidebarSize);
Tim van der Lippe1d6e57a2019-09-30 11:55:34679 }
Blink Reformat4c46d092018-04-07 15:32:37680 preferredSidebarSize += zoomFactor; // 1 css pixel for splitter border.
681
Paul Lewis9950e182019-12-16 16:06:07682 constraints = this._mainWidget ? this._mainWidget.constraints() : new Constraints();
Blink Reformat4c46d092018-04-07 15:32:37683 let minMainSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34684 if (!minMainSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07685 minMainSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34686 }
Blink Reformat4c46d092018-04-07 15:32:37687 minMainSize *= zoomFactor;
688
689 let preferredMainSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34690 if (!preferredMainSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07691 preferredMainSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34692 }
Blink Reformat4c46d092018-04-07 15:32:37693 preferredMainSize *= zoomFactor;
694 const savedMainSize = this.isVertical() ? this._savedVerticalMainSize : this._savedHorizontalMainSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34695 if (savedMainSize !== null) {
Blink Reformat4c46d092018-04-07 15:32:37696 preferredMainSize = Math.min(preferredMainSize, savedMainSize * zoomFactor);
Tim van der Lippe1d6e57a2019-09-30 11:55:34697 }
698 if (userAction) {
Blink Reformat4c46d092018-04-07 15:32:37699 preferredMainSize = minMainSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34700 }
Blink Reformat4c46d092018-04-07 15:32:37701
702 // Enough space for preferred.
703 const totalPreferred = preferredMainSize + preferredSidebarSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34704 if (totalPreferred <= totalSize) {
Blink Reformat4c46d092018-04-07 15:32:37705 return Number.constrain(sidebarSize, preferredSidebarSize, totalSize - preferredMainSize);
Tim van der Lippe1d6e57a2019-09-30 11:55:34706 }
Blink Reformat4c46d092018-04-07 15:32:37707
708 // Enough space for minimum.
709 if (minMainSize + minSidebarSize <= totalSize) {
710 const delta = totalPreferred - totalSize;
711 const sidebarDelta = delta * preferredSidebarSize / totalPreferred;
712 sidebarSize = preferredSidebarSize - sidebarDelta;
713 return Number.constrain(sidebarSize, minSidebarSize, totalSize - minMainSize);
714 }
715
716 // Not enough space even for minimum sizes.
717 return Math.max(0, totalSize - minMainSize);
718 }
719
720 /**
721 * @override
722 */
723 wasShown() {
724 this._forceUpdateLayout();
Paul Lewis50993692020-01-23 15:22:26725 self.UI.zoomManager.addEventListener(ZoomManagerEvents.ZoomChanged, this._onZoomChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37726 }
727
728 /**
729 * @override
730 */
731 willHide() {
Paul Lewis50993692020-01-23 15:22:26732 self.UI.zoomManager.removeEventListener(ZoomManagerEvents.ZoomChanged, this._onZoomChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37733 }
734
735 /**
736 * @override
737 */
738 onResize() {
739 this._updateLayout();
740 }
741
742 /**
743 * @override
744 */
745 onLayout() {
746 this._updateLayout();
747 }
748
749 /**
750 * @override
Paul Lewis9950e182019-12-16 16:06:07751 * @return {!Constraints}
Blink Reformat4c46d092018-04-07 15:32:37752 */
753 calculateConstraints() {
Tim van der Lippe0830b3d2019-10-03 13:20:07754 if (this._showMode === ShowMode.OnlyMain) {
Paul Lewis9950e182019-12-16 16:06:07755 return this._mainWidget ? this._mainWidget.constraints() : new Constraints();
Tim van der Lippe1d6e57a2019-09-30 11:55:34756 }
Tim van der Lippe0830b3d2019-10-03 13:20:07757 if (this._showMode === ShowMode.OnlySidebar) {
Paul Lewis9950e182019-12-16 16:06:07758 return this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Tim van der Lippe1d6e57a2019-09-30 11:55:34759 }
Blink Reformat4c46d092018-04-07 15:32:37760
Paul Lewis9950e182019-12-16 16:06:07761 let mainConstraints = this._mainWidget ? this._mainWidget.constraints() : new Constraints();
762 let sidebarConstraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Tim van der Lippe0830b3d2019-10-03 13:20:07763 const min = MinPadding;
Blink Reformat4c46d092018-04-07 15:32:37764 if (this._isVertical) {
765 mainConstraints = mainConstraints.widthToMax(min).addWidth(1); // 1 for splitter
766 sidebarConstraints = sidebarConstraints.widthToMax(min);
767 return mainConstraints.addWidth(sidebarConstraints).heightToMax(sidebarConstraints);
768 } else {
769 mainConstraints = mainConstraints.heightToMax(min).addHeight(1); // 1 for splitter
770 sidebarConstraints = sidebarConstraints.heightToMax(min);
771 return mainConstraints.widthToMax(sidebarConstraints).addHeight(sidebarConstraints);
772 }
773 }
774
775 /**
Tim van der Lippec02a97c2020-02-14 14:39:27776 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37777 */
778 _onResizeStart(event) {
779 this._resizeStartSizeDIP = this._sidebarSizeDIP;
780 }
781
782 /**
Tim van der Lippec02a97c2020-02-14 14:39:27783 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37784 */
785 _onResizeUpdate(event) {
786 const offset = event.data.currentPosition - event.data.startPosition;
Paul Lewis50993692020-01-23 15:22:26787 const offsetDIP = self.UI.zoomManager.cssToDIP(offset);
Blink Reformat4c46d092018-04-07 15:32:37788 const newSizeDIP =
789 this._secondIsSidebar ? this._resizeStartSizeDIP - offsetDIP : this._resizeStartSizeDIP + offsetDIP;
790 const constrainedSizeDIP = this._applyConstraints(newSizeDIP, true);
791 this._savedSidebarSizeDIP = constrainedSizeDIP;
792 this._saveSetting();
793 this._innerSetSidebarSizeDIP(constrainedSizeDIP, false, true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34794 if (this.isVertical()) {
Blink Reformat4c46d092018-04-07 15:32:37795 this._savedVerticalMainSize = this._totalSizeDIP() - this._sidebarSizeDIP;
Tim van der Lippe1d6e57a2019-09-30 11:55:34796 } else {
Blink Reformat4c46d092018-04-07 15:32:37797 this._savedHorizontalMainSize = this._totalSizeDIP() - this._sidebarSizeDIP;
Tim van der Lippe1d6e57a2019-09-30 11:55:34798 }
Blink Reformat4c46d092018-04-07 15:32:37799 }
800
801 /**
Tim van der Lippec02a97c2020-02-14 14:39:27802 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37803 */
804 _onResizeEnd(event) {
805 this._resizeStartSizeDIP = 0;
806 }
807
808 /**
809 * @param {boolean=} noSplitter
810 */
811 hideDefaultResizer(noSplitter) {
812 this.uninstallResizer(this._resizerElement);
Pavel Feldmanc9060ea2018-04-30 04:42:18813 this._sidebarElement.classList.toggle('no-default-splitter', !!noSplitter);
Blink Reformat4c46d092018-04-07 15:32:37814 }
815
816 /**
817 * @param {!Element} resizerElement
818 */
819 installResizer(resizerElement) {
820 this._resizerWidget.addElement(resizerElement);
821 }
822
823 /**
824 * @param {!Element} resizerElement
825 */
826 uninstallResizer(resizerElement) {
827 this._resizerWidget.removeElement(resizerElement);
828 }
829
830 /**
831 * @return {boolean}
832 */
833 hasCustomResizer() {
834 const elements = this._resizerWidget.elements();
835 return elements.length > 1 || (elements.length === 1 && elements[0] !== this._resizerElement);
836 }
837
838 /**
839 * @param {!Element} resizer
840 * @param {boolean} on
841 */
842 toggleResizer(resizer, on) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34843 if (on) {
Blink Reformat4c46d092018-04-07 15:32:37844 this.installResizer(resizer);
Tim van der Lippe1d6e57a2019-09-30 11:55:34845 } else {
Blink Reformat4c46d092018-04-07 15:32:37846 this.uninstallResizer(resizer);
Tim van der Lippe1d6e57a2019-09-30 11:55:34847 }
Blink Reformat4c46d092018-04-07 15:32:37848 }
849
850 /**
Tim van der Lippeaa76aa22020-02-14 14:38:24851 * @return {?SettingForOrientation}
Blink Reformat4c46d092018-04-07 15:32:37852 */
853 _settingForOrientation() {
854 const state = this._setting ? this._setting.get() : {};
855 return this._isVertical ? state.vertical : state.horizontal;
856 }
857
858 /**
859 * @return {number}
860 */
861 _preferredSidebarSizeDIP() {
862 let size = this._savedSidebarSizeDIP;
863 if (!size) {
864 size = this._isVertical ? this._defaultSidebarWidth : this._defaultSidebarHeight;
865 // If we have default value in percents, calculate it on first use.
Tim van der Lippe1d6e57a2019-09-30 11:55:34866 if (0 < size && size < 1) {
Blink Reformat4c46d092018-04-07 15:32:37867 size *= this._totalSizeDIP();
Tim van der Lippe1d6e57a2019-09-30 11:55:34868 }
Blink Reformat4c46d092018-04-07 15:32:37869 }
870 return size;
871 }
872
873 _restoreSidebarSizeFromSettings() {
874 const settingForOrientation = this._settingForOrientation();
875 this._savedSidebarSizeDIP = settingForOrientation ? settingForOrientation.size : 0;
876 }
877
878 _restoreAndApplyShowModeFromSettings() {
879 const orientationState = this._settingForOrientation();
880 this._savedShowMode = orientationState && orientationState.showMode ? orientationState.showMode : this._showMode;
881 this._showMode = this._savedShowMode;
882
883 switch (this._savedShowMode) {
Tim van der Lippe0830b3d2019-10-03 13:20:07884 case ShowMode.Both:
Blink Reformat4c46d092018-04-07 15:32:37885 this.showBoth();
886 break;
Tim van der Lippe0830b3d2019-10-03 13:20:07887 case ShowMode.OnlyMain:
Blink Reformat4c46d092018-04-07 15:32:37888 this.hideSidebar();
889 break;
Tim van der Lippe0830b3d2019-10-03 13:20:07890 case ShowMode.OnlySidebar:
Blink Reformat4c46d092018-04-07 15:32:37891 this.hideMain();
892 break;
893 }
894 }
895
896 _saveShowModeToSettings() {
897 this._savedShowMode = this._showMode;
898 this._saveSetting();
899 }
900
901 _saveSetting() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34902 if (!this._setting) {
Blink Reformat4c46d092018-04-07 15:32:37903 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34904 }
Blink Reformat4c46d092018-04-07 15:32:37905 const state = this._setting.get();
906 const orientationState = (this._isVertical ? state.vertical : state.horizontal) || {};
907
908 orientationState.size = this._savedSidebarSizeDIP;
Tim van der Lippe1d6e57a2019-09-30 11:55:34909 if (this._shouldSaveShowMode) {
Blink Reformat4c46d092018-04-07 15:32:37910 orientationState.showMode = this._savedShowMode;
Tim van der Lippe1d6e57a2019-09-30 11:55:34911 }
Blink Reformat4c46d092018-04-07 15:32:37912
Tim van der Lippe1d6e57a2019-09-30 11:55:34913 if (this._isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37914 state.vertical = orientationState;
Tim van der Lippe1d6e57a2019-09-30 11:55:34915 } else {
Blink Reformat4c46d092018-04-07 15:32:37916 state.horizontal = orientationState;
Tim van der Lippe1d6e57a2019-09-30 11:55:34917 }
Blink Reformat4c46d092018-04-07 15:32:37918 this._setting.set(state);
919 }
920
921 _forceUpdateLayout() {
922 // Force layout even if sidebar size does not change.
923 this._sidebarSizeDIP = -1;
924 this._updateLayout();
925 }
926
927 /**
Tim van der Lippec02a97c2020-02-14 14:39:27928 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37929 */
930 _onZoomChanged(event) {
931 this._forceUpdateLayout();
932 }
933
934 /**
935 * @param {string} title
Paul Lewis9950e182019-12-16 16:06:07936 * @return {!ToolbarButton}
Blink Reformat4c46d092018-04-07 15:32:37937 */
938 createShowHideSidebarButton(title) {
Mandy Chen84d56b62019-09-03 18:21:18939 this._showHideSidebarButtonTitle = title;
Paul Lewis9950e182019-12-16 16:06:07940 this._showHideSidebarButton = new ToolbarButton('', '');
941 this._showHideSidebarButton.addEventListener(ToolbarButton.Events.Click, buttonClicked, this);
Blink Reformat4c46d092018-04-07 15:32:37942 this._updateShowHideSidebarButton();
943
944 /**
Tim van der Lippec02a97c2020-02-14 14:39:27945 * @param {!Common.EventTarget.EventTargetEvent} event
Tim van der Lippe0830b3d2019-10-03 13:20:07946 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37947 */
948 function buttonClicked(event) {
Tim van der Lippe0830b3d2019-10-03 13:20:07949 if (this._showMode !== ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37950 this.showBoth(true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34951 } else {
Blink Reformat4c46d092018-04-07 15:32:37952 this.hideSidebar(true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34953 }
Blink Reformat4c46d092018-04-07 15:32:37954 }
955
956 return this._showHideSidebarButton;
957 }
958
959 _updateShowHideSidebarButton() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34960 if (!this._showHideSidebarButton) {
Blink Reformat4c46d092018-04-07 15:32:37961 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34962 }
Tim van der Lippe0830b3d2019-10-03 13:20:07963 const sidebarHidden = this._showMode === ShowMode.OnlyMain;
Blink Reformat4c46d092018-04-07 15:32:37964 let glyph = '';
965 if (sidebarHidden) {
966 glyph = this.isVertical() ?
967 (this.isSidebarSecond() ? 'largeicon-show-right-sidebar' : 'largeicon-show-left-sidebar') :
968 (this.isSidebarSecond() ? 'largeicon-show-bottom-sidebar' : 'largeicon-show-top-sidebar');
969 } else {
970 glyph = this.isVertical() ?
971 (this.isSidebarSecond() ? 'largeicon-hide-right-sidebar' : 'largeicon-hide-left-sidebar') :
972 (this.isSidebarSecond() ? 'largeicon-hide-bottom-sidebar' : 'largeicon-hide-top-sidebar');
973 }
974 this._showHideSidebarButton.setGlyph(glyph);
975 this._showHideSidebarButton.setTitle(
Paul Lewis17e384e2020-01-08 15:46:51976 sidebarHidden ? Common.UIString.UIString('Show %s', this._showHideSidebarButtonTitle) :
977 Common.UIString.UIString('Hide %s', this._showHideSidebarButtonTitle));
Blink Reformat4c46d092018-04-07 15:32:37978 }
Tim van der Lippe0830b3d2019-10-03 13:20:07979}
Blink Reformat4c46d092018-04-07 15:32:37980
Tim van der Lippe0830b3d2019-10-03 13:20:07981export const ShowMode = {
Blink Reformat4c46d092018-04-07 15:32:37982 Both: 'Both',
983 OnlyMain: 'OnlyMain',
984 OnlySidebar: 'OnlySidebar'
985};
986
987/** @enum {symbol} */
Tim van der Lippe0830b3d2019-10-03 13:20:07988export const Events = {
Blink Reformat4c46d092018-04-07 15:32:37989 SidebarSizeChanged: Symbol('SidebarSizeChanged'),
990 ShowModeChanged: Symbol('ShowModeChanged')
991};
992
Tim van der Lippec96ccd92019-11-29 16:23:54993const MinPadding = 20;
Tim van der Lippeaa76aa22020-02-14 14:38:24994
995/** @typedef {{showMode: string, size: number}} */
996export let SettingForOrientation;