OSDN Git Service

4ca1595f00fc5f03449471f5b8766e375192a076
[pettanr/clientJs.git] / 0.6.x / js / 20_ui / 06_AbstractUINode.js
1 // TODO -> Node[ 'inherits' ]\r
2 var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ](\r
3         'X.UI._AbstractUINode',\r
4         X_Class.ABSTRACT,\r
5         {\r
6                 phase             : 0,\r
7                 dirty             : XUI_Dirty.CLEAN,\r
8                 \r
9                 root              : null,\r
10                 rootData          : null,\r
11                 hoverList         : null,\r
12                 parent            : null,\r
13                 parentData        : null,\r
14                 xnode             : null,\r
15 \r
16                 usableAttrs       : XUI_Attr_Support,\r
17                 attrClass         : XUI_AttrClass,\r
18                 attrObject        : null,\r
19                 unverifiedAttrs   : null,\r
20                 \r
21                 role              : 1,\r
22                 pointerDisabled   : false,\r
23                 hoverClassName    : null,\r
24                 hovering          : false,\r
25                 \r
26                 reserveEvents     : null,\r
27                 gesture           : null,\r
28 \r
29                 absoluteX         : 0,\r
30                 absoluteY         : 0,\r
31                 \r
32                 boxX              : 0,\r
33                 boxY              : 0,\r
34                 boxWidth          : XUI_Attr_AUTO,\r
35                 boxWidthMin       : 0,\r
36                 boxWidthMax       : XUI_Attr_AUTO,      \r
37                 boxHeight         : XUI_Attr_AUTO,\r
38                 boxHeightMin      : 0,\r
39                 boxHeightMax      : XUI_Attr_AUTO,\r
40                 contentL          : 0,\r
41                 contentT          : 0,\r
42                 contentR          : 0,\r
43                 contentB          : 0,\r
44                 paddingL          : 0,\r
45                 paddingT          : 0,\r
46                 borderL           : 0,\r
47                 borderT           : 0,\r
48                 boxSizingOffsetLR : 0,\r
49                 boxSizingOffsetTB : 0,          \r
50                 contentWidth      : XUI_Attr_AUTO,\r
51                 contentWidthMin   : 0,\r
52                 contentWidthMax   : XUI_Attr_AUTO,\r
53                 contentWidthLast  : -1,\r
54                 contentHeight     : XUI_Attr_AUTO,\r
55                 contentHeightMin  : 0,\r
56                 contentHeightMax  : XUI_Attr_AUTO,\r
57                 contentHeightLast : -1,\r
58                 \r
59                 constraintW       : false,\r
60                 constraintH       : false,\r
61                 autoWidth         : false,\r
62                 autoHeight        : false,\r
63                 noWidth           : false,\r
64                 noHeight          : false,\r
65                 percentWidth      : false,\r
66                 percentHeight     : false,\r
67                 // :hover, :focus, :disabled\r
68                 \r
69                 initialize : function( root, rootData, parent, parentData ){\r
70                         this.root       = root;\r
71                         this.rootData   = rootData;\r
72                         this.parent     = parent;\r
73                         this.parentData = parentData;\r
74                         this.phase      = 1;\r
75                         \r
76                         this[ 'dispatch' ]( XUI_Event.INIT );\r
77                 },\r
78                 \r
79                 addToParent : function( xnodeParent ){\r
80                         xnodeParent && xnodeParent[ 'append' ]( this.xnode );\r
81                         \r
82                         this.phase = 2;\r
83                         this[ 'dispatch' ]( XUI_Event.ADDED );\r
84                 },\r
85                 \r
86                 creationComplete : function(){\r
87                         var events = this.reserveEvents,\r
88                                 l, i;\r
89                         \r
90                         this.phase = 3;\r
91                         this.User[ 'dispatch' ]( XUI_Event.CREATION_COMPLETE );\r
92                         \r
93                         // html 要素が親に追加されるまで控えていたイベントの登録\r
94                         if( events && ( l = events.length ) ){\r
95                                 for( i = 0; i < l; ++i ){\r
96                                         this.listen.apply( this, events[ i ] );\r
97                                 };\r
98                                 events.length = 0;\r
99                                 delete this.reserveEvents;\r
100                         };                      \r
101                 },\r
102                 \r
103                 /*\r
104                  * _UINode への setAttr の他、attrClass.prototype への setAttr にも対応する\r
105                  * 親要素が変化した場合、unverifiedAttrs を元に attrObject を再設定.\r
106                  */\r
107                 setAttr : function( name, def, v ){\r
108                         var attrs      = XUI_attrClassProto || this.attrObject,\r
109                                 propID     = def.No || def[ 5 ],\r
110                                 defaultVal = XUI_attrClassProto ? attrs[ propID ] : this.attrClass.prototype[ propID ], // def[ 0 ],\r
111                                 currentVal = attrs ? attrs[ propID ] : defaultVal,\r
112                                 dirty      = def[ 1 ],\r
113                                 user       = def[ 2 ],\r
114                                 type       = def[ 3 ],\r
115                                 list       = def[ 4 ],\r
116                                 length     = !!( type & XUI_Attr_Type.LENGTH        ),\r
117                                 minusLen   = !!( type & XUI_Attr_Type.MINUS_LENGTH  ),\r
118                                 percent    = !!( type & XUI_Attr_Type.PERCENT       ),\r
119                                 minusPct   = !!( type & XUI_Attr_Type.MINUS_PERCENT ),\r
120                                 numerical  = !!( type & XUI_Attr_Type.NUMERICAL     ),\r
121                                 auto       = !!( type & XUI_Attr_Type.AUTO          ),\r
122                                 color      = !!( type & XUI_Attr_Type.COLOR         ),\r
123                                 url        = !!( type & XUI_Attr_Type.URL           ),\r
124                                 fontName   = !!( type & XUI_Attr_Type.FONT_NAME     ),\r
125                                 flag       = !!( type & XUI_Attr_Type.BOOLEAN       ),\r
126                                 combi      = !!( type & XUI_Attr_Type.COMBI         ),\r
127                                 quartet    = !!( type & XUI_Attr_Type.QUARTET       ),\r
128                                 _v, i, l, nodes, root, roots;\r
129                 \r
130                         if( X_Type_isString( v ) ){\r
131                                 //v = v.toLowercase();\r
132                                 if( url || fontName ){\r
133                                         // good\r
134                                 } else\r
135                                 if( auto && v === 'auto' ){\r
136                                         v = XUI_Attr_AUTO;\r
137                                 } else\r
138                                 if( list && ( _v = list[ v ] ) ){\r
139                                         // good\r
140                                         console.log( v + ' ' + _v );\r
141                                         v = _v;\r
142                                 } else\r
143                                 if( ( percent || minusPct ) && v.lastIndexOf( '%' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + '%' ){\r
144                                         // good\r
145                                 } else\r
146                                 if( ( length || minusLen ) && v.lastIndexOf( 'em' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + 'em' ){\r
147                                         v = _v;\r
148                                 } else                          \r
149                                 if( v.indexOf( ' ' ) !== -1 ){\r
150                                         v = v.split( ' ' );\r
151                                 } else\r
152                                 if( color && X_Type_isNumber( _v = X_Node_CSS_objToIEFilterText( v ) ) ){\r
153                                         v = _v;\r
154                                 } else {\r
155                                         // bad\r
156                                         return;\r
157                                 };\r
158                         };\r
159                         \r
160                         if( ( quartet || combi ) && !X_Type_isArray( v ) ){\r
161                                 v = [ v ];\r
162                         };\r
163                         \r
164                         if( X_Type_isNumber( v ) ){\r
165                                 if( \r
166                                     ( length    && ( 0 <= v ) ) ||\r
167                                     ( minusLen  && ( v <= 0 ) ) ||\r
168                                     ( percent   && 0 <= v && v <= 1 ) ||\r
169                                         ( minusPct  && -1 <= v && v < 0 ) ||\r
170                                     ( numerical && 0 <= v ) ||\r
171                                     ( auto      && v === XUI_Attr_AUTO ) ||\r
172                                     ( color     && 0 <= v && v <= 0xFFFFFF ) ||\r
173                                     ( list      && list[ v ] )\r
174                                 ){\r
175                                         // good\r
176                                 } else {\r
177                                         // bad\r
178                                         return;\r
179                                 };\r
180                         } else\r
181                         if( X_Type_isBoolean( v ) && !flag ){\r
182                                 return;\r
183                         } else\r
184                         if( X_Type_isArray( v ) ){\r
185                                 if( v.length <= 4 && quartet ){\r
186                                         type &= ~XUI_Attr_Type.QUARTET;\r
187                                         switch( v.length ){\r
188                                                 case 1 :\r
189                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list,   propID ], v[ 0 ] );\r
190                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );\r
191                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );\r
192                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );\r
193                                                         break;\r
194                                                 case 2 :\r
195                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list,   propID ], v[ 0 ] );\r
196                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );\r
197                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );\r
198                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );\r
199                                                         break;\r
200                                                 case 3 :\r
201                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list,   propID ], v[ 0 ] );\r
202                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );\r
203                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );\r
204                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );\r
205                                                         break;\r
206                                                 case 4 :\r
207                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list,   propID ], v[ 0 ] );\r
208                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );\r
209                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );\r
210                                                         this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 3 ] );\r
211                                                         break;\r
212                                         };                                      \r
213                                 } else\r
214                                 if( v.length === 2 && combi ){\r
215                                         type &= ~XUI_Attr_Type.COMBI;\r
216                                         this.setAttr( false, [ defaultVal, user, dirty, type, list,   propID ], v[ 0 ] );\r
217                                         this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );\r
218                                 } else {\r
219                                         // bad\r
220                                         return;\r
221                                 };\r
222 \r
223                                 if( !XUI_attrClassProto && user === XUI_Attr_USER.XNODE && this.xnode ){\r
224                                         this.xnode[ 'css' ]( XUI_Attr_Rename[ name ] || name, XUI_AbstractUINode_createCssText( this, name ) );\r
225                                         //console.log( ( XUI_Attr_Rename[ name ] || name ) + ' ' + XUI_AbstractUINode_createCssText( this, name ) + ' ' + propID + ' ' + attrs[ propID ] );\r
226                                 };\r
227                                 return;\r
228                         };\r
229 \r
230                         if( !v && v !== 0 ) v = defaultVal;\r
231                         \r
232                         if( XUI_attrClassProto ){\r
233                                 attrs[ propID ] = v;\r
234                                 return;                 \r
235                         };              \r
236 \r
237                         if( currentVal !== v ){\r
238                                 switch( propID ){\r
239                                         case XUI_Attr_Support.left.No :\r
240                                                 this.constraintW = attrs[ XUI_Attr_Support.right.No ] !== null;\r
241                                                 break;\r
242                                         case XUI_Attr_Support.right.No :\r
243                                                 this.constraintW = attrs[ XUI_Attr_Support.left.No ] !== null;\r
244                                                 break;\r
245                                         case XUI_Attr_Support.top.No :\r
246                                                 this.constraintH = attrs[ XUI_Attr_Support.bottom.No ] !== null;\r
247                                                 break;\r
248                                         case XUI_Attr_Support.bottom.No :\r
249                                                 this.constraintH = attrs[ XUI_Attr_Support.top.No ] !== null;\r
250                                                 break;\r
251                                         case XUI_Attr_Support.width.No :\r
252                                                 this.autoWidth    = v === XUI_Attr_AUTO;\r
253                                                 this.percentWidth = X_Type_isString( v );\r
254                                                 break;\r
255                                         case XUI_Attr_Support.height.No :\r
256                                                 this.autoHeight    = v === XUI_Attr_AUTO;\r
257                                                 this.percentHeight = X_Type_isString( v );\r
258                                                 break;\r
259                                 };\r
260                                 \r
261                                 if( defaultVal === v ){\r
262                                         if( attrs ) delete attrs[ propID ];\r
263                                 } else {\r
264                                         if( !attrs ) attrs = this.attrObject = new this.attrClass;\r
265                                         attrs[ propID ] = v;\r
266                                 };\r
267                                 \r
268                                 if( name && user === XUI_Attr_USER.UINODE ){\r
269                                         this[ name ] = v;\r
270                                 };\r
271                                 \r
272                                 if( name && user === XUI_Attr_USER.XNODE && this.xnode ){\r
273                                         this.xnode[ 'css' ]( XUI_Attr_Rename[ name ] || name, XUI_AbstractUINode_createCssText( this, name ) );\r
274                                         //console.log( ( XUI_Attr_Rename[ name ] || name ) + ' ' + XUI_AbstractUINode_createCssText( this, name ) + ' ' + propID + ' ' + attrs[ propID ] );\r
275                                 } else\r
276                                 if( this.dirty < dirty ) this.dirty = dirty;\r
277                         };\r
278                 },\r
279 \r
280                 getAttr : function( name ){\r
281                         var attrs   = this.attrObject || this.attrClass.prototype || XUI_AttrClass,\r
282                                 support = this.usableAttrs[ name ],\r
283                 v, type, list;\r
284                         if( !support ) return;\r
285                         \r
286                         if( name.indexOf( 'border' ) === 0 ){\r
287                                 name = name.substr( 6 );\r
288                                 return [ this.getAttr( 'borderTop' + name ), this.getAttr( 'borderRight' + name ), this.getAttr( 'borderBottom' + name ), this.getAttr( 'borderLeft' + name ) ];\r
289                         };\r
290                         \r
291                         type = support[ 3 ];\r
292                         // Unit\r
293                         if( type & XUI_Attr_Type.QUARTET ){\r
294                                 return [ this.getAttr( name + 'Top' ), this.getAttr( name + 'Right' ), this.getAttr( name + 'Bottom' ), this.getAttr( name + 'Left' ) ];\r
295                         };\r
296                         if( type & XUI_Attr_Type.COMBI   ) return [ v, data[ ++propID ] ];\r
297                         \r
298                         v    = attrs[ support.No ];             \r
299                         if( type & XUI_Attr_Type.AUTO && v === XUI_Attr_AUTO ) return 'auto'; \r
300                         \r
301                         list = support[ 4 ];\r
302                         if( list ) return list[ v ];\r
303                         \r
304                         if( type & XUI_Attr_Type.COLOR && X_Type_isNumber( v ) ) return v;\r
305                         if( !( type & XUI_Attr_Type.NUMERICAL ) && X_Type_isNumber( v ) ) return v + 'em';\r
306                         return v;\r
307                 },\r
308                 \r
309                 // em, px, %\r
310                 getAttrWithUnit : function( prop, unit ){\r
311                         \r
312                 },\r
313 \r
314                 _remove : function(){\r
315                         switch( this.phase ){\r
316                                 case 4:\r
317                                 case 3:\r
318 \r
319                                 case 2:\r
320                                         \r
321                                 case 1:\r
322                                         this.xnode[ 'kill' ]();\r
323                                 \r
324                                         delete this.root;\r
325                                         delete this.rootData;\r
326                                         delete this.parent;\r
327                                         delete this.parentData;\r
328                                         delete this.xnode;\r
329                                         \r
330                                         delete this.phase;\r
331                         };\r
332                         \r
333                 },\r
334                 //killed\r
335 \r
336                 calculate : function( isNeedsDetection, x, y, allowedW, allowedH ){\r
337                         this.preMesure( allowedW, allowedH );\r
338                         \r
339                         this.noWidth  = this.boxWidth === XUI_Attr_AUTO;\r
340                         this.noHeight = this.boxHeight === XUI_Attr_AUTO;\r
341                         \r
342                         if( this.noWidth || this.noHeight ){\r
343                                 this.mesure();\r
344                                 this.postMesure();\r
345                         };\r
346                         \r
347                         if( !isNeedsDetection ){\r
348                                 this.boxX += x;\r
349                                 this.boxY += y;                 \r
350                         };\r
351                 },\r
352                 \r
353                 /*\r
354                  * X_Node_BoxModel の情報を引きながら top,left,width,height,padding,border の設定\r
355                  */\r
356                 updateLayout : function(){\r
357                         var x = this.boxX + ( this.parentData ? this.parentData.paddingL : 0 ),\r
358                                 y = this.boxY + ( this.parentData ? this.parentData.paddingT : 0 ),\r
359                                 w = X_UA[ 'IE5x' ] ? this.boxWidth  : this.contentWidth, // IE6 の互換モードも\r
360                                 h = X_UA[ 'IE5x' ] ? this.boxHeight : this.contentHeight;\r
361 \r
362                         this.xnode\r
363                                 [ 'css' ]( 'left',        x ? x + 'em' : 0 ) // 親の padding 分ずらす\r
364                                 [ 'css' ]( 'top',         y ? y + 'em' : 0 ) // 親の padding 分ずらす\r
365                                 [ 'css' ]( 'width',       this.noWidth  ? 'auto' : w ? w + 'em' : 0 )\r
366                                 [ 'css' ]( 'height',      this.noHeight ? 'auto' : h ? h + 'em' : 0 )\r
367                                 [ 'css' ]( 'padding',     XUI_AbstractUINode_createCssText( this, 'padding' ) ) // TODO 不要? その分 w, h に足す\r
368                                 [ 'css' ]( 'borderWidth', XUI_AbstractUINode_createCssText( this, 'borderWidth' ) );\r
369                 },\r
370 \r
371                 /*\r
372                  * 親の サイズを元に自身のサイズを計算していく\r
373                  */\r
374                 preMesure : function( allowedW, allowedH ){\r
375                         var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,\r
376                                 box   = attrs[ XUI_Attr_Support.sizing.No ],\r
377                                 min, max,\r
378                                 boxL, boxT, boxR, boxB,\r
379                                 contentW, contentH, boxMinus,\r
380                                 paddingT, paddingR, paddingB, paddingL,\r
381                                 borderT, borderR, borderB, borderL;\r
382                         \r
383                         // Width が確定するパターン\r
384                         // 自身が constraintW の場合 親が AUTO ではない\r
385                         // 自身が constraintW でない場合自身が  AUTO はなくかつ親 が AUTO の場合 or 自身は % でない\r
386                         \r
387                         paddingR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 1 ], allowedW );\r
388                         paddingL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 3 ], allowedW );\r
389                         borderR  = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 1 ], allowedW );\r
390                         borderL  = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 3 ], allowedW );\r
391                         boxMinus = 0;\r
392                         switch( box ){\r
393                                 case 3 : // border-box\r
394                                          boxMinus -= borderR + borderL;\r
395                                 case 2 : // padding-box\r
396                                          boxMinus -= paddingR + paddingL;\r
397                                 // case 1 : // content-box\r
398                         };\r
399                         this.contentL = borderL + paddingL;\r
400                         this.contentR = borderR + paddingR;\r
401                         this.paddingL = paddingL;\r
402                         this.borderL  = borderL;\r
403                         \r
404                         if( this.constraintW ? allowedW !== XUI_Attr_AUTO : !this.autoWidth && ( allowedW !== XUI_Attr_AUTO || !this.percentWidth ) ){\r
405                                 if( this.constraintW ){ // 制約レイアウト\r
406                                         contentW = allowedW - ( boxL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.left.No ], allowedW ) ) - ( boxR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.right.No ], allowedW ) );\r
407                                 } else {\r
408                                         contentW = XUI_AbstractUINode_calcFinalValue( attrs[ XUI_Attr_Support.width.No ], attrs[ XUI_Attr_Support.minWidth.No ], attrs[ XUI_Attr_Support.maxWidth.No ], allowedW );                                     \r
409                                 };\r
410                                 this.contentWidth      = contentW + boxMinus;\r
411                                 this.boxWidth          = this.contentWidth + this.contentL + this.contentR;\r
412                                 this.boxSizingOffsetLR = boxMinus;\r
413                                 delete this.contentWidthMin;\r
414                                 delete this.contentWidthMax;\r
415                                 delete this.boxWidthMin;\r
416                                 delete this.boxWidthMax;\r
417                         } else {        \r
418                                 this.contentWidthMin   = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], allowedW ) + boxMinus );\r
419                                 this.contentWidthMax   = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], allowedW ) + boxMinus );\r
420                                 this.boxWidthMin       = this.contentWidthMin + this.contentL + this.contentR;\r
421                                 this.boxWidthMax       = this.contentWidthMax + this.contentL + this.contentR;\r
422                                 this.contentWidth      = this.contentWidthMin;\r
423                                 this.boxWidth          = this.boxWidthMin;\r
424                                 this.boxSizingOffsetLR = boxMinus;\r
425                         };\r
426                         \r
427                         paddingT  = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 0 ], allowedH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して\r
428                         paddingB  = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 2 ], allowedH );\r
429                         borderT   = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No  + 0 ], allowedH );\r
430                         borderB   = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No  + 2 ], allowedH );\r
431                         boxMinus = 0;\r
432                         switch( box ){\r
433                                 case 3 : // border-box\r
434                                          boxMinus -= borderT + borderB;\r
435                                 case 2 : // padding-box\r
436                                          boxMinus -= paddingT + paddingB;\r
437                                 // case 1 : // content-box\r
438                         };\r
439                         this.contentT = borderT + paddingT;\r
440                         this.contentB = borderB + paddingB;\r
441                         this.paddingT = paddingT;\r
442                         this.borderT  = borderT;\r
443                         \r
444                         // Height\r
445                         if( this.constraintH ? allowedH !== XUI_Attr_AUTO : !this.autoHeight && ( allowedH !== XUI_Attr_AUTO || !this.percentHeight ) ){\r
446                                 if( this.constraintH ){ // 制約レイアウト\r
447                                         contentH = allowedH - ( boxT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.top.No ], allowedH ) ) - ( boxB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.bottom.No ], allowedH ) );\r
448                                 } else {\r
449                                         contentH = XUI_AbstractUINode_calcFinalValue( attrs[ XUI_Attr_Support.height.No ], attrs[ XUI_Attr_Support.minHeight.No ], attrs[ XUI_Attr_Support.maxHeight.No ], allowedH );\r
450                                 };                      \r
451                                 this.contentHeight     = contentH + boxMinus;\r
452                                 this.boxHeight         = this.contentHeight + this.contentT + this.contentB; // padding-box の場合 border だけ足される\r
453                                 this.boxSizingOffsetTB = boxMinus;\r
454                                 delete this.contentHeightMin;\r
455                                 delete this.contentHeightMax;\r
456                                 delete this.boxHeightMin;\r
457                                 delete this.boxHeightMax;\r
458                         } else {\r
459                                 this.contentHeightMin  = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], allowedH ) + boxMinus );\r
460                                 this.contentHeightMax  = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], allowedH ) + boxMinus );                                \r
461                                 this.boxHeightMin      = this.contentHeightMin + this.contentT + this.contentB;\r
462                                 this.boxHeightMax      = this.contentHeightMax + this.contentT + this.contentB;\r
463                                 this.contentHeight     = this.contentHeightMin;\r
464                                 this.boxHeight         = this.boxHeightMin;\r
465                                 this.boxSizingOffsetTB = boxMinus;\r
466                         };\r
467                         \r
468                         // x\r
469                         if( this.parentData && this.parentData.layout.overrideAttrsForChild.left ){\r
470                                 if( this.constraintW || attrs[ XUI_Attr_Support.right.No ] === null ){\r
471                                         this.boxX = ( boxL || boxL === 0 ) ? boxL : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.left.No ], allowedW );\r
472                                 } else {\r
473                                         this.boxX = allowedW - this.boxWidth - ( ( boxR || boxR === 0 ) ? boxR : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.right.No ], allowedW ) );\r
474                                 };\r
475                         } else {\r
476                                 delete this.boxX;\r
477                         };\r
478                         \r
479                         // y\r
480                         if( this.parentData && this.parentData.layout.overrideAttrsForChild.top ){\r
481                                 if( this.constraintH || attrs[ XUI_Attr_Support.bottom.No ] === null ){\r
482                                         this.boxY = ( boxT || boxT === 0 ) ? boxT : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.top.No ], allowedH );\r
483                                 } else {\r
484                                         this.boxY = allowedH - this.boxHeight - ( ( boxB || boxB === 0 ) ? boxB : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.bottom.No ], allowedH ) );\r
485                                 };\r
486                         } else {\r
487                                 delete this.boxY;\r
488                         };\r
489                 },\r
490                 \r
491                 /*\r
492                  * 描画・計測を行って、contentSize の決定\r
493                  */\r
494                 mesure : function(){\r
495                         var dirty = this.dirty,\r
496                                 w, _w, h, xnode;\r
497                         \r
498                         if( dirty === XUI_Dirty.CLEAN ){\r
499                                 if( this.percentWidth || this.percentHeight ){\r
500                                         \r
501                                 };\r
502                         };\r
503                         \r
504                         switch( dirty ){\r
505                                 \r
506                                 case XUI_Dirty.CONTENT : // コンテンツが変更された\r
507                                 case XUI_Dirty.FONT    : // フォントサイズが変更された\r
508                                         delete this.contentWidthLast;\r
509                                         delete this.contentHeightLast;\r
510                                         \r
511                                 case XUI_Dirty.LAYOUT : // レイアウトの再計算が必要\r
512                                 \r
513                                 default : // TODO レイアウト指定が不正な場合 bgcolor を変更、これ以下のレイアウトの中止\r
514                                 \r
515                                         w     = this.contentWidth;\r
516                                         h     = this.contentHeight;\r
517                                         xnode = this.xnode;\r
518                                         \r
519                                         /* http://web-designs.seesaa.net/article/188400668.html\r
520                                          * min-width の値が max-width の値より大きい場合は、max-width の値は min-width の値に設定される。\r
521                                          * \r
522                                          * テキストノードがあり\r
523                                          * 1. contentWidth === AUTO\r
524                                          *     style を更新して contentWidth の決定\r
525                                          *     min or max に引っかかったら style 更新\r
526                                          *     contentHeight === AUTO の場合\r
527                                          *     textHeight の決定\r
528                                          *     contentHeight !== AUTO の場合 scrollHeight のみ更新\r
529                                          * 2. contentHeight === AUTO かつ \r
530                                          *     コンテンツの高さの再取得が必要( contentWidth が最終計測時の contentWidth と一致 かつ フォント・コンテンツに変更無し の場合再取得不要)\r
531                                          *      style を更新して contentHeight の決定\r
532                                          *     必要でない\r
533                                          * 3. content のサイズがすでに決定している\r
534                                          *     コンテンツの高さの再取得が必要\r
535                                          *     必要でない\r
536                                          */\r
537                                         if( xnode[ '_xnodes' ] && xnode[ '_xnodes' ].length ){\r
538                                                 if( w === XUI_Attr_AUTO ){\r
539                                                         \r
540                                                         w = _w = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'width', 'auto' )[ 'clientWidth' ]() / X_Node_CSS_getCharSize( xnode ) );\r
541 \r
542                                                         if( this.contentWidthMax < w - this.boxSizingOffsetLR ){\r
543                                                                 this.noWidth = false;\r
544                                                                 w = this.contentWidthMax + this.boxSizingOffsetLR;\r
545                                                         };\r
546                                                         if( w - this.boxSizingOffsetLR < this.contentWidthMin ){\r
547                                                                 this.noWidth = false;\r
548                                                                 w = this.contentWidthMin + this.boxSizingOffsetLR;\r
549                                                         };\r
550 \r
551                                                         if( h === XUI_Attr_AUTO ){\r
552                                                                 w !== _w && xnode[ 'css' ]( 'width', w + 'em' );\r
553                                                                 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );\r
554                                                                 w !== _w && xnode[ 'css' ]( 'width', 'auto' );\r
555                                                         };\r
556 \r
557                                                         this.contentWidthLast = this.contentWidth = w;\r
558 \r
559                                                 } else\r
560                                                 if( h === XUI_Attr_AUTO ){\r
561                                                         if( w !== this.contentWidthLast ){\r
562                                                                 xnode[ 'css' ]( 'width', w + 'em' );                                                            \r
563                                                                 this.contentWidthLast = w;\r
564                                                                 \r
565                                                                 // ie8 clientHeight, ff scrollHeight & clientHeight\r
566                                                                 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );\r
567                                                         } else {\r
568                                                                 h = this.contentHeightLast === -1 ?\r
569                                                                                 XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) ) :\r
570                                                                                 this.contentHeightLast;\r
571                                                         };\r
572                                                 } else\r
573                                                 if( dirty !== XUI_Dirty.LAYOUT ){\r
574                                                         this.contentWidth  = this.contentWidthLast  = w;\r
575                                                         h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );\r
576                                                 };\r
577                                                 \r
578                                                 if( this.contentHeightMax < h - this.boxSizingOffsetTB ){\r
579                                                         this.noHeight = false;\r
580                                                         h = this.contentHeightMax + this.boxSizingOffsetTB;\r
581                                                 };\r
582                                                 if( h - this.boxSizingOffsetTB < this.contentHeightMin ){\r
583                                                         this.noHeight = false;\r
584                                                         h = this.contentHeightMin + this.boxSizingOffsetTB;\r
585                                                 };\r
586                                                 \r
587                                                 this.contentHeight = this.contentHeightLast = h;\r
588                                                 \r
589                                         } else {\r
590                                                 // コンテンツを持たないため基本のサイズは0\r
591                                                 if( w === XUI_Attr_AUTO ) this.contentWidth  = w = 0 < this.contentWidthMin  ? this.contentWidthMin  : 0;\r
592                                                 if( h === XUI_Attr_AUTO ) this.contentHeight = h = 0 < this.contentHeightMin ? this.contentHeightMin : 0;\r
593                                                 this.noWidth = this.noHeight = false;\r
594                                         };\r
595                                         \r
596                                         delete this.dirty;\r
597                                         break;                  \r
598                                 //case XUI_Dirty.PAINT : // 再描画のみ必要\r
599                                 //      break;\r
600                         };\r
601                 },\r
602                 /*\r
603                  * 自身の contentWidth, contentHeight を元に AUTO な width, height を確定していく\r
604                  */\r
605                 postMesure : function(){\r
606                         var     attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,\r
607                                 box   = attrs[ XUI_Attr_Support.sizing.No ],\r
608                                 contentW, contentH,\r
609                                 contentPlus,\r
610                                 paddingT, paddingR, paddingB, paddingL,\r
611                                 borderT, borderR, borderB, borderL,\r
612                                 min, max;\r
613                                 \r
614                         // Width\r
615                         if( this.boxWidth === XUI_Attr_AUTO ){\r
616                                 contentW = this.contentWidth;\r
617                                 paddingR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 1 ], contentW );                                  \r
618                                 paddingL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 3 ], contentW );                                  \r
619                                 borderR  = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 1 ], contentW );\r
620                                 borderL  = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 3 ], contentW );\r
621                                 contentPlus = 0;\r
622                                 switch( box ){\r
623                                         case 1 : // content-box\r
624                                                  contentPlus  = paddingR + paddingL;\r
625                                         case 2 : // padding-box\r
626                                                  contentPlus += borderR + borderL;\r
627                                         // case 3 : // border-box\r
628                                 };\r
629                                 \r
630                                 if( !this.constraintW ){\r
631                                         contentW += contentPlus;\r
632                                         min = this.boxWidthMin = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], contentW );\r
633                                         max = this.boxWidthMax = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], contentW );\r
634                                         if( contentW < min && contentPlus < min ){\r
635                                                 this.contentWidth = min - contentPlus;\r
636                                         } else\r
637                                         if( max < contentW && contentPlus < max ){\r
638                                                 this.contentWidth = max - contentPlus;\r
639                                         };\r
640                                 };\r
641                                 this.contentL = borderL + paddingL;\r
642                                 this.contentR = borderR + paddingR;\r
643                                 this.paddingL = paddingL;\r
644                                 this.borderL  = borderL;\r
645                                 this.boxWidth = this.contentWidth + this.contentL + this.contentR;\r
646                         };\r
647                         // Height\r
648                         if( this.boxHeight === XUI_Attr_AUTO ){\r
649                                 contentH    = this.contentHeight;\r
650                                 paddingT    = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 0 ], contentH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して\r
651                                 paddingB    = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 2 ], contentH );\r
652                                 borderT     = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No  + 0 ], contentH );\r
653                                 borderB     = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No  + 2 ], contentH );\r
654                                 contentPlus = 0;\r
655                                 switch( box ){\r
656                                         case 1 : // content-box\r
657                                                  contentPlus  = paddingT + paddingB;\r
658                                         case 2 : // padding-box\r
659                                                  contentPlus += borderT + borderB;\r
660                                         // case 3 : // border-box\r
661                                 };\r
662                                 if( !this.constraintH ){\r
663                                         contentH += contentPlus;\r
664                                         min = this.boxHeightMin = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], contentH );\r
665                                         max = this.boxHeightMax = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], contentH );\r
666                                         if( contentH < min && contentPlus < min ){\r
667                                                 this.contentHeight = min - contentPlus;\r
668                                         } else\r
669                                         if( max < contentH && contentPlus < max ){\r
670                                                 this.contentHeight = max - contentPlus;\r
671                                         };\r
672                                 };\r
673                                 this.contentT  = borderT + paddingT;\r
674                                 this.contentB  = borderB + paddingB;\r
675                                 this.paddingT  = paddingT;\r
676                                 this.borderT   = borderT;\r
677                                 this.boxHeight = this.contentHeight + this.contentT + this.contentB;\r
678                         };\r
679                 },\r
680 \r
681                 // TODO fontsize が変わることもある\r
682                 capcher : function( x, y ){\r
683                         if( this.pointerDisabled ) return false;\r
684                         \r
685                         x -= this.boxX;\r
686                         y -= this.boxY;\r
687 \r
688                         if( 0 <= x && x < this.boxWidth && 0 <= y && y < this.boxHeight ){\r
689                                 !this.hovering && ( this.rootData.hoverList[ this.rootData.hoverList.length ] = this );\r
690                                 this.rootData.targetNodeData = this;\r
691                                 return true;\r
692                         };\r
693                 },\r
694                 \r
695                 /*\r
696                  * context を明示しない場合、User が context になる!\r
697                  */\r
698                 listen : function( type, arg1, arg2, arg3 ){\r
699                         var root, events, counter, f;\r
700                         \r
701                         if( XUI_Event._START_POINTER <= type && type <= XUI_Event._END_POINTER ){\r
702                                 if( this.phase < 3 ){\r
703                                         if( !( events = this.reserveEvents ) ) this.reserveEvents = events = [];\r
704                                         events[ events.length ] = [ type, arg1, arg2, arg3 ];\r
705                                         return this;\r
706                                 };\r
707                                 if( XUI_Event._START_XUI_EVENT < type && type < XUI_Event._END_XUI_EVENT ){\r
708                                         if( !this.gesture ){\r
709                                                 this.gesture = new Hammer( this.rootData, this, type );\r
710                                         } else {\r
711                                                 this.gesture[ 'listen' ]( type );\r
712                                         };\r
713                                 } else {\r
714                                         //console.log( type );\r
715                                         root    = this.rootData;\r
716                                         counter = root.eventCounter;\r
717                                         if( counter[ type ] ){\r
718                                                 ++counter[ type ];\r
719                                         } else {\r
720                                                 counter[ type ] = 1;                            \r
721                                                 root.xnodeInteractiveLayer[ 'listen' ]( XUI_Event.IdToName[ type ], X_UI_eventRellay );\r
722                                         };\r
723                                 };\r
724                         };\r
725                         \r
726                         arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 ) );\r
727                         if( !f.kind ){\r
728                                 return X_EventDispatcher_listen.call( this, type, this.User, f );\r
729                         } else\r
730                         if( f.kind === X_Callback_FUNC_ONLY ){\r
731                                 return X_EventDispatcher_listen.call( this, type, this.User, f.func, f.supplement );\r
732                         };\r
733                         return X_EventDispatcher_listen.apply( this, arguments );\r
734                 },\r
735                 unlisten : function( type, arg1, arg2, arg3 ){\r
736                         var root, events, i, ev, counter, f;\r
737                         if( XUI_Event._START_POINTER <= type && type <= XUI_Event._END_POINTER ){\r
738                                 if( this.phase < 3 ){\r
739                                         if( !( events = this.reserveEvents ) ) return this;\r
740                                         for( i = events.length; i; ){\r
741                                                 ev = events[ --i ];\r
742                                                 if( ev[ 0 ] === type && ev[ 1 ] === arg1 && ev[ 2 ] === arg2 ){\r
743                                                         events.split( i, 1 );\r
744                                                         return this;\r
745                                                 };\r
746                                         }; \r
747                                         return this;\r
748                                 };\r
749 \r
750                                 if( XUI_Event._START_XUI_EVENT < type && type < XUI_Event._END_XUI_EVENT ){\r
751                                         this.gesture && this.gesture[ 'unlisten' ]( type );\r
752                                 } else {\r
753                                         root    = this.rootData;\r
754                                         counter = root.eventCounter;\r
755                                         if( !counter[ type ] ) return this;\r
756                                         --counter[ type ];\r
757                                         if( counter[ type ] === 0 ){\r
758                                                 root.xnodeInteractiveLayer[ 'unlisten' ]( XUI_Event.IdToName[ type ], X_UI_eventRellay );\r
759                                                 delete counter[ type ];\r
760                                         };\r
761                                 };\r
762                         };\r
763                         arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 ) );\r
764                         if( !f.kind ){\r
765                                 return X_EventDispatcher_unlisten.apply( this, [ type, this.User, f ] );\r
766                         } else\r
767                         if( f.kind === X_Callback_FUNC_ONLY ){\r
768                                 return X_EventDispatcher_unlisten.apply( this, [ type, this.User, f.func, f.supplement ] );\r
769                         };\r
770                         return X_EventDispatcher_unlisten.apply( this, arguments );\r
771                 },\r
772                 \r
773                 dispatch : function( e ){\r
774                         //console.log( e.type + ' ' + ( this[ '_listeners' ] && this[ '_listeners' ][ e.type ] ) );\r
775                         var xve  = XUI_Event,\r
776                                 ret  = X_EventDispatcher_dispatch.call( this, e ),\r
777                                 type = e.type || e;\r
778                         \r
779                         // TODO captureEvent PointerEvent\r
780                         if( ret & X_Callback_CAPTURE_POINTER && !this.hitChildData && XUI_Event._POINTER_MOVE === type ){\r
781                                 this.rootData.monopolyNodeData = this;\r
782                                 return ret;\r
783                         };\r
784                         this.rootData.monopolyNodeData = null;\r
785                         if( xve._START_BUBLEUP < type && this.parentData && !( ret & X_Callback_STOP_PROPAGATION ) && !( ret & X_Callback_STOP_NOW ) ) return this.parentData[ 'dispatch' ]( e );\r
786                         return ret;\r
787                 },\r
788                 \r
789                 setItemData : function(){\r
790                         // this[ 'dispatch' ]( UI_Event.ITEMDATA_CHANGED );\r
791                         // itemData.listen( X_Event_CHANGED ) -> this[ 'dispatch' ]( UI_Event.ITEMDATA_UPDATED );\r
792                 }\r
793                 \r
794         }\r
795 );\r
796 \r
797 function XUI_AbstractUINode_createCssText( that, name ){\r
798         var attrs      = that.attrObject || that.attrClass.prototype || XUI_AttrClass,\r
799                 def        = that.usableAttrs[ name ],\r
800                 no         = def.No,\r
801                 v          = attrs[ def.No ],\r
802                 type       = def[ 3 ],\r
803                 list       = def[ 4 ],\r
804                 flag       = !!( type & XUI_Attr_Type.BOOLEAN ),\r
805                 combi      = !!( type & XUI_Attr_Type.COMBI   ),\r
806                 quartet    = !!( type & XUI_Attr_Type.QUARTET );\r
807 \r
808         if( quartet ){\r
809                 if( attrs[ no + 1 ] === attrs[ no + 3 ] ){\r
810                         if( v === attrs[ no + 2 ] ){\r
811                                 if( v === attrs[ no + 1 ] ){\r
812                                         return XUI_AbstractUINode_createCssValue( v, type, list );\r
813                                 };\r
814                                 return [\r
815                                         XUI_AbstractUINode_createCssValue( v, type, list ),\r
816                                         XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list )\r
817                                 ].join( ' ' );\r
818                         };\r
819                         return [\r
820                                 XUI_AbstractUINode_createCssValue( v, type, list ),\r
821                                 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list ),\r
822                                 XUI_AbstractUINode_createCssValue( attrs[ no + 2 ], type, list )\r
823                         ].join( ' ' );\r
824                 };\r
825                 return [\r
826                         XUI_AbstractUINode_createCssValue( v, type, list ),\r
827                         XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list ),\r
828                         XUI_AbstractUINode_createCssValue( attrs[ no + 2 ], type, list ),\r
829                         XUI_AbstractUINode_createCssValue( attrs[ no + 3 ], type, list )\r
830                 ].join( ' ' );\r
831         } else\r
832         if( combi ){\r
833                 return [\r
834                         XUI_AbstractUINode_createCssValue( v, type, list ),\r
835                         XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list )\r
836                 ].join( ' ' );\r
837         } else\r
838         if( flag ){\r
839                 return v ? list : 'normal'; // \r
840         };\r
841         return XUI_AbstractUINode_createCssValue( v, type, list );\r
842 };\r
843 \r
844 function XUI_AbstractUINode_createCssValue( v, type, list ){\r
845         var length     = !!( type & XUI_Attr_Type.LENGTH        ),\r
846                 minusLen   = !!( type & XUI_Attr_Type.MINUS_LENGTH  ),\r
847                 percent    = !!( type & XUI_Attr_Type.PERCENT       ),\r
848                 minusPct   = !!( type & XUI_Attr_Type.MINUS_PERCENT ),\r
849                 numerical  = !!( type & XUI_Attr_Type.NUMERICAL     ),\r
850                 auto       = !!( type & XUI_Attr_Type.AUTO          ),\r
851                 color      = !!( type & XUI_Attr_Type.COLOR         ),\r
852                 url        = !!( type & XUI_Attr_Type.URL           ),\r
853                 fontName   = !!( type & XUI_Attr_Type.FONT_NAME     );\r
854         \r
855         if( X_Type_isNumber( v ) ){\r
856                 if( auto && v === XUI_Attr_AUTO ) return 'auto';\r
857                 if( length || minusLen ) return v + 'em';\r
858                 if( numerical ) return v;\r
859                 if( list && list[ v ] ) return list[ v ];\r
860                 if( color ){\r
861                         if( v < 0x100000 ){\r
862                                 v = '00000' + v.toString( 16 );\r
863                                 return '#' + v.substr( v.length - 6 );\r
864                         };\r
865                         return '#' + v.toString( 16 );\r
866                 };\r
867         };\r
868         if( X_Type_isString( v ) ){\r
869                 if( percent || minusPct || url || fontName ) return v;\r
870         };\r
871 };\r
872 \r
873 function XUI_AbstractUINode_calcValue( styleValue, srcValue ){\r
874         /*\r
875          * String の場合は必ず %\r
876          */     \r
877         if( X_Type_isString( styleValue ) ){\r
878                 return srcValue * parseFloat( styleValue ) / 100;\r
879         };\r
880         if( !X_Type_isNumber( styleValue ) ) return 0;\r
881         return styleValue;\r
882 };\r
883 \r
884 function XUI_AbstractUINode_calcFinalValue( styleValue, styleMin, styleMax, srcValue ){\r
885         var v    = XUI_AbstractUINode_calcValue( styleValue, srcValue ),\r
886                 min  = XUI_AbstractUINode_calcValue( styleMin, srcValue ),\r
887                 max  = XUI_AbstractUINode_calcValue( styleMax, srcValue );\r
888         return v <= min ? min : max <= v ? max : v;\r
889 };\r
890 function XUI_AbstractUINode_ceil( v ){\r
891         if( 0 <= v ){\r
892                 return ( v * 10 + 0.999 | 0 ) / 10;\r
893         };\r
894         return ( -v * 10 + 0.999 | 0 ) / -10;\r
895 };\r
896 \r
897 X.UI.AbstractUINode = X_Class_create(\r
898         'AbstractUINode',\r
899         X_Class.ABSTRACT,\r
900         {\r
901                 parent : function(){\r
902                         return X_Pair_get( this ).parent;\r
903                 },\r
904                 root : function(){\r
905                         return X_Pair_get( this ).root;\r
906                 },\r
907                 \r
908                 /*\r
909                  * unverifiedAttrs に全ての指定を控える\r
910                  * サポートされていない場合は無視される.親のレイアウトによって変わる\r
911                  */\r
912                 attr : function( nameOrObject, valueOrUnit ){\r
913                         var p = X_Pair_get( this ),\r
914                                 layout, k, def, attrs, v;\r
915                         if( nameOrObject && X_Type_isObject( nameOrObject ) ){\r
916                                 // setter\r
917                                 layout = p.parentData && p.parentData.layout.overrideAttrsForChild; // root には parent がない\r
918                                 for( k in nameOrObject ){\r
919                                         if( X_EMPTY_OBJECT[ k ] ) continue;\r
920                                         // 親のレイアウトマネージャの許可しない\r
921                                         if( layout && !layout[ k ] ){\r
922                                                 continue;\r
923                                         };\r
924                                         if( def = p.usableAttrs[ k ] ){\r
925                                                 p.setAttr( k, def, nameOrObject[ k ] );\r
926                                         };\r
927                                 };\r
928                         } else\r
929                         if( X_Type_isString( nameOrObject ) ){\r
930                                 if( valueOrUnit !== undefined ){\r
931                                         if( 'em,%'.indexOf( valueOrUnit ) === -1 ){\r
932                                                 // setter\r
933                                                 p.setAttr( nameOrObject, valueOrUnit );\r
934                                         } else {\r
935                                                 // getter with unit\r
936                                                 return p.getAttrWithUnit( nameOrObject, valueOrUnit );\r
937                                         };\r
938                                 };\r
939                                 // getter\r
940                                 if( attrs = ( p.attrObject || p.attrClass.prototype || XUI_AttrClass ) ){\r
941                                         def = p.usableAttrs[ nameOrObject ];\r
942                                         return def && attrs[ def.No ];\r
943                                 };\r
944                                 return v;\r
945                         };\r
946                         return this;\r
947                 },\r
948                 \r
949                 listen : function( type, arg1, arg2, arg3 ){\r
950                         X_Pair_get( this )[ 'listen' ]( type, arg1, arg2, arg3 );\r
951                         return this;\r
952                 },\r
953                 listenOnce : function( type, arg1, arg2, arg3 ){\r
954                         X_Pair_get( this )[ 'listenOnce' ]( type, arg1, arg2, arg3 );\r
955                         return this;\r
956                 },\r
957                 listening : function( type, arg1, arg2, arg3 ){\r
958                         return X_Pair_get( this )[ 'listening' ]( type, arg1, arg2, arg3 );\r
959                 },\r
960                 unlisten : function( type, arg1, arg2, arg3 ){\r
961                         X_Pair_get( this )[ 'unlisten' ]( type, arg1, arg2, arg3 );\r
962                         return this;\r
963                 },\r
964                 dispatch : function( e ){\r
965                         return X_Pair_get( this )[ 'dispatch' ]( e );\r
966                 },\r
967                         \r
968                 nextNode : function(){\r
969                         \r
970                 },\r
971                 prevNode : function(){\r
972                         \r
973                 },\r
974                 nodeIndex : function( v ){\r
975                         var data = X_Pair_get( this );\r
976                         if( typeof v === 'number' ){\r
977                                 // data.nodeIndex( v );\r
978                                 return this;\r
979                         };\r
980                         return data.parentData ? data.parentData.nodes.indexOf( data ) : 0;\r
981                 },\r
982                 displayIndex : function(){\r
983                         \r
984                 },\r
985                 getX : function(){\r
986                         // dirty の場合、rootData.calculate\r
987                         return X_Pair_get( this ).boxX;\r
988                 },\r
989                 getY : function(){\r
990                         // dirty の場合、rootData.calculate\r
991                         return X_Pair_get( this ).boxY;\r
992                 },\r
993                 getAbsoluteX : function(){\r
994                         // dirty の場合、rootData.calculate\r
995                         return X_Pair_get( this ).absoluteX;\r
996                 },\r
997                 getAbsoluteY: function(){\r
998                         // dirty の場合、rootData.calculate\r
999                         return X_Pair_get( this ).absoluteY;\r
1000                 },\r
1001                 getWidth : function(){\r
1002                         // dirty の場合、rootData.calculate\r
1003                         return X_Pair_get( this ).boxWidth;\r
1004                 },\r
1005                 getHeight : function(){\r
1006                         // dirty の場合、rootData.calculate\r
1007                         return X_Pair_get( this ).boxHeight;\r
1008                 },\r
1009                 \r
1010                 /*\r
1011                  * Repeater に於いて、繰り返されるアイテムの元(itemRenderer)からの複製に使用\r
1012                  */\r
1013                 clone : function( opt_cloneListener ){\r
1014                         var newNode = this.constructor(),\r
1015                                 newPair = X_Pair_get( newNode ),\r
1016                                 pair    = X_Pair_get( this ),\r
1017                                 attr, listeners, type, list, i, l;\r
1018 \r
1019                         // handleEvent 等の拡張されたオブジェクトもコピーする!\r
1020                         for( k in this ){\r
1021                                 if( this[ k ] !== newNode[ k ] && !newNode[ k ] ) newNode[ k ] = this[ k ];\r
1022                         };\r
1023                         \r
1024                         // User.UINODE な値は pair にコピーされているのでこれをコピー\r
1025                         for( k in pair ){\r
1026                                 if( pair[ k ] !== newPair[ k ] && !newPair[ k ] ) newPair[ k ] = pair[ k ];\r
1027                         };\r
1028                         \r
1029                         // attr もコピー\r
1030                         if( pair.attrObject ){\r
1031                                 attr = pair.attrClass();\r
1032                                 for( k in pair.attrObject ){\r
1033                                         if( pair.attrObject[ k ] !== attr[ k ] ) attr[ k ] = pair.attrObject[ k ];\r
1034                                 };\r
1035                                 newPair.attrObject = attr;\r
1036                         };\r
1037                         \r
1038                         // listener もコピーする!\r
1039                         if( opt_cloneListener && ( listeners = pair[ '_listeners' ] ) ){\r
1040                                 for( type in listeners ){\r
1041                                         list = listeners[ type ];\r
1042                                         for( i = 0, l = list.length; i < l; ++i ){\r
1043                                                 f = list[ i ];\r
1044                                                 switch( f.kind ){\r
1045                                                         case X_Callback_THIS_FUNC :\r
1046                                                                 if( f.lock ){\r
1047                                                                         X_EventDispatcher_systemListen( newNode, type, f.context === this ? newNode : f.context, f.func, f.supplement );\r
1048                                                                 } else {\r
1049                                                                         newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.context === this ? newNode : f.context, f.func, f.supplement );\r
1050                                                                 };\r
1051                                                                 break;\r
1052                                                         case X_Callback_HANDLEEVENT :\r
1053                                                                 if( f.lock ){\r
1054                                                                         X_EventDispatcher_systemListen( newNode, type, f.context === this ? newNode : f.context, f.supplement );\r
1055                                                                 } else {\r
1056                                                                         newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.context === this ? newNode : f.context, f.supplement );\r
1057                                                                 };\r
1058                                                                 break;\r
1059                                                         /*\r
1060                                                         case X_Callback_FUNC_ONLY :\r
1061                                                                 if( f.lock ){\r
1062                                                                         X_EventDispatcher_systemListen( newNode, type, f.func, f.supplement );\r
1063                                                                 } else {\r
1064                                                                         newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.func, f.supplement );\r
1065                                                                 };\r
1066                                                                 break;\r
1067                                                         default :\r
1068                                                                 newNode[ 'listen' ]( type, f );\r
1069                                                                 break; */\r
1070                                                 };\r
1071                                         };                              \r
1072                                 };\r
1073                         };\r
1074                         \r
1075                         return newNode;\r
1076                 }\r
1077         }\r
1078 );\r
1079 \r