2 X.UI.Layout.Canvas = X.UI.Layout.create( {
\r
3 name : 'CanvasLayout',
\r
5 overrideAttrsForSelf : {
\r
7 role : [ 0, X.UI.Dirty.CLEAN, X.UI.Attr.USER.UINODE, X.UI.Attr.Type.INIT_ONLY | X.UI.Attr.Type.LIST, 'none,chrome,container' ],
\r
9 width : [ '100%', X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH | X.UI.Attr.Type.PERCENT ],
\r
10 maxWidth : [ X.UI.Attr.AUTO, X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH | X.UI.Attr.Type.PERCENT ],
\r
11 height : [ 0, X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH | X.UI.Attr.Type.PERCENT ],
\r
12 maxHeight : [ X.UI.Attr.AUTO, X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH | X.UI.Attr.Type.PERCENT ]
\r
15 overrideAttrsForChild : {
\r
22 calculate : function( data, isNeedsDetection, x, y, w, h ){
\r
23 var uinodes, l, i, _x, _y, _w, _h, node;
\r
25 data.preMesure( w, h );
\r
27 if( isNeedsDetection && ( data.boxWidth === X.UI.Attr.AUTO || data.boxHeight === X.UI.Attr.AUTO ) ) return false;
\r
31 _w = data.contentWidth;
\r
32 _h = data.contentHeight;
\r
34 if( ( uinodes = data.uinodes ) && ( l = uinodes.length ) ){
\r
35 for( i = 0; i < l; ++i ){
\r
36 node = uinodes[ i ];
\r
37 node.calculate( false, _x, _y, _w, _h );
\r
40 if( data.contentHeight === X.UI.Attr.AUTO ){
\r
41 data.contentHeight = data.minContentHeight !== X.UI.Attr.AUTO ? data.minContentHeight : 0;
\r
45 data.updateLayout( x + data.boxX, y + data.boxY );
\r
52 X.UI._Box = X.UI._AbstractUINode.inherits(
\r
54 X.Class.PRIVATE_DATA | X.Class.SUPER_ACCESS, // 現状 super 指定がないとconstructor未定擬時に親のconstructor が使われない
\r
60 hitChildData : null,
\r
61 pointerChildren : true,
\r
67 Constructor : function( layout, args ){
\r
71 uinodes, arg, _data, attrs, support;
\r
73 if( !this.User.instanceOf( X.UI.Box ) ){
\r
74 //throw new Error( 'Box を継承したインスタンスだけが _Box のオーナーになれます' );
\r
77 this.xnode = X_Doc_create( 'div' );
\r
79 // すでに定義されていればそちらを採用
\r
80 // supportAttrs や attrClass が、layout を元に上書きされているため
\r
81 this.layout = this.layout || layout;
\r
83 for( ; i < l; ++i ){
\r
85 if( arg.instanceOf && arg.instanceOf( X.UI.AbstractUINode ) ){
\r
86 _data = X_Class_getPrivate( arg );
\r
87 if( !uinodes ) this.uinodes = uinodes = [];
\r
88 uinodes[ ++j ] = _data;
\r
90 //throw new Error( 'インスタンスはすでに親に追加されています ' + arg );
\r
93 if( arg.instanceOf && arg.instanceOf( X.UI.Layout.Base ) ){
\r
94 //this.layout = arg;
\r
96 if( X.Type.isObject( arg ) ){
\r
98 attrs = X_Class_override( attrs, arg );
\r
103 //throw new Error( 'AbstractUINode を継承したインスタンスを渡してください ' + arg );
\r
108 if( X_EMPTY_OBJECT[ p ] ) continue;
\r
109 ( support = this.supportAttrs[ p ] ) && this.setAttr( p, support, attrs[ p ] );
\r
113 initialize : function( root, rootData, parent, parentData ){
\r
114 var uinodes = this.uinodes,
\r
115 i = uinodes && uinodes.length;
\r
117 this.rootData = rootData;
\r
118 this.parent = parent;
\r
119 this.parentData = parentData;
\r
120 //this.xnode = X_Doc_create( 'div' );
\r
124 uinodes[ --i ].initialize( root, rootData, this.User, this );
\r
129 this.User.dispatch( { type : X.UI.Event.INIT } );
\r
132 addToParent : function( parentXNode ){
\r
133 var uinodes = this.uinodes,
\r
134 l = uinodes && uinodes.length,
\r
137 parentXNode && parentXNode.append( this.xnode );
\r
140 for( i = 0; i < l; ++i ){
\r
141 uinodes[ i ].addToParent( this.xnode );
\r
146 this.User.dispatch( { type : X.UI.Event.ADDED } );
\r
150 creationComplete : function(){
\r
151 var uinodes = this.uinodes,
\r
152 i = uinodes && uinodes.length;
\r
155 uinodes[ --i ].creationComplete();
\r
159 X.UI._AbstractUINode.prototype.creationComplete.apply( this, arguments );
\r
162 calculate : function( isNeedsDetection, x, y, w, h ){
\r
163 var ret = this.layout.calculate( this, isNeedsDetection, x, y, w, h );
\r
168 capcher : function( x, y ){
\r
169 var uinodes, child, _x, _y, hit, i;
\r
170 if( this.pointerDisabled ) return false;
\r
171 delete this.hitChildData;
\r
174 if( this.pointerChildren && ( uinodes = this.uinodes ) && ( i = uinodes.length ) ){
\r
175 _x = x - this.scrollingX;
\r
176 _y = y - this.scrollingY;
\r
178 child = uinodes[ --i ];
\r
179 if( !child.pointerDisabled && child.boxX <= _x && _x < child.boxX + child.boxWidth && child.boxY <= _y && _y < child.boxY + child.boxHeight && child.capcher( _x, _y ) ){
\r
180 //console.log( 'hit child ' + _x + ' ' + _y + ' boxX:' + child.boxX + ' boxY:' + child.boxY );
\r
181 this.hitChildData = child;
\r
186 if( this.through ){
\r
187 this.hitChildData && !this.hovering && ( this.rootData.hoverList[ this.rootData.hoverList.length ] = this );
\r
188 return !!this.hitChildData;
\r
190 hit = 0 <= x && x < this.boxWidth && 0 <= y && y < this.boxHeight;
\r
191 ( this.hitChildData || hit ) && !this.hovering && ( this.rootData.hoverList[ this.rootData.hoverList.length ] = this );
\r
192 if( hit && this.hitChildData === null ) this.rootData.targetNodeData = this;
\r
193 return hit || !!this.hitChildData;
\r
196 addAt : function( index, _uinodes ){
\r
197 //console.log( '# AddAt ' + this.phase )
\r
198 var uinodes = this.uinodes,
\r
199 num = uinodes.length,
\r
200 p1 = 1 <= this.phase,
\r
201 p2 = 2 <= this.phase,
\r
202 p3 = 3 <= this.phase,
\r
207 //console.log( '### AddAt ' + this.phase )
\r
208 for( l = _uinodes.length; i < l; ++i ){
\r
209 data = X_Class_getPrivate( _uinodes[ i ] );
\r
210 _p1 = p1 && data.phase < 1;
\r
211 _p2 = p2 && data.phase < 2;
\r
212 _p1 && data.initialize( this.root, this.rootData, this.User, this );
\r
213 if( index <= num ){
\r
214 // _p2 && this.xnode.insertBefore( data.xnode, uinodes[ index + i ].xnode );
\r
215 _p2 && uinodes[ index + i ].xnode.before( data.xnode );
\r
216 _p2 && data.addToParent( this.xnode );
\r
217 uinodes.splice( index + i, 0, data );
\r
219 _p2 && data.addToParent( this.xnode );
\r
220 uinodes[ uinodes.length ] = data;
\r
222 p3 && data.phase < 3 && data.creationComplete();
\r
224 4 <= this.phase && this.rootData.reserveCalc();
\r
227 remove : function( _uinodes ){
\r
228 //console.log( '# AddAt ' + this.phase )
\r
229 var uinodes = this.uinodes,
\r
230 i = _uinodes.length,
\r
233 //console.log( '### AddAt ' + this.phase )
\r
235 data = X_Class_getPrivate( _uinodes[ --i ] );
\r
236 if( ( n = uinodes.indexOf( data ) ) !== -1 ){
\r
237 uinodes.splice( n, 1 );
\r
241 4 <= this.phase && this.rootData.reserveCalc();
\r
244 removeAt : function( from, length ){
\r
245 var uinodes = this.uinodes,
\r
246 i = uinodes.length,
\r
247 to = from + ( X.Type.isNumber( length ) && 1 <= length ? length : 1 ),
\r
250 node = uinodes[ --i ];
\r
251 if( from <= i && i < to ){
\r
252 uinodes.splice( i, 1 );
\r
256 4 <= this.phase && this.rootData.reserveCalc();
\r
259 _remove : function(){
\r
260 var uinodes = this.uinodes,
\r
261 i = uinodes.length;
\r
262 for( ; i; ){ uinodes[ --i ]._remove(); };
\r
264 switch( this.phase ){
\r
268 this.xnode.remove();
\r
271 delete this.rootData;
\r
272 delete this.parent;
\r
273 delete this.parentData;
\r
281 X.UI.Box = X.UI.AbstractUINode.inherits(
\r
283 X.Class.SUPER_ACCESS,
\r
286 Constructor : function(){
\r
287 X_Class_newPrivate( this, X.UI.Layout.Canvas, arguments );
\r
290 add : function( node /* , node, node ... */ ){
\r
291 X_Class_getPrivate( this ).addAt( this.numNodes() + 1, Array.prototype.slice.call( arguments ) );
\r
294 addAt : function( index, node /* , node, node ... */ ){
\r
295 if( index < 0 ) index = 0;
\r
296 X_Class_getPrivate( this ).addAt( arguments[ 0 ], Array.prototype.slice.call( arguments, 1 ) );
\r
299 remove : function( node /* , node, node ... */ ){
\r
300 X_Class_getPrivate( this ).remove( Array.prototype.slice.call( arguments ) );
\r
303 removeAt : function( from, length ){
\r
304 X_Class_getPrivate( this ).removeAt( from, length );
\r
307 getNodesByClass : function( klass ){
\r
309 uinodes = X_Class_getPrivate( this ).uinodes,
\r
311 if( !uinodes || uinodes.length === 0 ) return ret;
\r
312 for( i = 0, l = uinodes.length; i < l; ++i ){
\r
313 node = uinodes[ i ].User;
\r
314 if( node.instanceOf( klass ) ) ret[ ret.length ] = node;
\r
318 getFirstChild : function(){
\r
319 return this.getNodeAt( 0 );
\r
321 getLastChild : function(){
\r
322 var uinodes = X_Class_getPrivate( this ).uinodes;
\r
323 return uinodes && uinodes.length && uinodes[ uinodes.length - 1 ].User || null;
\r
325 getNodeAt : function( index ){
\r
326 if( index < 0 ) return null;
\r
327 var uinodes = X_Class_getPrivate( this ).uinodes;
\r
328 return uinodes && uinodes[ index ].User || null;
\r
330 numNodes : function(){
\r
331 var uinodes = X_Class_getPrivate( this ).uinodes;
\r
332 return uinodes && uinodes.length || 0;
\r
338 * layout が設定されている Box のサブクラスに対して、layout を指定できない.
\r
341 X.UI.Box.presets = function(){
\r
342 var args = arguments,
\r
345 shadow = X_Class_getClassDef( this ).privateClass,
\r
346 layout = shadow.prototype.layout,
\r
347 arg, attrs, supports, klass, klassDef, privateKlass, boxName;
\r
349 for( ; i < l; ++i ){
\r
351 if( !arg ) continue;
\r
352 // レイアウトの preset ができるのは layout が未定義な Box だけ
\r
353 if( !shadow.prototype.layout && arg.instanceOf && arg.instanceOf( X.UI.Layout.Base ) ){
\r
356 if( ( klassDef = X_Class_getClassDef( arg ) ) && klassDef.isPrivate ){
\r
357 privateKlass = arg;
\r
358 layout = privateKlass.prototype.layout;
\r
360 if( X.Type.isObject( arg ) ){
\r
362 X_Class_override( attrs, arg, true );
\r
367 if( X.Type.isString( arg ) ){
\r
372 if( privateKlass ){
\r
373 supports = X.UI.Attr.createAttrDef( privateKlass.prototype.supportAttrs, layout.overrideAttrsForSelf );
\r
375 klass = this.inherits( privateKlass );
\r
376 privateKlass.prototype.supportAttrs = supports,
\r
377 privateKlass.prototype.attrClass = X.UI.Attr.preset( privateKlass.prototype.attrClass, supports, attrs );
\r
379 supports = X.UI.Attr.createAttrDef( shadow.prototype.supportAttrs, layout.overrideAttrsForSelf );
\r
381 klass = this.inherits(
\r
386 supportAttrs : supports,
\r
387 attrClass : X.UI.Attr.preset( shadow.prototype.attrClass, supports, attrs )
\r
393 klass.presets = this.presets || X.UI.Box.presets;
\r