Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: Source/devtools/front_end/SplitView.js

Issue 197823010: [DevTools] Add minimum size to WebInspector.View. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@splitdip2
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 Both: "Both", 88 Both: "Both",
89 OnlyMain: "OnlyMain", 89 OnlyMain: "OnlyMain",
90 OnlySidebar: "OnlySidebar" 90 OnlySidebar: "OnlySidebar"
91 } 91 }
92 92
93 WebInspector.SplitView.Events = { 93 WebInspector.SplitView.Events = {
94 SidebarSizeChanged: "SidebarSizeChanged", 94 SidebarSizeChanged: "SidebarSizeChanged",
95 ShowModeChanged: "ShowModeChanged" 95 ShowModeChanged: "ShowModeChanged"
96 } 96 }
97 97
98 WebInspector.SplitView.MinPadding = 20;
99
98 WebInspector.SplitView.prototype = { 100 WebInspector.SplitView.prototype = {
99 /** 101 /**
100 * @return {boolean} 102 * @return {boolean}
101 */ 103 */
102 isVertical: function() 104 isVertical: function()
103 { 105 {
104 return this._isVertical; 106 return this._isVertical;
105 }, 107 },
106 108
107 /** 109 /**
(...skipping 17 matching lines...) Expand all
125 { 127 {
126 this.element.classList.remove(this._isVertical ? "hbox" : "vbox"); 128 this.element.classList.remove(this._isVertical ? "hbox" : "vbox");
127 this._isVertical = isVertical; 129 this._isVertical = isVertical;
128 this.element.classList.add(this._isVertical ? "hbox" : "vbox"); 130 this.element.classList.add(this._isVertical ? "hbox" : "vbox");
129 delete this._resizerElementSize; 131 delete this._resizerElementSize;
130 this._sidebarSize = -1; 132 this._sidebarSize = -1;
131 this._restoreSidebarSizeFromSettings(); 133 this._restoreSidebarSizeFromSettings();
132 if (this._shouldSaveShowMode) 134 if (this._shouldSaveShowMode)
133 this._restoreAndApplyShowModeFromSettings(); 135 this._restoreAndApplyShowModeFromSettings();
134 this._updateShowHideSidebarButton(); 136 this._updateShowHideSidebarButton();
137 this.invalidateMinimumSize();
135 138
136 for (var i = 0; i < this._resizerElements.length; ++i) { 139 for (var i = 0; i < this._resizerElements.length; ++i) {
137 this._resizerElements[i].classList.toggle("ew-resizer-widget", this. _isVertical); 140 this._resizerElements[i].classList.toggle("ew-resizer-widget", this. _isVertical);
138 this._resizerElements[i].classList.toggle("ns-resizer-widget", !this ._isVertical); 141 this._resizerElements[i].classList.toggle("ns-resizer-widget", !this ._isVertical);
139 } 142 }
140 }, 143 },
141 144
142 /** 145 /**
143 * @param {boolean=} animate 146 * @param {boolean=} animate
144 */ 147 */
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 366
364 /** 367 /**
365 * @param {string} showMode 368 * @param {string} showMode
366 */ 369 */
367 _updateShowMode: function(showMode) 370 _updateShowMode: function(showMode)
368 { 371 {
369 this._showMode = showMode; 372 this._showMode = showMode;
370 this._saveShowModeToSettings(); 373 this._saveShowModeToSettings();
371 this._updateShowHideSidebarButton(); 374 this._updateShowHideSidebarButton();
372 this.dispatchEventToListeners(WebInspector.SplitView.Events.ShowModeChan ged, showMode); 375 this.dispatchEventToListeners(WebInspector.SplitView.Events.ShowModeChan ged, showMode);
376 this.invalidateMinimumSize();
373 }, 377 },
374 378
375 /** 379 /**
376 * @param {number} size 380 * @param {number} size
377 * @param {boolean=} ignoreConstraints 381 * @param {boolean=} ignoreConstraints
378 * @param {boolean=} animate 382 * @param {boolean=} animate
379 */ 383 */
380 _innerSetSidebarSize: function(size, ignoreConstraints, animate) 384 _innerSetSidebarSize: function(size, ignoreConstraints, animate)
381 { 385 {
382 if (this._showMode !== WebInspector.SplitView.ShowMode.Both) { 386 if (this._showMode !== WebInspector.SplitView.ShowMode.Both) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 window.cancelAnimationFrame(this._animationFrameHandle); 511 window.cancelAnimationFrame(this._animationFrameHandle);
508 delete this._animationFrameHandle; 512 delete this._animationFrameHandle;
509 } 513 }
510 if (this._animationCallback) { 514 if (this._animationCallback) {
511 this._animationCallback(); 515 this._animationCallback();
512 delete this._animationCallback; 516 delete this._animationCallback;
513 } 517 }
514 }, 518 },
515 519
516 /** 520 /**
517 * @param {number=} minWidth
518 * @param {number=} minHeight
519 */
520 setSidebarElementConstraints: function(minWidth, minHeight)
521 {
522 if (typeof minWidth === "number")
523 this._minimumSidebarWidth = minWidth;
524 if (typeof minHeight === "number")
525 this._minimumSidebarHeight = minHeight;
526 },
527
528 /**
529 * @param {number=} minWidth
530 * @param {number=} minHeight
531 */
532 setMainElementConstraints: function(minWidth, minHeight)
533 {
534 if (typeof minWidth === "number")
535 this._minimumMainWidth = minWidth;
536 if (typeof minHeight === "number")
537 this._minimumMainHeight = minHeight;
538 },
539
540 /**
541 * @param {number} sidebarSize 521 * @param {number} sidebarSize
542 * @return {number} 522 * @return {number}
543 */ 523 */
544 _applyConstraints: function(sidebarSize) 524 _applyConstraints: function(sidebarSize)
545 { 525 {
546 const minPadding = 20;
547 var totalSize = this.totalSize(); 526 var totalSize = this.totalSize();
548 var minimumSiderbarSizeContraint = this.isVertical() ? this._minimumSide barWidth : this._minimumSidebarHeight;
549 var from = minimumSiderbarSizeContraint || 0;
550 if (typeof minimumSiderbarSizeContraint !== "number")
551 from = Math.max(from, minPadding);
552 527
553 var minimumMainSizeConstraint = this.isVertical() ? this._minimumMainWid th : this._minimumMainHeight; 528 var size = this._sidebarView.minimumSize();
554 var minMainSize = minimumMainSizeConstraint || 0; 529 var from = this.isVertical() ? size.width : size.height;
555 if (typeof minimumMainSizeConstraint !== "number") 530 if (!from)
556 minMainSize = Math.max(minMainSize, minPadding); 531 from = WebInspector.SplitView.MinPadding;
532
533 size = this._mainView.minimumSize();
534 var minMainSize = this.isVertical() ? size.width : size.height;
535 if (!minMainSize)
536 minMainSize = WebInspector.SplitView.MinPadding;
557 537
558 var to = totalSize - minMainSize; 538 var to = totalSize - minMainSize;
559 if (from <= to) 539 if (from <= to)
560 return Number.constrain(sidebarSize, from, to); 540 return Number.constrain(sidebarSize, from, to);
561 541
562 return -1; 542 // If we don't have enough space (which is a very rare case), prioritize main view.
pfeldman 2014/03/14 06:23:10 This -1 was used for the case when _applyConstrain
dgozman 2014/03/14 15:55:15 I've removed check for this in _innerSetSidebarSiz
543 return Math.max(0, to);
563 }, 544 },
564 545
565 wasShown: function() 546 wasShown: function()
566 { 547 {
567 this._updateLayout(); 548 this._updateLayout();
568 }, 549 },
569 550
570 onResize: function() 551 onResize: function()
571 { 552 {
572 this._updateLayout(); 553 this._updateLayout();
573 }, 554 },
574 555
575 /** 556 /**
557 * @return {!Size}
558 */
559 calculateMinimumSize: function()
560 {
561 if (this._showMode === WebInspector.SplitView.ShowMode.OnlyMain)
562 return this._mainView.minimumSize();
563 if (this._showMode === WebInspector.SplitView.ShowMode.OnlySidebar)
564 return this._sidebarView.minimumSize();
565
566 var mainSize = this._mainView.minimumSize();
567 var sidebarSize = this._sidebarView.minimumSize();
568 var min = WebInspector.SplitView.MinPadding;
569 if (this._isVertical)
570 return new Size((mainSize.width || min) + (sidebarSize.width || min) , Math.max(mainSize.height, sidebarSize.height));
571 else
572 return new Size(Math.max(mainSize.width, sidebarSize.width), (mainSi ze.height || min) + (sidebarSize.height || min));
573 },
574
575 /**
576 * @param {!MouseEvent} event 576 * @param {!MouseEvent} event
577 * @return {boolean} 577 * @return {boolean}
578 */ 578 */
579 _startResizerDragging: function(event) 579 _startResizerDragging: function(event)
580 { 580 {
581 if (!this._resizable) 581 if (!this._resizable)
582 return false; 582 return false;
583 583
584 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) * WebInspector.zoomManager.zoomFactor(); 584 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) * WebInspector.zoomManager.zoomFactor();
585 this._dragOffset = (this._secondIsSidebar ? this.totalSize() - this._sid ebarSize : this._sidebarSize) - dipEventPosition; 585 this._dragOffset = (this._secondIsSidebar ? this.totalSize() - this._sid ebarSize : this._sidebarSize) - dipEventPosition;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 this._showHideSidebarButton.state = sidebarHidden ? "show" : "hide"; 812 this._showHideSidebarButton.state = sidebarHidden ? "show" : "hide";
813 this._showHideSidebarButton.element.classList.toggle("top-sidebar-show-h ide-button", !this.isVertical() && !this.isSidebarSecond()); 813 this._showHideSidebarButton.element.classList.toggle("top-sidebar-show-h ide-button", !this.isVertical() && !this.isSidebarSecond());
814 this._showHideSidebarButton.element.classList.toggle("right-sidebar-show -hide-button", this.isVertical() && this.isSidebarSecond()); 814 this._showHideSidebarButton.element.classList.toggle("right-sidebar-show -hide-button", this.isVertical() && this.isSidebarSecond());
815 this._showHideSidebarButton.element.classList.toggle("bottom-sidebar-sho w-hide-button", !this.isVertical() && this.isSidebarSecond()); 815 this._showHideSidebarButton.element.classList.toggle("bottom-sidebar-sho w-hide-button", !this.isVertical() && this.isSidebarSecond());
816 this._showHideSidebarButton.element.classList.toggle("left-sidebar-show- hide-button", this.isVertical() && !this.isSidebarSecond()); 816 this._showHideSidebarButton.element.classList.toggle("left-sidebar-show- hide-button", this.isVertical() && !this.isSidebarSecond());
817 this._showHideSidebarButton.title = sidebarHidden ? WebInspector.UIStrin g("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hide %s" , this._showHideSidebarButtonTitle); 817 this._showHideSidebarButton.title = sidebarHidden ? WebInspector.UIStrin g("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hide %s" , this._showHideSidebarButtonTitle);
818 }, 818 },
819 819
820 __proto__: WebInspector.View.prototype 820 __proto__: WebInspector.View.prototype
821 } 821 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698