Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / layout / component / Body.js
1 /**
2  * Component layout for components which maintain an inner body element which must be resized to synchronize with the
3  * Component size.
4  * @class Ext.layout.component.Body
5  * @extends Ext.layout.component.Component
6  * @private
7  */
8
9 Ext.define('Ext.layout.component.Body', {
10
11     /* Begin Definitions */
12
13     alias: ['layout.body'],
14
15     extend: 'Ext.layout.component.Component',
16
17     uses: ['Ext.layout.container.Container'],
18
19     /* End Definitions */
20
21     type: 'body',
22     
23     onLayout: function(width, height) {
24         var me = this,
25             owner = me.owner;
26
27         // Size the Component's encapsulating element according to the dimensions
28         me.setTargetSize(width, height);
29
30         // Size the Component's body element according to the content box of the encapsulating element
31         me.setBodySize.apply(me, arguments);
32
33         // We need to bind to the owner whenever we do not have a user set height or width.
34         if (owner && owner.layout && owner.layout.isLayout) {
35             if (!Ext.isNumber(owner.height) || !Ext.isNumber(owner.width)) {
36                 owner.layout.bindToOwnerCtComponent = true;
37             }
38             else {
39                 owner.layout.bindToOwnerCtComponent = false;
40             }
41         }
42         
43         me.callParent(arguments);
44     },
45
46     /**
47      * @private
48      * <p>Sizes the Component's body element to fit exactly within the content box of the Component's encapsulating element.<p>
49      */
50     setBodySize: function(width, height) {
51         var me = this,
52             owner = me.owner,
53             frameSize = owner.frameSize,
54             isNumber = Ext.isNumber;
55
56         if (isNumber(width)) {
57             width -= owner.el.getFrameWidth('lr') - frameSize.left - frameSize.right;
58         }
59         if (isNumber(height)) {
60             height -= owner.el.getFrameWidth('tb') - frameSize.top - frameSize.bottom;
61         }
62
63         me.setElementSize(owner.body, width, height);
64     }
65 });