1 // TODO -> Node[ 'inherits' ]
\r
2 var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ](
\r
3 'X.UI._AbstractUINode',
\r
9 dirty : XUI_Dirty.CLEAN,
\r
17 usableAttrs : XUI_Attr_Support,
\r
18 attrClass : XUI_AttrClass,
\r
20 unverifiedAttrs : null,
\r
23 pointerDisabled : false,
\r
26 reserveEvents : null,
\r
27 gestureOptions : null,
\r
28 gestureActivated : null,
\r
29 gestureTypes : null,
\r
30 gestureTriggered : null,
\r
31 gestureCanceled : null,
\r
32 gestureCurrentName : '',
\r
33 gestureStartEvent : null,
\r
34 gestureLastEvent : null,
\r
35 gestureLastMoveEvent : null,
\r
42 boxWidth : XUI_Attr_AUTO,
\r
44 boxWidthMax : XUI_Attr_AUTO,
\r
45 boxHeight : XUI_Attr_AUTO,
\r
47 boxHeightMax : XUI_Attr_AUTO,
\r
56 boxSizingOffsetLR : 0,
\r
57 boxSizingOffsetTB : 0,
\r
58 contentWidth : XUI_Attr_AUTO,
\r
59 contentWidthMin : 0,
\r
60 contentWidthMax : XUI_Attr_AUTO,
\r
61 contentWidthLast : -1,
\r
62 contentHeight : XUI_Attr_AUTO,
\r
63 contentHeightMin : 0,
\r
64 contentHeightMax : XUI_Attr_AUTO,
\r
65 contentHeightLast : -1,
\r
67 constraintW : false,
\r
68 constraintH : false,
\r
73 percentWidth : false,
\r
74 percentHeight : false,
\r
75 // :hover, :focus, :disabled
\r
77 initialize : function( root, rootData, parent, parentData ){
\r
79 this.rootData = rootData;
\r
80 this.parent = parent;
\r
81 this.parentData = parentData;
\r
84 this[ 'dispatch' ]( XUI_Event.INIT );
\r
87 addToParent : function( xnodeParent ){
\r
88 var attr = this.attrObject || this.attrClass.prototype,
\r
89 usableAttrs = this.usableAttrs,
\r
90 i = 0, l = usableAttrs.length, def, k;
\r
92 xnodeParent && xnodeParent[ 'append' ]( this.xnode );
\r
95 for( k in usableAttrs ){
\r
96 def = usableAttrs[ k ];
\r
97 if( def[ 2 ] === XUI_Attr_USER.XNODE && X_Object_inObject( def.No, attr ) && attr[ def.No ] !== def[ 0 ] ){
\r
98 this.xnode[ 'css' ]( XUI_Attr_Rename[ k ] || k, XUI_AbstractUINode_createCssText( this, k ) );
\r
104 this[ 'dispatch' ]( XUI_Event.ADDED );
\r
107 creationComplete : function(){
\r
108 var events = this.reserveEvents,
\r
112 this.User[ 'dispatch' ]( XUI_Event.CREATION_COMPLETE );
\r
114 // html 要素が親に追加されるまで控えていたイベントの登録
\r
116 if( events && ( l = events.length ) ){
\r
117 for( i = 0; i < l; ++i ){
\r
118 this.listen.apply( this, events[ i ] );
\r
121 delete this.reserveEvents;
\r
126 * _UINode への setAttr の他、attrClass.prototype への setAttr にも対応する
\r
127 * 親要素が変化した場合、unverifiedAttrs を元に attrObject を再設定.
\r
129 setAttr : function( name, def, v ){
\r
130 var attrs = XUI_attrClassProto || this.attrObject,
\r
131 propID = def.No || def[ 5 ],
\r
132 defaultVal = XUI_attrClassProto ? attrs[ propID ] : this.attrClass.prototype[ propID ], // def[ 0 ],
\r
133 currentVal = attrs ? attrs[ propID ] : defaultVal,
\r
138 length = !!( type & XUI_Attr_Type.LENGTH ),
\r
139 minusLen = !!( type & XUI_Attr_Type.MINUS_LENGTH ),
\r
140 percent = !!( type & XUI_Attr_Type.PERCENT ),
\r
141 minusPct = !!( type & XUI_Attr_Type.MINUS_PERCENT ),
\r
142 numerical = !!( type & XUI_Attr_Type.NUMERICAL ),
\r
143 auto = !!( type & XUI_Attr_Type.AUTO ),
\r
144 color = !!( type & XUI_Attr_Type.COLOR ),
\r
145 url = !!( type & XUI_Attr_Type.URL ),
\r
146 fontName = !!( type & XUI_Attr_Type.FONT_NAME ),
\r
147 flag = !!( type & XUI_Attr_Type.BOOLEAN ),
\r
148 combi = !!( type & XUI_Attr_Type.COMBI ),
\r
149 quartet = !!( type & XUI_Attr_Type.QUARTET ),
\r
150 _v, i, l, nodes, root, roots;
\r
152 if( X_Type_isString( v ) ){
\r
153 //v = v.toLowercase();
\r
154 if( url || fontName ){
\r
157 if( auto && v === 'auto' ){
\r
160 if( list && ( _v = list[ v ] ) ){
\r
162 console.log( v + ' ' + _v );
\r
165 if( ( percent || minusPct ) && v.lastIndexOf( '%' ) !== -1 && X_Type_isFinite( _v = parseFloat( v ) ) && v === _v + '%' ){
\r
168 if( ( length || minusLen ) && v.lastIndexOf( 'em' ) !== -1 && X_Type_isFinite( _v = parseFloat( v ) ) && v === _v + 'em' ){
\r
171 if( v.indexOf( ' ' ) !== -1 ){
\r
172 v = v.split( ' ' );
\r
174 if( color && X_Type_isNumber( _v = X_Node_CSS_parseColor( v ) ) ){
\r
182 if( ( quartet || combi ) && !X_Type_isArray( v ) ){
\r
186 if( X_Type_isNumber( v ) ){
\r
188 ( length && ( 0 <= v ) ) ||
\r
189 ( minusLen && ( v <= 0 ) ) ||
\r
190 ( percent && 0 <= v && v <= 1 ) ||
\r
191 ( minusPct && -1 <= v && v < 0 ) ||
\r
192 ( numerical && 0 <= v ) ||
\r
193 ( auto && v === XUI_Attr_AUTO ) ||
\r
194 ( color && ( 0 <= v && v <= 0xFFFFFF ) || ( v !== v ) ) || // isNaN
\r
195 ( list && list[ v ] )
\r
203 if( X_Type_isBoolean( v ) && !flag ){
\r
206 if( X_Type_isArray( v ) ){
\r
207 if( v.length <= 4 && quartet ){
\r
208 type &= ~XUI_Attr_Type.QUARTET;
\r
209 switch( v.length ){
\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[ 0 ] );
\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[ 0 ] );
\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[ 0 ] );
\r
220 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\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[ 1 ] );
\r
229 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
230 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
231 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\r
232 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 3 ] );
\r
236 if( v.length === 2 && combi ){
\r
237 type &= ~XUI_Attr_Type.COMBI;
\r
238 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
239 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
245 if( !XUI_attrClassProto && user === XUI_Attr_USER.XNODE && this.xnode ){
\r
246 this.xnode[ 'css' ]( XUI_Attr_Rename[ name ] || name, XUI_AbstractUINode_createCssText( this, name ) );
\r
247 //console.log( ( XUI_Attr_Rename[ name ] || name ) + ' ' + XUI_AbstractUINode_createCssText( this, name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
252 if( !v && v !== 0 ) v = defaultVal;
\r
254 // UIAttrClass の初期設定の場合、ここで終わる
\r
255 if( XUI_attrClassProto ){
\r
256 attrs[ propID ] = v;
\r
260 if( currentVal !== v ){
\r
262 case XUI_Attr_Support.left.No :
\r
263 this.constraintW = attrs[ XUI_Attr_Support.right.No ] !== null;
\r
265 case XUI_Attr_Support.right.No :
\r
266 this.constraintW = attrs[ XUI_Attr_Support.left.No ] !== null;
\r
268 case XUI_Attr_Support.top.No :
\r
269 this.constraintH = attrs[ XUI_Attr_Support.bottom.No ] !== null;
\r
271 case XUI_Attr_Support.bottom.No :
\r
272 this.constraintH = attrs[ XUI_Attr_Support.top.No ] !== null;
\r
274 case XUI_Attr_Support.width.No :
\r
275 this.autoWidth = v === XUI_Attr_AUTO;
\r
276 this.percentWidth = X_Type_isString( v );
\r
278 case XUI_Attr_Support.height.No :
\r
279 this.autoHeight = v === XUI_Attr_AUTO;
\r
280 this.percentHeight = X_Type_isString( v );
\r
284 if( defaultVal === v ){
\r
285 if( attrs ) delete attrs[ propID ];
\r
287 if( !attrs ) attrs = this.attrObject = new this.attrClass;
\r
288 attrs[ propID ] = v;
\r
291 if( name && user === XUI_Attr_USER.UINODE ){
\r
295 if( name && user === XUI_Attr_USER.XNODE && this.xnode ){
\r
296 this.xnode[ 'css' ]( XUI_Attr_Rename[ name ] || name, XUI_AbstractUINode_createCssText( this, name ) );
\r
297 //console.log( ( XUI_Attr_Rename[ name ] || name ) + ' ' + XUI_AbstractUINode_createCssText( this, name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
299 if( this.dirty < dirty ) this.dirty = dirty;
\r
303 getAttr : function( name ){
\r
304 var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,
\r
305 support = this.usableAttrs[ name ],
\r
307 if( !support ) return;
\r
309 if( name.indexOf( 'border' ) === 0 ){
\r
310 name = name.substr( 6 );
\r
311 return [ this.getAttr( 'borderTop' + name ), this.getAttr( 'borderRight' + name ), this.getAttr( 'borderBottom' + name ), this.getAttr( 'borderLeft' + name ) ];
\r
314 type = support[ 3 ];
\r
316 if( type & XUI_Attr_Type.QUARTET ){
\r
317 return [ this.getAttr( name + 'Top' ), this.getAttr( name + 'Right' ), this.getAttr( name + 'Bottom' ), this.getAttr( name + 'Left' ) ];
\r
319 if( type & XUI_Attr_Type.COMBI ) return [ v, data[ ++propID ] ];
\r
321 v = attrs[ support.No ];
\r
322 if( type & XUI_Attr_Type.AUTO && v === XUI_Attr_AUTO ) return 'auto';
\r
324 list = support[ 4 ];
\r
325 if( list ) return list[ v ];
\r
327 if( type & XUI_Attr_Type.COLOR && X_Type_isNumber( v ) ) return v;
\r
328 if( !( type & XUI_Attr_Type.NUMERICAL ) && X_Type_isNumber( v ) ) return v + 'em';
\r
333 getAttrWithUnit : function( prop, unit ){
\r
337 _remove : function(){
\r
338 switch( this.phase ){
\r
345 this.xnode[ 'remove' ]();
\r
348 delete this.rootData;
\r
349 delete this.parent;
\r
350 delete this.parentData;
\r
358 calculate : function( isNeedsDetection, x, y, allowedW, allowedH ){
\r
359 this.preMesure( allowedW, allowedH );
\r
361 this.noWidth = this.boxWidth === XUI_Attr_AUTO;
\r
362 this.noHeight = this.boxHeight === XUI_Attr_AUTO;
\r
364 if( this.noWidth || this.noHeight ){
\r
369 if( !isNeedsDetection ){
\r
376 * X_Node_BoxModel の情報を引きながら top,left,width,height,padding,border の設定
\r
378 updateLayout : function(){
\r
379 var x = this.boxX + ( this.parentData ? this.parentData.paddingL : 0 ),
\r
380 y = this.boxY + ( this.parentData ? this.parentData.paddingT : 0 ),
\r
381 w = X_UA[ 'IE5x' ] ? this.boxWidth : this.contentWidth, // IE6 の互換モードも
\r
382 h = X_UA[ 'IE5x' ] ? this.boxHeight : this.contentHeight;
\r
385 [ 'css' ]( 'left', x ? x + 'em' : 0 ) // 親の padding 分ずらす
\r
386 [ 'css' ]( 'top', y ? y + 'em' : 0 ) // 親の padding 分ずらす
\r
387 [ 'css' ]( 'width', this.noWidth ? 'auto' : w ? w + 'em' : 0 )
\r
388 [ 'css' ]( 'height', this.noHeight ? 'auto' : h ? h + 'em' : 0 )
\r
389 [ 'css' ]( 'padding', XUI_AbstractUINode_createCssText( this, 'padding' ) ) // TODO 不要? その分 w, h に足す
\r
390 [ 'css' ]( 'borderWidth', XUI_AbstractUINode_createCssText( this, 'borderWidth' ) );
\r
394 * 親の サイズを元に自身のサイズを計算していく
\r
396 preMesure : function( allowedW, allowedH ){
\r
397 var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,
\r
398 box = attrs[ XUI_Attr_Support.sizing.No ],
\r
400 boxL, boxT, boxR, boxB,
\r
401 contentW, contentH, boxMinus,
\r
402 paddingT, paddingR, paddingB, paddingL,
\r
403 borderT, borderR, borderB, borderL;
\r
406 // 自身が constraintW の場合 親が AUTO ではない
\r
407 // 自身が constraintW でない場合自身が AUTO はなくかつ親 が AUTO の場合 or 自身は % でない
\r
409 paddingR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 1 ], allowedW );
\r
410 paddingL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 3 ], allowedW );
\r
411 borderR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 1 ], allowedW );
\r
412 borderL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 3 ], allowedW );
\r
415 case 3 : // border-box
\r
416 boxMinus -= borderR + borderL;
\r
417 case 2 : // padding-box
\r
418 boxMinus -= paddingR + paddingL;
\r
419 // case 1 : // content-box
\r
421 this.contentL = borderL + paddingL;
\r
422 this.contentR = borderR + paddingR;
\r
423 this.paddingL = paddingL;
\r
424 this.borderL = borderL;
\r
426 if( this.constraintW ? allowedW !== XUI_Attr_AUTO : !this.autoWidth && ( allowedW !== XUI_Attr_AUTO || !this.percentWidth ) ){
\r
427 if( this.constraintW ){ // 制約レイアウト
\r
428 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
430 contentW = XUI_AbstractUINode_calcFinalValue( attrs[ XUI_Attr_Support.width.No ], attrs[ XUI_Attr_Support.minWidth.No ], attrs[ XUI_Attr_Support.maxWidth.No ], allowedW );
\r
432 this.contentWidth = contentW + boxMinus;
\r
433 this.boxWidth = this.contentWidth + this.contentL + this.contentR;
\r
434 this.boxSizingOffsetLR = boxMinus;
\r
435 delete this.contentWidthMin;
\r
436 delete this.contentWidthMax;
\r
437 delete this.boxWidthMin;
\r
438 delete this.boxWidthMax;
\r
440 this.contentWidthMin = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], allowedW ) + boxMinus );
\r
441 this.contentWidthMax = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], allowedW ) + boxMinus );
\r
442 this.boxWidthMin = this.contentWidthMin + this.contentL + this.contentR;
\r
443 this.boxWidthMax = this.contentWidthMax + this.contentL + this.contentR;
\r
444 this.contentWidth = this.contentWidthMin;
\r
445 this.boxWidth = this.boxWidthMin;
\r
446 this.boxSizingOffsetLR = boxMinus;
\r
449 paddingT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 0 ], allowedH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
450 paddingB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 2 ], allowedH );
\r
451 borderT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 0 ], allowedH );
\r
452 borderB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 2 ], allowedH );
\r
455 case 3 : // border-box
\r
456 boxMinus -= borderT + borderB;
\r
457 case 2 : // padding-box
\r
458 boxMinus -= paddingT + paddingB;
\r
459 // case 1 : // content-box
\r
461 this.contentT = borderT + paddingT;
\r
462 this.contentB = borderB + paddingB;
\r
463 this.paddingT = paddingT;
\r
464 this.borderT = borderT;
\r
467 if( this.constraintH ? allowedH !== XUI_Attr_AUTO : !this.autoHeight && ( allowedH !== XUI_Attr_AUTO || !this.percentHeight ) ){
\r
468 if( this.constraintH ){ // 制約レイアウト
\r
469 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
471 contentH = XUI_AbstractUINode_calcFinalValue( attrs[ XUI_Attr_Support.height.No ], attrs[ XUI_Attr_Support.minHeight.No ], attrs[ XUI_Attr_Support.maxHeight.No ], allowedH );
\r
473 this.contentHeight = contentH + boxMinus;
\r
474 this.boxHeight = this.contentHeight + this.contentT + this.contentB; // padding-box の場合 border だけ足される
\r
475 this.boxSizingOffsetTB = boxMinus;
\r
476 delete this.contentHeightMin;
\r
477 delete this.contentHeightMax;
\r
478 delete this.boxHeightMin;
\r
479 delete this.boxHeightMax;
\r
481 this.contentHeightMin = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], allowedH ) + boxMinus );
\r
482 this.contentHeightMax = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], allowedH ) + boxMinus );
\r
483 this.boxHeightMin = this.contentHeightMin + this.contentT + this.contentB;
\r
484 this.boxHeightMax = this.contentHeightMax + this.contentT + this.contentB;
\r
485 this.contentHeight = this.contentHeightMin;
\r
486 this.boxHeight = this.boxHeightMin;
\r
487 this.boxSizingOffsetTB = boxMinus;
\r
491 if( this.parentData && this.parentData.layout.overrideAttrsForChild.left ){
\r
492 if( this.constraintW || attrs[ XUI_Attr_Support.right.No ] === null ){
\r
493 this.boxX = ( boxL || boxL === 0 ) ? boxL : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.left.No ], allowedW );
\r
495 this.boxX = allowedW - this.boxWidth - ( ( boxR || boxR === 0 ) ? boxR : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.right.No ], allowedW ) );
\r
502 if( this.parentData && this.parentData.layout.overrideAttrsForChild.top ){
\r
503 if( this.constraintH || attrs[ XUI_Attr_Support.bottom.No ] === null ){
\r
504 this.boxY = ( boxT || boxT === 0 ) ? boxT : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.top.No ], allowedH );
\r
506 this.boxY = allowedH - this.boxHeight - ( ( boxB || boxB === 0 ) ? boxB : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.bottom.No ], allowedH ) );
\r
514 * 描画・計測を行って、contentSize の決定
\r
516 mesure : function(){
\r
517 var dirty = this.dirty,
\r
520 if( dirty === XUI_Dirty.CLEAN ){
\r
521 if( this.percentWidth || this.percentHeight ){
\r
528 case XUI_Dirty.CONTENT : // コンテンツが変更された
\r
529 case XUI_Dirty.FONT : // フォントサイズが変更された
\r
530 delete this.contentWidthLast;
\r
531 delete this.contentHeightLast;
\r
533 case XUI_Dirty.LAYOUT : // レイアウトの再計算が必要
\r
535 default : // TODO レイアウト指定が不正な場合 bgcolor を変更、これ以下のレイアウトの中止
\r
537 w = this.contentWidth;
\r
538 h = this.contentHeight;
\r
539 xnode = this.xnode;
\r
541 /* http://web-designs.seesaa.net/article/188400668.html
\r
542 * min-width の値が max-width の値より大きい場合は、max-width の値は min-width の値に設定される。
\r
545 * 1. contentWidth === AUTO
\r
546 * style を更新して contentWidth の決定
\r
547 * min or max に引っかかったら style 更新
\r
548 * contentHeight === AUTO の場合
\r
550 * contentHeight !== AUTO の場合 scrollHeight のみ更新
\r
551 * 2. contentHeight === AUTO かつ
\r
552 * コンテンツの高さの再取得が必要( contentWidth が最終計測時の contentWidth と一致 かつ フォント・コンテンツに変更無し の場合再取得不要)
\r
553 * style を更新して contentHeight の決定
\r
555 * 3. content のサイズがすでに決定している
\r
559 if( xnode[ '_xnodes' ] && xnode[ '_xnodes' ].length ){
\r
560 if( w === XUI_Attr_AUTO ){
\r
562 w = _w = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'width', 'auto' )[ 'clientWidth' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
564 if( this.contentWidthMax < w - this.boxSizingOffsetLR ){
\r
565 this.noWidth = false;
\r
566 w = this.contentWidthMax + this.boxSizingOffsetLR;
\r
568 if( w - this.boxSizingOffsetLR < this.contentWidthMin ){
\r
569 this.noWidth = false;
\r
570 w = this.contentWidthMin + this.boxSizingOffsetLR;
\r
573 if( h === XUI_Attr_AUTO ){
\r
574 w !== _w && xnode[ 'css' ]( 'width', w + 'em' );
\r
575 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
576 w !== _w && xnode[ 'css' ]( 'width', 'auto' );
\r
579 this.contentWidthLast = this.contentWidth = w;
\r
582 if( h === XUI_Attr_AUTO ){
\r
583 if( w !== this.contentWidthLast ){
\r
584 xnode[ 'css' ]( 'width', w + 'em' );
\r
585 this.contentWidthLast = w;
\r
587 // ie8 clientHeight, ff scrollHeight & clientHeight
\r
588 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
590 h = this.contentHeightLast === -1 ?
\r
591 XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) ) :
\r
592 this.contentHeightLast;
\r
595 if( dirty !== XUI_Dirty.LAYOUT ){
\r
596 this.contentWidth = this.contentWidthLast = w;
\r
597 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
600 if( this.contentHeightMax < h - this.boxSizingOffsetTB ){
\r
601 this.noHeight = false;
\r
602 h = this.contentHeightMax + this.boxSizingOffsetTB;
\r
604 if( h - this.boxSizingOffsetTB < this.contentHeightMin ){
\r
605 this.noHeight = false;
\r
606 h = this.contentHeightMin + this.boxSizingOffsetTB;
\r
609 this.contentHeight = this.contentHeightLast = h;
\r
612 // コンテンツを持たないため基本のサイズは0
\r
613 if( w === XUI_Attr_AUTO ) this.contentWidth = w = 0 < this.contentWidthMin ? this.contentWidthMin : 0;
\r
614 if( h === XUI_Attr_AUTO ) this.contentHeight = h = 0 < this.contentHeightMin ? this.contentHeightMin : 0;
\r
615 this.noWidth = this.noHeight = false;
\r
620 //case XUI_Dirty.PAINT : // 再描画のみ必要
\r
625 * 自身の contentWidth, contentHeight を元に AUTO な width, height を確定していく
\r
627 postMesure : function(){
\r
628 var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,
\r
629 box = attrs[ XUI_Attr_Support.sizing.No ],
\r
630 contentW, contentH,
\r
632 paddingT, paddingR, paddingB, paddingL,
\r
633 borderT, borderR, borderB, borderL,
\r
637 if( this.boxWidth === XUI_Attr_AUTO ){
\r
638 contentW = this.contentWidth;
\r
639 paddingR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 1 ], contentW );
\r
640 paddingL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 3 ], contentW );
\r
641 borderR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 1 ], contentW );
\r
642 borderL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 3 ], contentW );
\r
645 case 1 : // content-box
\r
646 contentPlus = paddingR + paddingL;
\r
647 case 2 : // padding-box
\r
648 contentPlus += borderR + borderL;
\r
649 // case 3 : // border-box
\r
652 if( !this.constraintW ){
\r
653 contentW += contentPlus;
\r
654 min = this.boxWidthMin = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], contentW );
\r
655 max = this.boxWidthMax = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], contentW );
\r
656 if( contentW < min && contentPlus < min ){
\r
657 this.contentWidth = min - contentPlus;
\r
659 if( max < contentW && contentPlus < max ){
\r
660 this.contentWidth = max - contentPlus;
\r
663 this.contentL = borderL + paddingL;
\r
664 this.contentR = borderR + paddingR;
\r
665 this.paddingL = paddingL;
\r
666 this.borderL = borderL;
\r
667 this.boxWidth = this.contentWidth + this.contentL + this.contentR;
\r
670 if( this.boxHeight === XUI_Attr_AUTO ){
\r
671 contentH = this.contentHeight;
\r
672 paddingT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 0 ], contentH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
673 paddingB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 2 ], contentH );
\r
674 borderT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 0 ], contentH );
\r
675 borderB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 2 ], contentH );
\r
678 case 1 : // content-box
\r
679 contentPlus = paddingT + paddingB;
\r
680 case 2 : // padding-box
\r
681 contentPlus += borderT + borderB;
\r
682 // case 3 : // border-box
\r
684 if( !this.constraintH ){
\r
685 contentH += contentPlus;
\r
686 min = this.boxHeightMin = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], contentH );
\r
687 max = this.boxHeightMax = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], contentH );
\r
688 if( contentH < min && contentPlus < min ){
\r
689 this.contentHeight = min - contentPlus;
\r
691 if( max < contentH && contentPlus < max ){
\r
692 this.contentHeight = max - contentPlus;
\r
695 this.contentT = borderT + paddingT;
\r
696 this.contentB = borderB + paddingB;
\r
697 this.paddingT = paddingT;
\r
698 this.borderT = borderT;
\r
699 this.boxHeight = this.contentHeight + this.contentT + this.contentB;
\r
703 // TODO fontsize が変わることもある
\r
704 capcher : function( x, y ){
\r
705 if( this.pointerDisabled ) return false;
\r
710 if( 0 <= x && x < this.boxWidth && 0 <= y && y < this.boxHeight ){
\r
711 !this.hovering && ( XUI_UINODES_HOVER[ XUI_UINODES_HOVER.length ] = this );
\r
712 XUI_uinodeTarget = this;
\r
713 //console.log( 'hit ' + this.xnode.className() )
\r
718 listen : XUI_$UINodeBase_listen,
\r
720 unlisten : XUI_$UINodeBase_unlisten,
\r
722 setItemData : function( itemData ){
\r
723 if( this.itemData === itemData ) return;
\r
725 this.itemData = itemData;
\r
727 this[ 'dispatch' ]( { type : XUI_Event.ITEMDATA_CHANGED, itemData : itemData } );
\r
728 // itemData && itemData.listen( X_Event_CHANGED )
\r
729 // dataFeild dataFormatter dataValidator
\r
731 // itemData.listen( X_Event_CHANGED ) -> this[ 'dispatch' ]( UI_Event.ITEMDATA_UPDATED );
\r
737 function XUI_AbstractUINode_createCssText( that, name ){
\r
738 var attrs = that.attrObject || that.attrClass.prototype || XUI_AttrClass,
\r
739 def = that.usableAttrs[ name ],
\r
741 v = attrs[ def.No ],
\r
744 flag = !!( type & XUI_Attr_Type.BOOLEAN ),
\r
745 combi = !!( type & XUI_Attr_Type.COMBI ),
\r
746 quartet = !!( type & XUI_Attr_Type.QUARTET );
\r
749 if( attrs[ no + 1 ] === attrs[ no + 3 ] ){
\r
750 if( v === attrs[ no + 2 ] ){
\r
751 if( v === attrs[ no + 1 ] ){
\r
752 return XUI_AbstractUINode_createCssValue( v, type, list );
\r
755 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
756 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list )
\r
760 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
761 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list ),
\r
762 XUI_AbstractUINode_createCssValue( attrs[ no + 2 ], type, list )
\r
766 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
767 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list ),
\r
768 XUI_AbstractUINode_createCssValue( attrs[ no + 2 ], type, list ),
\r
769 XUI_AbstractUINode_createCssValue( attrs[ no + 3 ], type, list )
\r
774 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
775 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list )
\r
779 return v ? list : 'normal'; //
\r
781 return XUI_AbstractUINode_createCssValue( v, type, list );
\r
784 function XUI_AbstractUINode_createCssValue( v, type, list ){
\r
785 var length = !!( type & XUI_Attr_Type.LENGTH ),
\r
786 minusLen = !!( type & XUI_Attr_Type.MINUS_LENGTH ),
\r
787 percent = !!( type & XUI_Attr_Type.PERCENT ),
\r
788 minusPct = !!( type & XUI_Attr_Type.MINUS_PERCENT ),
\r
789 numerical = !!( type & XUI_Attr_Type.NUMERICAL ),
\r
790 auto = !!( type & XUI_Attr_Type.AUTO ),
\r
791 color = !!( type & XUI_Attr_Type.COLOR ),
\r
792 url = !!( type & XUI_Attr_Type.URL ),
\r
793 fontName = !!( type & XUI_Attr_Type.FONT_NAME );
\r
795 if( X_Type_isNumber( v ) ){
\r
796 if( auto && v === XUI_Attr_AUTO ) return 'auto';
\r
797 if( length || minusLen ) return v ? v + 'em' : 0;
\r
798 if( numerical ) return v;
\r
799 if( list && list[ v ] ) return list[ v ];
\r
801 if( v < 0x100000 ){
\r
802 v = '00000' + v.toString( 16 );
\r
803 return '#' + v.substr( v.length - 6 );
\r
805 if( v !== v ){ // iSNaN
\r
808 return '#' + v.toString( 16 );
\r
811 if( X_Type_isString( v ) ){
\r
812 if( percent || minusPct || url || fontName ) return v;
\r
816 function XUI_AbstractUINode_calcValue( styleValue, srcValue ){
\r
820 if( X_Type_isString( styleValue ) ){
\r
821 return srcValue * parseFloat( styleValue ) / 100;
\r
823 if( !X_Type_isNumber( styleValue ) ) return 0;
\r
827 function XUI_AbstractUINode_calcFinalValue( styleValue, styleMin, styleMax, srcValue ){
\r
828 var v = XUI_AbstractUINode_calcValue( styleValue, srcValue ),
\r
829 min = XUI_AbstractUINode_calcValue( styleMin, srcValue ),
\r
830 max = XUI_AbstractUINode_calcValue( styleMax, srcValue );
\r
831 return v <= min ? min : max <= v ? max : v;
\r
833 function XUI_AbstractUINode_ceil( v ){
\r
835 return ( v * 10 + 0.999 | 0 ) / 10;
\r
837 return ( -v * 10 + 0.999 | 0 ) / -10;
\r
840 X.UI.AbstractUINode = X_Class_create(
\r
844 parent : function(){
\r
845 return X_Pair_get( this ).parent;
\r
848 return X_Pair_get( this ).root;
\r
852 * unverifiedAttrs に全ての指定を控える
\r
853 * サポートされていない場合は無視される.親のレイアウトによって変わる
\r
855 attr : function( nameOrObject, valueOrUnit ){
\r
856 var p = X_Pair_get( this ),
\r
857 layout, k, def, attrs, v;
\r
858 if( nameOrObject && X_Type_isObject( nameOrObject ) ){
\r
860 layout = p.parentData && p.parentData.layout.overrideAttrsForChild; // root には parent がない
\r
861 for( k in nameOrObject ){
\r
862 if( X_EMPTY_OBJECT[ k ] ) continue;
\r
863 // 親のレイアウトマネージャの許可しない
\r
864 if( layout && !layout[ k ] ){
\r
867 if( def = p.usableAttrs[ k ] ){
\r
868 p.setAttr( k, def, nameOrObject[ k ] );
\r
872 if( X_Type_isString( nameOrObject ) && ( def = p.usableAttrs[ nameOrObject ] ) ){
\r
873 if( valueOrUnit !== undefined ){
\r
874 if( 'em,%'.indexOf( valueOrUnit ) === -1 ){
\r
876 p.setAttr( nameOrObject, def, valueOrUnit );
\r
878 // getter with unit
\r
879 return p.getAttrWithUnit( nameOrObject, valueOrUnit );
\r
883 if( attrs = ( p.attrObject || p.attrClass.prototype || XUI_AttrClass ) ){
\r
884 def = p.usableAttrs[ nameOrObject ];
\r
885 return def && attrs[ def.No ];
\r
892 listen : function( type, arg1, arg2, arg3 ){
\r
893 var pair = X_Pair_get( this );
\r
895 ( !arg1 || !arg1.cbKind ) && ( arg1 = X_Closure_classifyCallbackArgs( arg1, arg2, arg3, this ) );
\r
897 if( arg1.cbKind === X_CLOSURE_FUNC_ONLY ){
\r
898 pair[ 'listen' ].apply( pair, [ type, this, arg1.func, arg1.supplement ] );
\r
900 pair[ 'listen' ]( type, arg1.context, arg1.func, arg1.supplement );
\r
904 listenOnce : function( type, arg1, arg2, arg3 ){
\r
905 X_Pair_get( this )[ 'listenOnce' ]( type, arg1, arg2, arg3 );
\r
908 listening : function( type, arg1, arg2, arg3 ){
\r
909 return X_Pair_get( this )[ 'listening' ]( type, arg1, arg2, arg3 );
\r
911 unlisten : function( type, arg1, arg2, arg3 ){
\r
912 var pair = X_Pair_get( this );
\r
914 ( !arg1 || !arg1.cbKind ) && ( arg1 = X_Closure_classifyCallbackArgs( arg1, arg2, arg3, this ) );
\r
916 if( arg1.cbKind === X_CLOSURE_FUNC_ONLY ){
\r
917 pair[ 'unlisten' ].apply( pair, [ type, this, arg1.func, arg1.supplement ] );
\r
919 pair[ 'unlisten' ]( type, arg1.context, arg1.func, arg1.supplement );
\r
923 dispatch : function( e ){
\r
924 return X_Pair_get( this )[ 'dispatch' ]( e );
\r
927 nextNode : function(){
\r
930 prevNode : function(){
\r
933 nodeIndex : function( v ){
\r
934 var data = X_Pair_get( this );
\r
935 if( typeof v === 'number' ){
\r
936 // data.nodeIndex( v );
\r
939 return data.parentData ? data.parentData.nodes.indexOf( data ) : 0;
\r
941 displayIndex : function(){
\r
945 // dirty の場合、rootData.calculate
\r
946 return X_Pair_get( this ).boxX;
\r
949 // dirty の場合、rootData.calculate
\r
950 return X_Pair_get( this ).boxY;
\r
952 getAbsoluteX : function(){
\r
953 // dirty の場合、rootData.calculate
\r
954 return X_Pair_get( this ).absoluteX;
\r
956 getAbsoluteY: function(){
\r
957 // dirty の場合、rootData.calculate
\r
958 return X_Pair_get( this ).absoluteY;
\r
960 getWidth : function(){
\r
961 // dirty の場合、rootData.calculate
\r
962 return X_Pair_get( this ).boxWidth;
\r
964 getHeight : function(){
\r
965 // dirty の場合、rootData.calculate
\r
966 return X_Pair_get( this ).boxHeight;
\r
970 * Repeater に於いて、繰り返されるアイテムの元(itemRenderer)からの複製に使用
\r
972 clone : function( opt_cloneListener ){
\r
974 //newPair = X_Pair_get( newNode ),
\r
975 pair = X_Pair_get( this ),
\r
976 attr, listeners, type, list, i, l, k, def, f;
\r
979 if( pair.attrObject ){
\r
981 for( k in pair.usableAttrs ){
\r
982 def = pair.usableAttrs[ k ];
\r
983 attr[ k ] = pair.attrObject[ def.No ];
\r
985 newNode = this.constructor( attr );
\r
988 // handleEvent 等の拡張されたオブジェクトもコピーする!
\r
990 if( this[ k ] !== newNode[ k ] && !newNode[ k ] ) newNode[ k ] = this[ k ];
\r
993 // User.UINODE な値は pair にコピーされているのでこれをコピー
\r
995 //pair[ k ] !== newPair[ k ] && !newPair[ k ] && console.log( k );
\r
996 //if( pair[ k ] !== newPair[ k ] && !newPair[ k ] && k !== 'attrObject' && k !== '_listeners' ){
\r
997 //newPair[ k ] = pair[ k ];
\r
998 //console.log( k );
\r
1004 // listener もコピーする!
\r
1005 if( opt_cloneListener && ( listeners = pair[ '_listeners' ] ) ){
\r
1006 for( type in listeners ){
\r
1007 list = listeners[ type ];
\r
1008 for( i = 0, l = list.length; i < l; ++i ){
\r
1010 switch( f.cbKind ){
\r
1011 case X_CLOSURE_THIS_FUNC :
\r
1012 newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.context === this ? newNode : f.context, f.func, f.supplement );
\r
1014 case X_CLOSURE_HANDLEEVENT :
\r
1015 newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.context === this ? newNode : f.context, f.supplement );
\r
1018 case X_CLOSURE_FUNC_ONLY :
\r
1020 newNode[ 'listen' ]( type, f.func, f.supplement );
\r
1022 newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.func, f.supplement );
\r
1026 newNode[ 'listen' ]( type, f );
\r
1032 if( opt_cloneListener && ( list = this.reserveEvents ) ){
\r
1033 for( i = 0, l = list.length; i < l; ++i ){
\r
1035 newNode[ f.once ? 'listenOnce' : 'listen' ]( f[ 0 ], newNode, f[ 1 ], f[ 2 ] );
\r