4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-layout-component-Component'>/**
19 </span> * @class Ext.layout.component.Component
20 * @extends Ext.layout.Layout
22 * <p>This class is intended to be extended or created via the <tt><b>{@link Ext.Component#componentLayout layout}</b></tt>
23 * configuration property. See <tt><b>{@link Ext.Component#componentLayout}</b></tt> for additional details.</p>
26 Ext.define('Ext.layout.component.Component', {
28 /* Begin Definitions */
30 extend: 'Ext.layout.Layout',
36 monitorChildren: true,
38 initLayout : function() {
43 if (!me.initialized) {
44 if (owner.frameSize) {
45 me.frameSize = owner.frameSize;
48 owner.frameSize = me.frameSize = {
56 me.callParent(arguments);
59 beforeLayout : function(width, height, isSetSize, layoutOwner) {
60 this.callParent(arguments);
64 ownerCt = owner.ownerCt,
65 layout = owner.layout,
66 isVisible = owner.isVisible(true),
67 ownerElChild = owner.el.child,
71 * Do not layout calculatedSized components for fixedLayouts unless the ownerCt == layoutOwner
72 * fixedLayouts means layouts which are never auto/auto in the sizing that comes from their ownerCt.
73 * Currently 3 layouts MAY be auto/auto (Auto, Border, and Box)
74 * The reason for not allowing component layouts is to stop component layouts from things such as Updater and
77 if (!isSetSize && !(Ext.isNumber(width) && Ext.isNumber(height)) && ownerCt && ownerCt.layout && ownerCt.layout.fixedLayout && ownerCt != layoutOwner) {
78 me.doContainerLayout();
82 // If an ownerCt is hidden, add my reference onto the layoutOnShow stack. Set the needsLayout flag.
83 // If the owner itself is a directly hidden floater, set the needsLayout object on that for when it is shown.
84 if (!isVisible && (owner.hiddenAncestor || owner.floating)) {
85 if (owner.hiddenAncestor) {
86 layoutCollection = owner.hiddenAncestor.layoutOnShow;
87 layoutCollection.remove(owner);
88 layoutCollection.add(owner);
97 if (isVisible && this.needsLayout(width, height)) {
99 me.rawHeight = height;
100 return owner.beforeComponentLayout(width, height, isSetSize, layoutOwner);
107 <span id='Ext-layout-component-Component-method-needsLayout'> /**
108 </span> * Check if the new size is different from the current size and only
109 * trigger a layout if it is necessary.
110 * @param {Mixed} width The new width to set.
111 * @param {Mixed} height The new height to set.
113 needsLayout : function(width, height) {
114 this.lastComponentSize = this.lastComponentSize || {
118 return (this.childrenChanged || this.lastComponentSize.width !== width || this.lastComponentSize.height !== height);
121 <span id='Ext-layout-component-Component-method-setElementSize'> /**
122 </span> * Set the size of any element supporting undefined, null, and values.
123 * @param {Mixed} width The new width to set.
124 * @param {Mixed} height The new height to set.
126 setElementSize: function(el, width, height) {
127 if (width !== undefined && height !== undefined) {
128 el.setSize(width, height);
130 else if (height !== undefined) {
131 el.setHeight(height);
133 else if (width !== undefined) {
138 <span id='Ext-layout-component-Component-method-getTarget'> /**
139 </span> * Returns the owner component's resize element.
140 * @return {Ext.core.Element}
142 getTarget : function() {
143 return this.owner.el;
146 <span id='Ext-layout-component-Component-method-getRenderTarget'> /**
147 </span> * <p>Returns the element into which rendering must take place. Defaults to the owner Component's encapsulating element.</p>
148 * May be overridden in Component layout managers which implement an inner element.
149 * @return {Ext.core.Element}
151 getRenderTarget : function() {
152 return this.owner.el;
155 <span id='Ext-layout-component-Component-method-setTargetSize'> /**
156 </span> * Set the size of the target element.
157 * @param {Mixed} width The new width to set.
158 * @param {Mixed} height The new height to set.
160 setTargetSize : function(width, height) {
162 me.setElementSize(me.owner.el, width, height);
164 if (me.owner.frameBody) {
165 var targetInfo = me.getTargetInfo(),
166 padding = targetInfo.padding,
167 border = targetInfo.border,
168 frameSize = me.frameSize;
170 me.setElementSize(me.owner.frameBody,
171 Ext.isNumber(width) ? (width - frameSize.left - frameSize.right - padding.left - padding.right - border.left - border.right) : width,
172 Ext.isNumber(height) ? (height - frameSize.top - frameSize.bottom - padding.top - padding.bottom - border.top - border.bottom) : height
177 width: !Ext.isNumber(width),
178 height: !Ext.isNumber(height)
181 me.lastComponentSize = {
187 getTargetInfo : function() {
188 if (!this.targetInfo) {
189 var target = this.getTarget(),
190 body = this.owner.getTargetEl();
194 top: target.getPadding('t'),
195 right: target.getPadding('r'),
196 bottom: target.getPadding('b'),
197 left: target.getPadding('l')
200 top: target.getBorderWidth('t'),
201 right: target.getBorderWidth('r'),
202 bottom: target.getBorderWidth('b'),
203 left: target.getBorderWidth('l')
206 top: body.getMargin('t'),
207 right: body.getMargin('r'),
208 bottom: body.getMargin('b'),
209 left: body.getMargin('l')
213 return this.targetInfo;
216 // Start laying out UP the ownerCt's layout when flagged to do so.
217 doOwnerCtLayouts: function() {
218 var owner = this.owner,
219 ownerCt = owner.ownerCt,
220 ownerCtComponentLayout, ownerCtContainerLayout;
226 ownerCtComponentLayout = ownerCt.componentLayout;
227 ownerCtContainerLayout = ownerCt.layout;
229 if (!owner.floating && ownerCtComponentLayout && ownerCtComponentLayout.monitorChildren && !ownerCtComponentLayout.layoutBusy) {
230 if (!ownerCt.suspendLayout && ownerCtContainerLayout && !ownerCtContainerLayout.layoutBusy) {
231 // AutoContainer Layout and Dock with auto in some dimension
232 if (ownerCtContainerLayout.bindToOwnerCtComponent === true) {
233 ownerCt.doComponentLayout();
236 else if (ownerCtContainerLayout.bindToOwnerCtContainer === true) {
237 ownerCtContainerLayout.layout();
243 doContainerLayout: function() {
246 ownerCt = owner.ownerCt,
247 layout = owner.layout,
248 ownerCtComponentLayout;
250 // Run the container layout if it exists (layout for child items)
251 // **Unless automatic laying out is suspended, or the layout is currently running**
252 if (!owner.suspendLayout && layout && layout.isLayout && !layout.layoutBusy) {
256 // Tell the ownerCt that it's child has changed and can be re-layed by ignoring the lastComponentSize cache.
257 if (ownerCt && ownerCt.componentLayout) {
258 ownerCtComponentLayout = ownerCt.componentLayout;
259 if (!owner.floating && ownerCtComponentLayout.monitorChildren && !ownerCtComponentLayout.layoutBusy) {
260 ownerCtComponentLayout.childrenChanged = true;
265 afterLayout : function(width, height, isSetSize, layoutOwner) {
266 this.doContainerLayout();
267 this.owner.afterComponentLayout(width, height, isSetSize, layoutOwner);