1 // TODO -> Node[ 'inherits' ]
\r
2 var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ](
\r
3 'X.UI._AbstractUINode',
\r
7 dirty : XUI_Dirty.CLEAN,
\r
16 usableAttrs : XUI_Attr_Support,
\r
17 attrClass : XUI_AttrClass,
\r
19 unverifiedAttrs : null,
\r
22 pointerDisabled : false,
\r
23 hoverClassName : null,
\r
26 reserveEvents : null,
\r
34 boxWidth : XUI_Attr_AUTO,
\r
36 boxWidthMax : XUI_Attr_AUTO,
\r
37 boxHeight : XUI_Attr_AUTO,
\r
39 boxHeightMax : XUI_Attr_AUTO,
\r
48 boxSizingOffsetLR : 0,
\r
49 boxSizingOffsetTB : 0,
\r
50 contentWidth : XUI_Attr_AUTO,
\r
51 contentWidthMin : 0,
\r
52 contentWidthMax : XUI_Attr_AUTO,
\r
53 contentWidthLast : -1,
\r
54 contentHeight : XUI_Attr_AUTO,
\r
55 contentHeightMin : 0,
\r
56 contentHeightMax : XUI_Attr_AUTO,
\r
57 contentHeightLast : -1,
\r
59 constraintW : false,
\r
60 constraintH : false,
\r
65 percentWidth : false,
\r
66 percentHeight : false,
\r
67 // :hover, :focus, :disabled
\r
69 initialize : function( root, rootData, parent, parentData ){
\r
71 this.rootData = rootData;
\r
72 this.parent = parent;
\r
73 this.parentData = parentData;
\r
76 this[ 'dispatch' ]( XUI_Event.INIT );
\r
79 addToParent : function( xnodeParent ){
\r
80 xnodeParent && xnodeParent[ 'append' ]( this.xnode );
\r
83 this[ 'dispatch' ]( XUI_Event.ADDED );
\r
86 creationComplete : function(){
\r
87 var events = this.reserveEvents,
\r
91 this.User[ 'dispatch' ]( XUI_Event.CREATION_COMPLETE );
\r
93 // html 要素が親に追加されるまで控えていたイベントの登録
\r
94 if( events && ( l = events.length ) ){
\r
95 for( i = 0; i < l; ++i ){
\r
96 this.listen.apply( this, events[ i ] );
\r
99 delete this.reserveEvents;
\r
104 * _UINode への setAttr の他、attrClass.prototype への setAttr にも対応する
\r
105 * 親要素が変化した場合、unverifiedAttrs を元に attrObject を再設定.
\r
107 setAttr : function( name, def, v ){
\r
108 var attrs = XUI_attrClassProto || this.attrObject,
\r
109 propID = def.No || def[ 5 ],
\r
110 defaultVal = XUI_attrClassProto ? attrs[ propID ] : this.attrClass.prototype[ propID ], // def[ 0 ],
\r
111 currentVal = attrs ? attrs[ propID ] : defaultVal,
\r
116 length = !!( type & XUI_Attr_Type.LENGTH ),
\r
117 minusLen = !!( type & XUI_Attr_Type.MINUS_LENGTH ),
\r
118 percent = !!( type & XUI_Attr_Type.PERCENT ),
\r
119 minusPct = !!( type & XUI_Attr_Type.MINUS_PERCENT ),
\r
120 numerical = !!( type & XUI_Attr_Type.NUMERICAL ),
\r
121 auto = !!( type & XUI_Attr_Type.AUTO ),
\r
122 color = !!( type & XUI_Attr_Type.COLOR ),
\r
123 url = !!( type & XUI_Attr_Type.URL ),
\r
124 fontName = !!( type & XUI_Attr_Type.FONT_NAME ),
\r
125 flag = !!( type & XUI_Attr_Type.BOOLEAN ),
\r
126 combi = !!( type & XUI_Attr_Type.COMBI ),
\r
127 quartet = !!( type & XUI_Attr_Type.QUARTET ),
\r
128 _v, i, l, nodes, root, roots;
\r
130 if( X_Type_isString( v ) ){
\r
131 //v = v.toLowercase();
\r
132 if( url || fontName ){
\r
135 if( auto && v === 'auto' ){
\r
138 if( list && ( _v = list[ v ] ) ){
\r
140 console.log( v + ' ' + _v );
\r
143 if( ( percent || minusPct ) && v.lastIndexOf( '%' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + '%' ){
\r
146 if( ( length || minusLen ) && v.lastIndexOf( 'em' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + 'em' ){
\r
149 if( v.indexOf( ' ' ) !== -1 ){
\r
150 v = v.split( ' ' );
\r
152 if( color && X_Type_isNumber( _v = X_Node_CSS_objToIEFilterText( v ) ) ){
\r
160 if( ( quartet || combi ) && !X_Type_isArray( v ) ){
\r
164 if( X_Type_isNumber( v ) ){
\r
166 ( length && ( 0 <= v ) ) ||
\r
167 ( minusLen && ( v <= 0 ) ) ||
\r
168 ( percent && 0 <= v && v <= 1 ) ||
\r
169 ( minusPct && -1 <= v && v < 0 ) ||
\r
170 ( numerical && 0 <= v ) ||
\r
171 ( auto && v === XUI_Attr_AUTO ) ||
\r
172 ( color && 0 <= v && v <= 0xFFFFFF ) ||
\r
173 ( list && list[ v ] )
\r
181 if( X_Type_isBoolean( v ) && !flag ){
\r
184 if( X_Type_isArray( v ) ){
\r
185 if( v.length <= 4 && quartet ){
\r
186 type &= ~XUI_Attr_Type.QUARTET;
\r
187 switch( v.length ){
\r
189 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
190 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
191 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
192 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
195 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
196 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
197 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
198 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
201 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
202 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
203 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\r
204 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
207 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
208 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
209 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\r
210 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 3 ] );
\r
214 if( v.length === 2 && combi ){
\r
215 type &= ~XUI_Attr_Type.COMBI;
\r
216 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
217 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
223 if( !XUI_attrClassProto && user === XUI_Attr_USER.XNODE && this.xnode ){
\r
224 this.xnode[ 'css' ]( XUI_Attr_Rename[ name ] || name, XUI_AbstractUINode_createCssText( this, name ) );
\r
225 //console.log( ( XUI_Attr_Rename[ name ] || name ) + ' ' + XUI_AbstractUINode_createCssText( this, name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
230 if( !v && v !== 0 ) v = defaultVal;
\r
232 if( XUI_attrClassProto ){
\r
233 attrs[ propID ] = v;
\r
237 if( currentVal !== v ){
\r
239 case XUI_Attr_Support.left.No :
\r
240 this.constraintW = attrs[ XUI_Attr_Support.right.No ] !== null;
\r
242 case XUI_Attr_Support.right.No :
\r
243 this.constraintW = attrs[ XUI_Attr_Support.left.No ] !== null;
\r
245 case XUI_Attr_Support.top.No :
\r
246 this.constraintH = attrs[ XUI_Attr_Support.bottom.No ] !== null;
\r
248 case XUI_Attr_Support.bottom.No :
\r
249 this.constraintH = attrs[ XUI_Attr_Support.top.No ] !== null;
\r
251 case XUI_Attr_Support.width.No :
\r
252 this.autoWidth = v === XUI_Attr_AUTO;
\r
253 this.percentWidth = X_Type_isString( v );
\r
255 case XUI_Attr_Support.height.No :
\r
256 this.autoHeight = v === XUI_Attr_AUTO;
\r
257 this.percentHeight = X_Type_isString( v );
\r
261 if( defaultVal === v ){
\r
262 if( attrs ) delete attrs[ propID ];
\r
264 if( !attrs ) attrs = this.attrObject = new this.attrClass;
\r
265 attrs[ propID ] = v;
\r
268 if( name && user === XUI_Attr_USER.UINODE ){
\r
272 if( name && user === XUI_Attr_USER.XNODE && this.xnode ){
\r
273 this.xnode[ 'css' ]( XUI_Attr_Rename[ name ] || name, XUI_AbstractUINode_createCssText( this, name ) );
\r
274 //console.log( ( XUI_Attr_Rename[ name ] || name ) + ' ' + XUI_AbstractUINode_createCssText( this, name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
276 if( this.dirty < dirty ) this.dirty = dirty;
\r
280 getAttr : function( name ){
\r
281 var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,
\r
282 support = this.usableAttrs[ name ],
\r
284 if( !support ) return;
\r
286 if( name.indexOf( 'border' ) === 0 ){
\r
287 name = name.substr( 6 );
\r
288 return [ this.getAttr( 'borderTop' + name ), this.getAttr( 'borderRight' + name ), this.getAttr( 'borderBottom' + name ), this.getAttr( 'borderLeft' + name ) ];
\r
291 type = support[ 3 ];
\r
293 if( type & XUI_Attr_Type.QUARTET ){
\r
294 return [ this.getAttr( name + 'Top' ), this.getAttr( name + 'Right' ), this.getAttr( name + 'Bottom' ), this.getAttr( name + 'Left' ) ];
\r
296 if( type & XUI_Attr_Type.COMBI ) return [ v, data[ ++propID ] ];
\r
298 v = attrs[ support.No ];
\r
299 if( type & XUI_Attr_Type.AUTO && v === XUI_Attr_AUTO ) return 'auto';
\r
301 list = support[ 4 ];
\r
302 if( list ) return list[ v ];
\r
304 if( type & XUI_Attr_Type.COLOR && X_Type_isNumber( v ) ) return v;
\r
305 if( !( type & XUI_Attr_Type.NUMERICAL ) && X_Type_isNumber( v ) ) return v + 'em';
\r
310 getAttrWithUnit : function( prop, unit ){
\r
314 _remove : function(){
\r
315 switch( this.phase ){
\r
322 this.xnode[ 'kill' ]();
\r
325 delete this.rootData;
\r
326 delete this.parent;
\r
327 delete this.parentData;
\r
336 calculate : function( isNeedsDetection, x, y, allowedW, allowedH ){
\r
337 this.preMesure( allowedW, allowedH );
\r
339 this.noWidth = this.boxWidth === XUI_Attr_AUTO;
\r
340 this.noHeight = this.boxHeight === XUI_Attr_AUTO;
\r
342 if( this.noWidth || this.noHeight ){
\r
347 if( !isNeedsDetection ){
\r
354 * X_Node_BoxModel の情報を引きながら top,left,width,height,padding,border の設定
\r
356 updateLayout : function(){
\r
357 var x = this.boxX + ( this.parentData ? this.parentData.paddingL : 0 ),
\r
358 y = this.boxY + ( this.parentData ? this.parentData.paddingT : 0 ),
\r
359 w = X_UA[ 'IE5x' ] ? this.boxWidth : this.contentWidth, // IE6 の互換モードも
\r
360 h = X_UA[ 'IE5x' ] ? this.boxHeight : this.contentHeight;
\r
363 [ 'css' ]( 'left', x ? x + 'em' : 0 ) // 親の padding 分ずらす
\r
364 [ 'css' ]( 'top', y ? y + 'em' : 0 ) // 親の padding 分ずらす
\r
365 [ 'css' ]( 'width', this.noWidth ? 'auto' : w ? w + 'em' : 0 )
\r
366 [ 'css' ]( 'height', this.noHeight ? 'auto' : h ? h + 'em' : 0 )
\r
367 [ 'css' ]( 'padding', XUI_AbstractUINode_createCssText( this, 'padding' ) ) // TODO 不要? その分 w, h に足す
\r
368 [ 'css' ]( 'borderWidth', XUI_AbstractUINode_createCssText( this, 'borderWidth' ) );
\r
372 * 親の サイズを元に自身のサイズを計算していく
\r
374 preMesure : function( allowedW, allowedH ){
\r
375 var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,
\r
376 box = attrs[ XUI_Attr_Support.sizing.No ],
\r
378 boxL, boxT, boxR, boxB,
\r
379 contentW, contentH, boxMinus,
\r
380 paddingT, paddingR, paddingB, paddingL,
\r
381 borderT, borderR, borderB, borderL;
\r
384 // 自身が constraintW の場合 親が AUTO ではない
\r
385 // 自身が constraintW でない場合自身が AUTO はなくかつ親 が AUTO の場合 or 自身は % でない
\r
387 paddingR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 1 ], allowedW );
\r
388 paddingL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 3 ], allowedW );
\r
389 borderR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 1 ], allowedW );
\r
390 borderL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 3 ], allowedW );
\r
393 case 3 : // border-box
\r
394 boxMinus -= borderR + borderL;
\r
395 case 2 : // padding-box
\r
396 boxMinus -= paddingR + paddingL;
\r
397 // case 1 : // content-box
\r
399 this.contentL = borderL + paddingL;
\r
400 this.contentR = borderR + paddingR;
\r
401 this.paddingL = paddingL;
\r
402 this.borderL = borderL;
\r
404 if( this.constraintW ? allowedW !== XUI_Attr_AUTO : !this.autoWidth && ( allowedW !== XUI_Attr_AUTO || !this.percentWidth ) ){
\r
405 if( this.constraintW ){ // 制約レイアウト
\r
406 contentW = allowedW - ( boxL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.left.No ], allowedW ) ) - ( boxR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.right.No ], allowedW ) );
\r
408 contentW = XUI_AbstractUINode_calcFinalValue( attrs[ XUI_Attr_Support.width.No ], attrs[ XUI_Attr_Support.minWidth.No ], attrs[ XUI_Attr_Support.maxWidth.No ], allowedW );
\r
410 this.contentWidth = contentW + boxMinus;
\r
411 this.boxWidth = this.contentWidth + this.contentL + this.contentR;
\r
412 this.boxSizingOffsetLR = boxMinus;
\r
413 delete this.contentWidthMin;
\r
414 delete this.contentWidthMax;
\r
415 delete this.boxWidthMin;
\r
416 delete this.boxWidthMax;
\r
418 this.contentWidthMin = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], allowedW ) + boxMinus );
\r
419 this.contentWidthMax = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], allowedW ) + boxMinus );
\r
420 this.boxWidthMin = this.contentWidthMin + this.contentL + this.contentR;
\r
421 this.boxWidthMax = this.contentWidthMax + this.contentL + this.contentR;
\r
422 this.contentWidth = this.contentWidthMin;
\r
423 this.boxWidth = this.boxWidthMin;
\r
424 this.boxSizingOffsetLR = boxMinus;
\r
427 paddingT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 0 ], allowedH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
428 paddingB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 2 ], allowedH );
\r
429 borderT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 0 ], allowedH );
\r
430 borderB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 2 ], allowedH );
\r
433 case 3 : // border-box
\r
434 boxMinus -= borderT + borderB;
\r
435 case 2 : // padding-box
\r
436 boxMinus -= paddingT + paddingB;
\r
437 // case 1 : // content-box
\r
439 this.contentT = borderT + paddingT;
\r
440 this.contentB = borderB + paddingB;
\r
441 this.paddingT = paddingT;
\r
442 this.borderT = borderT;
\r
445 if( this.constraintH ? allowedH !== XUI_Attr_AUTO : !this.autoHeight && ( allowedH !== XUI_Attr_AUTO || !this.percentHeight ) ){
\r
446 if( this.constraintH ){ // 制約レイアウト
\r
447 contentH = allowedH - ( boxT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.top.No ], allowedH ) ) - ( boxB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.bottom.No ], allowedH ) );
\r
449 contentH = XUI_AbstractUINode_calcFinalValue( attrs[ XUI_Attr_Support.height.No ], attrs[ XUI_Attr_Support.minHeight.No ], attrs[ XUI_Attr_Support.maxHeight.No ], allowedH );
\r
451 this.contentHeight = contentH + boxMinus;
\r
452 this.boxHeight = this.contentHeight + this.contentT + this.contentB; // padding-box の場合 border だけ足される
\r
453 this.boxSizingOffsetTB = boxMinus;
\r
454 delete this.contentHeightMin;
\r
455 delete this.contentHeightMax;
\r
456 delete this.boxHeightMin;
\r
457 delete this.boxHeightMax;
\r
459 this.contentHeightMin = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], allowedH ) + boxMinus );
\r
460 this.contentHeightMax = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], allowedH ) + boxMinus );
\r
461 this.boxHeightMin = this.contentHeightMin + this.contentT + this.contentB;
\r
462 this.boxHeightMax = this.contentHeightMax + this.contentT + this.contentB;
\r
463 this.contentHeight = this.contentHeightMin;
\r
464 this.boxHeight = this.boxHeightMin;
\r
465 this.boxSizingOffsetTB = boxMinus;
\r
469 if( this.parentData && this.parentData.layout.overrideAttrsForChild.left ){
\r
470 if( this.constraintW || attrs[ XUI_Attr_Support.right.No ] === null ){
\r
471 this.boxX = ( boxL || boxL === 0 ) ? boxL : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.left.No ], allowedW );
\r
473 this.boxX = allowedW - this.boxWidth - ( ( boxR || boxR === 0 ) ? boxR : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.right.No ], allowedW ) );
\r
480 if( this.parentData && this.parentData.layout.overrideAttrsForChild.top ){
\r
481 if( this.constraintH || attrs[ XUI_Attr_Support.bottom.No ] === null ){
\r
482 this.boxY = ( boxT || boxT === 0 ) ? boxT : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.top.No ], allowedH );
\r
484 this.boxY = allowedH - this.boxHeight - ( ( boxB || boxB === 0 ) ? boxB : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.bottom.No ], allowedH ) );
\r
492 * 描画・計測を行って、contentSize の決定
\r
494 mesure : function(){
\r
495 var dirty = this.dirty,
\r
498 if( dirty === XUI_Dirty.CLEAN ){
\r
499 if( this.percentWidth || this.percentHeight ){
\r
506 case XUI_Dirty.CONTENT : // コンテンツが変更された
\r
507 case XUI_Dirty.FONT : // フォントサイズが変更された
\r
508 delete this.contentWidthLast;
\r
509 delete this.contentHeightLast;
\r
511 case XUI_Dirty.LAYOUT : // レイアウトの再計算が必要
\r
513 default : // TODO レイアウト指定が不正な場合 bgcolor を変更、これ以下のレイアウトの中止
\r
515 w = this.contentWidth;
\r
516 h = this.contentHeight;
\r
517 xnode = this.xnode;
\r
519 /* http://web-designs.seesaa.net/article/188400668.html
\r
520 * min-width の値が max-width の値より大きい場合は、max-width の値は min-width の値に設定される。
\r
523 * 1. contentWidth === AUTO
\r
524 * style を更新して contentWidth の決定
\r
525 * min or max に引っかかったら style 更新
\r
526 * contentHeight === AUTO の場合
\r
528 * contentHeight !== AUTO の場合 scrollHeight のみ更新
\r
529 * 2. contentHeight === AUTO かつ
\r
530 * コンテンツの高さの再取得が必要( contentWidth が最終計測時の contentWidth と一致 かつ フォント・コンテンツに変更無し の場合再取得不要)
\r
531 * style を更新して contentHeight の決定
\r
533 * 3. content のサイズがすでに決定している
\r
537 if( xnode[ '_xnodes' ] && xnode[ '_xnodes' ].length ){
\r
538 if( w === XUI_Attr_AUTO ){
\r
540 w = _w = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'width', 'auto' )[ 'clientWidth' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
542 if( this.contentWidthMax < w - this.boxSizingOffsetLR ){
\r
543 this.noWidth = false;
\r
544 w = this.contentWidthMax + this.boxSizingOffsetLR;
\r
546 if( w - this.boxSizingOffsetLR < this.contentWidthMin ){
\r
547 this.noWidth = false;
\r
548 w = this.contentWidthMin + this.boxSizingOffsetLR;
\r
551 if( h === XUI_Attr_AUTO ){
\r
552 w !== _w && xnode[ 'css' ]( 'width', w + 'em' );
\r
553 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
554 w !== _w && xnode[ 'css' ]( 'width', 'auto' );
\r
557 this.contentWidthLast = this.contentWidth = w;
\r
560 if( h === XUI_Attr_AUTO ){
\r
561 if( w !== this.contentWidthLast ){
\r
562 xnode[ 'css' ]( 'width', w + 'em' );
\r
563 this.contentWidthLast = w;
\r
565 // ie8 clientHeight, ff scrollHeight & clientHeight
\r
566 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
568 h = this.contentHeightLast === -1 ?
\r
569 XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) ) :
\r
570 this.contentHeightLast;
\r
573 if( dirty !== XUI_Dirty.LAYOUT ){
\r
574 this.contentWidth = this.contentWidthLast = w;
\r
575 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
578 if( this.contentHeightMax < h - this.boxSizingOffsetTB ){
\r
579 this.noHeight = false;
\r
580 h = this.contentHeightMax + this.boxSizingOffsetTB;
\r
582 if( h - this.boxSizingOffsetTB < this.contentHeightMin ){
\r
583 this.noHeight = false;
\r
584 h = this.contentHeightMin + this.boxSizingOffsetTB;
\r
587 this.contentHeight = this.contentHeightLast = h;
\r
590 // コンテンツを持たないため基本のサイズは0
\r
591 if( w === XUI_Attr_AUTO ) this.contentWidth = w = 0 < this.contentWidthMin ? this.contentWidthMin : 0;
\r
592 if( h === XUI_Attr_AUTO ) this.contentHeight = h = 0 < this.contentHeightMin ? this.contentHeightMin : 0;
\r
593 this.noWidth = this.noHeight = false;
\r
598 //case XUI_Dirty.PAINT : // 再描画のみ必要
\r
603 * 自身の contentWidth, contentHeight を元に AUTO な width, height を確定していく
\r
605 postMesure : function(){
\r
606 var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,
\r
607 box = attrs[ XUI_Attr_Support.sizing.No ],
\r
608 contentW, contentH,
\r
610 paddingT, paddingR, paddingB, paddingL,
\r
611 borderT, borderR, borderB, borderL,
\r
615 if( this.boxWidth === XUI_Attr_AUTO ){
\r
616 contentW = this.contentWidth;
\r
617 paddingR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 1 ], contentW );
\r
618 paddingL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 3 ], contentW );
\r
619 borderR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 1 ], contentW );
\r
620 borderL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 3 ], contentW );
\r
623 case 1 : // content-box
\r
624 contentPlus = paddingR + paddingL;
\r
625 case 2 : // padding-box
\r
626 contentPlus += borderR + borderL;
\r
627 // case 3 : // border-box
\r
630 if( !this.constraintW ){
\r
631 contentW += contentPlus;
\r
632 min = this.boxWidthMin = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], contentW );
\r
633 max = this.boxWidthMax = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], contentW );
\r
634 if( contentW < min && contentPlus < min ){
\r
635 this.contentWidth = min - contentPlus;
\r
637 if( max < contentW && contentPlus < max ){
\r
638 this.contentWidth = max - contentPlus;
\r
641 this.contentL = borderL + paddingL;
\r
642 this.contentR = borderR + paddingR;
\r
643 this.paddingL = paddingL;
\r
644 this.borderL = borderL;
\r
645 this.boxWidth = this.contentWidth + this.contentL + this.contentR;
\r
648 if( this.boxHeight === XUI_Attr_AUTO ){
\r
649 contentH = this.contentHeight;
\r
650 paddingT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 0 ], contentH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
651 paddingB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 2 ], contentH );
\r
652 borderT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 0 ], contentH );
\r
653 borderB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 2 ], contentH );
\r
656 case 1 : // content-box
\r
657 contentPlus = paddingT + paddingB;
\r
658 case 2 : // padding-box
\r
659 contentPlus += borderT + borderB;
\r
660 // case 3 : // border-box
\r
662 if( !this.constraintH ){
\r
663 contentH += contentPlus;
\r
664 min = this.boxHeightMin = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], contentH );
\r
665 max = this.boxHeightMax = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], contentH );
\r
666 if( contentH < min && contentPlus < min ){
\r
667 this.contentHeight = min - contentPlus;
\r
669 if( max < contentH && contentPlus < max ){
\r
670 this.contentHeight = max - contentPlus;
\r
673 this.contentT = borderT + paddingT;
\r
674 this.contentB = borderB + paddingB;
\r
675 this.paddingT = paddingT;
\r
676 this.borderT = borderT;
\r
677 this.boxHeight = this.contentHeight + this.contentT + this.contentB;
\r
681 // TODO fontsize が変わることもある
\r
682 capcher : function( x, y ){
\r
683 if( this.pointerDisabled ) return false;
\r
688 if( 0 <= x && x < this.boxWidth && 0 <= y && y < this.boxHeight ){
\r
689 !this.hovering && ( this.rootData.hoverList[ this.rootData.hoverList.length ] = this );
\r
690 this.rootData.targetNodeData = this;
\r
696 * context を明示しない場合、User が context になる!
\r
698 listen : function( type, arg1, arg2, arg3 ){
\r
699 var root, events, counter, f;
\r
701 if( XUI_Event._START_POINTER <= type && type <= XUI_Event._END_POINTER ){
\r
702 if( this.phase < 3 ){
\r
703 if( !( events = this.reserveEvents ) ) this.reserveEvents = events = [];
\r
704 events[ events.length ] = [ type, arg1, arg2, arg3 ];
\r
707 if( XUI_Event._START_XUI_EVENT < type && type < XUI_Event._END_XUI_EVENT ){
\r
708 if( !this.gesture ){
\r
709 this.gesture = new Hammer( this.rootData, this, type );
\r
711 this.gesture[ 'listen' ]( type );
\r
714 //console.log( type );
\r
715 root = this.rootData;
\r
716 counter = root.eventCounter;
\r
717 if( counter[ type ] ){
\r
720 counter[ type ] = 1;
\r
721 root.xnodeInteractiveLayer[ 'listen' ]( XUI_Event.IdToName[ type ], X_UI_eventRellay );
\r
726 arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 ) );
\r
728 return X_EventDispatcher_listen.call( this, type, this.User, f );
\r
730 if( f.kind === X_Callback_FUNC_ONLY ){
\r
731 return X_EventDispatcher_listen.call( this, type, this.User, f.func, f.supplement );
\r
733 return X_EventDispatcher_listen.apply( this, arguments );
\r
735 unlisten : function( type, arg1, arg2, arg3 ){
\r
736 var root, events, i, ev, counter, f;
\r
737 if( XUI_Event._START_POINTER <= type && type <= XUI_Event._END_POINTER ){
\r
738 if( this.phase < 3 ){
\r
739 if( !( events = this.reserveEvents ) ) return this;
\r
740 for( i = events.length; i; ){
\r
741 ev = events[ --i ];
\r
742 if( ev[ 0 ] === type && ev[ 1 ] === arg1 && ev[ 2 ] === arg2 ){
\r
743 events.split( i, 1 );
\r
750 if( XUI_Event._START_XUI_EVENT < type && type < XUI_Event._END_XUI_EVENT ){
\r
751 this.gesture && this.gesture[ 'unlisten' ]( type );
\r
753 root = this.rootData;
\r
754 counter = root.eventCounter;
\r
755 if( !counter[ type ] ) return this;
\r
757 if( counter[ type ] === 0 ){
\r
758 root.xnodeInteractiveLayer[ 'unlisten' ]( XUI_Event.IdToName[ type ], X_UI_eventRellay );
\r
759 delete counter[ type ];
\r
763 arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 ) );
\r
765 return X_EventDispatcher_unlisten.apply( this, [ type, this.User, f ] );
\r
767 if( f.kind === X_Callback_FUNC_ONLY ){
\r
768 return X_EventDispatcher_unlisten.apply( this, [ type, this.User, f.func, f.supplement ] );
\r
770 return X_EventDispatcher_unlisten.apply( this, arguments );
\r
773 dispatch : function( e ){
\r
774 //console.log( e.type + ' ' + ( this[ '_listeners' ] && this[ '_listeners' ][ e.type ] ) );
\r
775 var xve = XUI_Event,
\r
776 ret = X_EventDispatcher_dispatch.call( this, e ),
\r
777 type = e.type || e;
\r
779 // TODO captureEvent PointerEvent
\r
780 if( ret & X_Callback_CAPTURE_POINTER && !this.hitChildData && XUI_Event._POINTER_MOVE === type ){
\r
781 this.rootData.monopolyNodeData = this;
\r
784 this.rootData.monopolyNodeData = null;
\r
785 if( xve._START_BUBLEUP < type && this.parentData && !( ret & X_Callback_STOP_PROPAGATION ) && !( ret & X_Callback_STOP_NOW ) ) return this.parentData[ 'dispatch' ]( e );
\r
789 setItemData : function(){
\r
790 // this[ 'dispatch' ]( UI_Event.ITEMDATA_CHANGED );
\r
791 // itemData.listen( X_Event_CHANGED ) -> this[ 'dispatch' ]( UI_Event.ITEMDATA_UPDATED );
\r
797 function XUI_AbstractUINode_createCssText( that, name ){
\r
798 var attrs = that.attrObject || that.attrClass.prototype || XUI_AttrClass,
\r
799 def = that.usableAttrs[ name ],
\r
801 v = attrs[ def.No ],
\r
804 flag = !!( type & XUI_Attr_Type.BOOLEAN ),
\r
805 combi = !!( type & XUI_Attr_Type.COMBI ),
\r
806 quartet = !!( type & XUI_Attr_Type.QUARTET );
\r
809 if( attrs[ no + 1 ] === attrs[ no + 3 ] ){
\r
810 if( v === attrs[ no + 2 ] ){
\r
811 if( v === attrs[ no + 1 ] ){
\r
812 return XUI_AbstractUINode_createCssValue( v, type, list );
\r
815 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
816 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list )
\r
820 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
821 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list ),
\r
822 XUI_AbstractUINode_createCssValue( attrs[ no + 2 ], type, list )
\r
826 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
827 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list ),
\r
828 XUI_AbstractUINode_createCssValue( attrs[ no + 2 ], type, list ),
\r
829 XUI_AbstractUINode_createCssValue( attrs[ no + 3 ], type, list )
\r
834 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
835 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list )
\r
839 return v ? list : 'normal'; //
\r
841 return XUI_AbstractUINode_createCssValue( v, type, list );
\r
844 function XUI_AbstractUINode_createCssValue( v, type, list ){
\r
845 var length = !!( type & XUI_Attr_Type.LENGTH ),
\r
846 minusLen = !!( type & XUI_Attr_Type.MINUS_LENGTH ),
\r
847 percent = !!( type & XUI_Attr_Type.PERCENT ),
\r
848 minusPct = !!( type & XUI_Attr_Type.MINUS_PERCENT ),
\r
849 numerical = !!( type & XUI_Attr_Type.NUMERICAL ),
\r
850 auto = !!( type & XUI_Attr_Type.AUTO ),
\r
851 color = !!( type & XUI_Attr_Type.COLOR ),
\r
852 url = !!( type & XUI_Attr_Type.URL ),
\r
853 fontName = !!( type & XUI_Attr_Type.FONT_NAME );
\r
855 if( X_Type_isNumber( v ) ){
\r
856 if( auto && v === XUI_Attr_AUTO ) return 'auto';
\r
857 if( length || minusLen ) return v + 'em';
\r
858 if( numerical ) return v;
\r
859 if( list && list[ v ] ) return list[ v ];
\r
861 if( v < 0x100000 ){
\r
862 v = '00000' + v.toString( 16 );
\r
863 return '#' + v.substr( v.length - 6 );
\r
865 return '#' + v.toString( 16 );
\r
868 if( X_Type_isString( v ) ){
\r
869 if( percent || minusPct || url || fontName ) return v;
\r
873 function XUI_AbstractUINode_calcValue( styleValue, srcValue ){
\r
877 if( X_Type_isString( styleValue ) ){
\r
878 return srcValue * parseFloat( styleValue ) / 100;
\r
880 if( !X_Type_isNumber( styleValue ) ) return 0;
\r
884 function XUI_AbstractUINode_calcFinalValue( styleValue, styleMin, styleMax, srcValue ){
\r
885 var v = XUI_AbstractUINode_calcValue( styleValue, srcValue ),
\r
886 min = XUI_AbstractUINode_calcValue( styleMin, srcValue ),
\r
887 max = XUI_AbstractUINode_calcValue( styleMax, srcValue );
\r
888 return v <= min ? min : max <= v ? max : v;
\r
890 function XUI_AbstractUINode_ceil( v ){
\r
892 return ( v * 10 + 0.999 | 0 ) / 10;
\r
894 return ( -v * 10 + 0.999 | 0 ) / -10;
\r
897 X.UI.AbstractUINode = X_Class_create(
\r
901 parent : function(){
\r
902 return X_Pair_get( this ).parent;
\r
905 return X_Pair_get( this ).root;
\r
909 * unverifiedAttrs に全ての指定を控える
\r
910 * サポートされていない場合は無視される.親のレイアウトによって変わる
\r
912 attr : function( nameOrObject, valueOrUnit ){
\r
913 var p = X_Pair_get( this ),
\r
914 layout, k, def, attrs, v;
\r
915 if( nameOrObject && X_Type_isObject( nameOrObject ) ){
\r
917 layout = p.parentData && p.parentData.layout.overrideAttrsForChild; // root には parent がない
\r
918 for( k in nameOrObject ){
\r
919 if( X_EMPTY_OBJECT[ k ] ) continue;
\r
920 // 親のレイアウトマネージャの許可しない
\r
921 if( layout && !layout[ k ] ){
\r
924 if( def = p.usableAttrs[ k ] ){
\r
925 p.setAttr( k, def, nameOrObject[ k ] );
\r
929 if( X_Type_isString( nameOrObject ) ){
\r
930 if( valueOrUnit !== undefined ){
\r
931 if( 'em,%'.indexOf( valueOrUnit ) === -1 ){
\r
933 p.setAttr( nameOrObject, valueOrUnit );
\r
935 // getter with unit
\r
936 return p.getAttrWithUnit( nameOrObject, valueOrUnit );
\r
940 if( attrs = ( p.attrObject || p.attrClass.prototype || XUI_AttrClass ) ){
\r
941 def = p.usableAttrs[ nameOrObject ];
\r
942 return def && attrs[ def.No ];
\r
949 listen : function( type, arg1, arg2, arg3 ){
\r
950 X_Pair_get( this )[ 'listen' ]( type, arg1, arg2, arg3 );
\r
953 listenOnce : function( type, arg1, arg2, arg3 ){
\r
954 X_Pair_get( this )[ 'listenOnce' ]( type, arg1, arg2, arg3 );
\r
957 listening : function( type, arg1, arg2, arg3 ){
\r
958 return X_Pair_get( this )[ 'listening' ]( type, arg1, arg2, arg3 );
\r
960 unlisten : function( type, arg1, arg2, arg3 ){
\r
961 X_Pair_get( this )[ 'unlisten' ]( type, arg1, arg2, arg3 );
\r
964 dispatch : function( e ){
\r
965 return X_Pair_get( this )[ 'dispatch' ]( e );
\r
968 nextNode : function(){
\r
971 prevNode : function(){
\r
974 nodeIndex : function( v ){
\r
975 var data = X_Pair_get( this );
\r
976 if( typeof v === 'number' ){
\r
977 // data.nodeIndex( v );
\r
980 return data.parentData ? data.parentData.nodes.indexOf( data ) : 0;
\r
982 displayIndex : function(){
\r
986 // dirty の場合、rootData.calculate
\r
987 return X_Pair_get( this ).boxX;
\r
990 // dirty の場合、rootData.calculate
\r
991 return X_Pair_get( this ).boxY;
\r
993 getAbsoluteX : function(){
\r
994 // dirty の場合、rootData.calculate
\r
995 return X_Pair_get( this ).absoluteX;
\r
997 getAbsoluteY: function(){
\r
998 // dirty の場合、rootData.calculate
\r
999 return X_Pair_get( this ).absoluteY;
\r
1001 getWidth : function(){
\r
1002 // dirty の場合、rootData.calculate
\r
1003 return X_Pair_get( this ).boxWidth;
\r
1005 getHeight : function(){
\r
1006 // dirty の場合、rootData.calculate
\r
1007 return X_Pair_get( this ).boxHeight;
\r
1011 * Repeater に於いて、繰り返されるアイテムの元(itemRenderer)からの複製に使用
\r
1013 clone : function( opt_cloneListener ){
\r
1014 var newNode = this.constructor(),
\r
1015 newPair = X_Pair_get( newNode ),
\r
1016 pair = X_Pair_get( this ),
\r
1017 attr, listeners, type, list, i, l;
\r
1019 // handleEvent 等の拡張されたオブジェクトもコピーする!
\r
1021 if( this[ k ] !== newNode[ k ] && !newNode[ k ] ) newNode[ k ] = this[ k ];
\r
1024 // User.UINODE な値は pair にコピーされているのでこれをコピー
\r
1026 if( pair[ k ] !== newPair[ k ] && !newPair[ k ] ) newPair[ k ] = pair[ k ];
\r
1030 if( pair.attrObject ){
\r
1031 attr = pair.attrClass();
\r
1032 for( k in pair.attrObject ){
\r
1033 if( pair.attrObject[ k ] !== attr[ k ] ) attr[ k ] = pair.attrObject[ k ];
\r
1035 newPair.attrObject = attr;
\r
1038 // listener もコピーする!
\r
1039 if( opt_cloneListener && ( listeners = pair[ '_listeners' ] ) ){
\r
1040 for( type in listeners ){
\r
1041 list = listeners[ type ];
\r
1042 for( i = 0, l = list.length; i < l; ++i ){
\r
1045 case X_Callback_THIS_FUNC :
\r
1047 X_EventDispatcher_systemListen( newNode, type, f.context === this ? newNode : f.context, f.func, f.supplement );
\r
1049 newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.context === this ? newNode : f.context, f.func, f.supplement );
\r
1052 case X_Callback_HANDLEEVENT :
\r
1054 X_EventDispatcher_systemListen( newNode, type, f.context === this ? newNode : f.context, f.supplement );
\r
1056 newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.context === this ? newNode : f.context, f.supplement );
\r
1060 case X_Callback_FUNC_ONLY :
\r
1062 X_EventDispatcher_systemListen( newNode, type, f.func, f.supplement );
\r
1064 newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.func, f.supplement );
\r
1068 newNode[ 'listen' ]( type, f );
\r