4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-layout-component-AbstractDock'>/**
19 </span> * @class Ext.layout.component.AbstractDock
20 * @extends Ext.layout.component.Component
22 * This ComponentLayout handles docking for Panels. It takes care of panels that are
23 * part of a ContainerLayout that sets this Panel's size and Panels that are part of
24 * an AutoContainerLayout in which this panel get his height based of the CSS or
28 Ext.define('Ext.layout.component.AbstractDock', {
30 /* Begin Definitions */
32 extend: 'Ext.layout.component.Component',
38 <span id='Ext-layout-component-AbstractDock-property-autoSizing'> /**
40 * @property autoSizing
42 * This flag is set to indicate this layout may have an autoHeight/autoWidth.
46 beforeLayout: function() {
47 var returnValue = this.callParent(arguments);
48 if (returnValue !== false && (!this.initializedBorders || this.childrenChanged) && (!this.owner.border || this.owner.manageBodyBorders)) {
49 this.handleItemBorders();
50 this.initializedBorders = true;
55 handleItemBorders: function() {
56 var owner = this.owner,
58 docked = this.getLayoutItems(),
65 oldBorders = this.borders,
72 i, ln, item, dock, side;
74 for (i = 0, ln = docked.length; i < ln; i++) {
78 if (item.ignoreBorderManagement) {
82 if (!borders[dock].satisfied) {
83 borders[dock].push(item);
84 borders[dock].satisfied = true;
87 if (!borders.top.satisfied && opposites[dock] !== 'top') {
88 borders.top.push(item);
90 if (!borders.right.satisfied && opposites[dock] !== 'right') {
91 borders.right.push(item);
93 if (!borders.bottom.satisfied && opposites[dock] !== 'bottom') {
94 borders.bottom.push(item);
96 if (!borders.left.satisfied && opposites[dock] !== 'left') {
97 borders.left.push(item);
102 for (side in oldBorders) {
103 if (oldBorders.hasOwnProperty(side)) {
104 ln = oldBorders[side].length;
105 if (!owner.manageBodyBorders) {
106 for (i = 0; i < ln; i++) {
107 oldBorders[side][i].removeCls(Ext.baseCSSPrefix + 'docked-noborder-' + side);
109 if (!oldBorders[side].satisfied && !owner.bodyBorder) {
110 body.removeCls(Ext.baseCSSPrefix + 'docked-noborder-' + side);
113 else if (oldBorders[side].satisfied) {
114 body.setStyle('border-' + side + '-width', '');
120 for (side in borders) {
121 if (borders.hasOwnProperty(side)) {
122 ln = borders[side].length;
123 if (!owner.manageBodyBorders) {
124 for (i = 0; i < ln; i++) {
125 borders[side][i].addCls(Ext.baseCSSPrefix + 'docked-noborder-' + side);
127 if ((!borders[side].satisfied && !owner.bodyBorder) || owner.bodyBorder === false) {
128 body.addCls(Ext.baseCSSPrefix + 'docked-noborder-' + side);
131 else if (borders[side].satisfied) {
132 body.setStyle('border-' + side + '-width', '1px');
137 this.borders = borders;
140 <span id='Ext-layout-component-AbstractDock-method-onLayout'> /**
142 * @param {Ext.Component} owner The Panel that owns this DockLayout
143 * @param {Ext.core.Element} target The target in which we are going to render the docked items
144 * @param {Array} args The arguments passed to the ComponentLayout.layout method
146 onLayout: function(width, height) {
150 layout = owner.layout,
151 target = me.getTarget(),
154 padding, border, frameSize;
156 // We start of by resetting all the layouts info
157 var info = me.info = {
165 // Clear isAutoDock flag
166 delete layout.isAutoDock;
168 Ext.applyIf(info, me.getTargetInfo());
170 // We need to bind to the ownerCt whenever we do not have a user set height or width.
171 if (owner && owner.ownerCt && owner.ownerCt.layout && owner.ownerCt.layout.isLayout) {
172 if (!Ext.isNumber(owner.height) || !Ext.isNumber(owner.width)) {
173 owner.ownerCt.layout.bindToOwnerCtComponent = true;
176 owner.ownerCt.layout.bindToOwnerCtComponent = false;
180 // Determine if we have an autoHeight or autoWidth.
181 if (height === undefined || height === null || width === undefined || width === null) {
182 padding = info.padding;
183 border = info.border;
184 frameSize = me.frameSize;
186 // Auto-everything, clear out any style height/width and read from css
187 if ((height === undefined || height === null) && (width === undefined || width === null)) {
190 me.setTargetSize(null);
191 me.setBodyBox({width: null, height: null});
194 else if (height === undefined || height === null) {
196 // Clear any sizing that we already set in a previous layout
197 me.setTargetSize(width);
198 me.setBodyBox({width: width - padding.left - border.left - padding.right - border.right - frameSize.left - frameSize.right, height: null});
203 // Clear any sizing that we already set in a previous layout
204 me.setTargetSize(null, height);
205 me.setBodyBox({width: null, height: height - padding.top - padding.bottom - border.top - border.bottom - frameSize.top - frameSize.bottom});
209 if (layout && layout.isLayout) {
210 // Auto-Sized so have the container layout notify the component layout.
211 layout.bindToOwnerCtComponent = true;
212 // Set flag so we don't do a redundant container layout
213 layout.isAutoDock = layout.autoSize !== true;
216 // If this is an autosized container layout, then we must compensate for a
217 // body that is being autosized. We do not want to adjust the body's size
218 // to accommodate the dock items, but rather we will want to adjust the
221 // This is necessary because, particularly in a Box layout, all child items
222 // are set with absolute dimensions that are not flexible to the size of its
223 // innerCt/target. So once they are laid out, they are sized for good. By
224 // shrinking the body box to accommodate dock items, we're merely cutting off
225 // parts of the body. Not good. Instead, the target's size should expand
226 // to fit the dock items in. This is valid because the target container is
227 // suppose to be autosized to fit everything accordingly.
228 info.autoSizedCtLayout = layout.autoSize === true;
231 // The dockItems method will add all the top and bottom docked items height
232 // to the info.panelSize height. That's why we have to call setSize after
233 // we dock all the items to actually set the panel's width and height.
234 // We have to do this because the panel body and docked items will be position
235 // absolute which doesn't stretch the panel.
236 me.dockItems(autoWidth, autoHeight);
237 me.setTargetSize(info.size.width, info.size.height);
240 me.setTargetSize(width, height);
243 me.callParent(arguments);
246 <span id='Ext-layout-component-AbstractDock-method-dockItems'> /**
248 * This method will first update all the information about the docked items,
249 * body dimensions and position, the panel's total size. It will then
250 * set all these values on the docked items and panel body.
251 * @param {Array} items Array containing all the docked items
252 * @param {Boolean} autoBoxes Set this to true if the Panel is part of an
253 * AutoContainerLayout
255 dockItems : function(autoWidth, autoHeight) {
256 this.calculateDockBoxes(autoWidth, autoHeight);
258 // Both calculateAutoBoxes and calculateSizedBoxes are changing the
259 // information about the body, panel size, and boxes for docked items
260 // inside a property called info.
261 var info = this.info,
266 // We are going to loop over all the boxes that were calculated
267 // and set the position of each item the box belongs to.
268 for (i = 0; i < ln; i++) {
270 dock.item.setPosition(dock.x, dock.y);
271 if ((autoWidth || autoHeight) && dock.layout && dock.layout.isLayout) {
272 // Auto-Sized so have the container layout notify the component layout.
273 dock.layout.bindToOwnerCtComponent = true;
277 // Don't adjust body width/height if the target is using an auto container layout.
278 // But, we do want to adjust the body size if the container layout is auto sized.
279 if (!info.autoSizedCtLayout) {
281 info.bodyBox.width = null;
284 info.bodyBox.height = null;
288 // If the bodyBox has been adjusted because of the docked items
289 // we will update the dimensions and position of the panel's body.
290 this.setBodyBox(info.bodyBox);
293 <span id='Ext-layout-component-AbstractDock-method-calculateDockBoxes'> /**
295 * This method will set up some initial information about the panel size and bodybox
296 * and then loop over all the items you pass it to take care of stretching, aligning,
297 * dock position and all calculations involved with adjusting the body box.
298 * @param {Array} items Array containing all the docked items we have to layout
300 calculateDockBoxes : function(autoWidth, autoHeight) {
301 // We want to use the Panel's el width, and the Panel's body height as the initial
302 // size we are going to use in calculateDockBoxes. We also want to account for
303 // the border of the panel.
305 target = me.getTarget(),
306 items = me.getLayoutItems(),
312 padding = info.padding,
313 border = info.border,
314 frameSize = me.frameSize,
317 // If this Panel is inside an AutoContainerLayout, we will base all the calculations
318 // around the height of the body and the width of the panel.
320 size.height = bodyEl.getHeight() + padding.top + border.top + padding.bottom + border.bottom + frameSize.top + frameSize.bottom;
323 size.height = target.getHeight();
326 size.width = bodyEl.getWidth() + padding.left + border.left + padding.right + border.right + frameSize.left + frameSize.right;
329 size.width = target.getWidth();
333 x: padding.left + frameSize.left,
334 y: padding.top + frameSize.top,
335 width: size.width - padding.left - border.left - padding.right - border.right - frameSize.left - frameSize.right,
336 height: size.height - border.top - padding.top - border.bottom - padding.bottom - frameSize.top - frameSize.bottom
339 // Loop over all the docked items
340 for (i = 0; i < ln; i++) {
342 // The initBox method will take care of stretching and alignment
343 // In some cases it will also layout the dock items to be able to
344 // get a width or height measurement
345 box = me.initBox(item);
347 if (autoHeight === true) {
348 box = me.adjustAutoBox(box, i);
351 box = me.adjustSizedBox(box, i);
354 // Save our box. This allows us to loop over all docked items and do all
355 // calculations first. Then in one loop we will actually size and position
356 // all the docked items that have changed.
357 info.boxes.push(box);
361 <span id='Ext-layout-component-AbstractDock-method-adjustSizedBox'> /**
363 * This method will adjust the position of the docked item and adjust the body box
365 * @param {Object} box The box containing information about the width and height
366 * of this docked item
367 * @param {Number} index The index position of this docked item
368 * @return {Object} The adjusted box
370 adjustSizedBox : function(box, index) {
371 var bodyBox = this.info.bodyBox,
372 frameSize = this.frameSize,
374 padding = info.padding,
376 border = info.border;
388 box.y = (bodyBox.y + bodyBox.height) - box.height;
392 box.x = (bodyBox.x + bodyBox.width) - box.width;
396 if (box.ignoreFrame) {
397 if (pos == 'bottom') {
398 box.y += (frameSize.bottom + padding.bottom + border.bottom);
401 box.y -= (frameSize.top + padding.top + border.top);
403 if (pos == 'right') {
404 box.x += (frameSize.right + padding.right + border.right);
407 box.x -= (frameSize.left + padding.left + border.left);
411 // If this is not an overlaying docked item, we have to adjust the body box
415 bodyBox.y += box.height;
416 bodyBox.height -= box.height;
420 bodyBox.x += box.width;
421 bodyBox.width -= box.width;
425 bodyBox.height -= box.height;
429 bodyBox.width -= box.width;
436 <span id='Ext-layout-component-AbstractDock-method-adjustAutoBox'> /**
438 * This method will adjust the position of the docked item inside an AutoContainerLayout
439 * and adjust the body box accordingly.
440 * @param {Object} box The box containing information about the width and height
441 * of this docked item
442 * @param {Number} index The index position of this docked item
443 * @return {Object} The adjusted box
445 adjustAutoBox : function (box, index) {
446 var info = this.info,
448 bodyBox = info.bodyBox,
451 boxesLn = boxes.length,
453 frameSize = this.frameSize,
454 padding = info.padding,
455 border = info.border,
456 autoSizedCtLayout = info.autoSizedCtLayout,
457 ln = (boxesLn < index) ? boxesLn : index,
460 if (pos == 'top' || pos == 'bottom') {
461 // This can affect the previously set left and right and bottom docked items
462 for (i = 0; i < ln; i++) {
463 adjustBox = boxes[i];
464 if (adjustBox.stretched && adjustBox.type == 'left' || adjustBox.type == 'right') {
465 adjustBox.height += box.height;
467 else if (adjustBox.type == 'bottom') {
468 adjustBox.y += box.height;
477 bodyBox.y += box.height;
478 if (owner.isFixedHeight()) {
479 bodyBox.height -= box.height;
481 size.height += box.height;
488 if (owner.isFixedHeight()) {
489 bodyBox.height -= box.height;
491 size.height += box.height;
494 box.y = (bodyBox.y + bodyBox.height);
500 bodyBox.x += box.width;
501 if (owner.isFixedWidth()) {
502 bodyBox.width -= box.width;
504 size.width += box.width;
511 if (owner.isFixedWidth()) {
512 bodyBox.width -= box.width;
514 size.width += box.width;
517 box.x = (bodyBox.x + bodyBox.width);
521 if (box.ignoreFrame) {
522 if (pos == 'bottom') {
523 box.y += (frameSize.bottom + padding.bottom + border.bottom);
526 box.y -= (frameSize.top + padding.top + border.top);
528 if (pos == 'right') {
529 box.x += (frameSize.right + padding.right + border.right);
532 box.x -= (frameSize.left + padding.left + border.left);
538 <span id='Ext-layout-component-AbstractDock-method-initBox'> /**
540 * This method will create a box object, with a reference to the item, the type of dock
541 * (top, left, bottom, right). It will also take care of stretching and aligning of the
543 * @param {Ext.Component} item The docked item we want to initialize the box for
544 * @return {Object} The initial box containing width and height and other useful information
546 initBox : function(item) {
548 bodyBox = me.info.bodyBox,
549 horizontal = (item.dock == 'top' || item.dock == 'bottom'),
551 frameSize = me.frameSize,
553 padding = info.padding,
554 border = info.border,
557 overlay: item.overlay,
559 offsets: Ext.core.Element.parseBox(item.offsets || {}),
560 ignoreFrame: item.ignoreParentFrame
562 // First we are going to take care of stretch and align properties for all four dock scenarios.
563 if (item.stretch !== false) {
564 box.stretched = true;
566 box.x = bodyBox.x + box.offsets.left;
567 box.width = bodyBox.width - (box.offsets.left + box.offsets.right);
568 if (box.ignoreFrame) {
569 box.width += (frameSize.left + frameSize.right + border.left + border.right + padding.left + padding.right);
571 item.setCalculatedSize(box.width - item.el.getMargin('lr'), undefined, owner);
574 box.y = bodyBox.y + box.offsets.top;
575 box.height = bodyBox.height - (box.offsets.bottom + box.offsets.top);
576 if (box.ignoreFrame) {
577 box.height += (frameSize.top + frameSize.bottom + border.top + border.bottom + padding.top + padding.bottom);
579 item.setCalculatedSize(undefined, box.height - item.el.getMargin('tb'), owner);
581 // At this point IE will report the left/right-docked toolbar as having a width equal to the
582 // container's full width. Forcing a repaint kicks it into shape so it reports the correct width.
583 if (!Ext.supports.ComputedStyle) {
589 item.doComponentLayout();
590 box.width = item.getWidth() - (box.offsets.left + box.offsets.right);
591 box.height = item.getHeight() - (box.offsets.bottom + box.offsets.top);
592 box.y += box.offsets.top;
594 box.x = (item.align == 'right') ? bodyBox.width - box.width : bodyBox.x;
595 box.x += box.offsets.left;
599 // If we haven't calculated the width or height of the docked item yet
600 // do so, since we need this for our upcoming calculations
601 if (box.width == undefined) {
602 box.width = item.getWidth() + item.el.getMargin('lr');
604 if (box.height == undefined) {
605 box.height = item.getHeight() + item.el.getMargin('tb');
611 <span id='Ext-layout-component-AbstractDock-method-getLayoutItems'> /**
613 * Returns an array containing all the <b>visible</b> docked items inside this layout's owner Panel
614 * @return {Array} An array containing all the <b>visible</b> docked items of the Panel
616 getLayoutItems : function() {
617 var it = this.owner.getDockedItems(),
621 for (; i < ln; i++) {
622 if (it[i].isVisible(true)) {
629 <span id='Ext-layout-component-AbstractDock-method-renderItems'> /**
631 * Render the top and left docked items before any existing DOM nodes in our render target,
632 * and then render the right and bottom docked items after. This is important, for such things
633 * as tab stops and ARIA readers, that the DOM nodes are in a meaningful order.
634 * Our collection of docked items will already be ordered via Panel.getDockedItems().
636 renderItems: function(items, target) {
637 var cns = target.dom.childNodes,
643 // Calculate the number of DOM nodes in our target that are not our docked items
644 for (i = 0; i < cnsLn; i++) {
645 cn = Ext.get(cns[i]);
646 for (j = 0; j < ln; j++) {
648 if (item.rendered && (cn.id == item.el.id || cn.down('#' + item.el.id))) {
658 // Now we go through our docked items and render/move them
659 for (i = 0, j = 0; i < ln; i++, j++) {
662 // If we're now at the right/bottom docked item, we jump ahead in our
663 // DOM position, just past the existing DOM nodes.
665 // TODO: This is affected if users provide custom weight values to their
666 // docked items, which puts it out of (t,l,r,b) order. Avoiding a second
667 // sort operation here, for now, in the name of performance. getDockedItems()
668 // needs the sort operation not just for this layout-time rendering, but
669 // also for getRefItems() to return a logical ordering (FocusManager, CQ, et al).
670 if (i === j && (item.dock === 'right' || item.dock === 'bottom')) {
674 // Same logic as Layout.renderItems()
675 if (item && !item.rendered) {
676 this.renderItem(item, target, j);
678 else if (!this.isValidParent(item, target, j)) {
679 this.moveItem(item, target, j);
684 <span id='Ext-layout-component-AbstractDock-method-setBodyBox'> /**
686 * This function will be called by the dockItems method. Since the body is positioned absolute,
687 * we need to give it dimensions and a position so that it is in the middle surrounded by
689 * @param {Object} box An object containing new x, y, width and height values for the
692 setBodyBox : function(box) {
697 bodyMargin = info.bodyMargin,
698 padding = info.padding,
699 border = info.border,
700 frameSize = me.frameSize;
702 // Panel collapse effectively hides the Panel's body, so this is a no-op.
703 if (owner.collapsed) {
707 if (Ext.isNumber(box.width)) {
708 box.width -= bodyMargin.left + bodyMargin.right;
711 if (Ext.isNumber(box.height)) {
712 box.height -= bodyMargin.top + bodyMargin.bottom;
715 me.setElementSize(body, box.width, box.height);
716 if (Ext.isNumber(box.x)) {
717 body.setLeft(box.x - padding.left - frameSize.left);
719 if (Ext.isNumber(box.y)) {
720 body.setTop(box.y - padding.top - frameSize.top);
724 <span id='Ext-layout-component-AbstractDock-method-configureItem'> /**
726 * We are overriding the Ext.layout.Layout configureItem method to also add a class that
727 * indicates the position of the docked item. We use the itemCls (x-docked) as a prefix.
728 * An example of a class added to a dock: right item is x-docked-right
729 * @param {Ext.Component} item The item we are configuring
731 configureItem : function(item, pos) {
732 this.callParent(arguments);
733 if (item.dock == 'top' || item.dock == 'bottom') {
734 item.layoutManagedWidth = 1;
735 item.layoutManagedHeight = 2;
737 item.layoutManagedWidth = 2;
738 item.layoutManagedHeight = 1;
741 item.addCls(Ext.baseCSSPrefix + 'docked');
742 item.addClsWithUI('docked-' + item.dock);
745 afterRemove : function(item) {
746 this.callParent(arguments);
748 item.el.removeCls(this.itemCls + '-' + item.dock);
750 var dom = item.el.dom;
752 if (!item.destroying && dom) {
753 dom.parentNode.removeChild(dom);
755 this.childrenChanged = true;