X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F20_ui%2F06_AbstractUINode.js;h=5e0dce71351788189be4b08c6edbe9b2e2a3b95f;hb=3d352d8bf476ab57cc333e8d02d0e6ea5efa69b7;hp=5bfc6c91e49ae30c05a5afa265d8e18f15327e82;hpb=2956150a7c2798e60639b36d69b0c13f6b20a62a;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/20_ui/06_AbstractUINode.js b/0.6.x/js/20_ui/06_AbstractUINode.js index 5bfc6c9..5e0dce7 100644 --- a/0.6.x/js/20_ui/06_AbstractUINode.js +++ b/0.6.x/js/20_ui/06_AbstractUINode.js @@ -1,7 +1,10 @@ +// TODO -> Node[ 'inherits' ] var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( 'X.UI._AbstractUINode', X_Class.ABSTRACT, { + itemData : null, + phase : 0, dirty : XUI_Dirty.CLEAN, @@ -12,7 +15,7 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( parentData : null, xnode : null, - supportAttrs : XUI_Attr_Support, + usableAttrs : XUI_Attr_Support, attrClass : XUI_AttrClass, attrObject : null, unverifiedAttrs : null, @@ -30,28 +33,30 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( boxX : 0, boxY : 0, - scrollWidth : 0, // remove? - scrollHeight : 0, // remove? boxWidth : XUI_Attr_AUTO, - minBoxWidth : 0, - maxBoxWidth : XUI_Attr_AUTO, + boxWidthMin : 0, + boxWidthMax : XUI_Attr_AUTO, boxHeight : XUI_Attr_AUTO, - minBoxHeight : 0, - maxBoxHeight : XUI_Attr_AUTO, + boxHeightMin : 0, + boxHeightMax : XUI_Attr_AUTO, contentL : 0, contentT : 0, contentR : 0, contentB : 0, + paddingL : 0, + paddingT : 0, + borderL : 0, + borderT : 0, boxSizingOffsetLR : 0, boxSizingOffsetTB : 0, contentWidth : XUI_Attr_AUTO, - minContentWidth : 0, - maxContentWidth : XUI_Attr_AUTO, - lastContentWidth : -1, + contentWidthMin : 0, + contentWidthMax : XUI_Attr_AUTO, + contentWidthLast : -1, contentHeight : XUI_Attr_AUTO, - minContentHeight : 0, - maxContentHeight : XUI_Attr_AUTO, - lastContentHeight : -1, + contentHeightMin : 0, + contentHeightMax : XUI_Attr_AUTO, + contentHeightLast : -1, constraintW : false, constraintH : false, @@ -68,15 +73,27 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( this.rootData = rootData; this.parent = parent; this.parentData = parentData; - //this.xnode = X_Doc_create( 'div' ); this.phase = 1; this[ 'dispatch' ]( XUI_Event.INIT ); }, addToParent : function( xnodeParent ){ + var attr = this.attrObject || this.attrClass.prototype, + usableAttrs = this.usableAttrs, + i = 0, l = usableAttrs.length, def; + xnodeParent && xnodeParent[ 'append' ]( this.xnode ); + if( attr ){ + for( k in usableAttrs ){ + def = usableAttrs[ k ]; + if( def[ 2 ] === XUI_Attr_USER.XNODE && X_Object_inObject( def.No, attr ) && attr[ k ] !== def[ 0 ] ){ + this.xnode[ 'css' ]( XUI_Attr_Rename[ k ] || k, XUI_AbstractUINode_createCssText( this, k ) ); + }; + }; + }; + this.phase = 2; this[ 'dispatch' ]( XUI_Event.ADDED ); }, @@ -89,6 +106,7 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( this.User[ 'dispatch' ]( XUI_Event.CREATION_COMPLETE ); // html 要素が親に追加されるまで控えていたイベントの登録 + // TODO listenOnce if( events && ( l = events.length ) ){ for( i = 0; i < l; ++i ){ this.listen.apply( this, events[ i ] ); @@ -227,6 +245,7 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( if( !v && v !== 0 ) v = defaultVal; + // UIAttrClass の初期設定の場合、ここで終わる if( XUI_attrClassProto ){ attrs[ propID ] = v; return; @@ -277,7 +296,7 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( getAttr : function( name ){ var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass, - support = this.supportAttrs[ name ], + support = this.usableAttrs[ name ], v, type, list; if( !support ) return; @@ -352,15 +371,17 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( * X_Node_BoxModel の情報を引きながら top,left,width,height,padding,border の設定 */ updateLayout : function(){ - var x = this.boxX, - y = this.boxY; + var x = this.boxX + ( this.parentData ? this.parentData.paddingL : 0 ), + y = this.boxY + ( this.parentData ? this.parentData.paddingT : 0 ), + w = X_UA[ 'IE5x' ] ? this.boxWidth : this.contentWidth, // IE6 の互換モードも + h = X_UA[ 'IE5x' ] ? this.boxHeight : this.contentHeight; this.xnode - [ 'css' ]( 'left', x ? x + 'em' : 0 ) - [ 'css' ]( 'top', y ? y + 'em' : 0 ) - [ 'css' ]( 'width', this.noWidth ? 'auto' : this.contentWidth ? this.contentWidth + 'em' : 0 ) - [ 'css' ]( 'height', this.noHeight ? 'auto' : this.contentHeight ? this.contentHeight + 'em' : 0 ) - [ 'css' ]( 'padding', XUI_AbstractUINode_createCssText( this, 'padding' ) ) + [ 'css' ]( 'left', x ? x + 'em' : 0 ) // 親の padding 分ずらす + [ 'css' ]( 'top', y ? y + 'em' : 0 ) // 親の padding 分ずらす + [ 'css' ]( 'width', this.noWidth ? 'auto' : w ? w + 'em' : 0 ) + [ 'css' ]( 'height', this.noHeight ? 'auto' : h ? h + 'em' : 0 ) + [ 'css' ]( 'padding', XUI_AbstractUINode_createCssText( this, 'padding' ) ) // TODO 不要? その分 w, h に足す [ 'css' ]( 'borderWidth', XUI_AbstractUINode_createCssText( this, 'borderWidth' ) ); }, @@ -394,6 +415,8 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( }; this.contentL = borderL + paddingL; this.contentR = borderR + paddingR; + this.paddingL = paddingL; + this.borderL = borderL; if( this.constraintW ? allowedW !== XUI_Attr_AUTO : !this.autoWidth && ( allowedW !== XUI_Attr_AUTO || !this.percentWidth ) ){ if( this.constraintW ){ // 制約レイアウト @@ -401,24 +424,21 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( } else { contentW = XUI_AbstractUINode_calcFinalValue( attrs[ XUI_Attr_Support.width.No ], attrs[ XUI_Attr_Support.minWidth.No ], attrs[ XUI_Attr_Support.maxWidth.No ], allowedW ); }; - this.contentWidth = contentW + boxMinus; - //this.scrollWidth = this.contentWidth + this.contentL + this.contentR; - this.boxWidth = contentW - boxMinus + this.contentL + this.contentR; + this.contentWidth = contentW + boxMinus; + this.boxWidth = this.contentWidth + this.contentL + this.contentR; this.boxSizingOffsetLR = boxMinus; - delete this.minContentWidth; - delete this.maxContentWidth; - delete this.minBoxWidth; - delete this.maxBoxWidth; + delete this.contentWidthMin; + delete this.contentWidthMax; + delete this.boxWidthMin; + delete this.boxWidthMax; } else { - this.minContentWidth = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], allowedW ) + boxMinus ); - this.maxContentWidth = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], allowedW ) + boxMinus ); - //this.scrollWidth = this.contentWidth + this.contentL + this.contentR; - this.minBoxWidth = this.minContentWidth - boxMinus + this.contentL + this.contentR; - this.maxBoxWidth = this.maxContentWidth - boxMinus + this.contentL + this.contentR; - //delete this.contentWidth; - //delete this.scrollWidth; - //delete this.boxWidth; - //delete this.boxSizingOffsetLR; + this.contentWidthMin = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], allowedW ) + boxMinus ); + this.contentWidthMax = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], allowedW ) + boxMinus ); + this.boxWidthMin = this.contentWidthMin + this.contentL + this.contentR; + this.boxWidthMax = this.contentWidthMax + this.contentL + this.contentR; + this.contentWidth = this.contentWidthMin; + this.boxWidth = this.boxWidthMin; + this.boxSizingOffsetLR = boxMinus; }; paddingT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 0 ], allowedH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して @@ -435,6 +455,8 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( }; this.contentT = borderT + paddingT; this.contentB = borderB + paddingB; + this.paddingT = paddingT; + this.borderT = borderT; // Height if( this.constraintH ? allowedH !== XUI_Attr_AUTO : !this.autoHeight && ( allowedH !== XUI_Attr_AUTO || !this.percentHeight ) ){ @@ -443,44 +465,37 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( } else { contentH = XUI_AbstractUINode_calcFinalValue( attrs[ XUI_Attr_Support.height.No ], attrs[ XUI_Attr_Support.minHeight.No ], attrs[ XUI_Attr_Support.maxHeight.No ], allowedH ); }; - this.contentHeight = contentH + boxMinus; - //this.scrollHeight = this.contentHeight + this.contentT + this.contentB; - this.boxHeight = contentH - boxMinus + this.contentT + this.contentB; // padding-box の場合 border だけ足される + this.contentHeight = contentH + boxMinus; + this.boxHeight = this.contentHeight + this.contentT + this.contentB; // padding-box の場合 border だけ足される this.boxSizingOffsetTB = boxMinus; - delete this.minContentHeight; - delete this.maxContentHeight; - delete this.minBoxHeight; - delete this.maxBoxHeight; + delete this.contentHeightMin; + delete this.contentHeightMax; + delete this.boxHeightMin; + delete this.boxHeightMax; } else { - this.minContentHeight = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], allowedH ) + boxMinus ); - this.maxContentHeight = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], allowedH ) + boxMinus ); - this.minBoxHeight = this.minContentHeight - boxMinus + this.contentT + this.contentB; - this.maxBoxHeight = this.maxContentHeight - boxMinus + this.contentT + this.contentB; - - //delete this.contentHeight; - //delete this.scrollHeight; - //delete this.boxHeight; - //delete this.boxSizingOffsetTB; + this.contentHeightMin = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], allowedH ) + boxMinus ); + this.contentHeightMax = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], allowedH ) + boxMinus ); + this.boxHeightMin = this.contentHeightMin + this.contentT + this.contentB; + this.boxHeightMax = this.contentHeightMax + this.contentT + this.contentB; + this.contentHeight = this.contentHeightMin; + this.boxHeight = this.boxHeightMin; + this.boxSizingOffsetTB = boxMinus; }; + // x if( this.parentData && this.parentData.layout.overrideAttrsForChild.left ){ - if( this.constraintW ){ - this.boxX = ( boxL || boxL === 0 ) ? boxL : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.left.No ], allowedW ); - } else - if( attrs[ XUI_Attr_Support.right.No ] === null ){ + if( this.constraintW || attrs[ XUI_Attr_Support.right.No ] === null ){ this.boxX = ( boxL || boxL === 0 ) ? boxL : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.left.No ], allowedW ); } else { - this.boxX = alllowW - this.boxWidth - ( ( boxR || boxR === 0 ) ? boxR : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.right.No ], allowedW ) ); + this.boxX = allowedW - this.boxWidth - ( ( boxR || boxR === 0 ) ? boxR : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.right.No ], allowedW ) ); }; } else { delete this.boxX; }; + // y if( this.parentData && this.parentData.layout.overrideAttrsForChild.top ){ - if( this.constraintH ){ - this.boxY = ( boxT || boxT === 0 ) ? boxT : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.top.No ], allowedH ); - } else - if( attrs[ XUI_Attr_Support.bottom.No ] === null ){ + if( this.constraintH || attrs[ XUI_Attr_Support.bottom.No ] === null ){ this.boxY = ( boxT || boxT === 0 ) ? boxT : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.top.No ], allowedH ); } else { this.boxY = allowedH - this.boxHeight - ( ( boxB || boxB === 0 ) ? boxB : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.bottom.No ], allowedH ) ); @@ -495,7 +510,6 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( */ mesure : function(){ var dirty = this.dirty, - //sup = X_UA[ 'Gecko' ] || ( X_UA[ 'Safari' ] && X_UA[ 'Windows' ] ) ? .01251 : 0, w, _w, h, xnode; if( dirty === XUI_Dirty.CLEAN ){ @@ -508,12 +522,12 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( case XUI_Dirty.CONTENT : // コンテンツが変更された case XUI_Dirty.FONT : // フォントサイズが変更された - delete this.lastContentWidth; - delete this.lastContentHeight; + delete this.contentWidthLast; + delete this.contentHeightLast; case XUI_Dirty.LAYOUT : // レイアウトの再計算が必要 - default : // TODO レイアウト崩れに対処 パフォーマンス悪い! + default : // TODO レイアウト指定が不正な場合 bgcolor を変更、これ以下のレイアウトの中止 w = this.contentWidth; h = this.contentHeight; @@ -542,13 +556,13 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( w = _w = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'width', 'auto' )[ 'clientWidth' ]() / X_Node_CSS_getCharSize( xnode ) ); - if( this.maxContentWidth < w - this.boxSizingOffsetLR ){ + if( this.contentWidthMax < w - this.boxSizingOffsetLR ){ this.noWidth = false; - w = this.maxContentWidth + this.boxSizingOffsetLR; + w = this.contentWidthMax + this.boxSizingOffsetLR; }; - if( w - this.boxSizingOffsetLR < this.minContentWidth ){ + if( w - this.boxSizingOffsetLR < this.contentWidthMin ){ this.noWidth = false; - w = this.minContentWidth + this.boxSizingOffsetLR; + w = this.contentWidthMin + this.boxSizingOffsetLR; }; if( h === XUI_Attr_AUTO ){ @@ -557,42 +571,42 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( w !== _w && xnode[ 'css' ]( 'width', 'auto' ); }; - this.lastContentWidth = this.contentWidth = w; + this.contentWidthLast = this.contentWidth = w; } else if( h === XUI_Attr_AUTO ){ - if( w !== this.lastContentWidth ){ + if( w !== this.contentWidthLast ){ xnode[ 'css' ]( 'width', w + 'em' ); - this.lastContentWidth = w; + this.contentWidthLast = w; // ie8 clientHeight, ff scrollHeight & clientHeight h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) ); } else { - h = this.lastContentHeight === -1 ? + h = this.contentHeightLast === -1 ? XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) ) : - this.lastContentHeight; + this.contentHeightLast; }; } else if( dirty !== XUI_Dirty.LAYOUT ){ - this.contentWidth = this.lastContentWidth = w; + this.contentWidth = this.contentWidthLast = w; h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) ); }; - if( this.maxContentHeight < h - this.boxSizingOffsetTB ){ + if( this.contentHeightMax < h - this.boxSizingOffsetTB ){ this.noHeight = false; - h = this.maxContentHeight + this.boxSizingOffsetTB; + h = this.contentHeightMax + this.boxSizingOffsetTB; }; - if( h - this.boxSizingOffsetTB < this.minContentHeight ){ + if( h - this.boxSizingOffsetTB < this.contentHeightMin ){ this.noHeight = false; - h = this.minContentHeight + this.boxSizingOffsetTB; + h = this.contentHeightMin + this.boxSizingOffsetTB; }; - this.contentHeight = this.lastContentHeight = h; + this.contentHeight = this.contentHeightLast = h; } else { // コンテンツを持たないため基本のサイズは0 - if( w === XUI_Attr_AUTO ) this.contentWidth = w = 0 < this.minContentWidth ? this.minContentWidth : 0; - if( h === XUI_Attr_AUTO ) this.contentHeight = h = 0 < this.minContentHeight ? this.minContentHeight : 0; + if( w === XUI_Attr_AUTO ) this.contentWidth = w = 0 < this.contentWidthMin ? this.contentWidthMin : 0; + if( h === XUI_Attr_AUTO ) this.contentHeight = h = 0 < this.contentHeightMin ? this.contentHeightMin : 0; this.noWidth = this.noHeight = false; }; @@ -623,17 +637,17 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( borderL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 3 ], contentW ); contentPlus = 0; switch( box ){ - case 3 : // border-box - contentPlus = borderR + borderL; + case 1 : // content-box + contentPlus = paddingR + paddingL; case 2 : // padding-box - contentPlus += paddingR + paddingL; - // case 1 : // content-box + contentPlus += borderR + borderL; + // case 3 : // border-box }; if( !this.constraintW ){ contentW += contentPlus; - min = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], contentW ); - max = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], contentW ); + min = this.boxWidthMin = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], contentW ); + max = this.boxWidthMax = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], contentW ); if( contentW < min && contentPlus < min ){ this.contentWidth = min - contentPlus; } else @@ -643,6 +657,8 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( }; this.contentL = borderL + paddingL; this.contentR = borderR + paddingR; + this.paddingL = paddingL; + this.borderL = borderL; this.boxWidth = this.contentWidth + this.contentL + this.contentR; }; // Height @@ -654,16 +670,16 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( borderB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 2 ], contentH ); contentPlus = 0; switch( box ){ - case 3 : // border-box - contentPlus = borderT + borderB; + case 1 : // content-box + contentPlus = paddingT + paddingB; case 2 : // padding-box - contentPlus += paddingT + paddingB; - // case 1 : // content-box + contentPlus += borderT + borderB; + // case 3 : // border-box }; if( !this.constraintH ){ contentH += contentPlus; - min = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], contentH ); - max = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], contentH ); + min = this.boxHeightMin = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], contentH ); + max = this.boxHeightMax = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], contentH ); if( contentH < min && contentPlus < min ){ this.contentHeight = min - contentPlus; } else @@ -673,10 +689,13 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( }; this.contentT = borderT + paddingT; this.contentB = borderB + paddingB; + this.paddingT = paddingT; + this.borderT = borderT; this.boxHeight = this.contentHeight + this.contentT + this.contentB; }; }, + // TODO fontsize が変わることもある capcher : function( x, y ){ if( this.pointerDisabled ) return false; @@ -695,6 +714,7 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( */ listen : function( type, arg1, arg2, arg3 ){ var root, events, counter, f; + if( XUI_Event._START_POINTER <= type && type <= XUI_Event._END_POINTER ){ if( this.phase < 3 ){ if( !( events = this.reserveEvents ) ) this.reserveEvents = events = []; @@ -719,11 +739,12 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( }; }; }; - arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 ) ); + + arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Closure_classifyCallbackArgs( arg1, arg2, arg3 ) ); if( !f.kind ){ return X_EventDispatcher_listen.call( this, type, this.User, f ); } else - if( f.kind === X_Callback_FUNC_ONLY ){ + if( f.kind === X_CLOSURE_FUNC_ONLY ){ return X_EventDispatcher_listen.call( this, type, this.User, f.func, f.supplement ); }; return X_EventDispatcher_listen.apply( this, arguments ); @@ -756,11 +777,11 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( }; }; }; - arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 ) ); + arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Closure_classifyCallbackArgs( arg1, arg2, arg3 ) ); if( !f.kind ){ return X_EventDispatcher_unlisten.apply( this, [ type, this.User, f ] ); } else - if( f.kind === X_Callback_FUNC_ONLY ){ + if( f.kind === X_CLOSURE_FUNC_ONLY ){ return X_EventDispatcher_unlisten.apply( this, [ type, this.User, f.func, f.supplement ] ); }; return X_EventDispatcher_unlisten.apply( this, arguments ); @@ -773,13 +794,25 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( type = e.type || e; // TODO captureEvent PointerEvent - if( ret & X_Callback_CAPTURE_POINTER && !this.hitChildData && XUI_Event._POINTER_MOVE === type ){ + if( ret & X_CALLBACK_CAPTURE_POINTER && !this.hitChildData && XUI_Event._POINTER_MOVE === type ){ this.rootData.monopolyNodeData = this; return ret; }; this.rootData.monopolyNodeData = null; - if( xve._START_BUBLEUP < type && this.parentData && !( ret & X_Callback_STOP_PROPAGATION ) && !( ret & X_Callback_STOP_NOW ) ) return this.parentData[ 'dispatch' ]( e ); + if( xve._START_BUBLEUP < type && this.parentData && !( ret & X_CALLBACK_STOP_PROPAGATION ) && !( ret & X_CALLBACK_STOP_NOW ) ) return this.parentData[ 'dispatch' ]( e ); return ret; + }, + + setItemData : function( itemData ){ + if( this.itemData === itemData ) return; + + this.itemData = itemData; + + this[ 'dispatch' ]( { type : XUI_Event.ITEMDATA_CHANGED, itemData : itemData } ); + // itemData && itemData.listen( X_Event_CHANGED ) + // dataFeild dataFormatter dataValidator + + // itemData.listen( X_Event_CHANGED ) -> this[ 'dispatch' ]( UI_Event.ITEMDATA_UPDATED ); } } @@ -787,7 +820,7 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( function XUI_AbstractUINode_createCssText( that, name ){ var attrs = that.attrObject || that.attrClass.prototype || XUI_AttrClass, - def = that.supportAttrs[ name ], + def = that.usableAttrs[ name ], no = def.No, v = attrs[ def.No ], type = def[ 3 ], @@ -912,16 +945,16 @@ X.UI.AbstractUINode = X_Class_create( if( layout && !layout[ k ] ){ continue; }; - if( def = p.supportAttrs[ k ] ){ + if( def = p.usableAttrs[ k ] ){ p.setAttr( k, def, nameOrObject[ k ] ); }; }; } else - if( X_Type_isString( nameOrObject ) ){ + if( X_Type_isString( nameOrObject ) && ( def = p.usableAttrs[ nameOrObject ] ) ){ if( valueOrUnit !== undefined ){ if( 'em,%'.indexOf( valueOrUnit ) === -1 ){ // setter - p.setAttr( nameOrObject, valueOrUnit ); + p.setAttr( nameOrObject, def, valueOrUnit ); } else { // getter with unit return p.getAttrWithUnit( nameOrObject, valueOrUnit ); @@ -929,7 +962,7 @@ X.UI.AbstractUINode = X_Class_create( }; // getter if( attrs = ( p.attrObject || p.attrClass.prototype || XUI_AttrClass ) ){ - def = p.supportAttrs[ nameOrObject ]; + def = p.usableAttrs[ nameOrObject ]; return def && attrs[ def.No ]; }; return v; @@ -996,6 +1029,87 @@ X.UI.AbstractUINode = X_Class_create( getHeight : function(){ // dirty の場合、rootData.calculate return X_Pair_get( this ).boxHeight; + }, + + /* + * Repeater に於いて、繰り返されるアイテムの元(itemRenderer)からの複製に使用 + */ + clone : function( opt_cloneListener ){ + var newNode, + //newPair = X_Pair_get( newNode ), + pair = X_Pair_get( this ), + attr, listeners, type, list, i, l; + + // attr もコピー + if( pair.attrObject ){ + attr = {}; + for( k in pair.usableAttrs ){ + def = pair.usableAttrs[ k ]; + attr[ k ] = pair.attrObject[ def.No ]; + }; + newNode = this.constructor( attr ); + }; + + // handleEvent 等の拡張されたオブジェクトもコピーする! + for( k in this ){ + if( this[ k ] !== newNode[ k ] && !newNode[ k ] ) newNode[ k ] = this[ k ]; + }; + + // User.UINODE な値は pair にコピーされているのでこれをコピー + for( k in pair ){ + //pair[ k ] !== newPair[ k ] && !newPair[ k ] && console.log( k ); + //if( pair[ k ] !== newPair[ k ] && !newPair[ k ] && k !== 'attrObject' && k !== '_listeners' ){ + //newPair[ k ] = pair[ k ]; + //console.log( k ); + //}; + }; + + + + // listener もコピーする! + if( opt_cloneListener && ( listeners = pair[ '_listeners' ] ) ){ + for( type in listeners ){ + list = listeners[ type ]; + for( i = 0, l = list.length; i < l; ++i ){ + f = list[ i ]; + switch( f.kind ){ + case X_CLOSURE_THIS_FUNC : + if( f.lock ){ + X_EventDispatcher_systemListen( newNode, type, f.context === this ? newNode : f.context, f.func, f.supplement ); + } else { + newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.context === this ? newNode : f.context, f.func, f.supplement ); + }; + break; + case X_CLOSURE_HANDLEEVENT : + if( f.lock ){ + X_EventDispatcher_systemListen( newNode, type, f.context === this ? newNode : f.context, f.supplement ); + } else { + newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.context === this ? newNode : f.context, f.supplement ); + }; + break; + /* + case X_CLOSURE_FUNC_ONLY : + if( f.lock ){ + X_EventDispatcher_systemListen( newNode, type, f.func, f.supplement ); + } else { + newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.func, f.supplement ); + }; + break; + default : + newNode[ 'listen' ]( type, f ); + break; */ + }; + }; + }; + } else + if( opt_cloneListener && ( list = this.reserveEvents ) ){ + for( i = 0, l = list.length; i < l; ++i ){ + f = list[ i ]; + newNode[ f.once ? 'listenOnce' : 'listen' ]( f[ 0 ], newNode, f[ 1 ], f[ 2 ] ); + }; + }; + + return newNode; } } );