blob: c3ba175e76bd672cfed8abf1a9944e9697c46e1d [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';
Paul Lewis9950e182019-12-16 16:06:0732import {Constraints} from './Geometry.js';
33import {Events as ResizerWidgetEvents, SimpleResizerWidget} from './ResizerWidget.js';
34import {ToolbarButton} from './Toolbar.js';
35import {Widget} from './Widget.js';
36import {Events as ZoomManagerEvents} from './ZoomManager.js';
37
Blink Reformat4c46d092018-04-07 15:32:3738/**
39 * @unrestricted
40 */
Paul Lewis9950e182019-12-16 16:06:0741export class SplitWidget extends Widget {
Blink Reformat4c46d092018-04-07 15:32:3742 /**
43 * @param {boolean} isVertical
44 * @param {boolean} secondIsSidebar
45 * @param {string=} settingName
46 * @param {number=} defaultSidebarWidth
47 * @param {number=} defaultSidebarHeight
48 * @param {boolean=} constraintsInDip
49 */
50 constructor(isVertical, secondIsSidebar, settingName, defaultSidebarWidth, defaultSidebarHeight, constraintsInDip) {
51 super(true);
52 this.element.classList.add('split-widget');
53 this.registerRequiredCSS('ui/splitWidget.css');
54
55 this.contentElement.classList.add('shadow-split-widget');
Joel Einbinder27131b22019-03-14 09:29:5456 this._sidebarElement =
57 this.contentElement.createChild('div', 'shadow-split-widget-contents shadow-split-widget-sidebar vbox');
Blink Reformat4c46d092018-04-07 15:32:3758 this._mainElement =
59 this.contentElement.createChild('div', 'shadow-split-widget-contents shadow-split-widget-main vbox');
Joel Einbinder7fbe24c2019-01-24 05:19:0160 this._mainElement.createChild('slot').name = 'insertion-point-main';
Joel Einbinder7fbe24c2019-01-24 05:19:0161 this._sidebarElement.createChild('slot').name = 'insertion-point-sidebar';
Blink Reformat4c46d092018-04-07 15:32:3762 this._resizerElement = this.contentElement.createChild('div', 'shadow-split-widget-resizer');
63 this._resizerElementSize = null;
64
Paul Lewis9950e182019-12-16 16:06:0765 this._resizerWidget = new SimpleResizerWidget();
Blink Reformat4c46d092018-04-07 15:32:3766 this._resizerWidget.setEnabled(true);
Paul Lewis9950e182019-12-16 16:06:0767 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeStart, this._onResizeStart, this);
68 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeUpdate, this._onResizeUpdate, this);
69 this._resizerWidget.addEventListener(ResizerWidgetEvents.ResizeEnd, this._onResizeEnd, this);
Blink Reformat4c46d092018-04-07 15:32:3770
71 this._defaultSidebarWidth = defaultSidebarWidth || 200;
72 this._defaultSidebarHeight = defaultSidebarHeight || this._defaultSidebarWidth;
73 this._constraintsInDip = !!constraintsInDip;
74 this._resizeStartSizeDIP = 0;
Paul Lewis17e384e2020-01-08 15:46:5175 // Note: go via self.Common for globally-namespaced singletons.
Paul Lewis6bcdb182020-01-23 11:08:0576 this._setting = settingName ? self.self.Common.settings.createSetting(settingName, {}) : null;
Blink Reformat4c46d092018-04-07 15:32:3777
78 this._totalSizeCSS = 0;
79 this._totalSizeOtherDimensionCSS = 0;
Paul Lewis9950e182019-12-16 16:06:0780 /** @type {?Widget} */
Blink Reformat4c46d092018-04-07 15:32:3781 this._mainWidget = null;
Paul Lewis9950e182019-12-16 16:06:0782 /** @type {?Widget} */
Blink Reformat4c46d092018-04-07 15:32:3783 this._sidebarWidget = null;
84 this._animationFrameHandle = 0;
85 /** @type {?function()} */
86 this._animationCallback = null;
87 this._showHideSidebarButtonTitle = '';
Paul Lewis9950e182019-12-16 16:06:0788 /** @type {?ToolbarButton} */
Blink Reformat4c46d092018-04-07 15:32:3789 this._showHideSidebarButton = null;
90 this._isVertical = false;
91 this._sidebarMinimized = false;
92 this._detaching = false;
93 this._sidebarSizeDIP = -1;
94 this._savedSidebarSizeDIP = this._sidebarSizeDIP;
95 this._secondIsSidebar = false;
96 this._shouldSaveShowMode = false;
97 /** @type {?number} */
98 this._savedVerticalMainSize = null;
99 /** @type {?number} */
100 this._savedHorizontalMainSize = null;
101
102 this.setSecondIsSidebar(secondIsSidebar);
103
104 this._innerSetVertical(isVertical);
Tim van der Lippe0830b3d2019-10-03 13:20:07105 this._showMode = ShowMode.Both;
Blink Reformat4c46d092018-04-07 15:32:37106 this._savedShowMode = this._showMode;
107
108 // Should be called after isVertical has the right value.
109 this.installResizer(this._resizerElement);
110 }
111
112 /**
113 * @return {boolean}
114 */
115 isVertical() {
116 return this._isVertical;
117 }
118
119 /**
120 * @param {boolean} isVertical
121 */
122 setVertical(isVertical) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34123 if (this._isVertical === isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37124 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34125 }
Blink Reformat4c46d092018-04-07 15:32:37126
127 this._innerSetVertical(isVertical);
128
Tim van der Lippe1d6e57a2019-09-30 11:55:34129 if (this.isShowing()) {
Blink Reformat4c46d092018-04-07 15:32:37130 this._updateLayout();
Tim van der Lippe1d6e57a2019-09-30 11:55:34131 }
Blink Reformat4c46d092018-04-07 15:32:37132 }
133
134 /**
135 * @param {boolean} isVertical
136 */
137 _innerSetVertical(isVertical) {
138 this.contentElement.classList.toggle('vbox', !isVertical);
139 this.contentElement.classList.toggle('hbox', isVertical);
140 this._isVertical = isVertical;
141
142 this._resizerElementSize = null;
143 this._sidebarSizeDIP = -1;
144 this._restoreSidebarSizeFromSettings();
Tim van der Lippe1d6e57a2019-09-30 11:55:34145 if (this._shouldSaveShowMode) {
Blink Reformat4c46d092018-04-07 15:32:37146 this._restoreAndApplyShowModeFromSettings();
Tim van der Lippe1d6e57a2019-09-30 11:55:34147 }
Blink Reformat4c46d092018-04-07 15:32:37148 this._updateShowHideSidebarButton();
149 // FIXME: reverse SplitWidget.isVertical meaning.
150 this._resizerWidget.setVertical(!isVertical);
151 this.invalidateConstraints();
152 }
153
154 /**
155 * @param {boolean=} animate
156 */
157 _updateLayout(animate) {
158 this._totalSizeCSS = 0; // Lazy update.
159 this._totalSizeOtherDimensionCSS = 0;
160
161 // Remove properties that might affect total size calculation.
162 this._mainElement.style.removeProperty('width');
163 this._mainElement.style.removeProperty('height');
164 this._sidebarElement.style.removeProperty('width');
165 this._sidebarElement.style.removeProperty('height');
166
167 this._innerSetSidebarSizeDIP(this._preferredSidebarSizeDIP(), !!animate);
168 }
169
170 /**
Paul Lewis9950e182019-12-16 16:06:07171 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37172 */
173 setMainWidget(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34174 if (this._mainWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37175 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34176 }
Blink Reformat4c46d092018-04-07 15:32:37177 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34178 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37179 this._mainWidget.detach();
Tim van der Lippe1d6e57a2019-09-30 11:55:34180 }
Blink Reformat4c46d092018-04-07 15:32:37181 this._mainWidget = widget;
182 if (widget) {
Joel Einbinder7fbe24c2019-01-24 05:19:01183 widget.element.slot = 'insertion-point-main';
Tim van der Lippe0830b3d2019-10-03 13:20:07184 if (this._showMode === ShowMode.OnlyMain || this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37185 widget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34186 }
Blink Reformat4c46d092018-04-07 15:32:37187 }
188 this.resumeInvalidations();
189 }
190
191 /**
Paul Lewis9950e182019-12-16 16:06:07192 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37193 */
194 setSidebarWidget(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34195 if (this._sidebarWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37196 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34197 }
Blink Reformat4c46d092018-04-07 15:32:37198 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34199 if (this._sidebarWidget) {
Blink Reformat4c46d092018-04-07 15:32:37200 this._sidebarWidget.detach();
Tim van der Lippe1d6e57a2019-09-30 11:55:34201 }
Blink Reformat4c46d092018-04-07 15:32:37202 this._sidebarWidget = widget;
203 if (widget) {
Joel Einbinder7fbe24c2019-01-24 05:19:01204 widget.element.slot = 'insertion-point-sidebar';
Tim van der Lippe0830b3d2019-10-03 13:20:07205 if (this._showMode === ShowMode.OnlySidebar || this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37206 widget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34207 }
Blink Reformat4c46d092018-04-07 15:32:37208 }
209 this.resumeInvalidations();
210 }
211
212 /**
Paul Lewis9950e182019-12-16 16:06:07213 * @return {?Widget}
Blink Reformat4c46d092018-04-07 15:32:37214 */
215 mainWidget() {
216 return this._mainWidget;
217 }
218
219 /**
Paul Lewis9950e182019-12-16 16:06:07220 * @return {?Widget}
Blink Reformat4c46d092018-04-07 15:32:37221 */
222 sidebarWidget() {
223 return this._sidebarWidget;
224 }
225
226 /**
227 * @override
Paul Lewis9950e182019-12-16 16:06:07228 * @param {!Widget} widget
Blink Reformat4c46d092018-04-07 15:32:37229 */
230 childWasDetached(widget) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34231 if (this._detaching) {
Blink Reformat4c46d092018-04-07 15:32:37232 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34233 }
234 if (this._mainWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37235 this._mainWidget = null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34236 }
237 if (this._sidebarWidget === widget) {
Blink Reformat4c46d092018-04-07 15:32:37238 this._sidebarWidget = null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34239 }
Blink Reformat4c46d092018-04-07 15:32:37240 this.invalidateConstraints();
241 }
242
243 /**
244 * @return {boolean}
245 */
246 isSidebarSecond() {
247 return this._secondIsSidebar;
248 }
249
250 enableShowModeSaving() {
251 this._shouldSaveShowMode = true;
252 this._restoreAndApplyShowModeFromSettings();
253 }
254
255 /**
256 * @return {string}
257 */
258 showMode() {
259 return this._showMode;
260 }
261
262 /**
263 * @param {boolean} secondIsSidebar
264 */
265 setSecondIsSidebar(secondIsSidebar) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34266 if (secondIsSidebar === this._secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54267 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34268 }
Blink Reformat4c46d092018-04-07 15:32:37269 this._secondIsSidebar = secondIsSidebar;
Joel Einbinder27131b22019-03-14 09:29:54270 if (!this._mainWidget || !this._mainWidget.shouldHideOnDetach()) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34271 if (secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54272 this.contentElement.insertBefore(this._mainElement, this._sidebarElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34273 } else {
Joel Einbinder27131b22019-03-14 09:29:54274 this.contentElement.insertBefore(this._mainElement, this._resizerElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34275 }
Joel Einbinder27131b22019-03-14 09:29:54276 } else if (!this._sidebarWidget || !this._sidebarWidget.shouldHideOnDetach()) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34277 if (secondIsSidebar) {
Joel Einbinder27131b22019-03-14 09:29:54278 this.contentElement.insertBefore(this._sidebarElement, this._resizerElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34279 } else {
Joel Einbinder27131b22019-03-14 09:29:54280 this.contentElement.insertBefore(this._sidebarElement, this._mainElement);
Tim van der Lippe1d6e57a2019-09-30 11:55:34281 }
Joel Einbinder27131b22019-03-14 09:29:54282 } else {
283 console.error('Could not swap split widget side. Both children widgets contain iframes.');
284 this._secondIsSidebar = !secondIsSidebar;
285 }
Blink Reformat4c46d092018-04-07 15:32:37286 }
287
288 /**
289 * @return {?string}
290 */
291 sidebarSide() {
Tim van der Lippe0830b3d2019-10-03 13:20:07292 if (this._showMode !== ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37293 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34294 }
Blink Reformat4c46d092018-04-07 15:32:37295 return this._isVertical ? (this._secondIsSidebar ? 'right' : 'left') : (this._secondIsSidebar ? 'bottom' : 'top');
296 }
297
298 /**
299 * @return {!Element}
300 */
301 resizerElement() {
302 return this._resizerElement;
303 }
304
305 /**
306 * @param {boolean=} animate
307 */
308 hideMain(animate) {
309 this._showOnly(this._sidebarWidget, this._mainWidget, this._sidebarElement, this._mainElement, animate);
Tim van der Lippe0830b3d2019-10-03 13:20:07310 this._updateShowMode(ShowMode.OnlySidebar);
Blink Reformat4c46d092018-04-07 15:32:37311 }
312
313 /**
314 * @param {boolean=} animate
315 */
316 hideSidebar(animate) {
317 this._showOnly(this._mainWidget, this._sidebarWidget, this._mainElement, this._sidebarElement, animate);
Tim van der Lippe0830b3d2019-10-03 13:20:07318 this._updateShowMode(ShowMode.OnlyMain);
Blink Reformat4c46d092018-04-07 15:32:37319 }
320
321 /**
322 * @param {boolean} minimized
323 */
324 setSidebarMinimized(minimized) {
325 this._sidebarMinimized = minimized;
326 this.invalidateConstraints();
327 }
328
329 /**
330 * @return {boolean}
331 */
332 isSidebarMinimized() {
333 return this._sidebarMinimized;
334 }
335
336 /**
Paul Lewis9950e182019-12-16 16:06:07337 * @param {?Widget} sideToShow
Blink Reformat4c46d092018-04-07 15:32:37338 * @param {?UI.Widget} sideToHide
339 * @param {!Element} shadowToShow
340 * @param {!Element} shadowToHide
341 * @param {boolean=} animate
342 */
343 _showOnly(sideToShow, sideToHide, shadowToShow, shadowToHide, animate) {
344 this._cancelAnimation();
345
346 /**
Tim van der Lippe0830b3d2019-10-03 13:20:07347 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37348 */
349 function callback() {
350 if (sideToShow) {
351 // Make sure main is first in the children list.
Tim van der Lippe1d6e57a2019-09-30 11:55:34352 if (sideToShow === this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37353 this._mainWidget.show(this.element, this._sidebarWidget ? this._sidebarWidget.element : null);
Tim van der Lippe1d6e57a2019-09-30 11:55:34354 } else {
Blink Reformat4c46d092018-04-07 15:32:37355 this._sidebarWidget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34356 }
Blink Reformat4c46d092018-04-07 15:32:37357 }
358 if (sideToHide) {
359 this._detaching = true;
360 sideToHide.detach();
361 this._detaching = false;
362 }
363
364 this._resizerElement.classList.add('hidden');
365 shadowToShow.classList.remove('hidden');
366 shadowToShow.classList.add('maximized');
367 shadowToHide.classList.add('hidden');
368 shadowToHide.classList.remove('maximized');
369 this._removeAllLayoutProperties();
370 this.doResize();
371 this._showFinishedForTest();
372 }
373
Tim van der Lippe1d6e57a2019-09-30 11:55:34374 if (animate) {
Blink Reformat4c46d092018-04-07 15:32:37375 this._animate(true, callback.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34376 } else {
Blink Reformat4c46d092018-04-07 15:32:37377 callback.call(this);
Tim van der Lippe1d6e57a2019-09-30 11:55:34378 }
Blink Reformat4c46d092018-04-07 15:32:37379
380 this._sidebarSizeDIP = -1;
381 this.setResizable(false);
382 }
383
384 _showFinishedForTest() {
385 // This method is sniffed in tests.
386 }
387
388 _removeAllLayoutProperties() {
389 this._sidebarElement.style.removeProperty('flexBasis');
390
391 this._mainElement.style.removeProperty('width');
392 this._mainElement.style.removeProperty('height');
393 this._sidebarElement.style.removeProperty('width');
394 this._sidebarElement.style.removeProperty('height');
395
396 this._resizerElement.style.removeProperty('left');
397 this._resizerElement.style.removeProperty('right');
398 this._resizerElement.style.removeProperty('top');
399 this._resizerElement.style.removeProperty('bottom');
400
401 this._resizerElement.style.removeProperty('margin-left');
402 this._resizerElement.style.removeProperty('margin-right');
403 this._resizerElement.style.removeProperty('margin-top');
404 this._resizerElement.style.removeProperty('margin-bottom');
405 }
406
407 /**
408 * @param {boolean=} animate
409 */
410 showBoth(animate) {
Tim van der Lippe0830b3d2019-10-03 13:20:07411 if (this._showMode === ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37412 animate = false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34413 }
Blink Reformat4c46d092018-04-07 15:32:37414
415 this._cancelAnimation();
416 this._mainElement.classList.remove('maximized', 'hidden');
417 this._sidebarElement.classList.remove('maximized', 'hidden');
418 this._resizerElement.classList.remove('hidden');
419 this.setResizable(true);
420
421 // Make sure main is the first in the children list.
422 this.suspendInvalidations();
Tim van der Lippe1d6e57a2019-09-30 11:55:34423 if (this._sidebarWidget) {
Blink Reformat4c46d092018-04-07 15:32:37424 this._sidebarWidget.show(this.element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34425 }
426 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37427 this._mainWidget.show(this.element, this._sidebarWidget ? this._sidebarWidget.element : null);
Tim van der Lippe1d6e57a2019-09-30 11:55:34428 }
Blink Reformat4c46d092018-04-07 15:32:37429 this.resumeInvalidations();
430 // Order widgets in DOM properly.
431 this.setSecondIsSidebar(this._secondIsSidebar);
432
433 this._sidebarSizeDIP = -1;
Tim van der Lippe0830b3d2019-10-03 13:20:07434 this._updateShowMode(ShowMode.Both);
Blink Reformat4c46d092018-04-07 15:32:37435 this._updateLayout(animate);
436 }
437
438 /**
439 * @param {boolean} resizable
440 */
441 setResizable(resizable) {
442 this._resizerWidget.setEnabled(resizable);
443 }
444
445 /**
446 * @return {boolean}
447 */
448 isResizable() {
449 return this._resizerWidget.isEnabled();
450 }
451
452 /**
453 * @param {number} size
454 */
455 setSidebarSize(size) {
Paul Lewis50993692020-01-23 15:22:26456 const sizeDIP = self.UI.zoomManager.cssToDIP(size);
Blink Reformat4c46d092018-04-07 15:32:37457 this._savedSidebarSizeDIP = sizeDIP;
458 this._saveSetting();
459 this._innerSetSidebarSizeDIP(sizeDIP, false, true);
460 }
461
462 /**
463 * @return {number}
464 */
465 sidebarSize() {
466 const sizeDIP = Math.max(0, this._sidebarSizeDIP);
Paul Lewis50993692020-01-23 15:22:26467 return self.UI.zoomManager.dipToCSS(sizeDIP);
Blink Reformat4c46d092018-04-07 15:32:37468 }
469
470 /**
471 * Returns total size in DIP.
472 * @return {number}
473 */
474 _totalSizeDIP() {
475 if (!this._totalSizeCSS) {
476 this._totalSizeCSS = this._isVertical ? this.contentElement.offsetWidth : this.contentElement.offsetHeight;
477 this._totalSizeOtherDimensionCSS =
478 this._isVertical ? this.contentElement.offsetHeight : this.contentElement.offsetWidth;
479 }
Paul Lewis50993692020-01-23 15:22:26480 return self.UI.zoomManager.cssToDIP(this._totalSizeCSS);
Blink Reformat4c46d092018-04-07 15:32:37481 }
482
483 /**
484 * @param {string} showMode
485 */
486 _updateShowMode(showMode) {
487 this._showMode = showMode;
488 this._saveShowModeToSettings();
489 this._updateShowHideSidebarButton();
Tim van der Lippe0830b3d2019-10-03 13:20:07490 this.dispatchEventToListeners(SplitWidget.Events.ShowModeChanged, showMode);
Blink Reformat4c46d092018-04-07 15:32:37491 this.invalidateConstraints();
492 }
493
494 /**
495 * @param {number} sizeDIP
496 * @param {boolean} animate
497 * @param {boolean=} userAction
498 */
499 _innerSetSidebarSizeDIP(sizeDIP, animate, userAction) {
Tim van der Lippe0830b3d2019-10-03 13:20:07500 if (this._showMode !== ShowMode.Both || !this.isShowing()) {
Blink Reformat4c46d092018-04-07 15:32:37501 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34502 }
Blink Reformat4c46d092018-04-07 15:32:37503
504 sizeDIP = this._applyConstraints(sizeDIP, userAction);
Tim van der Lippe1d6e57a2019-09-30 11:55:34505 if (this._sidebarSizeDIP === sizeDIP) {
Blink Reformat4c46d092018-04-07 15:32:37506 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34507 }
Blink Reformat4c46d092018-04-07 15:32:37508
509 if (!this._resizerElementSize) {
510 this._resizerElementSize =
511 this._isVertical ? this._resizerElement.offsetWidth : this._resizerElement.offsetHeight;
512 }
513
514 // Invalidate layout below.
515
516 this._removeAllLayoutProperties();
517
518 // this._totalSizeDIP is available below since we successfully applied constraints.
Paul Lewis50993692020-01-23 15:22:26519 const roundSizeCSS = Math.round(self.UI.zoomManager.dipToCSS(sizeDIP));
Blink Reformat4c46d092018-04-07 15:32:37520 const sidebarSizeValue = roundSizeCSS + 'px';
521 const mainSizeValue = (this._totalSizeCSS - roundSizeCSS) + 'px';
522 this._sidebarElement.style.flexBasis = sidebarSizeValue;
523
524 // Make both sides relayout boundaries.
525 if (this._isVertical) {
526 this._sidebarElement.style.width = sidebarSizeValue;
527 this._mainElement.style.width = mainSizeValue;
528 this._sidebarElement.style.height = this._totalSizeOtherDimensionCSS + 'px';
529 this._mainElement.style.height = this._totalSizeOtherDimensionCSS + 'px';
530 } else {
531 this._sidebarElement.style.height = sidebarSizeValue;
532 this._mainElement.style.height = mainSizeValue;
533 this._sidebarElement.style.width = this._totalSizeOtherDimensionCSS + 'px';
534 this._mainElement.style.width = this._totalSizeOtherDimensionCSS + 'px';
535 }
536
537 // Position resizer.
538 if (this._isVertical) {
539 if (this._secondIsSidebar) {
540 this._resizerElement.style.right = sidebarSizeValue;
541 this._resizerElement.style.marginRight = -this._resizerElementSize / 2 + 'px';
542 } else {
543 this._resizerElement.style.left = sidebarSizeValue;
544 this._resizerElement.style.marginLeft = -this._resizerElementSize / 2 + 'px';
545 }
546 } else {
547 if (this._secondIsSidebar) {
548 this._resizerElement.style.bottom = sidebarSizeValue;
549 this._resizerElement.style.marginBottom = -this._resizerElementSize / 2 + 'px';
550 } else {
551 this._resizerElement.style.top = sidebarSizeValue;
552 this._resizerElement.style.marginTop = -this._resizerElementSize / 2 + 'px';
553 }
554 }
555
556 this._sidebarSizeDIP = sizeDIP;
557
558 // Force layout.
559
560 if (animate) {
561 this._animate(false);
562 } else {
563 // No need to recalculate this._sidebarSizeDIP and this._totalSizeDIP again.
564 this.doResize();
Tim van der Lippe0830b3d2019-10-03 13:20:07565 this.dispatchEventToListeners(SplitWidget.Events.SidebarSizeChanged, this.sidebarSize());
Blink Reformat4c46d092018-04-07 15:32:37566 }
567 }
568
569 /**
570 * @param {boolean} reverse
571 * @param {function()=} callback
572 */
573 _animate(reverse, callback) {
574 const animationTime = 50;
575 this._animationCallback = callback || null;
576
577 let animatedMarginPropertyName;
Tim van der Lippe1d6e57a2019-09-30 11:55:34578 if (this._isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37579 animatedMarginPropertyName = this._secondIsSidebar ? 'margin-right' : 'margin-left';
Tim van der Lippe1d6e57a2019-09-30 11:55:34580 } else {
Blink Reformat4c46d092018-04-07 15:32:37581 animatedMarginPropertyName = this._secondIsSidebar ? 'margin-bottom' : 'margin-top';
Tim van der Lippe1d6e57a2019-09-30 11:55:34582 }
Blink Reformat4c46d092018-04-07 15:32:37583
Paul Lewis50993692020-01-23 15:22:26584 const marginFrom = reverse ? '0' : '-' + self.UI.zoomManager.dipToCSS(this._sidebarSizeDIP) + 'px';
585 const marginTo = reverse ? '-' + self.UI.zoomManager.dipToCSS(this._sidebarSizeDIP) + 'px' : '0';
Blink Reformat4c46d092018-04-07 15:32:37586
587 // This order of things is important.
588 // 1. Resize main element early and force layout.
589 this.contentElement.style.setProperty(animatedMarginPropertyName, marginFrom);
590 if (!reverse) {
591 suppressUnused(this._mainElement.offsetWidth);
592 suppressUnused(this._sidebarElement.offsetWidth);
593 }
594
595 // 2. Issue onresize to the sidebar element, its size won't change.
Tim van der Lippe1d6e57a2019-09-30 11:55:34596 if (!reverse) {
Blink Reformat4c46d092018-04-07 15:32:37597 this._sidebarWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34598 }
Blink Reformat4c46d092018-04-07 15:32:37599
600 // 3. Configure and run animation
601 this.contentElement.style.setProperty('transition', animatedMarginPropertyName + ' ' + animationTime + 'ms linear');
602
603 const boundAnimationFrame = animationFrame.bind(this);
604 let startTime;
605 /**
Tim van der Lippe0830b3d2019-10-03 13:20:07606 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37607 */
608 function animationFrame() {
609 this._animationFrameHandle = 0;
610
611 if (!startTime) {
612 // Kick animation on first frame.
613 this.contentElement.style.setProperty(animatedMarginPropertyName, marginTo);
614 startTime = window.performance.now();
615 } else if (window.performance.now() < startTime + animationTime) {
616 // Process regular animation frame.
Tim van der Lippe1d6e57a2019-09-30 11:55:34617 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37618 this._mainWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34619 }
Blink Reformat4c46d092018-04-07 15:32:37620 } else {
621 // Complete animation.
622 this._cancelAnimation();
Tim van der Lippe1d6e57a2019-09-30 11:55:34623 if (this._mainWidget) {
Blink Reformat4c46d092018-04-07 15:32:37624 this._mainWidget.doResize();
Tim van der Lippe1d6e57a2019-09-30 11:55:34625 }
Tim van der Lippe0830b3d2019-10-03 13:20:07626 this.dispatchEventToListeners(SplitWidget.Events.SidebarSizeChanged, this.sidebarSize());
Blink Reformat4c46d092018-04-07 15:32:37627 return;
628 }
629 this._animationFrameHandle = this.contentElement.window().requestAnimationFrame(boundAnimationFrame);
630 }
631 this._animationFrameHandle = this.contentElement.window().requestAnimationFrame(boundAnimationFrame);
632 }
633
634 _cancelAnimation() {
635 this.contentElement.style.removeProperty('margin-top');
636 this.contentElement.style.removeProperty('margin-right');
637 this.contentElement.style.removeProperty('margin-bottom');
638 this.contentElement.style.removeProperty('margin-left');
639 this.contentElement.style.removeProperty('transition');
640
641 if (this._animationFrameHandle) {
642 this.contentElement.window().cancelAnimationFrame(this._animationFrameHandle);
643 this._animationFrameHandle = 0;
644 }
645 if (this._animationCallback) {
646 this._animationCallback();
647 this._animationCallback = null;
648 }
649 }
650
651 /**
652 * @param {number} sidebarSize
653 * @param {boolean=} userAction
654 * @return {number}
655 */
656 _applyConstraints(sidebarSize, userAction) {
657 const totalSize = this._totalSizeDIP();
Paul Lewis50993692020-01-23 15:22:26658 const zoomFactor = this._constraintsInDip ? 1 : self.UI.zoomManager.zoomFactor();
Blink Reformat4c46d092018-04-07 15:32:37659
Paul Lewis9950e182019-12-16 16:06:07660 let constraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Blink Reformat4c46d092018-04-07 15:32:37661 let minSidebarSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34662 if (!minSidebarSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07663 minSidebarSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34664 }
Blink Reformat4c46d092018-04-07 15:32:37665 minSidebarSize *= zoomFactor;
Tim van der Lippe1d6e57a2019-09-30 11:55:34666 if (this._sidebarMinimized) {
Blink Reformat4c46d092018-04-07 15:32:37667 sidebarSize = minSidebarSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34668 }
Blink Reformat4c46d092018-04-07 15:32:37669
670 let preferredSidebarSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34671 if (!preferredSidebarSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07672 preferredSidebarSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34673 }
Blink Reformat4c46d092018-04-07 15:32:37674 preferredSidebarSize *= zoomFactor;
675 // Allow sidebar to be less than preferred by explicit user action.
Tim van der Lippe1d6e57a2019-09-30 11:55:34676 if (sidebarSize < preferredSidebarSize) {
Blink Reformat4c46d092018-04-07 15:32:37677 preferredSidebarSize = Math.max(sidebarSize, minSidebarSize);
Tim van der Lippe1d6e57a2019-09-30 11:55:34678 }
Blink Reformat4c46d092018-04-07 15:32:37679 preferredSidebarSize += zoomFactor; // 1 css pixel for splitter border.
680
Paul Lewis9950e182019-12-16 16:06:07681 constraints = this._mainWidget ? this._mainWidget.constraints() : new Constraints();
Blink Reformat4c46d092018-04-07 15:32:37682 let minMainSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34683 if (!minMainSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07684 minMainSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34685 }
Blink Reformat4c46d092018-04-07 15:32:37686 minMainSize *= zoomFactor;
687
688 let preferredMainSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height;
Tim van der Lippe1d6e57a2019-09-30 11:55:34689 if (!preferredMainSize) {
Tim van der Lippe0830b3d2019-10-03 13:20:07690 preferredMainSize = MinPadding;
Tim van der Lippe1d6e57a2019-09-30 11:55:34691 }
Blink Reformat4c46d092018-04-07 15:32:37692 preferredMainSize *= zoomFactor;
693 const savedMainSize = this.isVertical() ? this._savedVerticalMainSize : this._savedHorizontalMainSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34694 if (savedMainSize !== null) {
Blink Reformat4c46d092018-04-07 15:32:37695 preferredMainSize = Math.min(preferredMainSize, savedMainSize * zoomFactor);
Tim van der Lippe1d6e57a2019-09-30 11:55:34696 }
697 if (userAction) {
Blink Reformat4c46d092018-04-07 15:32:37698 preferredMainSize = minMainSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34699 }
Blink Reformat4c46d092018-04-07 15:32:37700
701 // Enough space for preferred.
702 const totalPreferred = preferredMainSize + preferredSidebarSize;
Tim van der Lippe1d6e57a2019-09-30 11:55:34703 if (totalPreferred <= totalSize) {
Blink Reformat4c46d092018-04-07 15:32:37704 return Number.constrain(sidebarSize, preferredSidebarSize, totalSize - preferredMainSize);
Tim van der Lippe1d6e57a2019-09-30 11:55:34705 }
Blink Reformat4c46d092018-04-07 15:32:37706
707 // Enough space for minimum.
708 if (minMainSize + minSidebarSize <= totalSize) {
709 const delta = totalPreferred - totalSize;
710 const sidebarDelta = delta * preferredSidebarSize / totalPreferred;
711 sidebarSize = preferredSidebarSize - sidebarDelta;
712 return Number.constrain(sidebarSize, minSidebarSize, totalSize - minMainSize);
713 }
714
715 // Not enough space even for minimum sizes.
716 return Math.max(0, totalSize - minMainSize);
717 }
718
719 /**
720 * @override
721 */
722 wasShown() {
723 this._forceUpdateLayout();
Paul Lewis50993692020-01-23 15:22:26724 self.UI.zoomManager.addEventListener(ZoomManagerEvents.ZoomChanged, this._onZoomChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37725 }
726
727 /**
728 * @override
729 */
730 willHide() {
Paul Lewis50993692020-01-23 15:22:26731 self.UI.zoomManager.removeEventListener(ZoomManagerEvents.ZoomChanged, this._onZoomChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37732 }
733
734 /**
735 * @override
736 */
737 onResize() {
738 this._updateLayout();
739 }
740
741 /**
742 * @override
743 */
744 onLayout() {
745 this._updateLayout();
746 }
747
748 /**
749 * @override
Paul Lewis9950e182019-12-16 16:06:07750 * @return {!Constraints}
Blink Reformat4c46d092018-04-07 15:32:37751 */
752 calculateConstraints() {
Tim van der Lippe0830b3d2019-10-03 13:20:07753 if (this._showMode === ShowMode.OnlyMain) {
Paul Lewis9950e182019-12-16 16:06:07754 return this._mainWidget ? this._mainWidget.constraints() : new Constraints();
Tim van der Lippe1d6e57a2019-09-30 11:55:34755 }
Tim van der Lippe0830b3d2019-10-03 13:20:07756 if (this._showMode === ShowMode.OnlySidebar) {
Paul Lewis9950e182019-12-16 16:06:07757 return this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Tim van der Lippe1d6e57a2019-09-30 11:55:34758 }
Blink Reformat4c46d092018-04-07 15:32:37759
Paul Lewis9950e182019-12-16 16:06:07760 let mainConstraints = this._mainWidget ? this._mainWidget.constraints() : new Constraints();
761 let sidebarConstraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new Constraints();
Tim van der Lippe0830b3d2019-10-03 13:20:07762 const min = MinPadding;
Blink Reformat4c46d092018-04-07 15:32:37763 if (this._isVertical) {
764 mainConstraints = mainConstraints.widthToMax(min).addWidth(1); // 1 for splitter
765 sidebarConstraints = sidebarConstraints.widthToMax(min);
766 return mainConstraints.addWidth(sidebarConstraints).heightToMax(sidebarConstraints);
767 } else {
768 mainConstraints = mainConstraints.heightToMax(min).addHeight(1); // 1 for splitter
769 sidebarConstraints = sidebarConstraints.heightToMax(min);
770 return mainConstraints.widthToMax(sidebarConstraints).addHeight(sidebarConstraints);
771 }
772 }
773
774 /**
775 * @param {!Common.Event} event
776 */
777 _onResizeStart(event) {
778 this._resizeStartSizeDIP = this._sidebarSizeDIP;
779 }
780
781 /**
782 * @param {!Common.Event} event
783 */
784 _onResizeUpdate(event) {
785 const offset = event.data.currentPosition - event.data.startPosition;
Paul Lewis50993692020-01-23 15:22:26786 const offsetDIP = self.UI.zoomManager.cssToDIP(offset);
Blink Reformat4c46d092018-04-07 15:32:37787 const newSizeDIP =
788 this._secondIsSidebar ? this._resizeStartSizeDIP - offsetDIP : this._resizeStartSizeDIP + offsetDIP;
789 const constrainedSizeDIP = this._applyConstraints(newSizeDIP, true);
790 this._savedSidebarSizeDIP = constrainedSizeDIP;
791 this._saveSetting();
792 this._innerSetSidebarSizeDIP(constrainedSizeDIP, false, true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34793 if (this.isVertical()) {
Blink Reformat4c46d092018-04-07 15:32:37794 this._savedVerticalMainSize = this._totalSizeDIP() - this._sidebarSizeDIP;
Tim van der Lippe1d6e57a2019-09-30 11:55:34795 } else {
Blink Reformat4c46d092018-04-07 15:32:37796 this._savedHorizontalMainSize = this._totalSizeDIP() - this._sidebarSizeDIP;
Tim van der Lippe1d6e57a2019-09-30 11:55:34797 }
Blink Reformat4c46d092018-04-07 15:32:37798 }
799
800 /**
801 * @param {!Common.Event} event
802 */
803 _onResizeEnd(event) {
804 this._resizeStartSizeDIP = 0;
805 }
806
807 /**
808 * @param {boolean=} noSplitter
809 */
810 hideDefaultResizer(noSplitter) {
811 this.uninstallResizer(this._resizerElement);
Pavel Feldmanc9060ea2018-04-30 04:42:18812 this._sidebarElement.classList.toggle('no-default-splitter', !!noSplitter);
Blink Reformat4c46d092018-04-07 15:32:37813 }
814
815 /**
816 * @param {!Element} resizerElement
817 */
818 installResizer(resizerElement) {
819 this._resizerWidget.addElement(resizerElement);
820 }
821
822 /**
823 * @param {!Element} resizerElement
824 */
825 uninstallResizer(resizerElement) {
826 this._resizerWidget.removeElement(resizerElement);
827 }
828
829 /**
830 * @return {boolean}
831 */
832 hasCustomResizer() {
833 const elements = this._resizerWidget.elements();
834 return elements.length > 1 || (elements.length === 1 && elements[0] !== this._resizerElement);
835 }
836
837 /**
838 * @param {!Element} resizer
839 * @param {boolean} on
840 */
841 toggleResizer(resizer, on) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34842 if (on) {
Blink Reformat4c46d092018-04-07 15:32:37843 this.installResizer(resizer);
Tim van der Lippe1d6e57a2019-09-30 11:55:34844 } else {
Blink Reformat4c46d092018-04-07 15:32:37845 this.uninstallResizer(resizer);
Tim van der Lippe1d6e57a2019-09-30 11:55:34846 }
Blink Reformat4c46d092018-04-07 15:32:37847 }
848
849 /**
Tim van der Lippe0830b3d2019-10-03 13:20:07850 * @return {?SplitWidget.SettingForOrientation}
Blink Reformat4c46d092018-04-07 15:32:37851 */
852 _settingForOrientation() {
853 const state = this._setting ? this._setting.get() : {};
854 return this._isVertical ? state.vertical : state.horizontal;
855 }
856
857 /**
858 * @return {number}
859 */
860 _preferredSidebarSizeDIP() {
861 let size = this._savedSidebarSizeDIP;
862 if (!size) {
863 size = this._isVertical ? this._defaultSidebarWidth : this._defaultSidebarHeight;
864 // If we have default value in percents, calculate it on first use.
Tim van der Lippe1d6e57a2019-09-30 11:55:34865 if (0 < size && size < 1) {
Blink Reformat4c46d092018-04-07 15:32:37866 size *= this._totalSizeDIP();
Tim van der Lippe1d6e57a2019-09-30 11:55:34867 }
Blink Reformat4c46d092018-04-07 15:32:37868 }
869 return size;
870 }
871
872 _restoreSidebarSizeFromSettings() {
873 const settingForOrientation = this._settingForOrientation();
874 this._savedSidebarSizeDIP = settingForOrientation ? settingForOrientation.size : 0;
875 }
876
877 _restoreAndApplyShowModeFromSettings() {
878 const orientationState = this._settingForOrientation();
879 this._savedShowMode = orientationState && orientationState.showMode ? orientationState.showMode : this._showMode;
880 this._showMode = this._savedShowMode;
881
882 switch (this._savedShowMode) {
Tim van der Lippe0830b3d2019-10-03 13:20:07883 case ShowMode.Both:
Blink Reformat4c46d092018-04-07 15:32:37884 this.showBoth();
885 break;
Tim van der Lippe0830b3d2019-10-03 13:20:07886 case ShowMode.OnlyMain:
Blink Reformat4c46d092018-04-07 15:32:37887 this.hideSidebar();
888 break;
Tim van der Lippe0830b3d2019-10-03 13:20:07889 case ShowMode.OnlySidebar:
Blink Reformat4c46d092018-04-07 15:32:37890 this.hideMain();
891 break;
892 }
893 }
894
895 _saveShowModeToSettings() {
896 this._savedShowMode = this._showMode;
897 this._saveSetting();
898 }
899
900 _saveSetting() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34901 if (!this._setting) {
Blink Reformat4c46d092018-04-07 15:32:37902 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34903 }
Blink Reformat4c46d092018-04-07 15:32:37904 const state = this._setting.get();
905 const orientationState = (this._isVertical ? state.vertical : state.horizontal) || {};
906
907 orientationState.size = this._savedSidebarSizeDIP;
Tim van der Lippe1d6e57a2019-09-30 11:55:34908 if (this._shouldSaveShowMode) {
Blink Reformat4c46d092018-04-07 15:32:37909 orientationState.showMode = this._savedShowMode;
Tim van der Lippe1d6e57a2019-09-30 11:55:34910 }
Blink Reformat4c46d092018-04-07 15:32:37911
Tim van der Lippe1d6e57a2019-09-30 11:55:34912 if (this._isVertical) {
Blink Reformat4c46d092018-04-07 15:32:37913 state.vertical = orientationState;
Tim van der Lippe1d6e57a2019-09-30 11:55:34914 } else {
Blink Reformat4c46d092018-04-07 15:32:37915 state.horizontal = orientationState;
Tim van der Lippe1d6e57a2019-09-30 11:55:34916 }
Blink Reformat4c46d092018-04-07 15:32:37917 this._setting.set(state);
918 }
919
920 _forceUpdateLayout() {
921 // Force layout even if sidebar size does not change.
922 this._sidebarSizeDIP = -1;
923 this._updateLayout();
924 }
925
926 /**
927 * @param {!Common.Event} event
928 */
929 _onZoomChanged(event) {
930 this._forceUpdateLayout();
931 }
932
933 /**
934 * @param {string} title
Paul Lewis9950e182019-12-16 16:06:07935 * @return {!ToolbarButton}
Blink Reformat4c46d092018-04-07 15:32:37936 */
937 createShowHideSidebarButton(title) {
Mandy Chen84d56b62019-09-03 18:21:18938 this._showHideSidebarButtonTitle = title;
Paul Lewis9950e182019-12-16 16:06:07939 this._showHideSidebarButton = new ToolbarButton('', '');
940 this._showHideSidebarButton.addEventListener(ToolbarButton.Events.Click, buttonClicked, this);
Blink Reformat4c46d092018-04-07 15:32:37941 this._updateShowHideSidebarButton();
942
943 /**
944 * @param {!Common.Event} event
Tim van der Lippe0830b3d2019-10-03 13:20:07945 * @this {SplitWidget}
Blink Reformat4c46d092018-04-07 15:32:37946 */
947 function buttonClicked(event) {
Tim van der Lippe0830b3d2019-10-03 13:20:07948 if (this._showMode !== ShowMode.Both) {
Blink Reformat4c46d092018-04-07 15:32:37949 this.showBoth(true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34950 } else {
Blink Reformat4c46d092018-04-07 15:32:37951 this.hideSidebar(true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34952 }
Blink Reformat4c46d092018-04-07 15:32:37953 }
954
955 return this._showHideSidebarButton;
956 }
957
958 _updateShowHideSidebarButton() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34959 if (!this._showHideSidebarButton) {
Blink Reformat4c46d092018-04-07 15:32:37960 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34961 }
Tim van der Lippe0830b3d2019-10-03 13:20:07962 const sidebarHidden = this._showMode === ShowMode.OnlyMain;
Blink Reformat4c46d092018-04-07 15:32:37963 let glyph = '';
964 if (sidebarHidden) {
965 glyph = this.isVertical() ?
966 (this.isSidebarSecond() ? 'largeicon-show-right-sidebar' : 'largeicon-show-left-sidebar') :
967 (this.isSidebarSecond() ? 'largeicon-show-bottom-sidebar' : 'largeicon-show-top-sidebar');
968 } else {
969 glyph = this.isVertical() ?
970 (this.isSidebarSecond() ? 'largeicon-hide-right-sidebar' : 'largeicon-hide-left-sidebar') :
971 (this.isSidebarSecond() ? 'largeicon-hide-bottom-sidebar' : 'largeicon-hide-top-sidebar');
972 }
973 this._showHideSidebarButton.setGlyph(glyph);
974 this._showHideSidebarButton.setTitle(
Paul Lewis17e384e2020-01-08 15:46:51975 sidebarHidden ? Common.UIString.UIString('Show %s', this._showHideSidebarButtonTitle) :
976 Common.UIString.UIString('Hide %s', this._showHideSidebarButtonTitle));
Blink Reformat4c46d092018-04-07 15:32:37977 }
Tim van der Lippe0830b3d2019-10-03 13:20:07978}
Blink Reformat4c46d092018-04-07 15:32:37979
Tim van der Lippe0830b3d2019-10-03 13:20:07980export const ShowMode = {
Blink Reformat4c46d092018-04-07 15:32:37981 Both: 'Both',
982 OnlyMain: 'OnlyMain',
983 OnlySidebar: 'OnlySidebar'
984};
985
986/** @enum {symbol} */
Tim van der Lippe0830b3d2019-10-03 13:20:07987export const Events = {
Blink Reformat4c46d092018-04-07 15:32:37988 SidebarSizeChanged: Symbol('SidebarSizeChanged'),
989 ShowModeChanged: Symbol('ShowModeChanged')
990};
991
Tim van der Lippec96ccd92019-11-29 16:23:54992const MinPadding = 20;