OSDN Git Service

Version 0.6.200, fix X.Node.Anime.
[pettanr/clientJs.git] / 0.6.x / js / 02_dom / 20_XNode.js
index cc826b1..ab4e26b 100644 (file)
@@ -8,7 +8,7 @@
  */
 var    Node = X[ 'Node' ] = X_EventDispatcher[ 'inherits' ](
        'X.Node',
-       X_Class.POOL_OBJECT,
+       X_Class.NONE,
        {
                /**
                 * 要素に振られるユニークID
@@ -445,6 +445,7 @@ function X_Node_toggleInGPUFlag( gpuRoot, xnodes, flag ){
  */
 function X_Node_create( tag, opt_attrs, opt_css ){
        var xnode;
+
        if( !this[ '_tag' ] ) return;
        this[ 'append' ]( xnode = X_Doc_create( tag, opt_attrs, opt_css ) );
        return xnode;
@@ -559,7 +560,8 @@ function X_Node_append( v ){
                        return X_Node_append.apply( this, X_HtmlParser_parse( v, true ) );
                case X_NodeType_XNODE :
                        // 親の xnodes から v を消す
-                       v.parent && v[ 'remove' ]();
+               if( v.parent === this && xnodes[ xnodes.length - 1 ] === v ) return this;
+                       v[ 'remove' ]();
                        // IE4 でテキストノードの追加、FIXED 済でない場合、親に要素の追加を通知
                        if( X_UA[ 'IE4' ] && !v[ '_tag' ] && ( ( this[ '_flags' ] & X_NodeFlags_IE4_FIXED ) === 0 ) ) this[ '_flags' ] |= X_NodeFlags_IE4_DIRTY_CHILDREN;
                        break;
@@ -779,6 +781,14 @@ function X_Node_remove(){
        
        if( !parent ) return this;
 
+       // stop() ->
+       if( this[ '_anime' ] && this[ '_anime' ].phase ){
+               console.log( 'Animation 中の REMOVE' );
+               X_NodeAnime_stopNow( this );
+       };
+       // 子孫にアニメーション中の要素が要る
+       // 先祖に GPU 化した要素が要る
+
        delete this.parent;
        parent[ '_xnodes' ].splice( parent[ '_xnodes' ].indexOf( this ), 1 );
        
@@ -789,7 +799,7 @@ function X_Node_remove(){
                if( X_UA_DOM.IE4 ){
                        if( elm = this[ '_rawObject' ] || X_Node__ie4getRawNode( this ) ){
                                X_Node_reserveRemoval[ X_Node_reserveRemoval.length ] = this;
-                               X_Node_reserveUpdate();                 
+                               X_Node_reserveUpdate();
                        } else
                        if( !this[ '_tag' ] && ( ( parent[ '_flags' ] & X_NodeFlags_IE4_FIXED ) === 0 ) ){
                                parent[ '_flags' ] |= X_NodeFlags_IE4_DIRTY_CHILDREN;
@@ -840,8 +850,6 @@ function X_Node_onKill( that ){
        
        parent && parent[ '_xnodes' ] && parent[ '_xnodes' ].splice( parent[ '_xnodes' ].indexOf( that ), 1 );
 
-       elm = that[ '_rawObject' ] || X_UA_DOM.IE4 && X_Node__ie4getRawNode( that );
-
        if( xnodes && ( i = xnodes.length ) ){
                delete that[ '_xnodes' ];
                for( ; i; ){
@@ -851,7 +859,14 @@ function X_Node_onKill( that ){
        };
 
        X_Node_CHASHE[ that[ '_uid' ] ] = null; // array に対して delete X_Node_CHASHE[ uid ] はまずい!
-       
+
+       if( that[ '_anime' ] && that[ '_anime' ].phase ){
+               console.log( 'Animation 中の KILL' );
+               X_NodeAnime_stopNow( that );
+       };
+
+       elm = that[ '_rawObject' ] || X_UA_DOM.IE4 && X_Node__ie4getRawNode( that );
+
 // remove _xnodes
        if( X_UA_DOM.IE4 ){
                if( elm ){
@@ -880,21 +895,15 @@ function X_Node_onKill( that ){
  * @example node.contains( testNode );
  */
 function X_Node_contains( v ){
-       var elm, type, xnodes, i;
+       var xnodes;
+       
        if( !v || !this[ '_tag' ] || this === v ) return false;
-       // contains ie4+
-       if( ( elm = this[ '_rawObject' ] || X_UA_DOM.IE4 && X_Node__ie4getRawNode( this ) ) && document.contains && ( type = X_Node_getType( v ) ) && ( type === X_NodeType_RAW_HTML || type === X_NodeType_RAW_TEXT ) ){
-               return elm.contains( v );
-       };
 
-       //if( document.compareDocumentPosition ){
-       //      
-       //};
        xnodes = this[ '_xnodes' ];
        if( !xnodes || !xnodes.length ) return false;
-       if( xnodes.indexOf( v ) !== -1 ) return true; // fast
-       for( i = xnodes.length; i; ){
-               if( xnodes[ --i ][ 'contains' ]( v ) ) return true;
+
+       while( v = v[ 'parent' ] ){
+               if( this === v ) return true;
        };
        return false;
 };
@@ -1217,6 +1226,23 @@ function X_Node_call( name /*, opt_args... */ ){
                        return this.parent ? X_Node_CSS_getCharSize( this ) : 0;
                case 'inGPU' :
                        return !!( this[ '_flags' ] & ( X_NodeFlags_GPU_NOW | X_NodeFlags_GPU_RELEASE_RESERVED ) );
+               case 'isGPUChild' :
+                       if( this[ '_flags' ] & X_NodeFlags_IN_TREE ){
+                               parent = this;
+                               while( parent = parent.parent ){
+                                       if( parent[ '_flags' ] & ( X_NodeFlags_GPU_NOW | X_NodeFlags_GPU_RELEASE_RESERVED ) ) return true;
+                               };
+                       };
+                       return false;
+               case 'containGPU' :
+                       
+                       return false;
+               case 'canAnimateNow' :
+                       return ( this[ '_flags' ] & X_NodeFlags_IN_TREE ) && X_NodeAnime_detectWaitAnimation( this, true, true ) === 6;
+               case 'animeState' :
+                       return this[ '_anime' ] ? this[ '_anime' ].phase : 0;
+               case 'animeProgress' :
+                       return this[ '_anime' ] && this[ '_anime' ].phase === 7 ? this[ '_anime' ].progress : 0;
        };
        
        X_Node_updateTimerID && X_Node_startUpdate();
@@ -1361,6 +1387,7 @@ function X_Node_startUpdate( time ){
                for( ; i; ){
                        xnodeOrElm = removal[ --i ];
                        // TODO GPU レイヤーの子の場合、remove をスキップする。 非GPU レイヤーへ apppend される場合、clone する?
+                       // GPU レイヤーを削除する場合、cssText = '' して GPU レイヤーを解除する
                        if( !xnodeOrElm[ 'instanceOf' ] ){
                                if( X_UA_DOM.IE4 ){
                                        xnodeOrElm.removeAttribute( 'id' ); // ?
@@ -1423,21 +1450,22 @@ var X_Node__commitUpdate =
 
                        // 1. GPU 一切の更新をスキップ
                        if( that[ '_flags' ] & X_NodeFlags_GPU_NOW ){
-                               //console.log( '更新のskip ' + !!( that[ '_flags' ] & X_Node_BitMask_IS_DIRTY ) );
+                               console.log( '更新のskip ' + !!( that[ '_flags' ] & X_Node_BitMask_IS_DIRTY ) );
                                that[ '_flags' ] & X_Node_BitMask_IS_DIRTY && X_Node__updateRawNode( that, elm );
                                return elm;
                        };
 
                        // 2. GPU解放予約
                        if( that[ '_flags' ] & X_NodeFlags_GPU_RELEASE_RESERVED ){
-                               // console.log( 'GPU 解放 ' );
+                               console.log( 'GPU 解放 ' );
                                //X_Node_updateReservedByReleaseGPU = true;
                                that[ '_flags' ] &= X_Node_BitMask_RESET_GPU;
-                               //return elm;// TODO もしかしたらこのタイミングで更新できるかも
+                               //return elm;// このタイミングで更新できるっぽい
                        };
 
                        // 3. GPU予約 -> GPU
                        if( that[ '_flags' ] & X_NodeFlags_GPU_RESERVED ){
+                               // TODO size 取得のための update の場合、GPU化をスキップ
                                that[ '_flags' ] &= X_Node_BitMask_RESET_GPU;
                                that[ '_flags' ] |= X_NodeFlags_GPU_NOW;
                        };
@@ -1490,7 +1518,7 @@ var X_Node__commitUpdate =
                                if( that[ '_flags' ] & X_NodeFlags_IS_SVG ){
                                        elm = document.createElementNS( 'http://www.w3.org/2000/svg', that[ '_tag' ].toLowerCase() );
                                        
-                                       // math http://www.w3.org/1998/Math/MathML
+                                       // TODO math http://www.w3.org/1998/Math/MathML
                                } else {
                                        elm = document.createElement( that[ '_tag' ] );
                                };