Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / layout / container / Auto.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.layout.container.Auto
17  * @extends Ext.layout.container.Container
18  *
19  * <p>The AutoLayout is the default layout manager delegated by {@link Ext.container.Container} to
20  * render any child Components when no <tt>{@link Ext.container.Container#layout layout}</tt> is configured into
21  * a <tt>{@link Ext.container.Container Container}.</tt>.  AutoLayout provides only a passthrough of any layout calls
22  * to any child containers.</p>
23  * {@img Ext.layout.container.Auto/Ext.layout.container.Auto.png Ext.layout.container.Auto container layout}
24  * Example usage:
25         Ext.create('Ext.Panel', {
26                 width: 500,
27                 height: 280,
28                 title: "AutoLayout Panel",
29                 layout: 'auto',
30                 renderTo: document.body,
31                 items: [{
32                         xtype: 'panel',
33                         title: 'Top Inner Panel',
34                         width: '75%',
35                         height: 90
36                 },{
37                         xtype: 'panel',
38                         title: 'Bottom Inner Panel',
39                         width: '75%',
40                         height: 90
41                 }]
42         });
43  */
44
45 Ext.define('Ext.layout.container.Auto', {
46
47     /* Begin Definitions */
48
49     alias: ['layout.auto', 'layout.autocontainer'],
50
51     extend: 'Ext.layout.container.Container',
52
53     /* End Definitions */
54
55     type: 'autocontainer',
56
57     bindToOwnerCtComponent: true,
58
59     // @private
60     onLayout : function(owner, target) {
61         var me = this,
62             items = me.getLayoutItems(),
63             ln = items.length,
64             i;
65
66         // Ensure the Container is only primed with the clear element if there are child items.
67         if (ln) {
68             // Auto layout uses natural HTML flow to arrange the child items.
69             // To ensure that all browsers (I'm looking at you IE!) add the bottom margin of the last child to the
70             // containing element height, we create a zero-sized element with style clear:both to force a "new line"
71             if (!me.clearEl) {
72                 me.clearEl = me.getRenderTarget().createChild({
73                     cls: Ext.baseCSSPrefix + 'clear',
74                     role: 'presentation'
75                 });
76             }
77
78             // Auto layout allows CSS to size its child items.
79             for (i = 0; i < ln; i++) {
80                 me.setItemSize(items[i]);
81             }
82         }
83     },
84
85     configureItem: function(item) {
86
87         // Auto layout does not manage any dimensions.
88         // We have to check our type, because this could be called as a superclass method in a subclass
89         if (this.type === 'autocontainer') {
90             item.layoutManagedHeight = 2;
91             item.layoutManagedWidth = 2;
92         }
93
94         this.callParent(arguments);
95     }
96 });