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 = {
166 Ext.applyIf(info, me.getTargetInfo());
168 // We need to bind to the ownerCt whenever we do not have a user set height or width.
169 if (owner && owner.ownerCt && owner.ownerCt.layout && owner.ownerCt.layout.isLayout) {
170 if (!Ext.isNumber(owner.height) || !Ext.isNumber(owner.width)) {
171 owner.ownerCt.layout.bindToOwnerCtComponent = true;
174 owner.ownerCt.layout.bindToOwnerCtComponent = false;
178 // Determine if we have an autoHeight or autoWidth.
179 if (height === undefined || height === null || width === undefined || width === null) {
180 padding = info.padding;
181 border = info.border;
182 frameSize = me.frameSize;
184 // Auto-everything, clear out any style height/width and read from css
185 if ((height === undefined || height === null) && (width === undefined || width === null)) {
188 me.setTargetSize(null);
189 me.setBodyBox({width: null, height: null});
192 else if (height === undefined || height === null) {
194 // Clear any sizing that we already set in a previous layout
195 me.setTargetSize(width);
196 me.setBodyBox({width: width - padding.left - border.left - padding.right - border.right - frameSize.left - frameSize.right, height: null});
201 // Clear any sizing that we already set in a previous layout
202 me.setTargetSize(null, height);
203 me.setBodyBox({width: null, height: height - padding.top - padding.bottom - border.top - border.bottom - frameSize.top - frameSize.bottom});
207 if (layout && layout.isLayout) {
208 // Auto-Sized so have the container layout notify the component layout.
209 layout.bindToOwnerCtComponent = true;
212 // If this is an autosized container layout, then we must compensate for a
213 // body that is being autosized. We do not want to adjust the body's size
214 // to accommodate the dock items, but rather we will want to adjust the
217 // This is necessary because, particularly in a Box layout, all child items
218 // are set with absolute dimensions that are not flexible to the size of its
219 // innerCt/target. So once they are laid out, they are sized for good. By
220 // shrinking the body box to accommodate dock items, we're merely cutting off
221 // parts of the body. Not good. Instead, the target's size should expand
222 // to fit the dock items in. This is valid because the target container is
223 // suppose to be autosized to fit everything accordingly.
224 info.autoSizedCtLayout = layout.autoSize === true;
227 // The dockItems method will add all the top and bottom docked items height
228 // to the info.panelSize height. That's why we have to call setSize after
229 // we dock all the items to actually set the panel's width and height.
230 // We have to do this because the panel body and docked items will be position
231 // absolute which doesn't stretch the panel.
232 me.dockItems(autoWidth, autoHeight);
233 me.setTargetSize(info.size.width, info.size.height);
236 me.setTargetSize(width, height);
239 me.callParent(arguments);
242 <span id='Ext-layout-component-AbstractDock-method-dockItems'> /**
244 * This method will first update all the information about the docked items,
245 * body dimensions and position, the panel's total size. It will then
246 * set all these values on the docked items and panel body.
247 * @param {Array} items Array containing all the docked items
248 * @param {Boolean} autoBoxes Set this to true if the Panel is part of an
249 * AutoContainerLayout
251 dockItems : function(autoWidth, autoHeight) {
252 this.calculateDockBoxes(autoWidth, autoHeight);
254 // Both calculateAutoBoxes and calculateSizedBoxes are changing the
255 // information about the body, panel size, and boxes for docked items
256 // inside a property called info.
257 var info = this.info,
262 // We are going to loop over all the boxes that were calculated
263 // and set the position of each item the box belongs to.
264 for (i = 0; i < ln; i++) {
266 dock.item.setPosition(dock.x, dock.y);
267 if ((autoWidth || autoHeight) && dock.layout && dock.layout.isLayout) {
268 // Auto-Sized so have the container layout notify the component layout.
269 dock.layout.bindToOwnerCtComponent = true;
273 // Don't adjust body width/height if the target is using an auto container layout.
274 // But, we do want to adjust the body size if the container layout is auto sized.
275 if (!info.autoSizedCtLayout) {
277 info.bodyBox.width = null;
280 info.bodyBox.height = null;
284 // If the bodyBox has been adjusted because of the docked items
285 // we will update the dimensions and position of the panel's body.
286 this.setBodyBox(info.bodyBox);
289 <span id='Ext-layout-component-AbstractDock-method-calculateDockBoxes'> /**
291 * This method will set up some initial information about the panel size and bodybox
292 * and then loop over all the items you pass it to take care of stretching, aligning,
293 * dock position and all calculations involved with adjusting the body box.
294 * @param {Array} items Array containing all the docked items we have to layout
296 calculateDockBoxes : function(autoWidth, autoHeight) {
297 // We want to use the Panel's el width, and the Panel's body height as the initial
298 // size we are going to use in calculateDockBoxes. We also want to account for
299 // the border of the panel.
301 target = me.getTarget(),
302 items = me.getLayoutItems(),
308 padding = info.padding,
309 border = info.border,
310 frameSize = me.frameSize,
313 // If this Panel is inside an AutoContainerLayout, we will base all the calculations
314 // around the height of the body and the width of the panel.
316 size.height = bodyEl.getHeight() + padding.top + border.top + padding.bottom + border.bottom + frameSize.top + frameSize.bottom;
319 size.height = target.getHeight();
322 size.width = bodyEl.getWidth() + padding.left + border.left + padding.right + border.right + frameSize.left + frameSize.right;
325 size.width = target.getWidth();
329 x: padding.left + frameSize.left,
330 y: padding.top + frameSize.top,
331 width: size.width - padding.left - border.left - padding.right - border.right - frameSize.left - frameSize.right,
332 height: size.height - border.top - padding.top - border.bottom - padding.bottom - frameSize.top - frameSize.bottom
335 // Loop over all the docked items
336 for (i = 0; i < ln; i++) {
338 // The initBox method will take care of stretching and alignment
339 // In some cases it will also layout the dock items to be able to
340 // get a width or height measurement
341 box = me.initBox(item);
343 if (autoHeight === true) {
344 box = me.adjustAutoBox(box, i);
347 box = me.adjustSizedBox(box, i);
350 // Save our box. This allows us to loop over all docked items and do all
351 // calculations first. Then in one loop we will actually size and position
352 // all the docked items that have changed.
353 info.boxes.push(box);
357 <span id='Ext-layout-component-AbstractDock-method-adjustSizedBox'> /**
359 * This method will adjust the position of the docked item and adjust the body box
361 * @param {Object} box The box containing information about the width and height
362 * of this docked item
363 * @param {Number} index The index position of this docked item
364 * @return {Object} The adjusted box
366 adjustSizedBox : function(box, index) {
367 var bodyBox = this.info.bodyBox,
368 frameSize = this.frameSize,
370 padding = info.padding,
372 border = info.border;
384 box.y = (bodyBox.y + bodyBox.height) - box.height;
388 box.x = (bodyBox.x + bodyBox.width) - box.width;
392 if (box.ignoreFrame) {
393 if (pos == 'bottom') {
394 box.y += (frameSize.bottom + padding.bottom + border.bottom);
397 box.y -= (frameSize.top + padding.top + border.top);
399 if (pos == 'right') {
400 box.x += (frameSize.right + padding.right + border.right);
403 box.x -= (frameSize.left + padding.left + border.left);
407 // If this is not an overlaying docked item, we have to adjust the body box
411 bodyBox.y += box.height;
412 bodyBox.height -= box.height;
416 bodyBox.x += box.width;
417 bodyBox.width -= box.width;
421 bodyBox.height -= box.height;
425 bodyBox.width -= box.width;
432 <span id='Ext-layout-component-AbstractDock-method-adjustAutoBox'> /**
434 * This method will adjust the position of the docked item inside an AutoContainerLayout
435 * and adjust the body box accordingly.
436 * @param {Object} box The box containing information about the width and height
437 * of this docked item
438 * @param {Number} index The index position of this docked item
439 * @return {Object} The adjusted box
441 adjustAutoBox : function (box, index) {
442 var info = this.info,
443 bodyBox = info.bodyBox,
446 boxesLn = boxes.length,
448 frameSize = this.frameSize,
449 padding = info.padding,
450 border = info.border,
451 autoSizedCtLayout = info.autoSizedCtLayout,
452 ln = (boxesLn < index) ? boxesLn : index,
455 if (pos == 'top' || pos == 'bottom') {
456 // This can affect the previously set left and right and bottom docked items
457 for (i = 0; i < ln; i++) {
458 adjustBox = boxes[i];
459 if (adjustBox.stretched && adjustBox.type == 'left' || adjustBox.type == 'right') {
460 adjustBox.height += box.height;
462 else if (adjustBox.type == 'bottom') {
463 adjustBox.y += box.height;
472 bodyBox.y += box.height;
474 size.height += box.height;
478 box.y = (bodyBox.y + bodyBox.height);
479 size.height += box.height;
485 bodyBox.x += box.width;
486 if (autoSizedCtLayout) {
487 size.width += box.width;
489 bodyBox.width -= box.width;
496 if (autoSizedCtLayout) {
497 size.width += box.width;
499 bodyBox.width -= box.width;
502 box.x = (bodyBox.x + bodyBox.width);
506 if (box.ignoreFrame) {
507 if (pos == 'bottom') {
508 box.y += (frameSize.bottom + padding.bottom + border.bottom);
511 box.y -= (frameSize.top + padding.top + border.top);
513 if (pos == 'right') {
514 box.x += (frameSize.right + padding.right + border.right);
517 box.x -= (frameSize.left + padding.left + border.left);
523 <span id='Ext-layout-component-AbstractDock-method-initBox'> /**
525 * This method will create a box object, with a reference to the item, the type of dock
526 * (top, left, bottom, right). It will also take care of stretching and aligning of the
528 * @param {Ext.Component} item The docked item we want to initialize the box for
529 * @return {Object} The initial box containing width and height and other useful information
531 initBox : function(item) {
533 bodyBox = me.info.bodyBox,
534 horizontal = (item.dock == 'top' || item.dock == 'bottom'),
536 frameSize = me.frameSize,
538 padding = info.padding,
539 border = info.border,
542 overlay: item.overlay,
544 offsets: Ext.core.Element.parseBox(item.offsets || {}),
545 ignoreFrame: item.ignoreParentFrame
547 // First we are going to take care of stretch and align properties for all four dock scenarios.
548 if (item.stretch !== false) {
549 box.stretched = true;
551 box.x = bodyBox.x + box.offsets.left;
552 box.width = bodyBox.width - (box.offsets.left + box.offsets.right);
553 if (box.ignoreFrame) {
554 box.width += (frameSize.left + frameSize.right + border.left + border.right + padding.left + padding.right);
556 item.setCalculatedSize(box.width - item.el.getMargin('lr'), undefined, owner);
559 box.y = bodyBox.y + box.offsets.top;
560 box.height = bodyBox.height - (box.offsets.bottom + box.offsets.top);
561 if (box.ignoreFrame) {
562 box.height += (frameSize.top + frameSize.bottom + border.top + border.bottom + padding.top + padding.bottom);
564 item.setCalculatedSize(undefined, box.height - item.el.getMargin('tb'), owner);
566 // At this point IE will report the left/right-docked toolbar as having a width equal to the
567 // container's full width. Forcing a repaint kicks it into shape so it reports the correct width.
568 if (!Ext.supports.ComputedStyle) {
574 item.doComponentLayout();
575 box.width = item.getWidth() - (box.offsets.left + box.offsets.right);
576 box.height = item.getHeight() - (box.offsets.bottom + box.offsets.top);
577 box.y += box.offsets.top;
579 box.x = (item.align == 'right') ? bodyBox.width - box.width : bodyBox.x;
580 box.x += box.offsets.left;
584 // If we haven't calculated the width or height of the docked item yet
585 // do so, since we need this for our upcoming calculations
586 if (box.width == undefined) {
587 box.width = item.getWidth() + item.el.getMargin('lr');
589 if (box.height == undefined) {
590 box.height = item.getHeight() + item.el.getMargin('tb');
596 <span id='Ext-layout-component-AbstractDock-method-getLayoutItems'> /**
598 * Returns an array containing all the <b>visible</b> docked items inside this layout's owner Panel
599 * @return {Array} An array containing all the <b>visible</b> docked items of the Panel
601 getLayoutItems : function() {
602 var it = this.owner.getDockedItems(),
606 for (; i < ln; i++) {
607 if (it[i].isVisible(true)) {
614 <span id='Ext-layout-component-AbstractDock-method-renderItems'> /**
616 * Render the top and left docked items before any existing DOM nodes in our render target,
617 * and then render the right and bottom docked items after. This is important, for such things
618 * as tab stops and ARIA readers, that the DOM nodes are in a meaningful order.
619 * Our collection of docked items will already be ordered via Panel.getDockedItems().
621 renderItems: function(items, target) {
622 var cns = target.dom.childNodes,
628 // Calculate the number of DOM nodes in our target that are not our docked items
629 for (i = 0; i < cnsLn; i++) {
630 cn = Ext.get(cns[i]);
631 for (j = 0; j < ln; j++) {
633 if (item.rendered && (cn.id == item.el.id || cn.down('#' + item.el.id))) {
643 // Now we go through our docked items and render/move them
644 for (i = 0, j = 0; i < ln; i++, j++) {
647 // If we're now at the right/bottom docked item, we jump ahead in our
648 // DOM position, just past the existing DOM nodes.
650 // TODO: This is affected if users provide custom weight values to their
651 // docked items, which puts it out of (t,l,r,b) order. Avoiding a second
652 // sort operation here, for now, in the name of performance. getDockedItems()
653 // needs the sort operation not just for this layout-time rendering, but
654 // also for getRefItems() to return a logical ordering (FocusManager, CQ, et al).
655 if (i === j && (item.dock === 'right' || item.dock === 'bottom')) {
659 // Same logic as Layout.renderItems()
660 if (item && !item.rendered) {
661 this.renderItem(item, target, j);
663 else if (!this.isValidParent(item, target, j)) {
664 this.moveItem(item, target, j);
669 <span id='Ext-layout-component-AbstractDock-method-setBodyBox'> /**
671 * This function will be called by the dockItems method. Since the body is positioned absolute,
672 * we need to give it dimensions and a position so that it is in the middle surrounded by
674 * @param {Object} box An object containing new x, y, width and height values for the
677 setBodyBox : function(box) {
682 bodyMargin = info.bodyMargin,
683 padding = info.padding,
684 border = info.border,
685 frameSize = me.frameSize;
687 // Panel collapse effectively hides the Panel's body, so this is a no-op.
688 if (owner.collapsed) {
692 if (Ext.isNumber(box.width)) {
693 box.width -= bodyMargin.left + bodyMargin.right;
696 if (Ext.isNumber(box.height)) {
697 box.height -= bodyMargin.top + bodyMargin.bottom;
700 me.setElementSize(body, box.width, box.height);
701 if (Ext.isNumber(box.x)) {
702 body.setLeft(box.x - padding.left - frameSize.left);
704 if (Ext.isNumber(box.y)) {
705 body.setTop(box.y - padding.top - frameSize.top);
709 <span id='Ext-layout-component-AbstractDock-method-configureItem'> /**
711 * We are overriding the Ext.layout.Layout configureItem method to also add a class that
712 * indicates the position of the docked item. We use the itemCls (x-docked) as a prefix.
713 * An example of a class added to a dock: right item is x-docked-right
714 * @param {Ext.Component} item The item we are configuring
716 configureItem : function(item, pos) {
717 this.callParent(arguments);
719 item.addCls(Ext.baseCSSPrefix + 'docked');
720 item.addClsWithUI('docked-' + item.dock);
723 afterRemove : function(item) {
724 this.callParent(arguments);
726 item.el.removeCls(this.itemCls + '-' + item.dock);
728 var dom = item.el.dom;
730 if (!item.destroying && dom) {
731 dom.parentNode.removeChild(dom);
733 this.childrenChanged = true;