OSDN Git Service

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