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

Unified 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: width/height -> right/bottom 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 side-by-side diff with in-line comments
Download patch
Index: Source/devtools/front_end/SplitView.js
diff --git a/Source/devtools/front_end/SplitView.js b/Source/devtools/front_end/SplitView.js
index 8a69df9d84d3f7b3d1106a8ad89ba0651b811feb..37e576e2f20c1e0b834ebd667f912f565702d358 100644
--- a/Source/devtools/front_end/SplitView.js
+++ b/Source/devtools/front_end/SplitView.js
@@ -96,6 +96,8 @@ WebInspector.SplitView.Events = {
ShowModeChanged: "ShowModeChanged"
}
+WebInspector.SplitView.MinPadding = 20;
+
WebInspector.SplitView.prototype = {
/**
* @return {boolean}
@@ -134,6 +136,7 @@ WebInspector.SplitView.prototype = {
this._restoreAndApplyShowModeFromSettings();
this._updateShowHideSidebarButton();
this._updateResizersClass();
+ this.invalidateMinimumSize();
},
/**
@@ -142,7 +145,7 @@ WebInspector.SplitView.prototype = {
_updateLayout: function(animate)
{
delete this._totalSize; // Lazy update.
- this._innerSetSidebarSize(this._preferredSidebarSize(), false, animate);
+ this._innerSetSidebarSize(this._preferredSidebarSize(), !!animate);
},
/**
@@ -346,8 +349,9 @@ WebInspector.SplitView.prototype = {
*/
setSidebarSize: function(size)
{
- this._innerSetSidebarSize(size);
- this._saveSidebarSizeToSettings();
+ this._savedSidebarSize = size;
+ this._saveSetting();
+ this._innerSetSidebarSize(size, false);
},
/**
@@ -378,30 +382,22 @@ WebInspector.SplitView.prototype = {
this._saveShowModeToSettings();
this._updateShowHideSidebarButton();
this.dispatchEventToListeners(WebInspector.SplitView.Events.ShowModeChanged, showMode);
+ this.invalidateMinimumSize();
},
/**
* @param {number} size
- * @param {boolean=} ignoreConstraints
- * @param {boolean=} animate
+ * @param {boolean} animate
*/
- _innerSetSidebarSize: function(size, ignoreConstraints, animate)
+ _innerSetSidebarSize: function(size, animate)
{
- if (this._showMode !== WebInspector.SplitView.ShowMode.Both) {
- this._sidebarSize = size;
+ if (this._showMode !== WebInspector.SplitView.ShowMode.Both || !this.isShowing())
return;
- }
- if (!ignoreConstraints)
- size = this._applyConstraints(size);
+ size = this._applyConstraints(size);
if (this._sidebarSize === size)
return;
- if (size < 0) {
- // Never apply bad values, fix it upon onResize instead.
- return;
- }
-
this._removeAllLayoutProperties();
var sizeValue = (size / WebInspector.zoomManager.zoomFactor()) + "px";
@@ -522,52 +518,29 @@ WebInspector.SplitView.prototype = {
},
/**
- * @param {number=} minWidth
- * @param {number=} minHeight
- */
- setSidebarElementConstraints: function(minWidth, minHeight)
- {
- if (typeof minWidth === "number")
- this._minimumSidebarWidth = minWidth;
- if (typeof minHeight === "number")
- this._minimumSidebarHeight = minHeight;
- },
-
- /**
- * @param {number=} minWidth
- * @param {number=} minHeight
- */
- setMainElementConstraints: function(minWidth, minHeight)
- {
- if (typeof minWidth === "number")
- this._minimumMainWidth = minWidth;
- if (typeof minHeight === "number")
- this._minimumMainHeight = minHeight;
- },
-
- /**
* @param {number} sidebarSize
* @return {number}
*/
_applyConstraints: function(sidebarSize)
{
- const minPadding = 20;
var totalSize = this.totalSize();
- var minimumSiderbarSizeContraint = this.isVertical() ? this._minimumSidebarWidth : this._minimumSidebarHeight;
- var from = minimumSiderbarSizeContraint || 0;
- if (typeof minimumSiderbarSizeContraint !== "number")
- from = Math.max(from, minPadding);
- var minimumMainSizeConstraint = this.isVertical() ? this._minimumMainWidth : this._minimumMainHeight;
- var minMainSize = minimumMainSizeConstraint || 0;
- if (typeof minimumMainSizeConstraint !== "number")
- minMainSize = Math.max(minMainSize, minPadding);
+ var size = this._sidebarView.minimumSize();
+ var from = this.isVertical() ? size.width : size.height;
+ if (!from)
+ from = WebInspector.SplitView.MinPadding;
+
+ size = this._mainView.minimumSize();
+ var minMainSize = this.isVertical() ? size.width : size.height;
+ if (!minMainSize)
+ minMainSize = WebInspector.SplitView.MinPadding;
var to = totalSize - minMainSize;
if (from <= to)
return Number.constrain(sidebarSize, from, to);
- return -1;
+ // If we don't have enough space (which is a very rare case), prioritize main view.
+ return Math.max(0, to);
},
wasShown: function()
@@ -580,6 +553,30 @@ WebInspector.SplitView.prototype = {
this._updateLayout();
},
+ onLayout: function()
+ {
+ this._updateLayout();
+ },
+
+ /**
+ * @return {!Size}
+ */
+ calculateMinimumSize: function()
+ {
+ if (this._showMode === WebInspector.SplitView.ShowMode.OnlyMain)
+ return this._mainView.minimumSize();
+ if (this._showMode === WebInspector.SplitView.ShowMode.OnlySidebar)
+ return this._sidebarView.minimumSize();
+
+ var mainSize = this._mainView.minimumSize();
+ var sidebarSize = this._sidebarView.minimumSize();
+ var min = WebInspector.SplitView.MinPadding;
+ if (this._isVertical)
+ return new Size((mainSize.width || min) + (sidebarSize.width || min), Math.max(mainSize.height, sidebarSize.height));
+ else
+ return new Size(Math.max(mainSize.width, sidebarSize.width), (mainSize.height || min) + (sidebarSize.height || min));
+ },
+
/**
* @param {!MouseEvent} event
* @return {boolean}
@@ -602,7 +599,10 @@ WebInspector.SplitView.prototype = {
var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) * WebInspector.zoomManager.zoomFactor();
var newOffset = dipEventPosition + this._dragOffset;
var newSize = (this._secondIsSidebar ? this.totalSize() - newOffset : newOffset);
- this.setSidebarSize(newSize);
+ var constrainedSize = this._applyConstraints(newSize);
+ this._savedSidebarSize = constrainedSize;
+ this._saveSetting();
+ this._innerSetSidebarSize(constrainedSize, false);
event.preventDefault();
},
@@ -612,7 +612,6 @@ WebInspector.SplitView.prototype = {
_endResizerDragging: function(event)
{
delete this._dragOffset;
- this._saveSidebarSizeToSettings();
},
hideDefaultResizer: function()
@@ -745,15 +744,6 @@ WebInspector.SplitView.prototype = {
}
},
- _saveSidebarSizeToSettings: function()
- {
- if (this._sidebarSize < 0)
- return;
-
- this._savedSidebarSize = this._sidebarSize;
- this._saveSetting();
- },
-
_saveShowModeToSettings: function()
{
this._savedShowMode = this._showMode;

Powered by Google App Engine
This is Rietveld 408576698