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