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( Node ) ){
\r
94 //this.layout = arg;
\r
96 if( arg.instanceOf && arg.instanceOf( X.UI.Layout.Base ) ){
\r
97 //this.layout = arg;
\r
99 if( X_Type_isObject( arg ) ){
\r
101 attrs = X_Class_override( attrs, arg );
\r
106 //throw new Error( 'AbstractUINode を継承したインスタンスを渡してください ' + arg );
\r
111 if( X_EMPTY_OBJECT[ p ] ) continue;
\r
112 ( support = this.supportAttrs[ p ] ) && this.setAttr( p, support, attrs[ p ] );
\r
116 initialize : function( root, rootData, parent, parentData ){
\r
117 var uinodes = this.uinodes,
\r
118 i = uinodes && uinodes.length;
\r
120 this.rootData = rootData;
\r
121 this.parent = parent;
\r
122 this.parentData = parentData;
\r
123 //this.xnode = X_Doc_create( 'div' );
\r
127 uinodes[ --i ].initialize( root, rootData, this.User, this );
\r
132 this.User.dispatch( { type : X.UI.Event.INIT } );
\r
135 addToParent : function( parentXNode ){
\r
136 var uinodes = this.uinodes,
\r
137 l = uinodes && uinodes.length,
\r
140 parentXNode && parentXNode.append( this.xnode );
\r
143 for( i = 0; i < l; ++i ){
\r
144 uinodes[ i ].addToParent( this.xnode );
\r
149 this.User.dispatch( { type : X.UI.Event.ADDED } );
\r
153 creationComplete : function(){
\r
154 var uinodes = this.uinodes,
\r
155 i = uinodes && uinodes.length;
\r
158 uinodes[ --i ].creationComplete();
\r
162 X.UI._AbstractUINode.prototype.creationComplete.apply( this, arguments );
\r
165 calculate : function( isNeedsDetection, x, y, w, h ){
\r
166 var ret = this.layout.calculate( this, isNeedsDetection, x, y, w, h );
\r
171 capcher : function( x, y ){
\r
172 var uinodes, child, _x, _y, hit, i;
\r
173 if( this.pointerDisabled ) return false;
\r
174 delete this.hitChildData;
\r
177 if( this.pointerChildren && ( uinodes = this.uinodes ) && ( i = uinodes.length ) ){
\r
178 _x = x - this.scrollingX;
\r
179 _y = y - this.scrollingY;
\r
181 child = uinodes[ --i ];
\r
182 if( !child.pointerDisabled && child.boxX <= _x && _x < child.boxX + child.boxWidth && child.boxY <= _y && _y < child.boxY + child.boxHeight && child.capcher( _x, _y ) ){
\r
183 //console.log( 'hit child ' + _x + ' ' + _y + ' boxX:' + child.boxX + ' boxY:' + child.boxY );
\r
184 this.hitChildData = child;
\r
189 if( this.through ){
\r
190 this.hitChildData && !this.hovering && ( this.rootData.hoverList[ this.rootData.hoverList.length ] = this );
\r
191 return !!this.hitChildData;
\r
193 hit = 0 <= x && x < this.boxWidth && 0 <= y && y < this.boxHeight;
\r
194 ( this.hitChildData || hit ) && !this.hovering && ( this.rootData.hoverList[ this.rootData.hoverList.length ] = this );
\r
195 if( hit && this.hitChildData === null ) this.rootData.targetNodeData = this;
\r
196 return hit || !!this.hitChildData;
\r
199 addAt : function( index, _uinodes ){
\r
200 //console.log( '# AddAt ' + this.phase )
\r
201 var uinodes = this.uinodes,
\r
202 num = uinodes.length,
\r
203 p1 = 1 <= this.phase,
\r
204 p2 = 2 <= this.phase,
\r
205 p3 = 3 <= this.phase,
\r
210 //console.log( '### AddAt ' + this.phase )
\r
211 for( l = _uinodes.length; i < l; ++i ){
\r
212 data = X_Class_getPrivate( _uinodes[ i ] );
\r
213 _p1 = p1 && data.phase < 1;
\r
214 _p2 = p2 && data.phase < 2;
\r
215 _p1 && data.initialize( this.root, this.rootData, this.User, this );
\r
216 if( index <= num ){
\r
217 // _p2 && this.xnode.insertBefore( data.xnode, uinodes[ index + i ].xnode );
\r
218 _p2 && uinodes[ index + i ].xnode.before( data.xnode );
\r
219 _p2 && data.addToParent( this.xnode );
\r
220 uinodes.splice( index + i, 0, data );
\r
222 _p2 && data.addToParent( this.xnode );
\r
223 uinodes[ uinodes.length ] = data;
\r
225 p3 && data.phase < 3 && data.creationComplete();
\r
227 4 <= this.phase && this.rootData.reserveCalc();
\r
230 remove : function( _uinodes ){
\r
231 //console.log( '# AddAt ' + this.phase )
\r
232 var uinodes = this.uinodes,
\r
233 i = _uinodes.length,
\r
236 //console.log( '### AddAt ' + this.phase )
\r
238 data = X_Class_getPrivate( _uinodes[ --i ] );
\r
239 if( ( n = uinodes.indexOf( data ) ) !== -1 ){
\r
240 uinodes.splice( n, 1 );
\r
244 4 <= this.phase && this.rootData.reserveCalc();
\r
247 removeAt : function( from, length ){
\r
248 var uinodes = this.uinodes,
\r
249 i = uinodes.length,
\r
250 to = from + ( X_Type_isNumber( length ) && 1 <= length ? length : 1 ),
\r
253 node = uinodes[ --i ];
\r
254 if( from <= i && i < to ){
\r
255 uinodes.splice( i, 1 );
\r
259 4 <= this.phase && this.rootData.reserveCalc();
\r
262 _remove : function(){
\r
263 var uinodes = this.uinodes,
\r
264 i = uinodes.length;
\r
265 for( ; i; ){ uinodes[ --i ]._remove(); };
\r
267 switch( this.phase ){
\r
271 this.xnode.remove();
\r
274 delete this.rootData;
\r
275 delete this.parent;
\r
276 delete this.parentData;
\r
284 X.UI.Box = X.UI.AbstractUINode.inherits(
\r
286 X.Class.SUPER_ACCESS,
\r
289 Constructor : function(){
\r
290 X_Class_newPrivate( this, X.UI.Layout.Canvas, arguments );
\r
293 add : function( node /* , node, node ... */ ){
\r
294 X_Class_getPrivate( this ).addAt( this.numNodes() + 1, Array.prototype.slice.call( arguments ) );
\r
297 addAt : function( index, node /* , node, node ... */ ){
\r
298 if( index < 0 ) index = 0;
\r
299 X_Class_getPrivate( this ).addAt( arguments[ 0 ], Array.prototype.slice.call( arguments, 1 ) );
\r
302 remove : function( node /* , node, node ... */ ){
\r
303 X_Class_getPrivate( this ).remove( Array.prototype.slice.call( arguments ) );
\r
306 removeAt : function( from, length ){
\r
307 X_Class_getPrivate( this ).removeAt( from, length );
\r
310 getNodesByClass : function( klass ){
\r
312 uinodes = X_Class_getPrivate( this ).uinodes,
\r
314 if( !uinodes || uinodes.length === 0 ) return ret;
\r
315 for( i = 0, l = uinodes.length; i < l; ++i ){
\r
316 node = uinodes[ i ].User;
\r
317 if( node.instanceOf( klass ) ) ret[ ret.length ] = node;
\r
321 getFirstChild : function(){
\r
322 return this.getNodeAt( 0 );
\r
324 getLastChild : function(){
\r
325 var uinodes = X_Class_getPrivate( this ).uinodes;
\r
326 return uinodes && uinodes.length && uinodes[ uinodes.length - 1 ].User || null;
\r
328 getNodeAt : function( index ){
\r
329 if( index < 0 ) return null;
\r
330 var uinodes = X_Class_getPrivate( this ).uinodes;
\r
331 return uinodes && uinodes[ index ].User || null;
\r
333 numNodes : function(){
\r
334 var uinodes = X_Class_getPrivate( this ).uinodes;
\r
335 return uinodes && uinodes.length || 0;
\r
341 * layout が設定されている Box のサブクラスに対して、layout を指定できない.
\r
344 X.UI.Box.presets = function(){
\r
345 var args = arguments,
\r
348 shadow = X_Class_getClassDef( this ).privateClass,
\r
349 layout = shadow.prototype.layout,
\r
350 arg, attrs, supports, klass, klassDef, privateKlass, boxName;
\r
352 for( ; i < l; ++i ){
\r
354 if( !arg ) continue;
\r
355 // レイアウトの preset ができるのは layout が未定義な Box だけ
\r
356 if( !shadow.prototype.layout && arg.instanceOf && arg.instanceOf( X.UI.Layout.Base ) ){
\r
359 if( ( klassDef = X_Class_getClassDef( arg ) ) && klassDef.isPrivate ){
\r
360 privateKlass = arg;
\r
361 layout = privateKlass.prototype.layout;
\r
363 if( X_Type_isObject( arg ) ){
\r
365 X_Class_override( attrs, arg, true );
\r
370 if( X_Type_isString( arg ) ){
\r
375 if( privateKlass ){
\r
376 supports = X.UI.Attr.createAttrDef( privateKlass.prototype.supportAttrs, layout.overrideAttrsForSelf );
\r
378 klass = this.inherits( privateKlass );
\r
379 privateKlass.prototype.supportAttrs = supports,
\r
380 privateKlass.prototype.attrClass = X.UI.Attr.preset( privateKlass.prototype.attrClass, supports, attrs );
\r
382 supports = X.UI.Attr.createAttrDef( shadow.prototype.supportAttrs, layout.overrideAttrsForSelf );
\r
384 klass = this.inherits(
\r
389 supportAttrs : supports,
\r
390 attrClass : X.UI.Attr.preset( shadow.prototype.attrClass, supports, attrs )
\r
396 klass.presets = this.presets || X.UI.Box.presets;
\r