2 * @class Ext.resizer.SplitterTracker
3 * @extends Ext.dd.DragTracker
4 * Private utility class for Ext.Splitter.
7 Ext.define('Ext.resizer.SplitterTracker', {
8 extend: 'Ext.dd.DragTracker',
9 requires: ['Ext.util.Region'],
12 overlayCls: Ext.baseCSSPrefix + 'resizable-overlay',
14 getPrevCmp: function() {
15 var splitter = this.getSplitter();
16 return splitter.previousSibling();
19 getNextCmp: function() {
20 var splitter = this.getSplitter();
21 return splitter.nextSibling();
24 // ensure the tracker is enabled, store boxes of previous and next
25 // components and calculate the constrain region
26 onBeforeStart: function(e) {
28 prevCmp = me.getPrevCmp(),
29 nextCmp = me.getNextCmp();
31 // SplitterTracker is disabled if any of its adjacents are collapsed.
32 if (nextCmp.collapsed || prevCmp.collapsed) {
35 // store boxes of previous and next
36 me.prevBox = prevCmp.getEl().getBox();
37 me.nextBox = nextCmp.getEl().getBox();
38 me.constrainTo = me.calculateConstrainRegion();
41 // We move the splitter el. Add the proxy class.
42 onStart: function(e) {
43 var splitter = this.getSplitter(),
46 splitter.addCls(splitter.baseCls + '-active');
47 overlay = this.overlay = Ext.getBody().createChild({
51 overlay.unselectable();
52 overlay.setSize(Ext.core.Element.getViewWidth(true), Ext.core.Element.getViewHeight(true));
56 // calculate the constrain Region in which the splitter el may be moved.
57 calculateConstrainRegion: function() {
59 splitter = me.getSplitter(),
60 splitWidth = splitter.getWidth(),
61 defaultMin = splitter.defaultSplitMin,
62 orient = splitter.orientation,
64 prevCmp = me.getPrevCmp(),
66 nextCmp = me.getNextCmp(),
67 // prev and nextConstrainRegions are the maximumBoxes minus the
68 // minimumBoxes. The result is always the intersection
69 // of these two boxes.
70 prevConstrainRegion, nextConstrainRegion;
72 // vertical splitters, so resizing left to right
73 if (orient === 'vertical') {
75 // Region constructor accepts (top, right, bottom, left)
76 // anchored/calculated from the left
77 prevConstrainRegion = Ext.create('Ext.util.Region',
79 // Right boundary is x + maxWidth if there IS a maxWidth.
80 // Otherwise it is calculated based upon the minWidth of the next Component
81 (prevCmp.maxWidth ? prevBox.x + prevCmp.maxWidth : nextBox.right - (nextCmp.minWidth || defaultMin)) + splitWidth,
83 prevBox.x + (prevCmp.minWidth || defaultMin)
85 // anchored/calculated from the right
86 nextConstrainRegion = Ext.create('Ext.util.Region',
88 nextBox.right - (nextCmp.minWidth || defaultMin),
90 // Left boundary is right - maxWidth if there IS a maxWidth.
91 // Otherwise it is calculated based upon the minWidth of the previous Component
92 (nextCmp.maxWidth ? nextBox.right - nextCmp.maxWidth : prevBox.x + (prevBox.minWidth || defaultMin)) - splitWidth
95 // anchored/calculated from the top
96 prevConstrainRegion = Ext.create('Ext.util.Region',
97 prevBox.y + (prevCmp.minHeight || defaultMin),
99 // Bottom boundary is y + maxHeight if there IS a maxHeight.
100 // Otherwise it is calculated based upon the minWidth of the next Component
101 (prevCmp.maxHeight ? prevBox.y + prevCmp.maxHeight : nextBox.bottom - (nextCmp.minHeight || defaultMin)) + splitWidth,
104 // anchored/calculated from the bottom
105 nextConstrainRegion = Ext.create('Ext.util.Region',
106 // Top boundary is bottom - maxHeight if there IS a maxHeight.
107 // Otherwise it is calculated based upon the minHeight of the previous Component
108 (nextCmp.maxHeight ? nextBox.bottom - nextCmp.maxHeight : prevBox.y + (prevCmp.minHeight || defaultMin)) - splitWidth,
110 nextBox.bottom - (nextCmp.minHeight || defaultMin),
115 // intersection of the two regions to provide region draggable
116 return prevConstrainRegion.intersect(nextConstrainRegion);
119 // Performs the actual resizing of the previous and next components
120 performResize: function(e) {
122 offset = me.getOffset('dragTarget'),
123 splitter = me.getSplitter(),
124 orient = splitter.orientation,
125 prevCmp = me.getPrevCmp(),
126 nextCmp = me.getNextCmp(),
127 owner = splitter.ownerCt,
128 layout = owner.getLayout();
130 // Inhibit automatic container layout caused by setSize calls below.
131 owner.suspendLayout = true;
133 if (orient === 'vertical') {
135 if (!prevCmp.maintainFlex) {
137 prevCmp.setSize(me.prevBox.width + offset[0], prevCmp.getHeight());
141 if (!nextCmp.maintainFlex) {
143 nextCmp.setSize(me.nextBox.width - offset[0], nextCmp.getHeight());
149 if (!prevCmp.maintainFlex) {
151 prevCmp.setSize(prevCmp.getWidth(), me.prevBox.height + offset[1]);
155 if (!nextCmp.maintainFlex) {
157 nextCmp.setSize(prevCmp.getWidth(), me.nextBox.height - offset[1]);
161 delete owner.suspendLayout;
165 // perform the resize and remove the proxy class from the splitter el
168 splitter = me.getSplitter();
170 splitter.removeCls(splitter.baseCls + '-active');
178 // Track the proxy and set the proper XY coordinates
179 // while constraining the drag
180 onDrag: function(e) {
182 offset = me.getOffset('dragTarget'),
183 splitter = me.getSplitter(),
184 splitEl = splitter.getEl(),
185 orient = splitter.orientation;
187 if (orient === "vertical") {
188 splitEl.setX(me.startRegion.left + offset[0]);
190 splitEl.setY(me.startRegion.top + offset[1]);
194 getSplitter: function() {
195 return Ext.getCmp(this.getDragCt().id);