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