BorderSplitterTracker.html
7.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-resizer-BorderSplitterTracker'>/**
</span> * Private utility class for Ext.BorderSplitter.
* @private
*/
Ext.define('Ext.resizer.BorderSplitterTracker', {
extend: 'Ext.resizer.SplitterTracker',
requires: ['Ext.util.Region'],
getPrevCmp: null,
getNextCmp: null,
// calculate the constrain Region in which the splitter el may be moved.
calculateConstrainRegion: function() {
var me = this,
splitter = me.splitter,
collapseTarget = splitter.collapseTarget,
defaultSplitMin = splitter.defaultSplitMin,
sizePropCap = splitter.vertical ? 'Width' : 'Height',
minSizeProp = 'min' + sizePropCap,
maxSizeProp = 'max' + sizePropCap,
getSizeMethod = 'get' + sizePropCap,
neighbors = splitter.neighbors,
length = neighbors.length,
box = collapseTarget.el.getBox(),
left = box.x,
top = box.y,
right = box.right,
bottom = box.bottom,
size = splitter.vertical ? (right - left) : (bottom - top),
//neighborSizes = [],
i, neighbor, minRange, maxRange, maxGrowth, maxShrink, targetSize;
// if size=100 and minSize=80, we can reduce by 20 so minRange = minSize-size = -20
minRange = (collapseTarget[minSizeProp] || Math.min(size,defaultSplitMin)) - size;
// if maxSize=150, maxRange = maxSize - size = 50
maxRange = collapseTarget[maxSizeProp];
if (!maxRange) {
maxRange = 1e9;
} else {
maxRange -= size;
}
targetSize = size;
for (i = 0; i < length; ++i) {
neighbor = neighbors[i];
size = neighbor[getSizeMethod]();
//neighborSizes.push(size);
maxGrowth = size - neighbor[maxSizeProp]; // NaN if no maxSize or negative
maxShrink = size - (neighbor[minSizeProp] || Math.min(size,defaultSplitMin));
if (!isNaN(maxGrowth)) {
// if neighbor can only grow by 10 (maxGrowth = -10), minRange cannot be
// -20 anymore, but now only -10:
if (minRange < maxGrowth) {
minRange = maxGrowth;
}
}
// if neighbor can shrink by 20 (maxShrink=20), maxRange cannot be 50 anymore,
// but now only 20:
if (maxRange > maxShrink) {
maxRange = maxShrink;
}
}
if (maxRange - minRange < 2) {
return null;
}
box = new Ext.util.Region(top, right, bottom, left);
me.constraintAdjusters[splitter.collapseDirection](box, minRange, maxRange, splitter);
me.dragInfo = {
minRange: minRange,
maxRange: maxRange,
//neighborSizes: neighborSizes,
targetSize: targetSize
};
return box;
},
constraintAdjusters: {
// splitter is to the right of the box
left: function (box, minRange, maxRange, splitter) {
box[0] = box.x = box.left = box.right + minRange;
box.right += maxRange + splitter.getWidth();
},
// splitter is below the box
top: function (box, minRange, maxRange, splitter) {
box[1] = box.y = box.top = box.bottom + minRange;
box.bottom += maxRange + splitter.getHeight();
},
// splitter is above the box
bottom: function (box, minRange, maxRange, splitter) {
box.bottom = box.top - minRange;
box.top -= maxRange + splitter.getHeight();
},
// splitter is to the left of the box
right: function (box, minRange, maxRange, splitter) {
box.right = box.left - minRange;
box.left -= maxRange + splitter.getWidth();
}
},
onBeforeStart: function(e) {
var me = this,
splitter = me.splitter,
collapseTarget = splitter.collapseTarget,
neighbors = splitter.neighbors,
collapseEl = me.getSplitter().collapseEl,
target = e.getTarget(),
length = neighbors.length,
i, neighbor;
if (collapseEl && target === splitter.collapseEl.dom) {
return false;
}
if (collapseTarget.collapsed) {
return false;
}
// disabled if any neighbors are collapsed in parallel direction.
for (i = 0; i < length; ++i) {
neighbor = neighbors[i];
if (neighbor.collapsed && neighbor.isHorz === collapseTarget.isHorz) {
return false;
}
}
if (!(me.constrainTo = me.calculateConstrainRegion())) {
return false;
}
me.createDragOverlay();
return true;
},
performResize: function(e, offset) {
var me = this,
splitter = me.splitter,
collapseDirection = splitter.collapseDirection,
collapseTarget = splitter.collapseTarget,
// a vertical splitter adjusts horizontal dimensions
adjusters = me.splitAdjusters[splitter.vertical ? 'horz' : 'vert'],
delta = offset[adjusters.index],
dragInfo = me.dragInfo,
//neighbors = splitter.neighbors,
//length = neighbors.length,
//neighborSizes = dragInfo.neighborSizes,
//isVert = collapseTarget.isVert,
//i, neighbor,
owner;
if (collapseDirection == 'right' || collapseDirection == 'bottom') {
// these splitters grow by moving left/up, so flip the sign of delta...
delta = -delta;
}
// now constrain delta to our computed range:
delta = Math.min(Math.max(dragInfo.minRange, delta), dragInfo.maxRange);
if (delta) {
(owner = splitter.ownerCt).suspendLayouts();
adjusters.adjustTarget(collapseTarget, dragInfo.targetSize, delta);
//for (i = 0; i < length; ++i) {
// neighbor = neighbors[i];
// if (!neighbor.isCenter && !neighbor.maintainFlex && neighbor.isVert == isVert) {
// delete neighbor.flex;
// adjusters.adjustNeighbor(neighbor, neighborSizes[i], delta);
// }
//}
owner.resumeLayouts(true);
}
},
splitAdjusters: {
horz: {
index: 0,
//adjustNeighbor: function (neighbor, size, delta) {
// neighbor.setSize(size - delta);
//},
adjustTarget: function (target, size, delta) {
target.flex = null;
target.setSize(size + delta);
}
},
vert: {
index: 1,
//adjustNeighbor: function (neighbor, size, delta) {
// neighbor.setSize(undefined, size - delta);
//},
adjustTarget: function (target, targetSize, delta) {
target.flex = null;
target.setSize(undefined, targetSize + delta);
}
}
}
});
</pre>
</body>
</html>