OSDN Git Service

a73c3e6467fb97dfa5a9dfa8cbacbe6be79fc270
[pettanr/clientJs.git] / 0.6.x / js / 20_ui / 20_PageRoot.js
1 var X_UI_rootData  = null,
2         X_UI_eventBusy = false;
3
4 function X_UI_eventRellay( e ){
5         var font    = X_ViewPort_baseFontSize,
6                 x       = e.clientX / font,
7                 y       = e.clientY / font,
8                 type    = XUI_Event.NameToID[ e.type ],
9                 i       = 0,
10                 data    = X_UI_rootData,
11                 sysOnly = false,
12                 ret     = X_Callback_NONE,
13                 list, parent, _ret;
14
15         // mouseup で alert を出すと mouseleave が発生、ということでイベント中のイベント発火を禁止
16         if( !data || X_UI_eventBusy ) return ret;
17         data._eventBusy = true;
18         
19         if( type !== '' + XUI_Event._POINTER_MOVE ){
20                 //console.log( e.type + ' ' + type + ' x:' + x + ', y:' + y );
21         };
22         
23         e.type = type;
24
25         if( data && ( data = data.monopolyNodeData ) && ( ret = data[ 'dispatch' ]( e ) ) & X_Callback_CAPTURE_POINTER ){
26                 X_UI_eventBusy = false;
27                 return ret | X_Callback_PREVENT_DEFAULT;
28         };
29         
30         list = X_UI_rootData.hoverList;
31         ( X_UI_rootData.targetNodeData = X_UI_rootData ).capcher( x, y );
32         data = X_UI_rootData.targetNodeData;
33
34         //data !== X_UI_rootData && console.log( data.xnode[ 'text' ]() );
35
36         while( data ){
37                 _ret = data[ 'dispatch' ]( e, sysOnly );
38                 ret |= _ret;
39                 if( _ret & X_Callback_CAPTURE_POINTER || _ret & X_Callback_STOP_PROPAGATION || _ret & X_Callback_STOP_NOW ) break; // sysOnly = true;
40                 data = data.parentData;
41         };
42         
43         for( i = list.length; i; ){
44                 parent = data = list[ --i ];
45                 while( parent.parentData && parent === parent.parentData.hitChildData ){
46                         parent = parent.parentData;
47                 };
48                 if( parent !== X_UI_rootData ){
49                         data.hoverClassName && data.xnode[ 'removeClass' ]( data.hoverClassName );
50                         data[ '_listeners' ] && data[ '_listeners' ][ XUI_Event.POINTER_OUT ] && data[ 'dispatch' ]( e, XUI_Event.POINTER_OUT, false ); // new Event
51                         delete data.hovering;
52                         list.splice( i, 1 );
53                         continue;
54                 };
55                 if( !data.hovering ){
56                         data.hoverClassName && data.xnode.addClassName( data.hoverClassName );
57                         data[ '_listeners' ] && data[ '_listeners' ][ XUI_Event.POINTER_IN ] && data[ 'dispatch' ]( e, XUI_Event.POINTER_IN, true ); // new Event
58                         data.hovering = true;
59                 };
60         };
61         X_UI_eventBusy = false;
62         return ret | X_Callback_PREVENT_DEFAULT;
63 };
64
65 /*
66  * body が存在したら要素を作成、css も指定
67  * 背景画像を読み終える onload で活動開始
68  */
69
70 var XUI_PageRoot = XUI_Box.inherits(
71         '_PageRoot',
72         X_Class.FINAL | X_Class.PRIVATE_DATA,
73         {
74                 layout                : XUI_Layout_Canvas,
75                 
76                 calcReserved          : false,
77                 hoverList             : null,
78                 targetNodeData        : null,
79                 monopolyNodeData      : null,
80                 
81                 xnodeInteractiveLayer : null,
82                 eventCounter          : null,
83                 cursorStyle           : null,
84                 
85                 Constructor : function( layout, args ){
86                         this[ 'Super' ]( layout, args );
87                         
88                         if( X_ViewPort_readyState === X_EVENT_XDOM_READY ){
89                                 X_Timer_once( 0, this, this.start );
90                         } else {
91                                 X.ViewPort[ 'listenOnce' ]( X_EVENT_XDOM_READY, this, this.start );
92                         };
93                         
94                         this.hoverList    = [];
95                         this.eventCounter = {};
96                         
97                         X_UI_rootData = this;
98                 },
99                 
100                 start : function(){
101                         this.initialize( this.User, this, null, null );
102                         X_Timer_once( 0, this, this.addToView );
103                 },
104                 addToView : function(){
105                         var     counter = this.eventCounter, flg;
106                         
107                         // this.xnodeInteractiveLayer の前に追加する!
108
109                         this.addToParent( X.Doc.body );
110                         
111                         this.xnodeInteractiveLayer = X.Doc.body.create( 'div', {
112                                 'class'      : 'mouse-operation-catcher',
113                                 unselectable : 'on'
114                         } );
115                         
116                         // hover や rollover rollout のための move イベントの追加
117                         ( X_UA[ 'IE' ] < 9 ? X_ViewPort_document : X_UA[ 'Opera' ] < 8 ? X_Node_body : X_ViewPort )[ 'listen' ]( 'pointermove', X_UI_eventRellay );
118                         if( counter[ XUI_Event._POINTER_MOVE ] ){
119                                 ++counter[ XUI_Event._POINTER_MOVE ];
120                         } else {
121                                 counter[ XUI_Event._POINTER_MOVE ] = 1;
122                         };
123
124                         X_Timer_once( 0, this, this.afterAddToView );
125                 },
126                 afterAddToView : function(){
127                         this.xnode[ 'className' ]( 'PageRoot' );
128                         
129                         this.creationComplete();
130                         X_Timer_once( 0, this, XUI_PageRoot_do1stCalculate );
131                 },
132                 
133                 reserveCalc : function(){
134                         if( this.calcReserved === false ){
135                                 this.calcReserved = true;
136                                 X_Timer_once( 0, this, this.calculate );
137                         };
138                 },
139                 calculate : function( e ){
140                         var cancelable = !e || ( e.type !== X_EVENT_VIEW_RESIZED && e.type !== X_EVENT_BASE_FONT_RESIZED ),
141                                 size, font, w, h;
142                         
143                         if( this[ 'dispatch' ]( { type : XUI_Event.LAYOUT_BEFORE, 'cancelable' : cancelable } ) & X_Callback_PREVENT_DEFAULT && cancelable ){
144                                 return X_Callback_NONE;
145                         };
146                         
147                         size = X[ 'ViewPort' ][ 'getSize' ]();
148                         font = X[ 'ViewPort' ][ 'getBaseFontSize' ]();
149                         this.layout.calculate( this, false, 0, 0, size[ 0 ] / font, size[ 1 ] / font );
150                         this.updateLayout();
151                         
152                         this.calcReserved = false;
153                         
154                         X_ViewPort[ 'listenOnce' ]( X_EVENT_AFTER_UPDATE, this, XUI_PageRoot_onViewUpdate );
155                         
156                         return X_Callback_NONE;
157                 },
158                 
159                 updateCoursor : function( cursor ){
160                         
161                 },
162                 
163                 _remove : function(){
164                         X_EventDispatcher_unlistenAll( this.xnodeInteractiveLayer );
165                         _Box.prototype._remove.call( this );
166                 }
167         }
168 );
169
170 function XUI_PageRoot_do1stCalculate(){
171         this.calculate();
172         this.phase = 4;
173         X.ViewPort
174                 [ 'listen' ]( X_EVENT_VIEW_RESIZED, this, this.calculate )
175                 [ 'listen' ]( X_EVENT_BASE_FONT_RESIZED, this, this.calculate );
176 };
177
178 function XUI_PageRoot_onViewUpdate( e ){
179         this[ 'dispatch' ]( XUI_Event.LAYOUT_COMPLETE );
180 };
181
182 X.UI.PageRoot = X.UI.Box.presets(
183         'PageRoot',
184         XUI_PageRoot,
185         {
186                 width  : '100%',
187                 height : '100%'
188         }
189 );
190