[Dojo-checkins] bill - r22253 - dijit/trunk/layout
dojo-checkins-admin at dojotoolkit.org
dojo-checkins-admin at dojotoolkit.org
Fri May 28 05:26:00 EDT 2010
Author: bill
Date: Fri May 28 02:25:39 2010
New Revision: 22253
Modified:
dijit/trunk/layout/BorderContainer.js
Log:
Optimize splitter dragging. dijit.layout._Splitter no longer directly changes the size of the associated pane. It now calls _layoutChildren() with "left"/"right"/"top"/"bottom", and the new width/height to set that pane to. Fixes #11229 !strict.
Modified: dijit/trunk/layout/BorderContainer.js
==============================================================================
--- dijit/trunk/layout/BorderContainer.js (original)
+++ dijit/trunk/layout/BorderContainer.js Fri May 28 02:25:39 2010
@@ -153,7 +153,7 @@
delete this["_"+region];
delete this["_" +region+"Widget"];
if(this._started){
- this._layoutChildren(child.region);
+ this._layoutChildren();
}
dojo.removeClass(child.domNode, this.baseClass+"Pane");
},
@@ -190,9 +190,21 @@
this.inherited(arguments);
},
- _layoutChildren: function(/*String?*/changedRegion){
+ _layoutChildren: function(/*String?*/changedRegion, /*Number?*/ changedRegionSize){
// summary:
- // This is the main routine for setting size/position of each child
+ // This is the main routine for setting size/position of each child.
+ // description:
+ // With no arguments, measures the height of top/bottom panes, the width
+ // of left/right panes, and then sizes all panes accordingly.
+ //
+ // With changedRegion specified (as "left", "top", "bottom", or "right"),
+ // it changes that region's width/height to changedRegionSize and
+ // then resizes other regions that were affected.
+ // changedRegion:
+ // The region should be changed because splitter was dragged.
+ // "left", "right", "top", or "bottom".
+ // changedRegionSize:
+ // The new width/height (in pixels) to make changedRegion
if(!this._borderBox || !this._borderBox.h){
// We are currently hidden, or we haven't been sized by our parent yet.
@@ -215,20 +227,20 @@
// (because words wrap around). I don't think width will ever change though
// (except when the user drags a splitter).
if(this._top){
- topStyle = layoutTopBottom && this._top.style;
- topHeight = dojo.marginBox(this._top).h;
+ topStyle = (changedRegion == "top" || layoutTopBottom) && this._top.style;
+ topHeight = changedRegion == "top" ? changedRegionSize : dojo.marginBox(this._top).h;
}
if(this._left){
- leftStyle = layoutSides && this._left.style;
- leftWidth = dojo.marginBox(this._left).w;
+ leftStyle = (changedRegion == "left" || layoutSides) && this._left.style;
+ leftWidth = changedRegion == "left" ? changedRegionSize : dojo.marginBox(this._left).w;
}
if(this._right){
- rightStyle = layoutSides && this._right.style;
- rightWidth = dojo.marginBox(this._right).w;
+ rightStyle = (changedRegion == "right" || layoutSides) && this._right.style;
+ rightWidth = changedRegion == "right" ? changedRegionSize : dojo.marginBox(this._right).w;
}
if(this._bottom){
- bottomStyle = layoutTopBottom && this._bottom.style;
- bottomHeight = dojo.marginBox(this._bottom).h;
+ bottomStyle = (changedRegion == "bottom" || layoutTopBottom) && this._bottom.style;
+ bottomHeight = changedRegion == "bottom" ? changedRegionSize : dojo.marginBox(this._bottom).h;
}
var splitters = this._splitters;
@@ -327,6 +339,14 @@
center: { h: middleHeight, w: middleWidth }
};
+ if(changedRegion){
+ // Respond to splitter drag event by changing changedRegion's width or height
+ var child = this["_" + changedRegion + "Widget"],
+ mb = {};
+ mb[ /top|bottom/.test(changedRegion) ? "h" : "w"] = changedRegionSize;
+ child.resize ? child.resize(mb, dim[child.region]) : dojo.marginBox(child.domNode, mb);
+ }
+
// Nodes in IE<8 don't respond to t/l/b/r, and TEXTAREA doesn't respond in any browser
var janky = dojo.isIE < 8 || (dojo.isIE && dojo.isQuirks) || dojo.some(this.getChildren(), function(child){
return child.domNode.tagName == "TEXTAREA" || child.domNode.tagName == "INPUT";
@@ -353,23 +373,21 @@
resizeWidget(this._centerWidget, dim.center);
}else{
- // We've already sized the children by setting style.top/bottom/left/right...
- // Now just need to call resize() on those children telling them their new size,
- // so they can re-layout themselves
-
- // Calculate which panes need a notification
- var resizeList = {};
- if(changedRegion){
- resizeList[changedRegion] = resizeList.center = true;
- if(/top|bottom/.test(changedRegion) && this.design != "sidebar"){
- resizeList.left = resizeList.right = true;
- }else if(/left|right/.test(changedRegion) && this.design == "sidebar"){
- resizeList.top = resizeList.bottom = true;
- }
- }
-
+ // Calculate which panes need a notification that their size has been changed
+ // (we've already set style.top/bottom/left/right on those other panes).
+ var notifySides = !changedRegion || (/top|bottom/.test(changedRegion) && this.design != "sidebar"),
+ notifyTopBottom = !changedRegion || (/left|right/.test(changedRegion) && this.design == "sidebar"),
+ notifyList = {
+ center: true,
+ left: notifySides,
+ right: notifySides,
+ top: notifyTopBottom,
+ bottom: notifyTopBottom
+ };
+
+ // Send notification to those panes that have changed size
dojo.forEach(this.getChildren(), function(child){
- if(child.resize && (!changedRegion || child.region in resizeList)){
+ if(child.resize && notifyList[child.region]){
child.resize(null, dim[child.region]);
}
}, this);
@@ -525,7 +543,6 @@
region = this.region,
splitterStart = parseInt(this.domNode.style[region], 10),
resize = this._resize,
- mb = {},
childNode = this.child.domNode,
layoutFunc = dojo.hitch(this.container, this.container._layoutChildren),
de = dojo.doc.body;
@@ -537,10 +554,7 @@
boundChildSize = Math.max(Math.min(childSize, max), min);
if(resize || forceResize){
- mb[dim] = boundChildSize;
- // TODO: inefficient; we set the marginBox here and then immediately layoutFunc() needs to query it
- dojo.marginBox(childNode, mb);
- layoutFunc(region);
+ layoutFunc(region, boundChildSize);
}
splitterStyle[region] = factor * delta + splitterStart + (boundChildSize - childSize) + "px";
}),
@@ -600,10 +614,7 @@
return;
}
var childSize = dojo.marginBox(this.child.domNode)[ horizontal ? 'h' : 'w' ] + this._factor * tick;
- var mb = {};
- mb[ this.horizontal ? "h" : "w"] = Math.max(Math.min(childSize, this._computeMaxSize()), this.child.minSize);
- dojo.marginBox(this.child.domNode, mb);
- this.container._layoutChildren(this.region);
+ this.container._layoutChildren(this.region, Math.max(Math.min(childSize, this._computeMaxSize()), this.child.minSize));
dojo.stopEvent(e);
},
More information about the Dojo-checkins
mailing list