Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / layout / component / Tip.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 Tip/ToolTip/etc. components
17  * @class Ext.layout.component.Tip
18  * @extends Ext.layout.component.Dock
19  * @private
20  */
21
22 Ext.define('Ext.layout.component.Tip', {
23
24     /* Begin Definitions */
25
26     alias: ['layout.tip'],
27
28     extend: 'Ext.layout.component.Dock',
29
30     /* End Definitions */
31
32     type: 'tip',
33     
34     onLayout: function(width, height) {
35         var me = this,
36             owner = me.owner,
37             el = owner.el,
38             minWidth,
39             maxWidth,
40             naturalWidth,
41             constrainedWidth,
42             xy = el.getXY();
43
44         // Position offscreen so the natural width is not affected by the viewport's right edge
45         el.setXY([-9999,-9999]);
46
47         // Calculate initial layout
48         this.callParent(arguments);
49
50         // Handle min/maxWidth for auto-width tips
51         if (!Ext.isNumber(width)) {
52             minWidth = owner.minWidth;
53             maxWidth = owner.maxWidth;
54             // IE6/7 in strict mode have a problem doing an autoWidth
55             if (Ext.isStrict && (Ext.isIE6 || Ext.isIE7)) {
56                 constrainedWidth = me.doAutoWidth();
57             } else {
58                 naturalWidth = el.getWidth();
59             }
60             if (naturalWidth < minWidth) {
61                 constrainedWidth = minWidth;
62             }
63             else if (naturalWidth > maxWidth) {
64                 constrainedWidth = maxWidth;
65             }
66             if (constrainedWidth) {
67                 this.callParent([constrainedWidth, height]);
68             }
69         }
70
71         // Restore position
72         el.setXY(xy);
73     },
74     
75     doAutoWidth: function(){
76         var me = this,
77             owner = me.owner,
78             body = owner.body,
79             width = body.getTextWidth();
80             
81         if (owner.header) {
82             width = Math.max(width, owner.header.getWidth());
83         }
84         if (!Ext.isDefined(me.frameWidth)) {
85             me.frameWidth = owner.el.getWidth() - body.getWidth();
86         }
87         width += me.frameWidth + body.getPadding('lr');
88         return width;
89     }
90 });
91