BorderSplitterTracker.html 7.7 KB

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