blob: e1424562d072b1fea18f634bc213b8779ec61e8b [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
Tim van der Lippeee97fa32020-04-23 15:20:5631// @ts-nocheck
32// TODO(crbug.com/1011811): Enable TypeScript compiler checks
33
Paul Lewis17e384e2020-01-08 15:46:5134import * as Common from '../common/common.js';
Jack Franklin1be909c2020-03-04 08:57:4135import * as Platform from '../platform/platform.js';
Tim van der Lippeaa76aa22020-02-14 14:38:2436
Paul Lewis9950e182019-12-16 16:06:0737import {Constraints} from './Geometry.js';
38import {Events as ResizerWidgetEvents, SimpleResizerWidget} from './ResizerWidget.js';
39import {ToolbarButton} from './Toolbar.js';
40import {Widget} from './Widget.js';
Paul Lewis6c914a12020-03-19 11:23:2141import {Events as ZoomManagerEvents, ZoomManager} from './ZoomManager.js';
Paul Lewis9950e182019-12-16 16:06:0742
Sigurd Schneider46da7db2020-05-20 13:45:1143
Paul Lewis9950e182019-12-16 16:06:0744export class SplitWidget extends Widget {
Blink Reformat4c46d092018-04-07 15:32:3745 /**
46 * @param {boolean} isVertical
47 * @param {boolean} secondIsSidebar
48 * @param {string=} settingName
49 * @param {number=} defaultSidebarWidth
50 * @param {number=} defaultSidebarHeight
51 * @param {boolean=} constraintsInDip
52 */
53 constructor(isVertical, secondIsSidebar, settingName, defaultSidebarWidth, defaultSidebarHeight, constraintsInDip) {
54 super(true);
55 this.element.classList.add('split-widget');
Jack Franklin71519f82020-11-03 12:08:5956 this.registerRequiredCSS('ui/splitWidget.css', {enableLegacyPatching: true});
Blink Reformat4c46d092018-04-07 15:32:3757
58 this.contentElement.classList.add('shadow-split-widget');
Joel Einbinder27131b22019-03-14 09:29:5459 this._sidebarElement =
60 this.contentElement.createChild('div', 'shadow-split-widget-contents shadow-split-widget-sidebar vbox');
Blink Reformat4c46d092018-04-07 15:32:3761 this._mainElement =
62 this.contentElement.createChild('div', 'shadow-split-widget-contents shadow-split-widget-main vbox');
Joel Einbinder7fbe24c2019-01-24 05:19:0163 this._mainElement.createChild('slot').name = 'insertion-point-main';
Joel Einbinder7fbe24c2019-01-24 05:19:0164 this._sidebarElement.createChild('slot').name = 'insertion-point-sidebar';
Blink Reformat4c46d092018-04-07 15:32:3765 this._resizerElement = this.contentElement.createChild('div', 'shadow-split-widget-resizer');
66 this._resizerElementSize = null;
67
Paul Lewis9950e182019-12-16 16:06:0768 this._resizerWidget = new SimpleResizerWidget();
Blink Reformat4c46d092018-04-07 15:32:3769 this._resizerWidget.setEnabled(true);
Paul Lewis9950e182019-12-16 16:06:0770 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeStart, this._onResizeStart, this);
71 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeUpdate, this._onResizeUpdate, this);
72 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeEnd, this._onResizeEnd, this);
Blink Reformat4c46d092018-04-07 15:32:3773
74 this._defaultSidebarWidth = defaultSidebarWidth || 200;
75 this._defaultSidebarHeight = defaultSidebarHeight || this._defaultSidebarWidth;
76 this._constraintsInDip = !!constraintsInDip;
77 this._resizeStartSizeDIP = 0;
Paul Lewis2d7d65c2020-03-16 17:26:3078 this._setting = settingName ? Common.Settings.Settings.instance().createSetting(settingName, {}) : null;
Blink Reformat4c46d092018-04-07 15:32:3779
80 this._totalSizeCSS = 0;
81 this._totalSizeOtherDimensionCSS = 0;
Paul Lewis9950e182019-12-16 16:06:0782 /** @type {?Widget} */
Blink Reformat4c46d092018-04-07 15:32:3783 this._mainWidget = null;
Paul Lewis9950e182019-12-16 16:06:0784 /** @type {?Widget} */
Blink Reformat4c46d092018-04-07 15:32:3785 this._sidebarWidget = null;
86 this._animationFrameHandle = 0;
Tim van der Lippeee97fa32020-04-23 15:20:5687 /** @type {?function():void} */
Blink Reformat4c46d092018-04-07 15:32:3788 this._animationCallback = null;
89 this._showHideSidebarButtonTitle = '';
Paul Lewis9950e182019-12-16 16:06:0790 /** @type {?ToolbarButton} */
Blink Reformat4c46d092018-04-07 15:32:3791 this._showHideSidebarButton = null;
92 this._isVertical = false;
93 this._sidebarMinimized = false;
94 this._detaching = false;
95 this._sidebarSizeDIP = -1;
96 this._savedSidebarSizeDIP = this._sidebarSizeDIP;
97 this._secondIsSidebar = false;
98 this._shouldSaveShowMode = false;
99 /** @type {?number} */
100 this._savedVerticalMainSize = null;
101 /** @type {?number} */
102 this._savedHorizontalMainSize = null;
103
104 this.setSecondIsSidebar(secondIsSidebar);
105
106 this._innerSetVertical(isVertical);
Tim van der Lippe0830b3d2019-10-03 13:20:07107 this._showMode = ShowMode.Both;
Blink Reformat4c46d092018-04-07 15:32:37108 this._savedShowMode = this._showMode;
109
110 // Should be called after isVertical has the right value.
111 this.installResizer(this._resizerElement);
112 }
113
114 /**
115 * @return {boolean}
116 */
117 isVertical() {
118 return this._isVertical;
119 }
120
121 /**
122 * @param {boolean} isVertical
123 */
124 setVertical(isVertical) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34125 if (this._isVertical === isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37126 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34127 }
Blink Reformat4c46d092018-04-07 15:32:37128
129 this._innerSetVertical(isVertical);
130
Tim van der Lippe1d6e57a2019-09-30 11:55:34131 if (this.isShowing()) {
Blink Reformat4c46d092018-04-07 15:32:37132 this._updateLayout();
Tim van der Lippe1d6e57a2019-09-30 11:55:34133 }
Blink Reformat4c46d092018-04-07 15:32:37134 }
135
136 /**
137 * @param {boolean} isVertical
138 */
139 _innerSetVertical(isVertical) {
140 this.contentElement.classList.toggle('vbox', !isVertical);
141 this.contentElement.classList.toggle('hbox', isVertical);
142 this._isVertical = isVertical;
143
144 this._resizerElementSize = null;
145 this._sidebarSizeDIP = -1;
146 this._restoreSidebarSizeFromSettings();
Tim van der Lippe1d6e57a2019-09-30 11:55:34147 if (this._shouldSaveShowMode) {
Blink Reformat4c46d092018-04-07 15:32:37148 this._restoreAndApplyShowModeFromSettings();
Tim van der Lippe1d6e57a2019-09-30 11:55:34149 }
Blink Reformat4c46d092018-04-07 15:32:37150 this._updateShowHideSidebarButton();
151 // FIXME: reverse SplitWidget.isVertical meaning.
152 this._resizerWidget.setVertical(!isVertical);
153 this.invalidateConstraints();
154 }
155
156 /**
157 * @param {boolean=} animate
158 */
159 _updateLayout(animate) {
160 this._totalSizeCSS = 0; // Lazy update.
161 this._totalSizeOtherDimensionCSS = 0;
162
163 // Remove properties that might affect total size calculation.
164 this._mainElement.style.removeProperty('width');
165 this._mainElement.style.removeProperty('height');
166 this._sidebarElement.style.removeProperty('width');
167 this._sidebarElement.style.removeProperty('height');
168
169 this._innerSetSidebarSizeDIP(this._preferredSidebarSizeDIP(), !!animate);
170 }
171
172 /**
Paul Lewis9950e182019-12-16 16:06:07173 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37174 */
175 setMainWidget(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34176 if (this._mainWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37177 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34178 }
Blink Reformat4c46d092018-04-07 15:32:37179 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34180 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37181 this._mainWidget.detach();
Tim van der Lippe1d6e57a2019-09-30 11:55:34182 }
Blink Reformat4c46d092018-04-07 15:32:37183 this._mainWidget = widget;
184 if (widget) {
Joel Einbinder7fbe24c2019-01-24 05:19:01185 widget.element.slot = 'insertion-point-main';
Tim van der Lippe0830b3d2019-10-03 13:20:07186 if (this._showMode === ShowMode.OnlyMain || this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37187 widget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34188 }
Blink Reformat4c46d092018-04-07 15:32:37189 }
190 this.resumeInvalidations();
191 }
192
193 /**
Paul Lewis9950e182019-12-16 16:06:07194 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37195 */
196 setSidebarWidget(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34197 if (this._sidebarWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37198 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34199 }
Blink Reformat4c46d092018-04-07 15:32:37200 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34201 if (this._sidebarWidget) {
Blink Reformat4c46d092018-04-07 15:32:37202 this._sidebarWidget.detach();
Tim van der Lippe1d6e57a2019-09-30 11:55:34203 }
Blink Reformat4c46d092018-04-07 15:32:37204 this._sidebarWidget = widget;
205 if (widget) {
Joel Einbinder7fbe24c2019-01-24 05:19:01206 widget.element.slot = 'insertion-point-sidebar';
Tim van der Lippe0830b3d2019-10-03 13:20:07207 if (this._showMode === ShowMode.OnlySidebar || this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37208 widget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34209 }
Blink Reformat4c46d092018-04-07 15:32:37210 }
211 this.resumeInvalidations();
212 }
213
214 /**
Paul Lewis9950e182019-12-16 16:06:07215 * @return {?Widget}
Blink Reformat4c46d092018-04-07 15:32:37216 */
217 mainWidget() {
218 return this._mainWidget;
219 }
220
221 /**
Paul Lewis9950e182019-12-16 16:06:07222 * @return {?Widget}
Blink Reformat4c46d092018-04-07 15:32:37223 */
224 sidebarWidget() {
225 return this._sidebarWidget;
226 }
227
228 /**
229 * @override
Paul Lewis9950e182019-12-16 16:06:07230 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37231 */
232 childWasDetached(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34233 if (this._detaching) {
Blink Reformat4c46d092018-04-07 15:32:37234 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34235 }
236 if (this._mainWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37237 this._mainWidget = null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34238 }
239 if (this._sidebarWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37240 this._sidebarWidget = null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34241 }
Blink Reformat4c46d092018-04-07 15:32:37242 this.invalidateConstraints();
243 }
244
245 /**
246 * @return {boolean}
247 */
248 isSidebarSecond() {
249 return this._secondIsSidebar;
250 }
251
252 enableShowModeSaving() {
253 this._shouldSaveShowMode = true;
254 this._restoreAndApplyShowModeFromSettings();
255 }
256
257 /**
258 * @return {string}
259 */
260 showMode() {
261 return this._showMode;
262 }
263
264 /**
265 * @param {boolean} secondIsSidebar
266 */
267 setSecondIsSidebar(secondIsSidebar) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34268 if (secondIsSidebar === this._secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54269 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34270 }
Blink Reformat4c46d092018-04-07 15:32:37271 this._secondIsSidebar = secondIsSidebar;
Joel Einbinder27131b22019-03-14 09:29:54272 if (!this._mainWidget || !this._mainWidget.shouldHideOnDetach()) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34273 if (secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54274 this.contentElement.insertBefore(this._mainElement, this._sidebarElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34275 } else {
Joel Einbinder27131b22019-03-14 09:29:54276 this.contentElement.insertBefore(this._mainElement, this._resizerElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34277 }
Joel Einbinder27131b22019-03-14 09:29:54278 } else if (!this._sidebarWidget || !this._sidebarWidget.shouldHideOnDetach()) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34279 if (secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54280 this.contentElement.insertBefore(this._sidebarElement, this._resizerElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34281 } else {
Joel Einbinder27131b22019-03-14 09:29:54282 this.contentElement.insertBefore(this._sidebarElement, this._mainElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34283 }
Joel Einbinder27131b22019-03-14 09:29:54284 } else {
285 console.error('Could not swap split widget side. Both children widgets contain iframes.');
286 this._secondIsSidebar = !secondIsSidebar;
287 }
Blink Reformat4c46d092018-04-07 15:32:37288 }
289
290 /**
291 * @return {?string}
292 */
293 sidebarSide() {
Tim van der Lippe0830b3d2019-10-03 13:20:07294 if (this._showMode !== ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37295 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34296 }
Blink Reformat4c46d092018-04-07 15:32:37297 return this._isVertical ? (this._secondIsSidebar ? 'right' : 'left') : (this._secondIsSidebar ? 'bottom' : 'top');
298 }
299
300 /**
301 * @return {!Element}
302 */
303 resizerElement() {
304 return this._resizerElement;
305 }
306
307 /**
308 * @param {boolean=} animate
309 */
310 hideMain(animate) {
311 this._showOnly(this._sidebarWidget, this._mainWidget, this._sidebarElement, this._mainElement, animate);
Tim van der Lippe0830b3d2019-10-03 13:20:07312 this._updateShowMode(ShowMode.OnlySidebar);
Blink Reformat4c46d092018-04-07 15:32:37313 }
314
315 /**
316 * @param {boolean=} animate
317 */
318 hideSidebar(animate) {
319 this._showOnly(this._mainWidget, this._sidebarWidget, this._mainElement, this._sidebarElement, animate);
Tim van der Lippe0830b3d2019-10-03 13:20:07320 this._updateShowMode(ShowMode.OnlyMain);
Blink Reformat4c46d092018-04-07 15:32:37321 }
322
323 /**
324 * @param {boolean} minimized
325 */
326 setSidebarMinimized(minimized) {
327 this._sidebarMinimized = minimized;
328 this.invalidateConstraints();
329 }
330
331 /**
332 * @return {boolean}
333 */
334 isSidebarMinimized() {
335 return this._sidebarMinimized;
336 }
337
338 /**
Paul Lewis9950e182019-12-16 16:06:07339 * @param {?Widget} sideToShow
Tim van der Lippeaa76aa22020-02-14 14:38:24340 * @param {?Widget} sideToHide
Blink Reformat4c46d092018-04-07 15:32:37341 * @param {!Element} shadowToShow
342 * @param {!Element} shadowToHide
343 * @param {boolean=} animate
344 */
345 _showOnly(sideToShow, sideToHide, shadowToShow, shadowToHide, animate) {
346 this._cancelAnimation();
347
348 /**
Tim van der Lippe0830b3d2019-10-03 13:20:07349 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37350 */
351 function callback() {
352 if (sideToShow) {
353 // Make sure main is first in the children list.
Tim van der Lippe1d6e57a2019-09-30 11:55:34354 if (sideToShow === this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37355 this._mainWidget.show(this.element, this._sidebarWidget ? this._sidebarWidget.element : null);
Tim van der Lippe1d6e57a2019-09-30 11:55:34356 } else {
Blink Reformat4c46d092018-04-07 15:32:37357 this._sidebarWidget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34358 }
Blink Reformat4c46d092018-04-07 15:32:37359 }
360 if (sideToHide) {
361 this._detaching = true;
362 sideToHide.detach();
363 this._detaching = false;
364 }
365
366 this._resizerElement.classList.add('hidden');
367 shadowToShow.classList.remove('hidden');
368 shadowToShow.classList.add('maximized');
369 shadowToHide.classList.add('hidden');
370 shadowToHide.classList.remove('maximized');
371 this._removeAllLayoutProperties();
372 this.doResize();
373 this._showFinishedForTest();
374 }
375
Tim van der Lippe1d6e57a2019-09-30 11:55:34376 if (animate) {
Blink Reformat4c46d092018-04-07 15:32:37377 this._animate(true, callback.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34378 } else {
Blink Reformat4c46d092018-04-07 15:32:37379 callback.call(this);
Tim van der Lippe1d6e57a2019-09-30 11:55:34380 }
Blink Reformat4c46d092018-04-07 15:32:37381
382 this._sidebarSizeDIP = -1;
383 this.setResizable(false);
384 }
385
386 _showFinishedForTest() {
387 // This method is sniffed in tests.
388 }
389
390 _removeAllLayoutProperties() {
391 this._sidebarElement.style.removeProperty('flexBasis');
392
393 this._mainElement.style.removeProperty('width');
394 this._mainElement.style.removeProperty('height');
395 this._sidebarElement.style.removeProperty('width');
396 this._sidebarElement.style.removeProperty('height');
397
398 this._resizerElement.style.removeProperty('left');
399 this._resizerElement.style.removeProperty('right');
400 this._resizerElement.style.removeProperty('top');
401 this._resizerElement.style.removeProperty('bottom');
402
403 this._resizerElement.style.removeProperty('margin-left');
404 this._resizerElement.style.removeProperty('margin-right');
405 this._resizerElement.style.removeProperty('margin-top');
406 this._resizerElement.style.removeProperty('margin-bottom');
407 }
408
409 /**
410 * @param {boolean=} animate
411 */
412 showBoth(animate) {
Tim van der Lippe0830b3d2019-10-03 13:20:07413 if (this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37414 animate = false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34415 }
Blink Reformat4c46d092018-04-07 15:32:37416
417 this._cancelAnimation();
418 this._mainElement.classList.remove('maximized', 'hidden');
419 this._sidebarElement.classList.remove('maximized', 'hidden');
420 this._resizerElement.classList.remove('hidden');
421 this.setResizable(true);
422
423 // Make sure main is the first in the children list.
424 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34425 if (this._sidebarWidget) {
Blink Reformat4c46d092018-04-07 15:32:37426 this._sidebarWidget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34427 }
428 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37429 this._mainWidget.show(this.element, this._sidebarWidget ? this._sidebarWidget.element : null);
Tim van der Lippe1d6e57a2019-09-30 11:55:34430 }
Blink Reformat4c46d092018-04-07 15:32:37431 this.resumeInvalidations();
432 // Order widgets in DOM properly.
433 this.setSecondIsSidebar(this._secondIsSidebar);
434
435 this._sidebarSizeDIP = -1;
Tim van der Lippe0830b3d2019-10-03 13:20:07436 this._updateShowMode(ShowMode.Both);
Blink Reformat4c46d092018-04-07 15:32:37437 this._updateLayout(animate);
438 }
439
440 /**
441 * @param {boolean} resizable
442 */
443 setResizable(resizable) {
444 this._resizerWidget.setEnabled(resizable);
445 }
446
447 /**
448 * @return {boolean}
449 */
450 isResizable() {
451 return this._resizerWidget.isEnabled();
452 }
453
454 /**
455 * @param {number} size
456 */
457 setSidebarSize(size) {
Paul Lewis6c914a12020-03-19 11:23:21458 const sizeDIP = ZoomManager.instance().cssToDIP(size);
Blink Reformat4c46d092018-04-07 15:32:37459 this._savedSidebarSizeDIP = sizeDIP;
460 this._saveSetting();
461 this._innerSetSidebarSizeDIP(sizeDIP, false, true);
462 }
463
464 /**
465 * @return {number}
466 */
467 sidebarSize() {
468 const sizeDIP = Math.max(0, this._sidebarSizeDIP);
Paul Lewis6c914a12020-03-19 11:23:21469 return ZoomManager.instance().dipToCSS(sizeDIP);
Blink Reformat4c46d092018-04-07 15:32:37470 }
471
472 /**
473 * Returns total size in DIP.
474 * @return {number}
475 */
476 _totalSizeDIP() {
477 if (!this._totalSizeCSS) {
478 this._totalSizeCSS = this._isVertical ? this.contentElement.offsetWidth : this.contentElement.offsetHeight;
479 this._totalSizeOtherDimensionCSS =
480 this._isVertical ? this.contentElement.offsetHeight : this.contentElement.offsetWidth;
481 }
Paul Lewis6c914a12020-03-19 11:23:21482 return ZoomManager.instance().cssToDIP(this._totalSizeCSS);
Blink Reformat4c46d092018-04-07 15:32:37483 }
484
485 /**
486 * @param {string} showMode
487 */
488 _updateShowMode(showMode) {
489 this._showMode = showMode;
490 this._saveShowModeToSettings();
491 this._updateShowHideSidebarButton();
Tim van der Lippe3fffd0d2020-03-27 15:47:51492 this.dispatchEventToListeners(Events.ShowModeChanged, showMode);
Blink Reformat4c46d092018-04-07 15:32:37493 this.invalidateConstraints();
494 }
495
496 /**
497 * @param {number} sizeDIP
498 * @param {boolean} animate
499 * @param {boolean=} userAction
500 */
501 _innerSetSidebarSizeDIP(sizeDIP, animate, userAction) {
Tim van der Lippe0830b3d2019-10-03 13:20:07502 if (this._showMode !== ShowMode.Both || !this.isShowing()) {
Blink Reformat4c46d092018-04-07 15:32:37503 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34504 }
Blink Reformat4c46d092018-04-07 15:32:37505
506 sizeDIP = this._applyConstraints(sizeDIP, userAction);
Tim van der Lippe1d6e57a2019-09-30 11:55:34507 if (this._sidebarSizeDIP === sizeDIP) {
Blink Reformat4c46d092018-04-07 15:32:37508 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34509 }
Blink Reformat4c46d092018-04-07 15:32:37510
511 if (!this._resizerElementSize) {
512 this._resizerElementSize =
513 this._isVertical ? this._resizerElement.offsetWidth : this._resizerElement.offsetHeight;
514 }
515
516 // Invalidate layout below.
517
518 this._removeAllLayoutProperties();
519
520 // this._totalSizeDIP is available below since we successfully applied constraints.
Paul Lewis6c914a12020-03-19 11:23:21521 const roundSizeCSS = Math.round(ZoomManager.instance().dipToCSS(sizeDIP));
Blink Reformat4c46d092018-04-07 15:32:37522 const sidebarSizeValue = roundSizeCSS + 'px';
523 const mainSizeValue = (this._totalSizeCSS - roundSizeCSS) + 'px';
524 this._sidebarElement.style.flexBasis = sidebarSizeValue;
525
526 // Make both sides relayout boundaries.
527 if (this._isVertical) {
528 this._sidebarElement.style.width = sidebarSizeValue;
529 this._mainElement.style.width = mainSizeValue;
530 this._sidebarElement.style.height = this._totalSizeOtherDimensionCSS + 'px';
531 this._mainElement.style.height = this._totalSizeOtherDimensionCSS + 'px';
532 } else {
533 this._sidebarElement.style.height = sidebarSizeValue;
534 this._mainElement.style.height = mainSizeValue;
535 this._sidebarElement.style.width = this._totalSizeOtherDimensionCSS + 'px';
536 this._mainElement.style.width = this._totalSizeOtherDimensionCSS + 'px';
537 }
538
539 // Position resizer.
540 if (this._isVertical) {
541 if (this._secondIsSidebar) {
542 this._resizerElement.style.right = sidebarSizeValue;
543 this._resizerElement.style.marginRight = -this._resizerElementSize / 2 + 'px';
544 } else {
545 this._resizerElement.style.left = sidebarSizeValue;
546 this._resizerElement.style.marginLeft = -this._resizerElementSize / 2 + 'px';
547 }
548 } else {
549 if (this._secondIsSidebar) {
550 this._resizerElement.style.bottom = sidebarSizeValue;
551 this._resizerElement.style.marginBottom = -this._resizerElementSize / 2 + 'px';
552 } else {
553 this._resizerElement.style.top = sidebarSizeValue;
554 this._resizerElement.style.marginTop = -this._resizerElementSize / 2 + 'px';
555 }
556 }
557
558 this._sidebarSizeDIP = sizeDIP;
559
560 // Force layout.
561
562 if (animate) {
563 this._animate(false);
564 } else {
565 // No need to recalculate this._sidebarSizeDIP and this._totalSizeDIP again.
566 this.doResize();
Tim van der Lippe3fffd0d2020-03-27 15:47:51567 this.dispatchEventToListeners(Events.SidebarSizeChanged, this.sidebarSize());
Blink Reformat4c46d092018-04-07 15:32:37568 }
569 }
570
571 /**
572 * @param {boolean} reverse
Tim van der Lippe403a88d2020-05-13 11:51:32573 * @param {function():void=} callback
Blink Reformat4c46d092018-04-07 15:32:37574 */
575 _animate(reverse, callback) {
576 const animationTime = 50;
577 this._animationCallback = callback || null;
578
579 let animatedMarginPropertyName;
Tim van der Lippe1d6e57a2019-09-30 11:55:34580 if (this._isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37581 animatedMarginPropertyName = this._secondIsSidebar ? 'margin-right' : 'margin-left';
Tim van der Lippe1d6e57a2019-09-30 11:55:34582 } else {
Blink Reformat4c46d092018-04-07 15:32:37583 animatedMarginPropertyName = this._secondIsSidebar ? 'margin-bottom' : 'margin-top';
Tim van der Lippe1d6e57a2019-09-30 11:55:34584 }
Blink Reformat4c46d092018-04-07 15:32:37585
Paul Lewis6c914a12020-03-19 11:23:21586 const marginFrom = reverse ? '0' : '-' + ZoomManager.instance().dipToCSS(this._sidebarSizeDIP) + 'px';
587 const marginTo = reverse ? '-' + ZoomManager.instance().dipToCSS(this._sidebarSizeDIP) + 'px' : '0';
Blink Reformat4c46d092018-04-07 15:32:37588
589 // This order of things is important.
590 // 1. Resize main element early and force layout.
591 this.contentElement.style.setProperty(animatedMarginPropertyName, marginFrom);
592 if (!reverse) {
593 suppressUnused(this._mainElement.offsetWidth);
594 suppressUnused(this._sidebarElement.offsetWidth);
595 }
596
597 // 2. Issue onresize to the sidebar element, its size won't change.
Tim van der Lippe1d6e57a2019-09-30 11:55:34598 if (!reverse) {
Blink Reformat4c46d092018-04-07 15:32:37599 this._sidebarWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34600 }
Blink Reformat4c46d092018-04-07 15:32:37601
602 // 3. Configure and run animation
603 this.contentElement.style.setProperty('transition', animatedMarginPropertyName + ' ' + animationTime + 'ms linear');
604
605 const boundAnimationFrame = animationFrame.bind(this);
606 let startTime;
607 /**
Tim van der Lippe0830b3d2019-10-03 13:20:07608 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37609 */
610 function animationFrame() {
611 this._animationFrameHandle = 0;
612
613 if (!startTime) {
614 // Kick animation on first frame.
615 this.contentElement.style.setProperty(animatedMarginPropertyName, marginTo);
616 startTime = window.performance.now();
617 } else if (window.performance.now() < startTime + animationTime) {
618 // Process regular animation frame.
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 }
Blink Reformat4c46d092018-04-07 15:32:37622 } else {
623 // Complete animation.
624 this._cancelAnimation();
Tim van der Lippe1d6e57a2019-09-30 11:55:34625 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37626 this._mainWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34627 }
Tim van der Lippe3fffd0d2020-03-27 15:47:51628 this.dispatchEventToListeners(Events.SidebarSizeChanged, this.sidebarSize());
Blink Reformat4c46d092018-04-07 15:32:37629 return;
630 }
631 this._animationFrameHandle = this.contentElement.window().requestAnimationFrame(boundAnimationFrame);
632 }
633 this._animationFrameHandle = this.contentElement.window().requestAnimationFrame(boundAnimationFrame);
634 }
635
636 _cancelAnimation() {
637 this.contentElement.style.removeProperty('margin-top');
638 this.contentElement.style.removeProperty('margin-right');
639 this.contentElement.style.removeProperty('margin-bottom');
640 this.contentElement.style.removeProperty('margin-left');
641 this.contentElement.style.removeProperty('transition');
642
643 if (this._animationFrameHandle) {
644 this.contentElement.window().cancelAnimationFrame(this._animationFrameHandle);
645 this._animationFrameHandle = 0;
646 }
647 if (this._animationCallback) {
648 this._animationCallback();
649 this._animationCallback = null;
650 }
651 }
652
653 /**
654 * @param {number} sidebarSize
655 * @param {boolean=} userAction
656 * @return {number}
657 */
658 _applyConstraints(sidebarSize, userAction) {
659 const totalSize = this._totalSizeDIP();
Paul Lewis6c914a12020-03-19 11:23:21660 const zoomFactor = this._constraintsInDip ? 1 : ZoomManager.instance().zoomFactor();
Blink Reformat4c46d092018-04-07 15:32:37661
Paul Lewis9950e182019-12-16 16:06:07662 let constraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Blink Reformat4c46d092018-04-07 15:32:37663 let minSidebarSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34664 if (!minSidebarSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07665 minSidebarSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34666 }
Blink Reformat4c46d092018-04-07 15:32:37667 minSidebarSize *= zoomFactor;
Tim van der Lippe1d6e57a2019-09-30 11:55:34668 if (this._sidebarMinimized) {
Blink Reformat4c46d092018-04-07 15:32:37669 sidebarSize = minSidebarSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34670 }
Blink Reformat4c46d092018-04-07 15:32:37671
672 let preferredSidebarSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34673 if (!preferredSidebarSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07674 preferredSidebarSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34675 }
Blink Reformat4c46d092018-04-07 15:32:37676 preferredSidebarSize *= zoomFactor;
677 // Allow sidebar to be less than preferred by explicit user action.
Tim van der Lippe1d6e57a2019-09-30 11:55:34678 if (sidebarSize < preferredSidebarSize) {
Blink Reformat4c46d092018-04-07 15:32:37679 preferredSidebarSize = Math.max(sidebarSize, minSidebarSize);
Tim van der Lippe1d6e57a2019-09-30 11:55:34680 }
Blink Reformat4c46d092018-04-07 15:32:37681 preferredSidebarSize += zoomFactor; // 1 css pixel for splitter border.
682
Paul Lewis9950e182019-12-16 16:06:07683 constraints = this._mainWidget ? this._mainWidget.constraints() : new Constraints();
Blink Reformat4c46d092018-04-07 15:32:37684 let minMainSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34685 if (!minMainSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07686 minMainSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34687 }
Blink Reformat4c46d092018-04-07 15:32:37688 minMainSize *= zoomFactor;
689
690 let preferredMainSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34691 if (!preferredMainSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07692 preferredMainSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34693 }
Blink Reformat4c46d092018-04-07 15:32:37694 preferredMainSize *= zoomFactor;
695 const savedMainSize = this.isVertical() ? this._savedVerticalMainSize : this._savedHorizontalMainSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34696 if (savedMainSize !== null) {
Blink Reformat4c46d092018-04-07 15:32:37697 preferredMainSize = Math.min(preferredMainSize, savedMainSize * zoomFactor);
Tim van der Lippe1d6e57a2019-09-30 11:55:34698 }
699 if (userAction) {
Blink Reformat4c46d092018-04-07 15:32:37700 preferredMainSize = minMainSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34701 }
Blink Reformat4c46d092018-04-07 15:32:37702
703 // Enough space for preferred.
704 const totalPreferred = preferredMainSize + preferredSidebarSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34705 if (totalPreferred <= totalSize) {
Jack Franklin1be909c2020-03-04 08:57:41706 return Platform.NumberUtilities.clamp(sidebarSize, preferredSidebarSize, totalSize - preferredMainSize);
Tim van der Lippe1d6e57a2019-09-30 11:55:34707 }
Blink Reformat4c46d092018-04-07 15:32:37708
709 // Enough space for minimum.
710 if (minMainSize + minSidebarSize <= totalSize) {
711 const delta = totalPreferred - totalSize;
712 const sidebarDelta = delta * preferredSidebarSize / totalPreferred;
713 sidebarSize = preferredSidebarSize - sidebarDelta;
Jack Franklin1be909c2020-03-04 08:57:41714 return Platform.NumberUtilities.clamp(sidebarSize, minSidebarSize, totalSize - minMainSize);
Blink Reformat4c46d092018-04-07 15:32:37715 }
716
717 // Not enough space even for minimum sizes.
718 return Math.max(0, totalSize - minMainSize);
719 }
720
721 /**
722 * @override
723 */
724 wasShown() {
725 this._forceUpdateLayout();
Paul Lewis6c914a12020-03-19 11:23:21726 ZoomManager.instance().addEventListener(ZoomManagerEvents.ZoomChanged, this._onZoomChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37727 }
728
729 /**
730 * @override
731 */
732 willHide() {
Paul Lewis6c914a12020-03-19 11:23:21733 ZoomManager.instance().removeEventListener(ZoomManagerEvents.ZoomChanged, this._onZoomChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37734 }
735
736 /**
737 * @override
738 */
739 onResize() {
740 this._updateLayout();
741 }
742
743 /**
744 * @override
745 */
746 onLayout() {
747 this._updateLayout();
748 }
749
750 /**
751 * @override
Paul Lewis9950e182019-12-16 16:06:07752 * @return {!Constraints}
Blink Reformat4c46d092018-04-07 15:32:37753 */
754 calculateConstraints() {
Tim van der Lippe0830b3d2019-10-03 13:20:07755 if (this._showMode === ShowMode.OnlyMain) {
Paul Lewis9950e182019-12-16 16:06:07756 return this._mainWidget ? this._mainWidget.constraints() : new Constraints();
Tim van der Lippe1d6e57a2019-09-30 11:55:34757 }
Tim van der Lippe0830b3d2019-10-03 13:20:07758 if (this._showMode === ShowMode.OnlySidebar) {
Paul Lewis9950e182019-12-16 16:06:07759 return this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Tim van der Lippe1d6e57a2019-09-30 11:55:34760 }
Blink Reformat4c46d092018-04-07 15:32:37761
Paul Lewis9950e182019-12-16 16:06:07762 let mainConstraints = this._mainWidget ? this._mainWidget.constraints() : new Constraints();
763 let sidebarConstraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Tim van der Lippe0830b3d2019-10-03 13:20:07764 const min = MinPadding;
Blink Reformat4c46d092018-04-07 15:32:37765 if (this._isVertical) {
766 mainConstraints = mainConstraints.widthToMax(min).addWidth(1); // 1 for splitter
767 sidebarConstraints = sidebarConstraints.widthToMax(min);
768 return mainConstraints.addWidth(sidebarConstraints).heightToMax(sidebarConstraints);
Mathias Bynensf06e8c02020-02-28 13:58:28769 }
Blink Reformat4c46d092018-04-07 15:32:37770 mainConstraints = mainConstraints.heightToMax(min).addHeight(1); // 1 for splitter
771 sidebarConstraints = sidebarConstraints.heightToMax(min);
772 return mainConstraints.widthToMax(sidebarConstraints).addHeight(sidebarConstraints);
Blink Reformat4c46d092018-04-07 15:32:37773 }
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 Lewis6c914a12020-03-19 11:23:21787 const offsetDIP = ZoomManager.instance().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) {
Simon Zünd3141f412020-08-12 09:52:51820 this._resizerWidget.addElement(/** @type {!HTMLElement} */ (resizerElement));
Blink Reformat4c46d092018-04-07 15:32:37821 }
822
823 /**
824 * @param {!Element} resizerElement
825 */
826 uninstallResizer(resizerElement) {
Simon Zünd3141f412020-08-12 09:52:51827 this._resizerWidget.removeElement(/** @type {!HTMLElement} */ (resizerElement));
Blink Reformat4c46d092018-04-07 15:32:37828 }
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;