X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F20_ui%2F06_AbstractUINode.js;h=5919e21c85b6b3f2e06d9affdeca4f83074b0c74;hb=ef25747bebf1799d49f9bd0d64e339da9ea61d13;hp=4ca1595f00fc5f03449471f5b8766e375192a076;hpb=86c591d2888cf7b24365c1950646fb1f6190efd1;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 4ca1595..5919e21 100644 --- a/0.6.x/js/20_ui/06_AbstractUINode.js +++ b/0.6.x/js/20_ui/06_AbstractUINode.js @@ -3,12 +3,13 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( 'X.UI._AbstractUINode', X_Class.ABSTRACT, { + itemData : null, + phase : 0, dirty : XUI_Dirty.CLEAN, root : null, rootData : null, - hoverList : null, parent : null, parentData : null, xnode : null, @@ -20,11 +21,18 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( role : 1, pointerDisabled : false, - hoverClassName : null, hovering : false, reserveEvents : null, - gesture : null, + gestureOptions : null, + gestureActivated : null, + gestureTypes : null, + gestureTriggered : null, + gestureCanceled : null, + gestureCurrentName : '', + gestureStartEvent : null, + gestureLastEvent : null, + gestureLastMoveEvent : null, absoluteX : 0, absoluteY : 0, @@ -77,8 +85,21 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( }, addToParent : function( xnodeParent ){ + var attr = this.attrObject || this.attrClass.prototype, + usableAttrs = this.usableAttrs, + i = 0, l = usableAttrs.length, def, k; + 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[ def.No ] !== def[ 0 ] ){ + this.xnode[ 'css' ]( XUI_Attr_Rename[ k ] || k, XUI_AbstractUINode_createCssText( this, k ) ); + }; + }; + }; + this.phase = 2; this[ 'dispatch' ]( XUI_Event.ADDED ); }, @@ -91,6 +112,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 ] ); @@ -140,17 +162,17 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( console.log( v + ' ' + _v ); v = _v; } else - if( ( percent || minusPct ) && v.lastIndexOf( '%' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + '%' ){ + if( ( percent || minusPct ) && v.lastIndexOf( '%' ) !== -1 && X_Type_isFinite( _v = parseFloat( v ) ) && v === _v + '%' ){ // good } else - if( ( length || minusLen ) && v.lastIndexOf( 'em' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + 'em' ){ + if( ( length || minusLen ) && v.lastIndexOf( 'em' ) !== -1 && X_Type_isFinite( _v = parseFloat( v ) ) && v === _v + 'em' ){ v = _v; } else if( v.indexOf( ' ' ) !== -1 ){ v = v.split( ' ' ); } else - if( color && X_Type_isNumber( _v = X_Node_CSS_objToIEFilterText( v ) ) ){ - v = _v; + if( color && X_Type_isNumber( _v = X_Node_CSS_parseColor( v ) ) ){ + v = _v; } else { // bad return; @@ -169,7 +191,7 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( ( minusPct && -1 <= v && v < 0 ) || ( numerical && 0 <= v ) || ( auto && v === XUI_Attr_AUTO ) || - ( color && 0 <= v && v <= 0xFFFFFF ) || + ( color && ( 0 <= v && v <= 0xFFFFFF ) || ( v !== v ) ) || // isNaN ( list && list[ v ] ) ){ // good @@ -229,6 +251,7 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( if( !v && v !== 0 ) v = defaultVal; + // UIAttrClass の初期設定の場合、ここで終わる if( XUI_attrClassProto ){ attrs[ propID ] = v; return; @@ -319,13 +342,12 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( case 2: case 1: - this.xnode[ 'kill' ](); + this.xnode[ 'remove' ](); delete this.root; delete this.rootData; delete this.parent; delete this.parentData; - delete this.xnode; delete this.phase; }; @@ -686,108 +708,26 @@ var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ]( y -= this.boxY; if( 0 <= x && x < this.boxWidth && 0 <= y && y < this.boxHeight ){ - !this.hovering && ( this.rootData.hoverList[ this.rootData.hoverList.length ] = this ); - this.rootData.targetNodeData = this; + !this.hovering && ( XUI_UINODES_HOVER[ XUI_UINODES_HOVER.length ] = this ); + XUI_uinodeTarget = this; + //console.log( 'hit ' + this.xnode.className() ) return true; }; }, - /* - * context を明示しない場合、User が context になる! - */ - 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 = []; - events[ events.length ] = [ type, arg1, arg2, arg3 ]; - return this; - }; - if( XUI_Event._START_XUI_EVENT < type && type < XUI_Event._END_XUI_EVENT ){ - if( !this.gesture ){ - this.gesture = new Hammer( this.rootData, this, type ); - } else { - this.gesture[ 'listen' ]( type ); - }; - } else { - //console.log( type ); - root = this.rootData; - counter = root.eventCounter; - if( counter[ type ] ){ - ++counter[ type ]; - } else { - counter[ type ] = 1; - root.xnodeInteractiveLayer[ 'listen' ]( XUI_Event.IdToName[ type ], X_UI_eventRellay ); - }; - }; - }; - - arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_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 ){ - return X_EventDispatcher_listen.call( this, type, this.User, f.func, f.supplement ); - }; - return X_EventDispatcher_listen.apply( this, arguments ); - }, - unlisten : function( type, arg1, arg2, arg3 ){ - var root, events, i, ev, counter, f; - if( XUI_Event._START_POINTER <= type && type <= XUI_Event._END_POINTER ){ - if( this.phase < 3 ){ - if( !( events = this.reserveEvents ) ) return this; - for( i = events.length; i; ){ - ev = events[ --i ]; - if( ev[ 0 ] === type && ev[ 1 ] === arg1 && ev[ 2 ] === arg2 ){ - events.split( i, 1 ); - return this; - }; - }; - return this; - }; - - if( XUI_Event._START_XUI_EVENT < type && type < XUI_Event._END_XUI_EVENT ){ - this.gesture && this.gesture[ 'unlisten' ]( type ); - } else { - root = this.rootData; - counter = root.eventCounter; - if( !counter[ type ] ) return this; - --counter[ type ]; - if( counter[ type ] === 0 ){ - root.xnodeInteractiveLayer[ 'unlisten' ]( XUI_Event.IdToName[ type ], X_UI_eventRellay ); - delete counter[ type ]; - }; - }; - }; - arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_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 ){ - return X_EventDispatcher_unlisten.apply( this, [ type, this.User, f.func, f.supplement ] ); - }; - return X_EventDispatcher_unlisten.apply( this, arguments ); - }, + listen : XUI_$UINodeBase_listen, - dispatch : function( e ){ - //console.log( e.type + ' ' + ( this[ '_listeners' ] && this[ '_listeners' ][ e.type ] ) ); - var xve = XUI_Event, - ret = X_EventDispatcher_dispatch.call( this, e ), - type = e.type || e; - - // TODO captureEvent PointerEvent - 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 ); - return ret; - }, + unlisten : XUI_$UINodeBase_unlisten, - setItemData : function(){ - // this[ 'dispatch' ]( UI_Event.ITEMDATA_CHANGED ); + 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 ); } @@ -854,13 +794,16 @@ function XUI_AbstractUINode_createCssValue( v, type, list ){ if( X_Type_isNumber( v ) ){ if( auto && v === XUI_Attr_AUTO ) return 'auto'; - if( length || minusLen ) return v + 'em'; + if( length || minusLen ) return v ? v + 'em' : 0; if( numerical ) return v; if( list && list[ v ] ) return list[ v ]; if( color ){ if( v < 0x100000 ){ v = '00000' + v.toString( 16 ); return '#' + v.substr( v.length - 6 ); + } else + if( v !== v ){ // iSNaN + return 'none'; }; return '#' + v.toString( 16 ); }; @@ -926,11 +869,11 @@ X.UI.AbstractUINode = X_Class_create( }; }; } 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 ); @@ -947,7 +890,15 @@ X.UI.AbstractUINode = X_Class_create( }, listen : function( type, arg1, arg2, arg3 ){ - X_Pair_get( this )[ 'listen' ]( type, arg1, arg2, arg3 ); + var pair = X_Pair_get( this ); + + ( !arg1 || !arg1.cbKind ) && ( arg1 = X_Closure_classifyCallbackArgs( arg1, arg2, arg3, this ) ); + + if( arg1.cbKind === X_CLOSURE_FUNC_ONLY ){ + pair[ 'listen' ].apply( pair, [ type, this, arg1.func, arg1.supplement ] ); + } else { + pair[ 'listen' ]( type, arg1.context, arg1.func, arg1.supplement ); + }; return this; }, listenOnce : function( type, arg1, arg2, arg3 ){ @@ -958,7 +909,15 @@ X.UI.AbstractUINode = X_Class_create( return X_Pair_get( this )[ 'listening' ]( type, arg1, arg2, arg3 ); }, unlisten : function( type, arg1, arg2, arg3 ){ - X_Pair_get( this )[ 'unlisten' ]( type, arg1, arg2, arg3 ); + var pair = X_Pair_get( this ); + + ( !arg1 || !arg1.cbKind ) && ( arg1 = X_Closure_classifyCallbackArgs( arg1, arg2, arg3, this ) ); + + if( arg1.cbKind === X_CLOSURE_FUNC_ONLY ){ + pair[ 'unlisten' ].apply( pair, [ type, this, arg1.func, arg1.supplement ] ); + } else { + pair[ 'unlisten' ]( type, arg1.context, arg1.func, arg1.supplement ); + }; return this; }, dispatch : function( e ){ @@ -1011,10 +970,20 @@ X.UI.AbstractUINode = X_Class_create( * Repeater に於いて、繰り返されるアイテムの元(itemRenderer)からの複製に使用 */ clone : function( opt_cloneListener ){ - var newNode = this.constructor(), - newPair = X_Pair_get( newNode ), + var newNode, + //newPair = X_Pair_get( newNode ), pair = X_Pair_get( this ), - attr, listeners, type, list, i, l; + attr, listeners, type, list, i, l, k, def, f; + + // 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 ){ @@ -1023,17 +992,14 @@ X.UI.AbstractUINode = X_Class_create( // User.UINODE な値は pair にコピーされているのでこれをコピー for( k in pair ){ - if( pair[ k ] !== newPair[ k ] && !newPair[ k ] ) newPair[ k ] = pair[ k ]; + //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 ); + //}; }; - // attr もコピー - if( pair.attrObject ){ - attr = pair.attrClass(); - for( k in pair.attrObject ){ - if( pair.attrObject[ k ] !== attr[ k ] ) attr[ k ] = pair.attrObject[ k ]; - }; - newPair.attrObject = attr; - }; + // listener もコピーする! if( opt_cloneListener && ( listeners = pair[ '_listeners' ] ) ){ @@ -1041,25 +1007,17 @@ X.UI.AbstractUINode = X_Class_create( list = listeners[ type ]; for( i = 0, l = list.length; i < l; ++i ){ f = list[ i ]; - switch( f.kind ){ - case X_Callback_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 ); - }; + switch( f.cbKind ){ + case X_CLOSURE_THIS_FUNC : + newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.context === this ? newNode : f.context, f.func, f.supplement ); break; - case X_Callback_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 ); - }; + case X_CLOSURE_HANDLEEVENT : + newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.context === this ? newNode : f.context, f.supplement ); break; /* - case X_Callback_FUNC_ONLY : + case X_CLOSURE_FUNC_ONLY : if( f.lock ){ - X_EventDispatcher_systemListen( newNode, type, f.func, f.supplement ); + newNode[ 'listen' ]( type, f.func, f.supplement ); } else { newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.func, f.supplement ); }; @@ -1070,6 +1028,12 @@ X.UI.AbstractUINode = X_Class_create( }; }; }; + } 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;