OSDN Git Service

Version 0.6.194, X.UI.Page working.
[pettanr/clientJs.git] / 0.6.x / js / 20_ui / 15_ScrollBox.js
1 /*\r
2  * scroll 要素は常にひとつ\r
3  * ScrollManager\r
4  * indicatorX, Y は再利用\r
5  */\r
6 var XUI_ScrollBox_current,\r
7         XUI_ScrollBox_indicatorV,\r
8         XUI_ScrollBox_indicatorH;\r
9 \r
10 function XUI_ScrollBox_start( scrollBox ){\r
11         // 既存スクロールの停止\r
12         if( scrollBox.hasVScroll ){\r
13                 if( !XUI_ScrollBox_indicatorV ){\r
14                         XUI_ScrollBox_indicatorV = X_Doc_create( 'div' )[ 'className' ]( 'ScrollBox-IndicatorV' );\r
15                         \r
16                 };\r
17                 scrollBox.xnode[ 'append' ]( XUI_ScrollBox_indicatorV );\r
18                 XUI_ScrollBox_indicatorV[ 'animate' ](\r
19                                 { opacity : 0 },\r
20                                 { opacity : 1 },\r
21                                 900, 'circular', 300\r
22                         );\r
23                 scrollBox\r
24                         [ 'listenOnce' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorV, XUI_ScrollBox_indicatorHandleEvent );\r
25         };\r
26         if( scrollBox.hasHScroll ){\r
27                 if( !XUI_ScrollBox_indicatorH ){\r
28                         XUI_ScrollBox_indicatorH = X_Doc_create( 'div' )[ 'className' ]( 'ScrollBox-IndicatorH' );\r
29                 };\r
30                 scrollBox.xnode[ 'append' ]( XUI_ScrollBox_indicatorH );\r
31                 XUI_ScrollBox_indicatorH[ 'animate' ](\r
32                                 { opacity : 0 },\r
33                                 { opacity : 1 },\r
34                                 900, 'circular', 300\r
35                         );\r
36                 scrollBox\r
37                         [ 'listenOnce' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorH, XUI_ScrollBox_indicatorHandleEvent );\r
38         };\r
39 };\r
40 \r
41 function XUI_ScrollBox_indicatorHandleEvent( e ){\r
42         switch( e.type ){\r
43                 case X_EVENT_CANCELED :\r
44                 case XUI_Event.SCROLL_END :\r
45                         console.log( '-fadeout-' );\r
46                         this[ 'animate' ](\r
47                                 { opacity : 1 },\r
48                                 { opacity : 0 },\r
49                                 900, 'circular', 300\r
50                         );\r
51                         break;\r
52         };\r
53 };\r
54 \r
55 \r
56 var X_UI_ScrollBox_SUPPORT_ATTRS = {\r
57                 // スクロール開始するために必要な移動距離、縦か横、どちらか制限する場合、より重要\r
58                 directionLockThreshold : [     10, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.LENGTH ],\r
59                 scrollXEnabled         : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
60                 scrollYEnabled         : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
61                 scrollEnabled          : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
62                 bounceEnabled          : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
63                 bounceTime             : [    300, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.TIME ],\r
64                 useWheel               : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
65                 useKey                 : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
66                 hasScrollShadow        : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
67                 scrollShadowColor      : [ '#000', XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.COLOR ]\r
68         };\r
69 \r
70 var XUI_ScrollBox = XUI_ChromeBox.inherits(\r
71         '_ScrollBox',\r
72         X_Class.NONE,\r
73         {\r
74                 layout                 : XUI_Layout_Canvas,\r
75                 \r
76                 directionLockThreshold : 10,\r
77                 scrollXEnabled         : true,\r
78                 scrollYEnabled         : true,\r
79                 scrollEnabled          : true,\r
80                 bounceEnabled          : true,\r
81                 momentumEnabled        : true,\r
82                 bounceTime             : 600,\r
83                 useWheel               : true,\r
84                 useKey                 : true,\r
85                 hasScrollShadow        : true,\r
86                 scrollShadowColor      : '#000',\r
87                 \r
88                 scrolling       : false,\r
89                 \r
90                 initiated       : '',\r
91                 moved               : false,\r
92                 directionLocked : '',\r
93                 startTime       : 0,\r
94                 endTime         : 0,\r
95                 isInTransition  : false,\r
96 \r
97                 hasHScroll      : false,\r
98                 hasVScroll      : false,\r
99 \r
100                 wrapperOffset   : 0,\r
101                 wheelTimeout    : 0,\r
102                 requestFrameID  : 0,\r
103                 \r
104                 fontSize        : 0,\r
105                 \r
106                 scrollX         : 0, // px\r
107                 scrollY         : 0, // px\r
108                 scrollXMax      : 0, // px\r
109                 scrollYMax      : 0, // px\r
110                 scrollXRatio    : 0, // この値は scroll 不要になっても保持される。 scroll 必要時に参照される\r
111                 scrollYRatio    : 0,            \r
112                 startX          : 0, // px\r
113                 startY          : 0, // px\r
114                 absStartX       : 0, // px\r
115                 absStartY       : 0, // px\r
116                 pointX          : 0, // px\r
117                 pointY          : 0, // px\r
118                 distX               : 0, // px\r
119                 distY               : 0, // px\r
120                 directionX      : 0, // -1, 0, 1\r
121                 directionY      : 0, // -1, 0, 1\r
122                 \r
123                 lastScrollWidth  : 0,\r
124                 lastScrollHeight : 0,\r
125                 lastBoxWidth     : 0,\r
126                 lastBoxHeight    : 0,\r
127                 \r
128                 _containerNode   : null,\r
129                 xnodeSlider      : null,\r
130                 \r
131                 Constructor : function( user, layout, args ){\r
132                         this[ 'Super' ]( user, layout, args );\r
133                         this._containerNode = X_Pair_get( this.containerNode );\r
134                         this.xnodeSlider = this._containerNode.xnode[ 'className' ]( 'ScrollSlider' )[ 'listen' ]( X_EVENT_ANIME_END, this, X_UI_ScrollBox_onAnimeEnd );\r
135                         this.xnode[ 'className' ]( 'ScrollBox' );\r
136                 },\r
137                 \r
138                 creationComplete : function(){\r
139                         XUI_Box.prototype.creationComplete.apply( this, arguments );\r
140                 },\r
141                 \r
142                 calculate : function(){\r
143                         this.lastScrollWidth  = this._containerNode.boxWidth;\r
144                         this.lastScrollHeight = this._containerNode.boxHeight;\r
145                         this.lastBoxWidth     = this.boxWidth;\r
146                         this.lastBoxHeight    = this.boxHeight;\r
147                         \r
148                         XUI_Box.prototype.calculate.apply( this, arguments );\r
149                         \r
150                         // TODO root の layout_complete 後に。\r
151                         // TODO calculate 前に scroll の解放。\r
152                         \r
153                         if(\r
154                                         this.lastScrollWidth  !== this._containerNode.boxWidth ||\r
155                                         this.lastScrollHeight !== this._containerNode.boxHeight ||\r
156                                         this.lastBoxWidth    !== this.boxWidth    || this.lastBoxHeight    !== this.boxHeight\r
157                                 ){\r
158                                         console.log( 'scroll - calc' );\r
159                                         XUI_rootData[ 'listenOnce' ]( XUI_Event.LAYOUT_COMPLETE, this, X_UI_ScrollBox_onLayoutComplete );\r
160                                 };\r
161                 },\r
162         \r
163                 scrollTo : function( x, y, opt_time, opt_easing, opt_release ){\r
164                         //if( this.scrollX === x && this.scrollY === y ) return;\r
165                         \r
166                         opt_time    = 0 <= opt_time ? opt_time : 0;\r
167                         opt_easing  = opt_easing || 'circular';\r
168                         opt_release = 0 <= opt_release ? opt_release : 300;\r
169         \r
170                         this.isInTransition = 0 < opt_time;\r
171         \r
172                         X_UI_ScrollBox_translate( this, x, y, opt_time, opt_easing, opt_release );\r
173                 },\r
174                 \r
175                 _remove : function(){\r
176                         XUI_AbstractUINode.prototype._remove.apply( this, arguments );\r
177                         \r
178                         if( this.scrolling ){\r
179                                 // scroller 削除\r
180                                 this[ 'unlisten' ]( XUI_Event._POINTER_DOWN, X_UI_ScrollBox_onStart )\r
181                                         [ 'unlisten' ]( XUI_Event.DRAG, X_UI_ScrollBox_onMove )\r
182                                         [ 'unlisten' ]( XUI_Event.DRAG_END, X_UI_ScrollBox_onEnd );\r
183                                 XUI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );\r
184                                 \r
185                                 XUI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_COMPLETE, this, X_UI_ScrollBox_onLayoutComplete );\r
186                                 this[ 'unlisten' ]( XUI_Event.SCROLL_END, XUI_rootData, XUI_rootData.calculate );\r
187                                 \r
188                                 this.xnodeSlider[ 'stop' ]();\r
189                         };\r
190                 }\r
191                 \r
192         }\r
193 );\r
194 \r
195 function X_UI_ScrollBox_onLayoutBefore( e ){\r
196         if( e[ 'cancelable' ] && this.isInTransition && X_Node_Anime_translateZ ){\r
197                 this[ 'listenOnce' ]( XUI_Event.SCROLL_END, XUI_rootData, XUI_rootData.calculate );\r
198                 return X_CALLBACK_PREVENT_DEFAULT;\r
199         };\r
200         this.scrollXRatio = this.scrollX / this.scrollXMax;\r
201         this.scrollYRatio = this.scrollY / this.scrollYMax;\r
202         this.xnodeSlider[ 'stop' ]();\r
203         this.isInTransition = false;\r
204         return X_CALLBACK_NONE;\r
205 };\r
206 \r
207 function X_UI_ScrollBox_onLayoutComplete( e ){\r
208         // scroll の停止、GPU の解除\r
209         var font = this.fontSize = this.xnodeSlider[ 'call' ]( 'fontSize' );\r
210 \r
211         this.scrollXMax = ( this.boxWidth  - this._containerNode.boxWidth )  * font | 0;\r
212         this.scrollYMax = ( this.boxHeight - this._containerNode.boxHeight ) * font | 0;\r
213 \r
214         this.hasHScroll = this.scrollXEnabled && ( this.scrollXMax < -1 ); // < 0 だと \r
215         this.hasVScroll = this.scrollYEnabled && ( this.scrollYMax < -1 );\r
216 \r
217         if( !this.hasHScroll ){\r
218                 this.scrollXMax  = 0;\r
219         };\r
220 \r
221         if( !this.hasVScroll ){\r
222                 this.scrollYMax   = 0;\r
223         };\r
224 \r
225         delete this.endTime;\r
226         delete this.directionX;\r
227         delete this.directionY;\r
228 \r
229         X_UI_ScrollBox_resetPosition( this, 0 );\r
230 \r
231         if( this.hasHScroll || this.hasVScroll ){\r
232                 // scroll が必要。\r
233                 if( this.scrolling ){\r
234                         X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 100, '', 300 );\r
235                 } else {\r
236                         // scroller 作る\r
237                         this[ 'listen' ]( XUI_Event._POINTER_DOWN, X_UI_ScrollBox_onStart )\r
238                                 [ 'listen' ]( XUI_Event.DRAG, X_UI_ScrollBox_onMove )\r
239                                 [ 'listen' ]( XUI_Event.DRAG_END, X_UI_ScrollBox_onEnd );\r
240                         XUI_rootData[ 'listen' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );\r
241                         \r
242                         X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 100, '', 300 );\r
243                         this.scrolling = true;\r
244                 };\r
245         } else\r
246         // scroll 不要\r
247         if( this.scrolling ){\r
248                 // scroller 削除\r
249                 this[ 'unlisten' ]( XUI_Event._POINTER_DOWN, X_UI_ScrollBox_onStart )\r
250                         [ 'unlisten' ]( XUI_Event.DRAG, X_UI_ScrollBox_onMove )\r
251                         [ 'unlisten' ]( XUI_Event.DRAG_END, X_UI_ScrollBox_onEnd );\r
252                 XUI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );\r
253                 \r
254                 ( this.scrollX !== 0 || this.scrollY !== 0 ) && X_UI_ScrollBox_translate( this, 0, 0, 100, '', 300 );\r
255                 \r
256                 delete this.scrolling;\r
257                 delete this.scrollXRatio;\r
258                 delete this.scrollYRatio;\r
259         };\r
260 };\r
261 \r
262 // TODO use scrollLeft, scrollTop\r
263 function X_UI_ScrollBox_translate( that, x, y, opt_time, opt_easing, opt_release ){\r
264         var scrollBoxH = that.fontSize * that.boxHeight,\r
265                 scrollBoxW = that.fontSize * that.boxWidth,\r
266                 indicatorH, indicatorW;\r
267         \r
268         opt_time    = 0 <= opt_time ? opt_time : 0;\r
269         opt_easing  = opt_easing === '' ? '' : opt_easing || 'circular';\r
270         opt_release = 0 <= opt_release ? opt_release : 300;\r
271         \r
272         that.xnodeSlider[ 'animate' ](\r
273                 {\r
274                         x : that.scrollX,\r
275                         y : that.scrollY\r
276                 },\r
277                 {\r
278                         x : x,\r
279                         y : y\r
280                 },\r
281                 opt_time, opt_easing, opt_release\r
282         );\r
283 \r
284         if( X_UA[ 'IE' ] < 6 ){\r
285                 XUI_ScrollBox_indicatorV && XUI_ScrollBox_indicatorV[ 'css' ]( 'left', ( scrollBoxW - that.fontSize * 0.6 | 0 ) + 'px' );\r
286                 XUI_ScrollBox_indicatorH && XUI_ScrollBox_indicatorH[ 'css' ]( 'top' , ( scrollBoxH - that.fontSize * 0.6 | 0 ) + 'px' );\r
287         };\r
288 \r
289         if( that.hasVScroll && XUI_ScrollBox_indicatorV ){\r
290                 indicatorH = scrollBoxH * scrollBoxH / ( - that.scrollYMax + scrollBoxH );\r
291                 scrollBoxH -= indicatorH;\r
292 \r
293                 XUI_ScrollBox_indicatorV\r
294                         [ 'css' ]({\r
295                                 height : ( indicatorH | 0 ) + 'px'\r
296                         })\r
297                         [ 'animate' ](\r
298                         {\r
299                                 y : scrollBoxH * that.scrollY / that.scrollYMax\r
300                         },\r
301                         {\r
302                                 y : scrollBoxH * y / that.scrollYMax,\r
303                                 opacity : 1\r
304                         },\r
305                         opt_time, opt_easing, opt_release\r
306                 );\r
307         };\r
308         if( that.hasHScroll && XUI_ScrollBox_indicatorH ){\r
309                 indicatorW = scrollBoxW * scrollBoxW / ( - that.scrollXMax + scrollBoxW );\r
310                 scrollBoxW -= indicatorW;\r
311                 XUI_ScrollBox_indicatorH\r
312                         [ 'css' ]({\r
313                                 width : ( indicatorW | 0 ) + 'px'\r
314                         })\r
315                         [ 'animate' ](\r
316                         {\r
317                                 x : scrollBoxW * that.scrollX / that.scrollXMax\r
318                         },\r
319                         {\r
320                                 x : scrollBoxW * x / that.scrollXMax,\r
321                                 opacity : 1\r
322                         },\r
323                         opt_time, opt_easing, opt_release\r
324                 );\r
325         };\r
326         \r
327         that.scrollX   = x;\r
328         that.scrollXEm = x / that.fontSize;\r
329         that.scrollY   = y;\r
330         that.scrollYEm = y / that.fontSize;\r
331 };\r
332 \r
333 function X_UI_ScrollBox_onStart( e ){\r
334         var ret = X_CALLBACK_NONE;\r
335         \r
336         if( !this.scrollEnabled || ( this.initiated && e.pointerType !== this.initiated ) ){\r
337                 return ret;\r
338         };\r
339 \r
340         this.initiated       = e.pointerType;\r
341         this.moved                   = false;\r
342         this.distX                   = 0;\r
343         this.distY                   = 0;\r
344         this.directionX      = 0;\r
345         this.directionY      = 0;\r
346         this.directionLocked = '';\r
347         this.startTime       = X_Timer_now();\r
348 \r
349         // スクロール中の停止\r
350         if( this.isInTransition ){\r
351                 this.isInTransition = false;\r
352                 //console.log( '-1-' );\r
353                 this[ 'dispatch' ]( XUI_Event.SCROLL_END );\r
354                 // TODO current位置\r
355                 this.xnodeSlider[ 'stop' ]();\r
356         };                      \r
357 \r
358         this.startX    = this.scrollX;\r
359         this.startY    = this.scrollY;\r
360         this.absStartX = this.scrollX;\r
361         this.absStartY = this.scrollY;\r
362         this.pointX    = e.pageX;\r
363         this.pointY    = e.pageY;\r
364         \r
365         console.log( 'scrollstart ' + e.pageY + e.target.className() );\r
366 \r
367         return ret | X_CALLBACK_PREVENT_DEFAULT;\r
368 };\r
369 \r
370 function X_UI_ScrollBox_onMove( e ){\r
371         var ret = X_CALLBACK_NONE,\r
372                 deltaX, deltaY, timestamp,\r
373                 newX, newY,\r
374                 absDistX, absDistY;\r
375         // 規定以上の move でスクロール開始\r
376 \r
377 //console.log( 'scrollmove ' + e.buttons + ' ' + e.button );\r
378 \r
379         if( !this.scrollEnabled || e.pointerType !== this.initiated ){\r
380                 return ret;\r
381         };\r
382 \r
383         // gpu の用意\r
384         if( !this.xnodeSlider[ '_anime' ] ){\r
385                 //console.log( 'gpuレイヤーの用意 ' + e.pageY );\r
386                 //console.log( 'mov1 x:' + this.scrollX + ' y:' + this.scrollY );\r
387                 X_UI_ScrollBox_translate( this, this.scrollX, this.scrollY, 0, '', 300 );\r
388                 return ret;\r
389         };\r
390 \r
391         deltaX          = e.pageX - this.pointX;\r
392         deltaY          = e.pageY - this.pointY;\r
393         timestamp       = X_Timer_now();\r
394 \r
395         this.pointX     = e.pageX;\r
396         this.pointY     = e.pageY;\r
397 \r
398         this.distX      += deltaX;\r
399         this.distY      += deltaY;\r
400         absDistX        = Math.abs(this.distX);\r
401         absDistY        = Math.abs(this.distY);\r
402         \r
403         // We need to move at least 10 pixels for the scrolling to initiate\r
404         if( 300 < timestamp - this.endTime && ( absDistX < 10 && absDistY < 10 ) ){\r
405                 return ret;\r
406         };\r
407 \r
408         // If you are scrolling in one direction lock the other\r
409         if( !this.directionLocked ){\r
410                 if( absDistX > absDistY + this.directionLockThreshold ){\r
411                         this.directionLocked = 'h';             // lock horizontally\r
412                 } else\r
413                 if( absDistY >= absDistX + this.directionLockThreshold ){\r
414                         this.directionLocked = 'v';             // lock vertically\r
415                 } else {\r
416                         this.directionLocked = 'n';             // no lock\r
417                 };\r
418         };\r
419 \r
420         if( this.directionLocked === 'h' ){\r
421                 deltaY = 0;\r
422         } else\r
423         if( this.directionLocked === 'v' ){\r
424                 deltaX = 0;\r
425         };\r
426 \r
427         deltaX = this.hasHScroll ? deltaX : 0;\r
428         deltaY = this.hasVScroll ? deltaY : 0;\r
429 \r
430         if( !this.moved ){\r
431                 this[ 'dispatch' ]( XUI_Event.SCROLL_BEFORE_MOVE );\r
432                 this.moved  = true;\r
433                 this.minusX = deltaX;\r
434                 this.minusY = deltaY;\r
435                 // indicator\r
436                 XUI_ScrollBox_start( this );\r
437         } else {\r
438                 this[ 'dispatch' ]( XUI_Event.SCROLL_MOVE );\r
439         };\r
440 \r
441         newX = this.scrollX + deltaX;// - this.minusX;\r
442         newY = this.scrollY + deltaY;// - this.minusY;\r
443 \r
444         // Slow down if outside of the boundaries\r
445         if( 0 < newX || newX < this.scrollXMax ){\r
446                 newX = this.bounceEnabled ? this.scrollX + ( deltaX ) / 3 : 0 < newX ? 0 : this.scrollXMax;\r
447         };\r
448         \r
449         if( 0 < newY || newY < this.scrollYMax ){\r
450                 //console.log( 'slow... ' + newY + ' ' + this.scrollYMax );\r
451                 newY = this.bounceEnabled ? this.scrollY + ( deltaY ) / 3 : 0 < newY ? 0 : this.scrollYMax;\r
452         };\r
453 \r
454         this.directionX = 0 < deltaX ? -1 : deltaX < 0 ? 1 : 0;\r
455         this.directionY = 0 < deltaY ? -1 : deltaY < 0 ? 1 : 0;\r
456 \r
457         //console.log( 'mov2 x:' + newX + ' y:' + newY );\r
458         X_UI_ScrollBox_translate( this, newX, newY, 0, '', 300 );\r
459 \r
460         if( 300 < timestamp - this.startTime ){\r
461                 this.startTime = timestamp;\r
462                 this.startX = this.scrollX;\r
463                 this.startY = this.scrollY;\r
464         };\r
465         // イベントの拘束\r
466         return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_CAPTURE_POINTER;\r
467 };\r
468 \r
469 function X_UI_ScrollBox_onEnd( e ){\r
470         var ret    = X_CALLBACK_NONE,\r
471                 time   = 0,\r
472                 easing = '',\r
473                 newX, newY,\r
474                 momentumX, momentumY,\r
475                 duration, distanceX, distanceY;\r
476         \r
477         //console.log( e.type + ' onend ' + XUI_Event.POINTER_OUT  );\r
478         \r
479         if( !this.scrollEnabled || e.pointerType !== this.initiated ){\r
480                 //console.log( e.type + ' onend 1 ' + e.pointerType + ' ' + this.initiated  );\r
481                 return ret;\r
482         };\r
483 \r
484         delete this.isInTransition;\r
485         delete this.initiated;\r
486         this.endTime = X_Timer_now();                   \r
487 \r
488         duration  = this.endTime - this.startTime;\r
489         newX      = Math.round( this.scrollX );\r
490         newY      = Math.round( this.scrollY );\r
491         distanceX = Math.abs(newX - this.startX);\r
492         distanceY = Math.abs(newY - this.startY);\r
493 \r
494         // reset if we are outside of the boundaries\r
495         if( X_UI_ScrollBox_resetPosition( this, this.bounceTime ) ){\r
496                 //console.log( e.type + ' onend 2 ' + XUI_Event.POINTER_OUT  );\r
497                 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;\r
498         };\r
499 \r
500         // we scrolled less than 10 pixels\r
501         if( !this.moved ){\r
502                 this[ 'dispatch' ]( X_EVENT_CANCELED );\r
503                 //console.log( 'we scrolled less than 10 pixels ' + e.pageY );\r
504                 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;\r
505         };\r
506 \r
507         // start momentum animation if needed\r
508         if( this.momentumEnabled && duration < 300 ){\r
509                 momentumX = this.hasHScroll ?\r
510                                                 X_UI_ScrollBox_momentum( this.scrollX, this.startX, duration, this.scrollXMax, this.bounceEnabled ? this.boxWidth  * this.fontSize : 0, this.deceleration ) :\r
511                                                 { destination: newX, duration: 0 };\r
512                 momentumY = this.hasVScroll   ?\r
513                                                 X_UI_ScrollBox_momentum( this.scrollY, this.startY, duration, this.scrollYMax, this.bounceEnabled ? this.boxHeight * this.fontSize : 0, this.deceleration ) :\r
514                                                 { destination: newY, duration: 0 };\r
515                 newX = momentumX.destination;\r
516                 newY = momentumY.destination;\r
517                 time = Math.max( momentumX.duration, momentumY.duration ) | 0;\r
518                 this.isInTransition = true;\r
519         } else {\r
520                 //console.log( '慣性無し' );\r
521         };\r
522 \r
523         if( newX != this.scrollX || newY != this.scrollY ){\r
524                 // change easing function when scroller goes out of the boundaries\r
525                 if( 0 < newX || newX < this.scrollXMax || 0 < newY || newY < this.scrollYMax ){\r
526                         easing = 'quadratic';\r
527                 };\r
528 \r
529                 //console.log( 'end2 x:' + newX + ' y:' + newY + '<-y:' + this.scrollY + ' t:' + time );\r
530                 this.scrollTo( newX, newY, time, easing, 1000 );\r
531         } else {\r
532                 //console.log( 'end1 x:' + newX + ' y:' + newY );\r
533                 this.scrollTo( newX, newY, 0, '', 1000 );       // ensures that the last position is rounded\r
534                 //console.log( '-3-' );\r
535                 this[ 'dispatch' ]( XUI_Event.SCROLL_END );             \r
536         };\r
537 \r
538         return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;\r
539 };\r
540 \r
541 function X_UI_ScrollBox_resetPosition( that, time ){\r
542         var x = that.scrollX,\r
543                 y = that.scrollY;\r
544 \r
545         time = time || 0;\r
546 \r
547         if( !that.hasHScroll || 0 < that.scrollX ){\r
548                 x = 0;\r
549         } else\r
550         if( that.scrollX < that.scrollXMax ){\r
551                 x = that.scrollXMax;\r
552         };\r
553 \r
554         if( !that.hasVScroll || 0 < that.scrollY ){\r
555                 y = 0;\r
556         } else\r
557         if( that.scrollY < that.scrollYMax ){\r
558                 y = that.scrollYMax;\r
559         };\r
560 \r
561         if( x === that.scrollX && y === that.scrollY ){\r
562                 //console.log( 'no バウンド y:' + y + ' max:' + that.scrollYMax );\r
563                 return false;\r
564         };\r
565 \r
566         //console.log( ' ===> resetPosition - バウンド!' );\r
567         //console.log( '      x:' + x + ' y:' + y );\r
568         that.scrollTo( x, y, time, that.bounceEasing, 1000 );\r
569 \r
570         return true;\r
571 };\r
572 \r
573 function X_UI_ScrollBox_onAnimeEnd( e ){\r
574         if( e.target !== this.xnodeSlider ){\r
575                 console.log( '- not much -' );\r
576                 console.dir(e);\r
577         };\r
578         if( e.target === this.xnodeSlider && this.isInTransition && !X_UI_ScrollBox_resetPosition( this, this.bounceTime ) ){\r
579                 this.isInTransition = false;\r
580                 //console.log( '-2-' );\r
581                 this[ 'dispatch' ]( XUI_Event.SCROLL_END );\r
582         };\r
583         //console.log(' -2.1- '+this.isInTransition );\r
584         return X_CALLBACK_NONE;\r
585 };\r
586 \r
587 function X_UI_ScrollBox_momentum( current, start, time, lowerMargin, wrapperSize, deceleration ){\r
588         var distance = current - start,\r
589                 speed    = Math.abs( distance ) / time,\r
590                 destination,\r
591                 duration;\r
592 \r
593         deceleration = deceleration === undefined ? 0.0006 : deceleration;\r
594 \r
595         destination  = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 );\r
596         duration     = speed / deceleration;\r
597 \r
598         if( destination < lowerMargin ){\r
599                 destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin;\r
600                 distance    = Math.abs( destination - current );\r
601                 duration    = distance / speed;\r
602         } else\r
603         if ( destination > 0 ) {\r
604                 destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0;\r
605                 distance    = Math.abs( current ) + destination;\r
606                 duration    = distance / speed;\r
607         };\r
608 \r
609         return {\r
610                 destination : Math.round( destination ),\r
611                 duration    : duration\r
612         };\r
613 };\r
614 \r
615 X.UI.ScrollBox = X.UI.ChromeBox.inherits(\r
616         'ScrollBox',\r
617         X_Class.NONE,\r
618         {\r
619                 Constructor : function(){\r
620                         var supports, slider;\r
621                         \r
622                         if( XUI_ScrollBox.prototype.usableAttrs === XUI_ChromeBox.prototype.usableAttrs ){\r
623                                 XUI_ScrollBox.prototype.usableAttrs = supports = XUI_Attr_createAttrDef( XUI_Attr_Support, X_UI_ScrollBox_SUPPORT_ATTRS );\r
624                 \r
625                                 XUI_ScrollBox.prototype.attrClass   = XUI_Attr_preset( XUI_Box.prototype.attrClass, supports, { width  : '100%', height : '100%', bgColor : 0x111111 } );\r
626                         };\r
627                         \r
628                         var args = [\r
629                                                 XUI_Layout_Vertical,                    \r
630                                                 {\r
631                                                         name      : 'ScrollBox-Scroller',\r
632                                                         role      : 'container',\r
633                                                         width     : 'auto',\r
634                                                         minWidth  : '100%',\r
635                                                         height    : 'auto',\r
636                                                         minHeight : '100%'\r
637                                                 }\r
638                                         ],\r
639                                 l    = arguments.length, i = 0, j = 1,\r
640                                 arg, attr;\r
641                         \r
642                         for( ; i < l; ++i ){\r
643                                 arg = arguments[ i ];\r
644                                 if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( XUI_LayoutBase ) ){\r
645                                         args[ 0 ] = arg;\r
646                                 } else\r
647                                 if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( X.UI.AbstractUINode ) ){\r
648                                         args[ ++j ] = arg;\r
649                                 } else\r
650                                 if( X_Type_isObject( arg ) ){\r
651                                         args[ ++j ] = attr = arg;\r
652                                         slider = attr.scrollSlider;\r
653                                 };\r
654                         };\r
655                         \r
656                         X_Pair_create(\r
657                                 this,\r
658                                 XUI_ScrollBox(\r
659                                         this,\r
660                                         null,\r
661                                         [\r
662                                                 slider || X.UI.VBox.apply( 0, args )\r
663                                         ]\r
664                                 )\r
665                         );\r
666                         \r
667                         //attr && this.attr( attr );\r
668                 },\r
669                 scrollX  : function(){\r
670                         \r
671                 },\r
672                 scrollY  : function(){\r
673                         \r
674                 },\r
675                 scrollWidth : function(){\r
676                         \r
677                 },\r
678                 scrollHeight : function(){\r
679                         \r
680                 },\r
681                 scrollTo : function( nodeOrX, y ){\r
682                         \r
683                 }\r
684         }\r
685 );\r
686 \r