OSDN Git Service

Version 0.6.182, fix X.UA.
[pettanr/clientJs.git] / 0.6.x / js / 20_ui / 15_ScrollBox.js
index 15a613f..817ebdb 100644 (file)
@@ -1,33 +1,10 @@
+/*\r
+ * scroll 要素は常にひとつ\r
+ * ScrollManager\r
+ * indicatorX, Y は再利用\r
+ */\r
 \r
 \r
-function X_UI_ScrollBox_momentum( current, start, time, lowerMargin, wrapperSize, deceleration ){\r
-       var distance = current - start,\r
-               speed    = Math.abs( distance ) / time,\r
-               destination,\r
-               duration;\r
-\r
-       deceleration = deceleration === undefined ? 0.0006 : deceleration;\r
-\r
-       destination  = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 );\r
-       duration     = speed / deceleration;\r
-\r
-       if( destination < lowerMargin ){\r
-               destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin;\r
-               distance    = Math.abs( destination - current );\r
-               duration    = distance / speed;\r
-       } else\r
-       if ( destination > 0 ) {\r
-               destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0;\r
-               distance    = Math.abs( current ) + destination;\r
-               duration    = distance / speed;\r
-       };\r
-\r
-       return {\r
-               destination : Math.round( destination ),\r
-               duration    : duration\r
-       };\r
-};\r
-\r
 var X_UI_ScrollBox_SUPPORT_ATTRS = {\r
                // スクロール開始するために必要な移動距離、縦か横、どちらか制限する場合、より重要\r
                directionLockThreshold : [     10, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.LENGTH ],\r
@@ -35,18 +12,19 @@ var X_UI_ScrollBox_SUPPORT_ATTRS = {
                scrollYEnabled         : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
                scrollEnabled          : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
                bounceEnabled          : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
-               bounceTime             : [    600, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.TIME ],\r
+               bounceTime             : [    300, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.TIME ],\r
                useWheel               : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
                useKey                 : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
                hasScrollShadow        : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
                scrollShadowColor      : [ '#000', XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.COLOR ]\r
        };\r
 \r
-\r
 var XUI_ScrollBox = XUI_ChromeBox.inherits(\r
        '_ScrollBox',\r
-       X_Class.PRIVATE_DATA,\r
+       X_Class.NONE,\r
        {\r
+               layout                 : XUI_Layout_Canvas,\r
+               \r
                directionLockThreshold : 10,\r
                scrollXEnabled         : true,\r
                scrollYEnabled         : true,\r
@@ -59,8 +37,6 @@ var XUI_ScrollBox = XUI_ChromeBox.inherits(
                hasScrollShadow        : true,\r
                scrollShadowColor      : '#000',\r
                \r
-               supportAttrs    : XUI_Attr_createAttrDef( XUI_Attr_Support, X_UI_ScrollBox_SUPPORT_ATTRS ),\r
-               \r
                scrolling       : false,\r
                \r
                initiated       : '',\r
@@ -68,7 +44,6 @@ var XUI_ScrollBox = XUI_ChromeBox.inherits(
                directionLocked : '',\r
                startTime       : 0,\r
                endTime         : 0,\r
-               isAnimating     : false,\r
                isInTransition  : false,\r
 \r
                hasHScroll      : false,\r
@@ -105,9 +80,12 @@ var XUI_ScrollBox = XUI_ChromeBox.inherits(
                _containerNode   : null,\r
                xnodeSlider      : null,\r
                \r
-               Constructor : function( layout, args ){\r
-                       this[ 'Super' ]( layout, args );\r
-                       this._containerNode = X_Class_getPrivate( this.containerNode );\r
+               xnodeIndicatorX  : null,\r
+               xnodeIndicatorY  : null,\r
+               \r
+               Constructor : function( user, layout, args ){\r
+                       this[ 'Super' ]( user, layout, args );\r
+                       this._containerNode = X_Pair_get( this.containerNode );\r
                        this.xnodeSlider = this._containerNode.xnode[ 'className' ]( 'ScrollSlider' ).listen( X_EVENT_ANIME_END, this, X_UI_ScrollBox_onAnimeEnd );\r
                        this.xnode[ 'className' ]( 'ScrollBox' );\r
                },\r
@@ -159,51 +137,51 @@ var XUI_ScrollBox = XUI_ChromeBox.inherits(
 );\r
 \r
 function X_UI_ScrollBox_onLayoutBefore( e ){\r
+       if( e[ 'cancelable' ] && this.isInTransition && X_Node_Anime_translateZ ){\r
+               this[ 'listenOnce' ]( XUI_Event.SCROLL_END, X_UI_rootData, X_UI_rootData.calculate );\r
+               return X_CALLBACK_PREVENT_DEFAULT;\r
+       };\r
        this.scrollXRatio = this.scrollX ? this.scrollXMax / this.scrollX : 0;\r
        this.scrollYRatio = this.scrollY ? this.scrollYMax / this.scrollY : 0;\r
-       this.xnodeSlider.stop();\r
+       this.xnodeSlider[ 'stop' ]();\r
+       this.isInTransition = false;\r
+       return X_CALLBACK_NONE;\r
 };\r
 \r
 function X_UI_ScrollBox_onLayoutComplete( e ){\r
        // scroll の停止、GPU の解除\r
-       var font = this.fontSize = this.xnodeSlider.call( 'fontSize' );\r
-       \r
-       this.scrollXMax = ( this.boxWidth  - this._containerNode.boxWidth )  * font;\r
-       this.scrollYMax = ( this.boxHeight - this._containerNode.boxHeight ) * font;\r
+       var font = this.fontSize = this.xnodeSlider[ 'call' ]( 'fontSize' );\r
 \r
-       this.hasHScroll = this.scrollXEnabled && this.scrollXMax < 0;\r
-       this.hasVScroll = this.scrollYEnabled && this.scrollYMax < 0;\r
+       this.scrollXMax = ( this.boxWidth  - this._containerNode.boxWidth )  * font | 0;\r
+       this.scrollYMax = ( this.boxHeight - this._containerNode.boxHeight ) * font | 0;\r
+\r
+       this.hasHScroll = this.scrollXEnabled && ( this.scrollXMax < -1 ); // < 0 だと \r
+       this.hasVScroll = this.scrollYEnabled && ( this.scrollYMax < -1 );\r
 \r
        if( !this.hasHScroll ){\r
                this.scrollXMax  = 0;\r
-               //this.scrollWidth = this.boxWidth;\r
        };\r
 \r
        if( !this.hasVScroll ){\r
                this.scrollYMax   = 0;\r
-               //this.scrollHeight = this.boxHeight;\r
        };\r
 \r
        delete this.endTime;\r
        delete this.directionX;\r
        delete this.directionY;\r
 \r
-       //this.wrapperOffset = this.xnodeWrapper[ 'offset' ]();\r
-\r
-       //this[ 'dispatch' ]('refresh');\r
-\r
        X_UI_ScrollBox_resetPosition( this, 0 );\r
 \r
        if( this.hasHScroll || this.hasVScroll ){\r
                // scroll が必要。\r
                if( this.scrolling ){\r
-                       X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 0, '', 0 );\r
+                       X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 100, '', 300 );\r
                } else {\r
                        // scroller 作る\r
                        this[ 'listen' ]( XUI_Event._POINTER_DOWN, this, X_UI_ScrollBox_onStart );\r
                        X_UI_rootData[ 'listen' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );\r
                        \r
-                       X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 0, '', 0 );\r
+                       X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 100, '', 300 );\r
                        this.scrolling = true;\r
                };\r
        } else\r
@@ -211,9 +189,9 @@ function X_UI_ScrollBox_onLayoutComplete( e ){
        if( this.scrolling ){\r
                // scroller 削除\r
                this[ 'unlisten' ]( XUI_Event._POINTER_DOWN, this, X_UI_ScrollBox_onStart );\r
-               X_UI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_BEFORE,   this, X_UI_ScrollBox_onLayoutBefore );\r
+               X_UI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );\r
                \r
-               ( this.scrollX !== 0 || this.scrollY !== 0 ) && X_UI_ScrollBox_translate( this, 0, 0, 0, '', 0 );\r
+               ( this.scrollX !== 0 || this.scrollY !== 0 ) && X_UI_ScrollBox_translate( this, 0, 0, 100, '', 300 );\r
                \r
                delete this.scrolling;\r
                delete this.scrollXRatio;\r
@@ -221,13 +199,14 @@ function X_UI_ScrollBox_onLayoutComplete( e ){
        };\r
 };\r
 \r
+               // TODO use scrollLeft, scrollTop\r
                function X_UI_ScrollBox_translate( that, x, y, opt_time, opt_easing, opt_release ){\r
                        \r
                        opt_time    = 0 <= opt_time ? opt_time : 0;\r
                        opt_easing  = opt_easing === '' ? '' : opt_easing || 'circular';\r
                        opt_release = 0 <= opt_release ? opt_release : 300;\r
                        \r
-                       that.xnodeSlider.animate(\r
+                       that.xnodeSlider[ 'animate' ](\r
                                {\r
                                        x : that.scrollX,\r
                                        y : that.scrollY\r
@@ -250,7 +229,7 @@ function X_UI_ScrollBox_onLayoutComplete( e ){
                };\r
 \r
 function X_UI_ScrollBox_onStart( e ){\r
-       var ret = X_Callback_NONE;\r
+       var ret = X_CALLBACK_NONE;\r
 \r
        // React to left mouse button only\r
        if( e.pointerType === 'mouse' && e.button !== 0 ){\r
@@ -271,9 +250,11 @@ function X_UI_ScrollBox_onStart( e ){
        this.startTime       = X_Timer_now();\r
 \r
        // スクロール中の停止\r
-       if( this.isInTransition || this.isAnimating ){\r
-               this.isInTransition = this.isAnimating = false;\r
+       if( this.isInTransition ){\r
+               this.isInTransition = false;\r
                this[ 'dispatch' ]( XUI_Event.SCROLL_END );\r
+               // TODO current位置\r
+               this.xnodeSlider[ 'stop' ]();\r
        };                      \r
 \r
        this.startX    = this.scrollX;\r
@@ -283,19 +264,23 @@ function X_UI_ScrollBox_onStart( e ){
        this.pointX    = e.pageX;\r
        this.pointY    = e.pageY;\r
        \r
+       console.log( 'scrollstart ' + e.pageY );\r
+       \r
        this[ 'listen' ]( XUI_Event._POINTER_MOVE, this, X_UI_ScrollBox_onMove );\r
        this[ 'listen' ]( [ XUI_Event._POINTER_UP, XUI_Event._POINTER_CANCEL ], this, X_UI_ScrollBox_onEnd );\r
 \r
-       return ret | X_Callback_PREVENT_DEFAULT;\r
+       return ret | X_CALLBACK_PREVENT_DEFAULT;\r
 };\r
 \r
 function X_UI_ScrollBox_onMove( e ){\r
-       var ret = X_Callback_NONE,\r
+       var ret = X_CALLBACK_NONE,\r
                deltaX, deltaY, timestamp,\r
                newX, newY,\r
                absDistX, absDistY;\r
        // 規定以上の move でスクロール開始\r
-       \r
+\r
+//console.log( 'scrollmove ' + e.buttons + ' ' + e.button );\r
+\r
        if( !this.scrollEnabled || e.pointerType !== this.initiated ){\r
                return ret;\r
        };\r
@@ -385,11 +370,11 @@ function X_UI_ScrollBox_onMove( e ){
                this.startY = this.scrollY;\r
        };\r
        // イベントの拘束\r
-       return ret | X_Callback_PREVENT_DEFAULT | X_Callback_CAPTURE_POINTER;\r
+       return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_CAPTURE_POINTER;\r
 };\r
 \r
 function X_UI_ScrollBox_onEnd( e ){\r
-       var ret    = X_Callback_NONE,\r
+       var ret    = X_CALLBACK_NONE,\r
                time   = 0,\r
                easing = '',\r
                newX, newY,\r
@@ -421,7 +406,7 @@ function X_UI_ScrollBox_onEnd( e ){
        // we scrolled less than 10 pixels\r
        if( !this.moved ){\r
                // this[ 'dispatch' ]( X_EVENT_CANCELED );\r
-               console.log( 'we scrolled less than 10 pixels' );\r
+               console.log( 'we scrolled less than 10 pixels ' + e.pageY );\r
                return ret;\r
        };\r
 \r
@@ -485,8 +470,8 @@ function X_UI_ScrollBox_resetPosition( that, time ){
                return false;\r
        };\r
 \r
-       //console.log( 'バウンド!' );\r
-       //console.log( 'rese x:' + x + ' y:' + y );\r
+       console.log( ' ===> resetPosition - バウンド!' );\r
+       console.log( '      x:' + x + ' y:' + y );\r
        that.scrollTo( x, y, time, that.bounceEasing, 1000 );\r
 \r
        return true;\r
@@ -494,61 +479,96 @@ function X_UI_ScrollBox_resetPosition( that, time ){
 \r
 function X_UI_ScrollBox_onAnimeEnd( e ){\r
        if( e.target !== this.xnodeSlider || !this.isInTransition ){\r
-               return X_Callback_NONE;\r
+               return X_CALLBACK_NONE;\r
        };\r
        if( !X_UI_ScrollBox_resetPosition( this, this.bounceTime ) ){\r
                this.isInTransition = false;\r
-               this.dispatch( XUI_Event.SCROLL_END );\r
+               this[ 'dispatch' ]( XUI_Event.SCROLL_END );\r
+       };\r
+       return X_CALLBACK_NONE;\r
+};\r
+\r
+function X_UI_ScrollBox_momentum( current, start, time, lowerMargin, wrapperSize, deceleration ){\r
+       var distance = current - start,\r
+               speed    = Math.abs( distance ) / time,\r
+               destination,\r
+               duration;\r
+\r
+       deceleration = deceleration === undefined ? 0.0006 : deceleration;\r
+\r
+       destination  = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 );\r
+       duration     = speed / deceleration;\r
+\r
+       if( destination < lowerMargin ){\r
+               destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin;\r
+               distance    = Math.abs( destination - current );\r
+               duration    = distance / speed;\r
+       } else\r
+       if ( destination > 0 ) {\r
+               destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0;\r
+               distance    = Math.abs( current ) + destination;\r
+               duration    = distance / speed;\r
+       };\r
+\r
+       return {\r
+               destination : Math.round( destination ),\r
+               duration    : duration\r
        };\r
-       return X_Callback_NONE;\r
 };\r
 \r
 X.UI.ScrollBox = X.UI.ChromeBox.inherits(\r
        'ScrollBox',\r
        X_Class.NONE,\r
-       XUI_ScrollBox,\r
        {\r
                Constructor : function(){\r
+                       var supports, slider;\r
+                       \r
+                       if( XUI_ScrollBox.prototype.usableAttrs === XUI_ChromeBox.prototype.usableAttrs ){\r
+                               XUI_ScrollBox.prototype.usableAttrs = supports = XUI_Attr_createAttrDef( XUI_Attr_Support, X_UI_ScrollBox_SUPPORT_ATTRS );\r
+               \r
+                               XUI_ScrollBox.prototype.attrClass   = XUI_Attr_preset( XUI_Box.prototype.attrClass, supports, { width  : '100%', height : '100%', bgColor : 0x111111 } );\r
+                       };\r
+                       \r
                        var args = [\r
                                                XUI_Layout_Vertical,                    \r
                                                {\r
-                                                       name   : 'ScrollBox-Scroller',\r
-                                                       role   : 'container',\r
-                                                       width       : 'auto',\r
-                                                       minWidth    : '100%',\r
-                                                       height      : 'auto',\r
-                                                       minHeight   : '100%'\r
+                                                       name      : 'ScrollBox-Scroller',\r
+                                                       role      : 'container',\r
+                                                       width     : 'auto',\r
+                                                       minWidth  : '100%',\r
+                                                       height    : 'auto',\r
+                                                       minHeight : '100%'\r
                                                }\r
                                        ],\r
                                i    = arguments.length,\r
-                               arg, layout, attr;\r
+                               arg, attr;\r
                        \r
                        for( ; i; ){\r
                                arg = arguments[ --i ];\r
                                if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( XUI_LayoutBase ) ){\r
-                                       layout = arg;\r
+                                       args[ 0 ] = arg;\r
                                } else\r
                                if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( X.UI.AbstractUINode ) ){\r
                                        args[ args.length ] = arg;\r
                                } else\r
                                if( X_Type_isObject( arg ) ){\r
-                                       attr = arg;\r
+                                       args[ args.length ] = attr = arg;\r
+                                       slider = attr.scrollSlider;\r
                                };\r
                        };\r
                        \r
-                       X_Class_newPrivate(\r
+                       X_Pair_create(\r
                                this,\r
-                               XUI_Layout_Canvas,\r
-                               [\r
-                                       {\r
-                                               width  : '100%',\r
-                                               height : '100%'\r
-                                       },\r
-                                       X.UI.VBox.apply( 0, args )\r
-                               ]\r
+                               XUI_ScrollBox(\r
+                                       this,\r
+                                       null,\r
+                                       [\r
+                                               slider || X.UI.VBox.apply( 0, args )\r
+                                       ]\r
+                               )\r
                        );\r
                        \r
-                       attr && this.attr( attr );\r
+                       //attr && this.attr( attr );\r
                },\r
                scrollX  : function(){\r
                        \r
@@ -566,4 +586,5 @@ X.UI.ScrollBox = X.UI.ChromeBox.inherits(
                        \r
                }\r
        }\r
-);
\ No newline at end of file
+);\r
+\r