OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * | 10 * |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 Both: "Both", | 87 Both: "Both", |
88 OnlyMain: "OnlyMain", | 88 OnlyMain: "OnlyMain", |
89 OnlySidebar: "OnlySidebar" | 89 OnlySidebar: "OnlySidebar" |
90 } | 90 } |
91 | 91 |
92 WebInspector.SplitView.Events = { | 92 WebInspector.SplitView.Events = { |
93 SidebarSizeChanged: "SidebarSizeChanged", | 93 SidebarSizeChanged: "SidebarSizeChanged", |
94 ShowModeChanged: "ShowModeChanged" | 94 ShowModeChanged: "ShowModeChanged" |
95 } | 95 } |
96 | 96 |
97 WebInspector.SplitView.MinPadding = 20; | |
98 | |
97 WebInspector.SplitView.prototype = { | 99 WebInspector.SplitView.prototype = { |
98 /** | 100 /** |
99 * @return {boolean} | 101 * @return {boolean} |
100 */ | 102 */ |
101 isVertical: function() | 103 isVertical: function() |
102 { | 104 { |
103 return this._isVertical; | 105 return this._isVertical; |
104 }, | 106 }, |
105 | 107 |
106 /** | 108 /** |
(...skipping 18 matching lines...) Expand all Loading... | |
125 this.element.classList.remove(this._isVertical ? "hbox" : "vbox"); | 127 this.element.classList.remove(this._isVertical ? "hbox" : "vbox"); |
126 this._isVertical = isVertical; | 128 this._isVertical = isVertical; |
127 this.element.classList.add(this._isVertical ? "hbox" : "vbox"); | 129 this.element.classList.add(this._isVertical ? "hbox" : "vbox"); |
128 delete this._resizerElementSize; | 130 delete this._resizerElementSize; |
129 this._sidebarSize = -1; | 131 this._sidebarSize = -1; |
130 this._restoreSidebarSizeFromSettings(); | 132 this._restoreSidebarSizeFromSettings(); |
131 if (this._shouldSaveShowMode) | 133 if (this._shouldSaveShowMode) |
132 this._restoreAndApplyShowModeFromSettings(); | 134 this._restoreAndApplyShowModeFromSettings(); |
133 this._updateShowHideSidebarButton(); | 135 this._updateShowHideSidebarButton(); |
134 this._updateResizersClass(); | 136 this._updateResizersClass(); |
137 this.invalidateMinimumSize(); | |
135 }, | 138 }, |
136 | 139 |
137 /** | 140 /** |
138 * @param {boolean=} animate | 141 * @param {boolean=} animate |
139 */ | 142 */ |
140 _updateLayout: function(animate) | 143 _updateLayout: function(animate) |
141 { | 144 { |
142 delete this._totalSize; // Lazy update. | 145 delete this._totalSize; // Lazy update. |
143 this._innerSetSidebarSize(this._preferredSidebarSize(), false, animate); | 146 this._innerSetSidebarSize(this._preferredSidebarSize(), !!animate); |
144 }, | 147 }, |
145 | 148 |
146 /** | 149 /** |
147 * @return {!Element} | 150 * @return {!Element} |
148 */ | 151 */ |
149 mainElement: function() | 152 mainElement: function() |
150 { | 153 { |
151 return this._mainElement; | 154 return this._mainElement; |
152 }, | 155 }, |
153 | 156 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 { | 340 { |
338 this._resizable = resizable; | 341 this._resizable = resizable; |
339 this._updateResizersClass(); | 342 this._updateResizersClass(); |
340 }, | 343 }, |
341 | 344 |
342 /** | 345 /** |
343 * @param {number} size | 346 * @param {number} size |
344 */ | 347 */ |
345 setSidebarSize: function(size) | 348 setSidebarSize: function(size) |
346 { | 349 { |
347 this._innerSetSidebarSize(size); | 350 this._savedSidebarSize = size; |
348 this._saveSidebarSizeToSettings(); | 351 this._saveSetting(); |
352 this._innerSetSidebarSize(size, false); | |
349 }, | 353 }, |
350 | 354 |
351 /** | 355 /** |
352 * @return {number} | 356 * @return {number} |
353 */ | 357 */ |
354 sidebarSize: function() | 358 sidebarSize: function() |
355 { | 359 { |
356 return Math.max(0, this._sidebarSize); | 360 return Math.max(0, this._sidebarSize); |
357 }, | 361 }, |
358 | 362 |
(...skipping 10 matching lines...) Expand all Loading... | |
369 | 373 |
370 /** | 374 /** |
371 * @param {string} showMode | 375 * @param {string} showMode |
372 */ | 376 */ |
373 _updateShowMode: function(showMode) | 377 _updateShowMode: function(showMode) |
374 { | 378 { |
375 this._showMode = showMode; | 379 this._showMode = showMode; |
376 this._saveShowModeToSettings(); | 380 this._saveShowModeToSettings(); |
377 this._updateShowHideSidebarButton(); | 381 this._updateShowHideSidebarButton(); |
378 this.dispatchEventToListeners(WebInspector.SplitView.Events.ShowModeChan ged, showMode); | 382 this.dispatchEventToListeners(WebInspector.SplitView.Events.ShowModeChan ged, showMode); |
383 this.invalidateMinimumSize(); | |
379 }, | 384 }, |
380 | 385 |
381 /** | 386 /** |
382 * @param {number} size | 387 * @param {number} size |
383 * @param {boolean=} ignoreConstraints | 388 * @param {boolean} animate |
384 * @param {boolean=} animate | |
385 */ | 389 */ |
386 _innerSetSidebarSize: function(size, ignoreConstraints, animate) | 390 _innerSetSidebarSize: function(size, animate) |
387 { | 391 { |
388 if (this._showMode !== WebInspector.SplitView.ShowMode.Both) { | 392 if (this._showMode !== WebInspector.SplitView.ShowMode.Both || !this.isS howing()) |
389 this._sidebarSize = size; | |
390 return; | 393 return; |
391 } | |
392 | 394 |
393 if (!ignoreConstraints) | 395 size = this._applyConstraints(size); |
394 size = this._applyConstraints(size); | |
395 if (this._sidebarSize === size) | 396 if (this._sidebarSize === size) |
396 return; | 397 return; |
397 | 398 |
398 if (size < 0) { | |
399 // Never apply bad values, fix it upon onResize instead. | |
400 return; | |
401 } | |
402 | |
403 this._removeAllLayoutProperties(); | 399 this._removeAllLayoutProperties(); |
404 | 400 |
405 var sizeValue = (size / WebInspector.zoomManager.zoomFactor()) + "px"; | 401 var sizeValue = (size / WebInspector.zoomManager.zoomFactor()) + "px"; |
406 this.sidebarElement().style.flexBasis = sizeValue; | 402 this.sidebarElement().style.flexBasis = sizeValue; |
407 | 403 |
408 if (!this._resizerElementSize) | 404 if (!this._resizerElementSize) |
409 this._resizerElementSize = this._isVertical ? this._resizerElement.o ffsetWidth : this._resizerElement.offsetHeight; | 405 this._resizerElementSize = this._isVertical ? this._resizerElement.o ffsetWidth : this._resizerElement.offsetHeight; |
410 | 406 |
411 // Position resizer. | 407 // Position resizer. |
412 if (this._isVertical) { | 408 if (this._isVertical) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 window.cancelAnimationFrame(this._animationFrameHandle); | 509 window.cancelAnimationFrame(this._animationFrameHandle); |
514 delete this._animationFrameHandle; | 510 delete this._animationFrameHandle; |
515 } | 511 } |
516 if (this._animationCallback) { | 512 if (this._animationCallback) { |
517 this._animationCallback(); | 513 this._animationCallback(); |
518 delete this._animationCallback; | 514 delete this._animationCallback; |
519 } | 515 } |
520 }, | 516 }, |
521 | 517 |
522 /** | 518 /** |
523 * @param {number=} minWidth | |
524 * @param {number=} minHeight | |
525 */ | |
526 setSidebarElementConstraints: function(minWidth, minHeight) | |
527 { | |
528 if (typeof minWidth === "number") | |
529 this._minimumSidebarWidth = minWidth; | |
530 if (typeof minHeight === "number") | |
531 this._minimumSidebarHeight = minHeight; | |
532 }, | |
533 | |
534 /** | |
535 * @param {number=} minWidth | |
536 * @param {number=} minHeight | |
537 */ | |
538 setMainElementConstraints: function(minWidth, minHeight) | |
539 { | |
540 if (typeof minWidth === "number") | |
541 this._minimumMainWidth = minWidth; | |
542 if (typeof minHeight === "number") | |
543 this._minimumMainHeight = minHeight; | |
544 }, | |
545 | |
546 /** | |
547 * @param {number} sidebarSize | 519 * @param {number} sidebarSize |
548 * @return {number} | 520 * @return {number} |
549 */ | 521 */ |
550 _applyConstraints: function(sidebarSize) | 522 _applyConstraints: function(sidebarSize) |
551 { | 523 { |
552 const minPadding = 20; | |
553 var totalSize = this.totalSize(); | 524 var totalSize = this.totalSize(); |
554 var minimumSiderbarSizeContraint = this.isVertical() ? this._minimumSide barWidth : this._minimumSidebarHeight; | |
555 var from = minimumSiderbarSizeContraint || 0; | |
556 if (typeof minimumSiderbarSizeContraint !== "number") | |
557 from = Math.max(from, minPadding); | |
558 | 525 |
559 var minimumMainSizeConstraint = this.isVertical() ? this._minimumMainWid th : this._minimumMainHeight; | 526 var size = this._sidebarView.minimumSize(); |
560 var minMainSize = minimumMainSizeConstraint || 0; | 527 var from = this.isVertical() ? size.width : size.height; |
561 if (typeof minimumMainSizeConstraint !== "number") | 528 if (!from) |
562 minMainSize = Math.max(minMainSize, minPadding); | 529 from = WebInspector.SplitView.MinPadding; |
530 | |
531 size = this._mainView.minimumSize(); | |
532 var minMainSize = this.isVertical() ? size.width : size.height; | |
533 if (!minMainSize) | |
534 minMainSize = WebInspector.SplitView.MinPadding; | |
563 | 535 |
564 var to = totalSize - minMainSize; | 536 var to = totalSize - minMainSize; |
565 if (from <= to) | 537 if (from <= to) |
566 return Number.constrain(sidebarSize, from, to); | 538 return Number.constrain(sidebarSize, from, to); |
567 | 539 |
568 return -1; | 540 // If we don't have enough space (which is a very rare case), prioritize main view. |
541 return Math.max(0, to); | |
569 }, | 542 }, |
570 | 543 |
571 wasShown: function() | 544 wasShown: function() |
572 { | 545 { |
573 this._forceUpdateLayout(); | 546 this._forceUpdateLayout(); |
574 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Event s.ZoomChanged, this._onZoomChanged, this); | 547 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Event s.ZoomChanged, this._onZoomChanged, this); |
575 }, | 548 }, |
576 | 549 |
577 willHide: function() | 550 willHide: function() |
578 { | 551 { |
579 WebInspector.zoomManager.removeEventListener(WebInspector.ZoomManager.Ev ents.ZoomChanged, this._onZoomChanged, this); | 552 WebInspector.zoomManager.removeEventListener(WebInspector.ZoomManager.Ev ents.ZoomChanged, this._onZoomChanged, this); |
580 }, | 553 }, |
581 | 554 |
582 onResize: function() | 555 onResize: function() |
583 { | 556 { |
584 this._updateLayout(); | 557 this._updateLayout(); |
585 }, | 558 }, |
586 | 559 |
560 onLayout: function() | |
561 { | |
562 this._updateLayout(); | |
563 }, | |
564 | |
565 /** | |
566 * @return {!Size} | |
567 */ | |
568 calculateMinimumSize: function() | |
569 { | |
570 if (this._showMode === WebInspector.SplitView.ShowMode.OnlyMain) | |
571 return this._mainView.minimumSize(); | |
572 if (this._showMode === WebInspector.SplitView.ShowMode.OnlySidebar) | |
573 return this._sidebarView.minimumSize(); | |
574 | |
575 var mainSize = this._mainView.minimumSize(); | |
576 var sidebarSize = this._sidebarView.minimumSize(); | |
577 var min = WebInspector.SplitView.MinPadding; | |
578 if (this._isVertical) | |
vsevik
2014/03/25 13:26:04
Does it mean we should also invalidateMinimumSize
dgozman
2014/03/25 14:13:58
It's already done.
| |
579 return new Size((mainSize.width || min) + (sidebarSize.width || min) , Math.max(mainSize.height, sidebarSize.height)); | |
580 else | |
581 return new Size(Math.max(mainSize.width, sidebarSize.width), (mainSi ze.height || min) + (sidebarSize.height || min)); | |
582 }, | |
583 | |
587 /** | 584 /** |
588 * @param {!MouseEvent} event | 585 * @param {!MouseEvent} event |
589 * @return {boolean} | 586 * @return {boolean} |
590 */ | 587 */ |
591 _startResizerDragging: function(event) | 588 _startResizerDragging: function(event) |
592 { | 589 { |
593 if (!this._resizable) | 590 if (!this._resizable) |
594 return false; | 591 return false; |
595 | 592 |
596 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) * WebInspector.zoomManager.zoomFactor(); | 593 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) * WebInspector.zoomManager.zoomFactor(); |
597 this._dragOffset = (this._secondIsSidebar ? this.totalSize() - this._sid ebarSize : this._sidebarSize) - dipEventPosition; | 594 this._dragOffset = (this._secondIsSidebar ? this.totalSize() - this._sid ebarSize : this._sidebarSize) - dipEventPosition; |
598 return true; | 595 return true; |
599 }, | 596 }, |
600 | 597 |
601 /** | 598 /** |
602 * @param {!MouseEvent} event | 599 * @param {!MouseEvent} event |
603 */ | 600 */ |
604 _resizerDragging: function(event) | 601 _resizerDragging: function(event) |
605 { | 602 { |
606 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) * WebInspector.zoomManager.zoomFactor(); | 603 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) * WebInspector.zoomManager.zoomFactor(); |
607 var newOffset = dipEventPosition + this._dragOffset; | 604 var newOffset = dipEventPosition + this._dragOffset; |
608 var newSize = (this._secondIsSidebar ? this.totalSize() - newOffset : ne wOffset); | 605 var newSize = (this._secondIsSidebar ? this.totalSize() - newOffset : ne wOffset); |
609 this.setSidebarSize(newSize); | 606 var constrainedSize = this._applyConstraints(newSize); |
607 this._savedSidebarSize = constrainedSize; | |
608 this._saveSetting(); | |
609 this._innerSetSidebarSize(constrainedSize, false); | |
610 event.preventDefault(); | 610 event.preventDefault(); |
611 }, | 611 }, |
612 | 612 |
613 /** | 613 /** |
614 * @param {!MouseEvent} event | 614 * @param {!MouseEvent} event |
615 */ | 615 */ |
616 _endResizerDragging: function(event) | 616 _endResizerDragging: function(event) |
617 { | 617 { |
618 delete this._dragOffset; | 618 delete this._dragOffset; |
619 this._saveSidebarSizeToSettings(); | |
620 }, | 619 }, |
621 | 620 |
622 hideDefaultResizer: function() | 621 hideDefaultResizer: function() |
623 { | 622 { |
624 this.uninstallResizer(this._resizerElement); | 623 this.uninstallResizer(this._resizerElement); |
625 }, | 624 }, |
626 | 625 |
627 /** | 626 /** |
628 * @param {!Element} resizerElement | 627 * @param {!Element} resizerElement |
629 */ | 628 */ |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
742 break; | 741 break; |
743 case WebInspector.SplitView.ShowMode.OnlyMain: | 742 case WebInspector.SplitView.ShowMode.OnlyMain: |
744 this.hideSidebar(); | 743 this.hideSidebar(); |
745 break; | 744 break; |
746 case WebInspector.SplitView.ShowMode.OnlySidebar: | 745 case WebInspector.SplitView.ShowMode.OnlySidebar: |
747 this.hideMain(); | 746 this.hideMain(); |
748 break; | 747 break; |
749 } | 748 } |
750 }, | 749 }, |
751 | 750 |
752 _saveSidebarSizeToSettings: function() | |
753 { | |
754 if (this._sidebarSize < 0) | |
755 return; | |
756 | |
757 this._savedSidebarSize = this._sidebarSize; | |
758 this._saveSetting(); | |
759 }, | |
760 | |
761 _saveShowModeToSettings: function() | 751 _saveShowModeToSettings: function() |
762 { | 752 { |
763 this._savedShowMode = this._showMode; | 753 this._savedShowMode = this._showMode; |
764 this._saveSetting(); | 754 this._saveSetting(); |
765 }, | 755 }, |
766 | 756 |
767 _saveSetting: function() | 757 _saveSetting: function() |
768 { | 758 { |
769 var setting = this._setting(); | 759 var setting = this._setting(); |
770 if (!setting) | 760 if (!setting) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 this._showHideSidebarButton.state = sidebarHidden ? "show" : "hide"; | 825 this._showHideSidebarButton.state = sidebarHidden ? "show" : "hide"; |
836 this._showHideSidebarButton.element.classList.toggle("top-sidebar-show-h ide-button", !this.isVertical() && !this.isSidebarSecond()); | 826 this._showHideSidebarButton.element.classList.toggle("top-sidebar-show-h ide-button", !this.isVertical() && !this.isSidebarSecond()); |
837 this._showHideSidebarButton.element.classList.toggle("right-sidebar-show -hide-button", this.isVertical() && this.isSidebarSecond()); | 827 this._showHideSidebarButton.element.classList.toggle("right-sidebar-show -hide-button", this.isVertical() && this.isSidebarSecond()); |
838 this._showHideSidebarButton.element.classList.toggle("bottom-sidebar-sho w-hide-button", !this.isVertical() && this.isSidebarSecond()); | 828 this._showHideSidebarButton.element.classList.toggle("bottom-sidebar-sho w-hide-button", !this.isVertical() && this.isSidebarSecond()); |
839 this._showHideSidebarButton.element.classList.toggle("left-sidebar-show- hide-button", this.isVertical() && !this.isSidebarSecond()); | 829 this._showHideSidebarButton.element.classList.toggle("left-sidebar-show- hide-button", this.isVertical() && !this.isSidebarSecond()); |
840 this._showHideSidebarButton.title = sidebarHidden ? WebInspector.UIStrin g("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hide %s" , this._showHideSidebarButtonTitle); | 830 this._showHideSidebarButton.title = sidebarHidden ? WebInspector.UIStrin g("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hide %s" , this._showHideSidebarButtonTitle); |
841 }, | 831 }, |
842 | 832 |
843 __proto__: WebInspector.View.prototype | 833 __proto__: WebInspector.View.prototype |
844 } | 834 } |
OLD | NEW |