X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F02_dom%2F10_XNodeAnime.js;h=2d20bad71dc7ea1432eb462cb86620ccaa3950bb;hb=b28fd52ddc41a1c927f92fa7eeeb6891c41e55d9;hp=9a3078c48854ce60aac1151b1261d42403beee0e;hpb=babda23632a3176d9fe546fbab6f79c1fef0e3d4;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/02_dom/10_XNodeAnime.js b/0.6.x/js/02_dom/10_XNodeAnime.js index 9a3078c..2d20bad 100644 --- a/0.6.x/js/02_dom/10_XNodeAnime.js +++ b/0.6.x/js/02_dom/10_XNodeAnime.js @@ -1,26 +1,26 @@ var ease = { - quadratic: { + 'quadratic' : { style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)', fn: function (k) { return k * ( 2 - k ); } }, - circular: { + 'circular' : { style: 'cubic-bezier(0.1, 0.57, 0.1, 1)', // Not properly "circular" but this looks better, it should be (0.075, 0.82, 0.165, 1) fn: function (k) { return Math.sqrt( 1 - ( --k * k ) ); } }, - back: { + 'back' : { style: 'cubic-bezier(0.175, 0.885, 0.32, 1.275)', fn: function (k) { var b = 4; return ( k = k - 1 ) * k * ( ( b + 1 ) * k + b ) + 1; } }, - bounce: { + 'bounce' : { style: '', fn: function (k) { if ( ( k /= 1 ) < ( 1 / 2.75 ) ) { @@ -34,7 +34,7 @@ var } } }, - elastic: { + 'elastic' : { style: '', fn: function (k) { var f = 0.22, @@ -61,49 +61,63 @@ var X_Node_ANIMATIONS = [], X_Node_Anime_reserved = false, X_Node_Anime_updateTimerID = 0, X_Node_Anime_needsDetection = false, + X_Node_Anime_onTransition = false, + X_Node_Anime_hasTransform = !!X_Node_CSS_VENDER_PREFIX[ 'transform' ], /* Opera mobile で translateZ(0) が有効だと XY が 0 0 になる */ - /* GPUレイヤーにいる間に要素のコンテンツを変更をすると transitionend が動かなくなるっぽい Mac safari と firefox, 手当てが済むまでここは常に false */ - X_Node_Anime_translateZ = X_Node_CSS_VENDER_PREFIX[ 'perspective' ] && !X_UA.OperaMobile && !X_UA.OperaTablet ? ' translateZ(0)' : '', + /* GPUレイヤーにいる間に要素のコンテンツを変更をすると transitionend が動かなくなるっぽい Mac safari と firefox */ + X_Node_Anime_translateZ = X_Node_CSS_VENDER_PREFIX[ 'perspective' ] && !X_UA[ 'OperaMobile' ] && !X_UA[ 'OperaTablet' ] ? ' translateZ(0)' : '', /* Opera12(XP,8.1) 切った方がスムース, win Safari3 で、たまに動作が止まってしまう、、、 */ - X_Node_Anime_hasTransition = !!X_Node_CSS_VENDER_PREFIX[ 'transitionDelay' ] && !X_UA.Opera && !( X_UA.Webkit <= 528.16 ), + X_Node_Anime_hasTransition = !!X_Node_CSS_VENDER_PREFIX[ 'transitionDelay' ] && !X_UA[ 'Opera' ], // && !( X_UA[ 'Webkit' ] <= 528.16 ), X_Node_Anime_transitionProps = X_Node_Anime_hasTransform ? X_Node_CSS_VENDER_PREFIX[ 'transform' ] : 'left,top', // transitionEnd イベント中に要素の更新( X_Node_startUpdate() )ができるか? // iOS3+4 では可能、iOS6.1.5 で不可。TODO iOS5 及び他の環境で調査。ダメな場合、anime.html が正しく描画されない。 - X_Node_updateOnTransitionEnd = X_UA.iOS < 6, - X_Node_Anime_onTransition = false; + X_Node_updateOnTransitionEnd = false; //X_UA[ 'iOS' ] < 6; // gpu化だけ transformX , willChange // 終了位置の変更 // 中断 /* + * TODO : DX Anime * TODO : scale, ActiveX transform, zoom, fontSizeScale * TODO : rotate, ActiveX transform -> 位置補正のために size 情報が必要なので、commitUpdate 後に計算して適用 * TODO : matrix * TODO : skew * TODO : filter * TODO 前回位置からの継続 + * TODO scrollLeft, scrollTop + */ +/** + * GPU サポートの効いたアニメーションの設定 X.Event.ANIME_START, X.Event.ANIME_END, X.Event.GPU_RELEASED + * + * @alias Node.prototype.animate + * @param {object} start { x : 0, y : 0, opacity : 1 } + * @param {object} dest { x : 100, y : 100, opacity : 0 } + * @param {number=} duartion アニメーション時間 ms + * @param {string=} easing 'quadratic', 'circular', 'back', 'bounce', 'elastic' + * @param {number=} wait GPU レイヤーの遅延解除 ms + * @return {Node} メソッドチェーン */ -Node.prototype.animate = function( start, dest, duration, easing, wait ){ - var isNew = !this._anime, - obj = this._anime || ( this._anime = {} ); +function X_Node_animate( start, dest, duration, easing, wait ){ + var isNew = !this[ '_anime' ], + obj = this[ '_anime' ] || ( this[ '_anime' ] = {} ); - obj.duration = 0 <= duration && X.Type.isFinite( duration ) ? duration : 500; - obj.easing = ease[ easing ] || ease.circular; + obj.duration = 0 <= duration && X_Type_isFinite( duration ) ? duration : 500; + obj.easing = ease[ easing ] || ease[ 'circular' ]; // 現在 GPUレイヤーのtop になっているか?将来については phase で判定 obj.gpuParent = obj.gpuParent || false; obj.phase = duration === 0 ? 9 : obj.phase === 9 ? 9 : 0; // - obj.wait = X.Type.isFinite( wait ) ? wait : 1000; + obj.wait = X_Type_isFinite( wait ) ? wait : 1000; obj.startTime = X_Timer_now(); - obj.startX = ( start.x || start.x === 0 ) ? start.x : obj.x || 0; - obj.startY = ( start.y || start.y === 0 ) ? start.y : obj.y || 0; + obj.startX = ( start.x || start.x === 0 ) ? start.x : obj.x || NaN; + obj.startY = ( start.y || start.y === 0 ) ? start.y : obj.y || NaN; obj.startA = 0 <= start.opacity && start.opacity <= 1 ? start.opacity : obj.a || 1; obj.destTime = obj.startTime + obj.duration; - obj.destX = ( dest.x || dest.x === 0 ) ? dest.x : obj.destX || 0; - obj.destY = ( dest.y || dest.y === 0 ) ? dest.y : obj.destY || 0; + obj.destX = ( dest.x || dest.x === 0 ) ? dest.x : obj.destX || NaN; + obj.destY = ( dest.y || dest.y === 0 ) ? dest.y : obj.destY || NaN; obj.destA = 0 <= dest.opacity && dest.opacity <= 1 ? dest.opacity : obj.destA || 1; X_Node_ANIMATIONS.indexOf( this ) === -1 && @@ -115,7 +129,7 @@ Node.prototype.animate = function( start, dest, duration, easing, wait ){ if( X_Node_Anime_hasTransition ){ if( obj.gpuTimerID ){ - X.Timer.remove( obj.gpuTimerID ); + X_Timer_remove( obj.gpuTimerID ); delete obj.gpuTimerID; }; @@ -123,28 +137,44 @@ Node.prototype.animate = function( start, dest, duration, easing, wait ){ X_Node_Anime_reserveUpdate( true ); } else { - X_System.unlisten( X.Event.UPDATED, X_Node_Anime_updateAnimationsNoTransition ); - X_Node_Anime_updateTimerID || ( X_Node_Anime_updateTimerID = X.Timer.requestFrame( X_Node_Anime_updateAnimationsNoTransition ) ); + if( !X_Node_Anime_reserved ){ + X_Node_Anime_reserved = true; + if( X_Node_updateTimerID ){ + X_System[ 'listen' ]( X_EVENT_UPDATED, X_Node_Anime_updateAnimationsNoTransition ); + X_Node_Anime_updateTimerID && X_Timer_cancelFrame( X_Node_Anime_updateTimerID ); + X_Node_Anime_updateTimerID = 0; + } else { + X_System[ 'unlisten' ]( X_EVENT_UPDATED, X_Node_Anime_updateAnimationsNoTransition ); + X_Node_Anime_updateTimerID = X_Timer_requestFrame( X_Node_Anime_updateAnimationsNoTransition ); + }; + }; - isNew && this.dispatch( { type : X.Event.ANIME_START, gpu : false } ); + isNew && this[ 'dispatch' ]( { type : X_EVENT_ANIME_START, 'gpu' : false } ); }; - console.log( 'animate ' + this._id + ' y:' + obj.startX + ' > ' + obj.destX + ' d:' + obj.duration ); + // console.log( 'animate() ' + this[ '_id' ] + ' y:' + obj.startY + ' > ' + obj.destY + ' d:' + obj.duration ); return this; }; -Node.prototype.stop = function(){ - var obj = this._anime; - if( !obj ) return; +/** + * アニメーションの停止。 + * @alias Node.prototype.stop + * @return {Node} メソッドチェーン + */ +function X_Node_stop(){ + var obj = this[ '_anime' ]; + + if( !obj ) return this; + if( X_Node_Anime_hasTransition ){ obj.phase = 100; X_Node_Anime_needsDetection = true; X_Node_Anime_reserveUpdate(); } else { X_Node_ANIMATIONS.splice( X_Node_ANIMATIONS.indexOf( this ), 1 ); - //obj.gpuTimerID && X.Timer.remove( obj.gpuTimerID ); - delete this._anime; + //obj.gpuTimerID && X_Timer_remove( obj.gpuTimerID ); + delete this[ '_anime' ]; }; return this; }; @@ -154,24 +184,26 @@ function X_Node_Anime_reserveUpdate( before ){ X_Node_Anime_reserved = true; if( X_Node_updateTimerID ){ - console.log( before ? '> BEFORE_UPDATE' : '> UPDATED' ); + //console.log( before ? '> BEFORE_UPDATE' : '> UPDATED' ); before = false; - X_System.listenOnce( before ? X.Event.BEFORE_UPDATE : X.Event.UPDATED, X_Node_Anime_updateAnimations ); + X_System[ 'listenOnce' ]( before ? X_EVENT_BEFORE_UPDATE : X_EVENT_UPDATED, X_Node_Anime_updateAnimations ); } else { - console.log( '> Timer' ); + //console.log( '> Timer' ); // Opera12 requestAnimationFrame では transition が動かない、、、 X_Node_Anime_updateTimerID = - X_UA.Opera ? - X.Timer.once( 0, X_Node_Anime_updateAnimations ) : - X.Timer.requestFrame( X_Node_Anime_updateAnimations ); + X_UA[ 'Opera' ] ? + X_Timer_once( 0, X_Node_Anime_updateAnimations ) : + X_Timer_requestFrame( X_Node_Anime_updateAnimations ); }; + } else { + // console.log( ' X_Node_Anime_reserved 済、予約なし' ); }; }; function X_Node_Anime_updateAnimations( v, updateNow ){ - var i = X_Node_ANIMATIONS.length, ret, c = false; + var i = X_Node_ANIMATIONS.length, c = false, ret, xnode; - //console.log( v.type || v ); + // console.log( v.type || v ); //console.log( 'updateAnimations len:' + i + ' time:' + v + ' det:' + X_Node_Anime_needsDetection ); @@ -179,12 +211,12 @@ function X_Node_Anime_updateAnimations( v, updateNow ){ for( ; i; ){ xnode = X_Node_ANIMATIONS[ --i ]; - //console.log( 'phase : ' + xnode._id + ' ' + xnode._anime.phase + ' ' + xnode._anime.duration ); + //console.log( 'phase : ' + xnode[ '_id' ] + ' ' + xnode[ '_anime' ].phase + ' ' + xnode[ '_anime' ].duration ); ret = X_Node_Anime_updateAnimation( xnode ); if( ret === true ){ X_Node_ANIMATIONS.splice( i, 1 ); - xnode._anime.gpuTimerID && X.Timer.remove( xnode._anime.gpuTimerID ); - delete xnode._anime; + xnode[ '_anime' ].gpuTimerID && X_Timer_remove( xnode[ '_anime' ].gpuTimerID ); + delete xnode[ '_anime' ]; } else if( ret !== false ){ c = true; @@ -200,11 +232,11 @@ function X_Node_Anime_updateAnimations( v, updateNow ){ }; }; -// TODO X.Timer.requestFrame 経由の BEFORE_UPDATE で更新を行う +// TODO X_Timer_requestFrame 経由の BEFORE_UPDATE で更新を行う function X_Node_Anime_detectAnimationLayers(){ var i = X_Node_ANIMATIONS.length, l = i, - j, xnode, parent, hasGPUChild, remove; + j, xnode, parent, _xnode, hasGPUChild, remove; for( ; i; ){ xnode = X_Node_ANIMATIONS[ --i ]; @@ -215,44 +247,44 @@ function X_Node_Anime_detectAnimationLayers(){ if( xnode.parent === _xnode.parent ){ continue; } else - if( _xnode.contains( xnode ) ){ - if( ( _xnode._anime.phase === 3 && _xnode._anime.gpuParent ) || _xnode._anime.phase === 10 ){ - _xnode._anime.phase = 15; + if( _xnode[ 'contains' ]( xnode ) ){ + if( ( _xnode[ '_anime' ].phase === 3 && _xnode[ '_anime' ].gpuParent ) || _xnode[ '_anime' ].phase === 10 ){ + _xnode[ '_anime' ].phase = 15; } else - if( xnode._anime.gpuParent ){ + if( xnode[ '_anime' ].gpuParent ){ parent = true; - xnode._anime.phase = xnode._anime.phase === 2 ? 6 : 15;// GPU レイヤーの解除 > アニメーションは継続, すでに終了フェイズなら破棄 + xnode[ '_anime' ].phase = xnode[ '_anime' ].phase === 2 ? 6 : 15;// GPU レイヤーの解除 > アニメーションは継続, すでに終了フェイズなら破棄 } else - if( [ 7, 8, 9, 13, 14 ].indexOf( xnode._anime.phase ) !== -1 ){// GPU レイヤーの中止 + if( [ 7, 8, 9, 13, 14 ].indexOf( xnode[ '_anime' ].phase ) !== -1 ){// GPU レイヤーの中止 parent = true; - xnode._anime.phase -= 8; + xnode[ '_anime' ].phase -= 8; }; break; } else - if( xnode.contains( _xnode ) ){ - if( ( xnode._anime.phase === 3 && xnode._anime.gpuParent ) || xnode._anime.phase === 10 ){ - xnode._anime.phase = 15; + if( xnode[ 'contains' ]( _xnode ) ){ + if( ( xnode[ '_anime' ].phase === 3 && xnode[ '_anime' ].gpuParent ) || xnode[ '_anime' ].phase === 10 ){ + xnode[ '_anime' ].phase = 15; } else - if( _xnode._anime.gpuParent ){ + if( _xnode[ '_anime' ].gpuParent ){ hasGPUChild = true; - _xnode._anime.phase = _xnode._anime.phase === 2 ? 6 : 15;// GPU レイヤーの解除 > アニメーションは継続, すでに終了フェイズなら破棄 + _xnode[ '_anime' ].phase = _xnode[ '_anime' ].phase === 2 ? 6 : 15;// GPU レイヤーの解除 > アニメーションは継続, すでに終了フェイズなら破棄 } else - if( [ 7, 8, 9, 13, 14 ].indexOf( _xnode._anime.phase ) !== -1 ){// GPU レイヤーの中止 + if( [ 7, 8, 9, 13, 14 ].indexOf( _xnode[ '_anime' ].phase ) !== -1 ){// GPU レイヤーの中止 hasGPUChild = true; - _xnode._anime.phase -= 8; + _xnode[ '_anime' ].phase -= 8; }; break; }; }; - if( !parent && xnode._anime.phase !== 15 ){ - if( xnode._anime.phase === 0 ){ + if( !parent && xnode[ '_anime' ].phase !== 15 ){ + if( xnode[ '_anime' ].phase === 0 ){ // 新規 - xnode._anime.phase = hasGPUChild ? 7 : 8;// 非GPU -> GPU 子に GPU アニメをもつなら、タイミングをずらす。 + xnode[ '_anime' ].phase = hasGPUChild ? 7 : 8;// 非GPU -> GPU 子に GPU アニメをもつなら、タイミングをずらす。 } else - if( [ 3, 4, 10, 100 ].indexOf( xnode._anime.phase ) === -1 ){ + if( [ 3, 4, 10, 100 ].indexOf( xnode[ '_anime' ].phase ) === -1 ){ // 非GPU -> GPU - xnode._anime.phase = hasGPUChild ? 13 : 14;// 非GPU -> GPU 子に GPU アニメをもつなら、タイミングをずらす。 + xnode[ '_anime' ].phase = hasGPUChild ? 13 : 14;// 非GPU -> GPU 子に GPU アニメをもつなら、タイミングをずらす。 }; }; }; @@ -260,11 +292,8 @@ function X_Node_Anime_detectAnimationLayers(){ X_Node_Anime_needsDetection = false; }; -/* TODO - * 0:無, 1:子のGPU解除待 2:GPU予約, 3:GPU now!, 4:GPU解除予約 - */ function X_Node_Anime_updateAnimation( xnode ){ - var obj = xnode._anime, + var obj = xnode[ '_anime' ], phase = obj.phase, current, time; switch( phase ){ @@ -278,45 +307,47 @@ function X_Node_Anime_updateAnimation( xnode ){ break; case 0 : // 開始位置+アニメーションの設定 case 8 : - X_ViewPort.unlisten( X.Event.AFTER_UPDATE, xnode, X_Node_Anime_gpuReleased ); + X_ViewPort[ 'unlisten' ]( X_EVENT_AFTER_UPDATE, xnode, X_Node_Anime_gpuReleased ); - xnode.css({ - willChange : X_Node_Anime_transitionProps + ',opacity,width,height', + xnode[ 'css' ]({ + //willChange : X_Node_Anime_transitionProps + ',opacity,width,height', backfaceVisibility : 'hidden', transitionTimingFunction : obj.easing.style, transitionDelay : '0s' // 0.001 にすると transitionend のタイミングが狂う、、、 }); - console.log( '開始位置 ' + phase ); + //console.log( '開始位置 ' + phase ); X_Node_Anime_updatePosition( xnode, obj.startX, obj.startY, obj.startA, phase === 8 ); - xnode.dispatch( { type : X.Event.ANIME_START, gpu : phase === 8 } ); + xnode[ 'dispatch' ]( { type : X_EVENT_ANIME_START, 'gpu' : phase === 8 } ); ++obj.phase; break; case 1 : case 9 : // 終了位置の設定 obj.gpuParent = phase === 9; if( obj.duration ){ - xnode.listenOnce( 'transitionend', X_Node_Anime_onTransitionEnd ); + xnode[ 'listenOnce' ]( 'transitionend', X_Node_Anime_onTransitionEnd ); - xnode.css({ + xnode[ 'css' ]({ transitionProperty : X_Node_Anime_transitionProps + ',opacity,width,height', transitionDuration : obj.duration + 'ms' }); - console.log( '修了位置 ' + phase ); + //console.log( '修了位置 ' + phase ); X_Node_Anime_updatePosition( xnode, obj.destX, obj.destY, obj.destA, obj.gpuParent ); obj.phase = 2; break; }; - console.log( 'duration = 0 の場合、アニメーションの解除' ); + //console.log( 'duration = 0 の場合、アニメーションの解除' ); // duration = 0 の場合、アニメーションの解除 - case 3 : // アニメーションの解除 + case 3 : // TransitionEnd -> アニメーションの解除 obj.phase = obj.gpuParent ? 10 : 4; + + console.log( '#### アニメーションの解除 ' + obj.phase ); + // このタイミングで animation 関連の css を削除したところ(X_Node_Anime_clearTransition)、iOS3、4 で再描画忘れが度々起きるように、、、 if( !obj.gpuParent ) X_Node_Anime_clearTransition( xnode ); - xnode.dispatch( { type : X.Event.ANIME_END, gpu : obj.gpuParent } ); break; case 4 : @@ -326,10 +357,10 @@ function X_Node_Anime_updateAnimation( xnode ){ case 10 : // アニメーションは停止・GPUレイヤーは解除していない(再アニメーションに備えて待機) - X_Node_Anime_clearTransition( xnode ); // TODO X_Node_Anime_releaseGPULayer に移動? if( !obj.gpuTimerID ){ + console.log( '#### アニメーションは停止 ' + obj.wait ); if( obj.wait ){ - obj.gpuTimerID = X.Timer.once( obj.wait, xnode, X_Node_Anime_releaseGPULayer ); + obj.gpuTimerID = X_Timer_once( obj.wait, xnode, X_Node_Anime_releaseGPULayer ); } else { X_Node_Anime_releaseGPULayer.call( xnode ); }; @@ -351,7 +382,7 @@ function X_Node_Anime_updateAnimation( xnode ){ X_Node_Anime_clearTransition( xnode ); X_Node_Anime_updatePosition( xnode, obj.destX, obj.destY, obj.destA, phase === 14 ); obj.phase = phase === 14 ? 10 : 4; - xnode.dispatch( { type : X.Event.ANIME_END, gpu : obj.gpuParent } ); + xnode[ 'dispatch' ]( time, { type : X_EVENT_ANIME_END, 'gpu' : obj.gpuParent } ); } else { current = X_Node_Anime_getComputedPosition( xnode ); obj.startX = current.x; @@ -366,17 +397,18 @@ function X_Node_Anime_updateAnimation( xnode ){ case 15 : // GPU有効で停止(待機)している xnode の解除 - //console.log( 'GPU有効で停止(待機)している xnode の解除' + xnode._tag + xnode.getOrder() ); - console.log( 'GPU有効で停止(待機)している xnode のGPU解除' ); + //console.log( 'GPU有効で停止(待機)している xnode の解除' + xnode[ '_tag' ] + xnode[ 'getOrder' ]() ); + // console.log( 'GPU有効で停止(待機)している xnode のGPU解除' ); X_Node_Anime_clearTransition( xnode ); X_Node_Anime_updatePosition( xnode, obj.destX, obj.destY, obj.destA, false ); - obj.gpuTimerID && X.Timer.remove( obj.gpuTimerID ); - X_ViewPort.listenOnce( X.Event.AFTER_UPDATE, xnode, X_Node_Anime_gpuReleased ); + //obj.gpuTimerID && X_Timer_remove( obj.gpuTimerID ); + //delete obj.gpuTimerID; + X_ViewPort[ 'listenOnce' ]( X_EVENT_AFTER_UPDATE, xnode, X_Node_Anime_gpuReleased ); return true; case 100 : // stop() : アニメーションを中断して削除 //console.log( 'stop() gpu:' + obj.gpuParent ); - console.log( 'アニメーションを中断して削除' ); + // console.log( 'アニメーションを中断して削除' ); current = X_Node_Anime_getComputedPosition( xnode ); X_Node_Anime_clearTransition( xnode ); @@ -388,7 +420,7 @@ function X_Node_Anime_updateAnimation( xnode ){ }; function X_Node_Anime_getComputedPosition( that ) { - var matrix = X_node_CSS_getComputedStyle( that._rawObject, null ), + var matrix = X_Node_CSS_getComputedStyle( that[ '_rawObject' ], null ), x, y; if ( X_Node_Anime_hasTransform ) { @@ -396,21 +428,28 @@ function X_Node_Anime_getComputedPosition( that ) { x = + ( matrix[ 12 ] || matrix[ 4 ] ); y = + ( matrix[ 13 ] || matrix[ 5 ] ); } else { - x = + parseInt( matrix.left ); - y = + parseInt( matrix.top ); + x = + parseFloat( matrix.left ); + y = + parseFloat( matrix.top ); }; return { x : x, y : y, a : matrix[ X_Node_CSS_Support[ 'opacity' ] ] }; }; function X_Node_Anime_onTransitionEnd( e ){ - if( !this._anime || this._anime.phase !== 2 ) return X.Callback.PREVENT_DEFAULT | X.Callback.STOP_PROPAGATION; - this._anime.phase = 3; + console.log( '[TransitionEnd] ' + ( this[ '_anime' ] && this[ '_anime' ].phase ) ); + + if( !this[ '_anime' ] || this[ '_anime' ].phase !== 2 ){ + // ここで return してしまうと、view の更新イベント待ちの場合、アニメが止まる + X_Node_Anime_reserved && !X_Node_Anime_updateTimerID && !X_Node_updateTimerID && X_Node_Anime_reserveUpdate( X_Node_Anime_reserved = false ); + return X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_STOP_PROPAGATION; + }; + + this[ '_anime' ].phase = 3; - console.log( 'トランジション終了' ); + X_Node_Anime_clearTransition( this ); // X_EVENT_ANIME_END より前で呼んでおく X_Node_Anime_onTransition = true; - this.dispatch( { type : X.Event.ANIME_END, gpu : this._anime.gpuParent } ); + this[ 'dispatch' ]( { type : X_EVENT_ANIME_END, 'gpu' : this[ '_anime' ].gpuParent } ); X_Node_Anime_onTransition = false; X_Node_Anime_needsDetection = true; @@ -418,37 +457,38 @@ function X_Node_Anime_onTransitionEnd( e ){ // win+Gecko は不可 X_Node_Anime_updateAnimations( 0, X_Node_updateOnTransitionEnd ); - return X.Callback.PREVENT_DEFAULT | X.Callback.STOP_PROPAGATION; + return X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_STOP_PROPAGATION; }; function X_Node_Anime_releaseGPULayer(){ - var obj = this._anime, tmp; + var obj = this[ '_anime' ], tmp; if( !obj ){ - console.log( '_anime無' ); + // console.log( '_anime無' ); return; }; + X_Node_Anime_clearTransition( this ); X_Node_Anime_updatePosition( this, obj.destX, obj.destY, obj.destA, false ); X_Node_ANIMATIONS.splice( X_Node_ANIMATIONS.indexOf( this ), 1 ); delete obj.gpuTimerID; - delete this._anime; + delete this[ '_anime' ]; console.log( 'GPUレイヤーの破棄を指示' ); - X_ViewPort.listenOnce( X.Event.AFTER_UPDATE, this, X_Node_Anime_gpuReleased ); + X_ViewPort[ 'listenOnce' ]( X_EVENT_AFTER_UPDATE, this, X_Node_Anime_gpuReleased ); }; function X_Node_Anime_gpuReleased(){ - console.log( 'GPU レイヤーが解放されました' ); - this.dispatch( { type : X.Event.GPU_RELEASED, gpu : true } ); + //console.log( 'GPU レイヤーが解放されました' ); + this[ 'dispatch' ]( { type : X_EVENT_GPU_RELEASED, 'gpu' : true } ); }; function X_Node_Anime_clearTransition( xnode ){ // 開始座標のセット(新規のみ) // アニメーション指定のセット(または解除)(対象のみ) // 目標座標のセット - xnode.unlisten( 'transitionend', X_Node_Anime_onTransitionEnd ); + xnode[ 'unlisten' ]( 'transitionend', X_Node_Anime_onTransitionEnd ); - xnode.css({ - willChange : '', + xnode[ 'css' ]({ + //willChange : '', backfaceVisibility : '', transitionTimingFunction : '', transitionDelay : '', @@ -457,42 +497,45 @@ function X_Node_Anime_clearTransition( xnode ){ }; function X_Node_Anime_updatePosition( xnode, x, y, opacity, useGPU ){ - //console.log( 'y : ' + y + ' gpu : ' + !!useGPU ); + console.log( 'updatePosition x:' + x + ' gpu:' + !!useGPU ); if( X_Node_Anime_hasTransform ){ - xnode.css({ + xnode[ 'css' ]({ transform : 'translate(' + ( x | 0 ) + 'px,' + ( y | 0 ) + 'px)' + ( useGPU ? X_Node_Anime_translateZ : '' ), opacity : opacity }); } else { - xnode.css({ + x === x && xnode[ 'css' ]({ left : ( x | 0 ) + 'px', + opacity : opacity }); + y === y && xnode[ 'css' ]({ top : ( y | 0 ) + 'px', - opacity : opacity - }); + opacity : opacity }); }; - if( useGPU ){ - if( xnode._flags & X_Node_State.GPU_RELEASE_RESERVED ){ - xnode._flags &= X_Node_BitMask_RESET_GPU; - xnode._flags |= X_Node_State.GPU_NOW; - } else - if( xnode._flags & X_Node_State.GPU_NOW ){ + if( X_Node_Anime_translateZ ){ + if( useGPU ){ + if( xnode[ '_flags' ] & X_NodeFlags_GPU_RELEASE_RESERVED ){ + xnode[ '_flags' ] &= X_Node_BitMask_RESET_GPU; + xnode[ '_flags' ] |= X_NodeFlags_GPU_NOW; + } else + if( xnode[ '_flags' ] & X_NodeFlags_GPU_NOW ){ + } else { + xnode[ '_flags' ] &= X_Node_BitMask_RESET_GPU; + xnode[ '_flags' ] |= X_NodeFlags_GPU_RESERVED; + }; } else { - xnode._flags &= X_Node_BitMask_RESET_GPU; - xnode._flags |= X_Node_State.GPU_RESERVED; - }; - } else { - if( xnode._flags & X_Node_State.GPU_NOW ){ - xnode._flags &= X_Node_BitMask_RESET_GPU; - xnode._flags |= X_Node_State.GPU_RELEASE_RESERVED; - } else - if( xnode._flags & X_Node_State.GPU_RESERVED ){ - xnode._flags &= X_Node_BitMask_RESET_GPU; - }; + if( xnode[ '_flags' ] & X_NodeFlags_GPU_NOW ){ + xnode[ '_flags' ] &= X_Node_BitMask_RESET_GPU; + xnode[ '_flags' ] |= X_NodeFlags_GPU_RELEASE_RESERVED; + } else + if( xnode[ '_flags' ] & X_NodeFlags_GPU_RESERVED ){ + xnode[ '_flags' ] &= X_Node_BitMask_RESET_GPU; + }; + }; }; }; -function X_Node_Anime_updateAnimationsNoTransition(){ +function X_Node_Anime_updateAnimationsNoTransition( e ){ var i = X_Node_ANIMATIONS.length, now = X_Timer_now(), obj, @@ -501,16 +544,16 @@ function X_Node_Anime_updateAnimationsNoTransition(){ for( ; i; ){ xnode = X_Node_ANIMATIONS[ --i ]; - obj = xnode._anime; + obj = xnode[ '_anime' ]; if( obj.destTime <= now ){ X_Node_Anime_updatePosition( xnode, obj.destX, obj.destY, obj.destA, false ); - delete xnode._anime; + delete xnode[ '_anime' ]; X_Node_ANIMATIONS.splice( i, 1 ); // filter な 親が解除されないと子要素への filter が反映されない - xnode.asyncDispatch( { type : X.Event.ANIME_END, gpu : false } ); + xnode[ 'asyncDispatch' ]( { type : X_EVENT_ANIME_END, 'gpu' : false } ); } else { easing = obj.easing.fn( ( now - obj.startTime ) / obj.duration ); newX = ( obj.destX - obj.startX ) * easing + obj.startX; @@ -524,14 +567,21 @@ function X_Node_Anime_updateAnimationsNoTransition(){ }; }; - if( c ){ + c && console.log( 'anime... ' + X_Node_updateTimerID ); + + if( X_Node_Anime_reserved = c ){ if( X_Node_updateTimerID ){ - X_System.listen( X.Event.UPDATED, X_Node_Anime_updateAnimationsNoTransition ); + // scrollbox では X_System X_EVENT_UPDATED は不可。。。 + !e || e.type !== X_EVENT_UPDATED ? + X_System[ 'listen' ]( X_EVENT_UPDATED, X_Node_Anime_updateAnimationsNoTransition ) : + X_Node_Anime_updateTimerID && X_Timer_cancelFrame( X_Node_Anime_updateTimerID ); X_Node_Anime_updateTimerID = 0; } else { - X_Node_Anime_updateTimerID = X.Timer.requestFrame( X_Node_Anime_updateAnimationsNoTransition ); + X_System[ 'unlisten' ]( X_EVENT_UPDATED, X_Node_Anime_updateAnimationsNoTransition ); + X_Node_Anime_updateTimerID = X_Timer_requestFrame( X_Node_Anime_updateAnimationsNoTransition ); }; } else { + X_System[ 'unlisten' ]( X_EVENT_UPDATED, X_Node_Anime_updateAnimationsNoTransition ); X_Node_Anime_updateTimerID = 0; }; };