1 var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ](
\r
2 'X.UI._AbstractUINode',
\r
6 dirty : XUI_Dirty.CLEAN,
\r
15 supportAttrs : XUI_Attr_Support,
\r
16 attrClass : XUI_AttrClass,
\r
18 unverifiedAttrs : null,
\r
21 pointerDisabled : false,
\r
22 hoverClassName : null,
\r
25 reserveEvents : null,
\r
33 scrollWidth : 0, // remove?
\r
34 scrollHeight : 0, // remove?
\r
35 boxWidth : XUI_Attr_AUTO,
\r
37 maxBoxWidth : XUI_Attr_AUTO,
\r
38 boxHeight : XUI_Attr_AUTO,
\r
40 maxBoxHeight : XUI_Attr_AUTO,
\r
49 boxSizingOffsetLR : 0,
\r
50 boxSizingOffsetTB : 0,
\r
51 contentWidth : XUI_Attr_AUTO,
\r
52 minContentWidth : 0,
\r
53 maxContentWidth : XUI_Attr_AUTO,
\r
54 lastContentWidth : -1,
\r
55 contentHeight : XUI_Attr_AUTO,
\r
56 minContentHeight : 0,
\r
57 maxContentHeight : XUI_Attr_AUTO,
\r
58 lastContentHeight : -1,
\r
60 constraintW : false,
\r
61 constraintH : false,
\r
66 percentWidth : false,
\r
67 percentHeight : false,
\r
68 // :hover, :focus, :disabled
\r
70 initialize : function( root, rootData, parent, parentData ){
\r
72 this.rootData = rootData;
\r
73 this.parent = parent;
\r
74 this.parentData = parentData;
\r
75 //this.xnode = X_Doc_create( 'div' );
\r
78 this[ 'dispatch' ]( XUI_Event.INIT );
\r
81 addToParent : function( xnodeParent ){
\r
82 xnodeParent && xnodeParent[ 'append' ]( this.xnode );
\r
85 this[ 'dispatch' ]( XUI_Event.ADDED );
\r
88 creationComplete : function(){
\r
89 var events = this.reserveEvents,
\r
93 this.User[ 'dispatch' ]( XUI_Event.CREATION_COMPLETE );
\r
95 // html 要素が親に追加されるまで控えていたイベントの登録
\r
96 if( events && ( l = events.length ) ){
\r
97 for( i = 0; i < l; ++i ){
\r
98 this.listen.apply( this, events[ i ] );
\r
101 delete this.reserveEvents;
\r
106 * _UINode への setAttr の他、attrClass.prototype への setAttr にも対応する
\r
107 * 親要素が変化した場合、unverifiedAttrs を元に attrObject を再設定.
\r
109 setAttr : function( name, def, v ){
\r
110 var attrs = XUI_attrClassProto || this.attrObject,
\r
111 propID = def.No || def[ 5 ],
\r
112 defaultVal = XUI_attrClassProto ? attrs[ propID ] : this.attrClass.prototype[ propID ], // def[ 0 ],
\r
113 currentVal = attrs ? attrs[ propID ] : defaultVal,
\r
118 length = !!( type & XUI_Attr_Type.LENGTH ),
\r
119 minusLen = !!( type & XUI_Attr_Type.MINUS_LENGTH ),
\r
120 percent = !!( type & XUI_Attr_Type.PERCENT ),
\r
121 minusPct = !!( type & XUI_Attr_Type.MINUS_PERCENT ),
\r
122 numerical = !!( type & XUI_Attr_Type.NUMERICAL ),
\r
123 auto = !!( type & XUI_Attr_Type.AUTO ),
\r
124 color = !!( type & XUI_Attr_Type.COLOR ),
\r
125 url = !!( type & XUI_Attr_Type.URL ),
\r
126 fontName = !!( type & XUI_Attr_Type.FONT_NAME ),
\r
127 flag = !!( type & XUI_Attr_Type.BOOLEAN ),
\r
128 combi = !!( type & XUI_Attr_Type.COMBI ),
\r
129 quartet = !!( type & XUI_Attr_Type.QUARTET ),
\r
130 _v, i, l, nodes, root, roots;
\r
132 if( X_Type_isString( v ) ){
\r
133 //v = v.toLowercase();
\r
134 if( url || fontName ){
\r
137 if( auto && v === 'auto' ){
\r
140 if( list && ( _v = list[ v ] ) ){
\r
142 console.log( v + ' ' + _v );
\r
145 if( ( percent || minusPct ) && v.lastIndexOf( '%' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + '%' ){
\r
148 if( ( length || minusLen ) && v.lastIndexOf( 'em' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + 'em' ){
\r
151 if( v.indexOf( ' ' ) !== -1 ){
\r
152 v = v.split( ' ' );
\r
154 if( color && X_Type_isNumber( _v = X_Node_CSS_objToIEFilterText( v ) ) ){
\r
162 if( ( quartet || combi ) && !X_Type_isArray( v ) ){
\r
166 if( X_Type_isNumber( v ) ){
\r
168 ( length && ( 0 <= v ) ) ||
\r
169 ( minusLen && ( v <= 0 ) ) ||
\r
170 ( percent && 0 <= v && v <= 1 ) ||
\r
171 ( minusPct && -1 <= v && v < 0 ) ||
\r
172 ( numerical && 0 <= v ) ||
\r
173 ( auto && v === XUI_Attr_AUTO ) ||
\r
174 ( color && 0 <= v && v <= 0xFFFFFF ) ||
\r
175 ( list && list[ v ] )
\r
183 if( X_Type_isBoolean( v ) && !flag ){
\r
186 if( X_Type_isArray( v ) ){
\r
187 if( v.length <= 4 && quartet ){
\r
188 type &= ~XUI_Attr_Type.QUARTET;
\r
189 switch( v.length ){
\r
191 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
192 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
193 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
194 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
197 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
198 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
199 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
200 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
203 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
204 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
205 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\r
206 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
209 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
210 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
211 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\r
212 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 3 ] );
\r
216 if( v.length === 2 && combi ){
\r
217 type &= ~XUI_Attr_Type.COMBI;
\r
218 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
219 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
225 if( !XUI_attrClassProto && user === XUI_Attr_USER.XNODE && this.xnode ){
\r
226 this.xnode[ 'css' ]( XUI_Attr_Rename[ name ] || name, XUI_AbstractUINode_createCssText( this, name ) );
\r
227 //console.log( ( XUI_Attr_Rename[ name ] || name ) + ' ' + XUI_AbstractUINode_createCssText( this, name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
232 if( !v && v !== 0 ) v = defaultVal;
\r
234 if( XUI_attrClassProto ){
\r
235 attrs[ propID ] = v;
\r
239 if( currentVal !== v ){
\r
241 case XUI_Attr_Support.left.No :
\r
242 this.constraintW = attrs[ XUI_Attr_Support.right.No ] !== null;
\r
244 case XUI_Attr_Support.right.No :
\r
245 this.constraintW = attrs[ XUI_Attr_Support.left.No ] !== null;
\r
247 case XUI_Attr_Support.top.No :
\r
248 this.constraintH = attrs[ XUI_Attr_Support.bottom.No ] !== null;
\r
250 case XUI_Attr_Support.bottom.No :
\r
251 this.constraintH = attrs[ XUI_Attr_Support.top.No ] !== null;
\r
253 case XUI_Attr_Support.width.No :
\r
254 this.autoWidth = v === XUI_Attr_AUTO;
\r
255 this.percentWidth = X_Type_isString( v );
\r
257 case XUI_Attr_Support.height.No :
\r
258 this.autoHeight = v === XUI_Attr_AUTO;
\r
259 this.percentHeight = X_Type_isString( v );
\r
263 if( defaultVal === v ){
\r
264 if( attrs ) delete attrs[ propID ];
\r
266 if( !attrs ) attrs = this.attrObject = new this.attrClass;
\r
267 attrs[ propID ] = v;
\r
270 if( name && user === XUI_Attr_USER.UINODE ){
\r
274 if( name && user === XUI_Attr_USER.XNODE && this.xnode ){
\r
275 this.xnode[ 'css' ]( XUI_Attr_Rename[ name ] || name, XUI_AbstractUINode_createCssText( this, name ) );
\r
276 //console.log( ( XUI_Attr_Rename[ name ] || name ) + ' ' + XUI_AbstractUINode_createCssText( this, name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
278 if( this.dirty < dirty ) this.dirty = dirty;
\r
282 getAttr : function( name ){
\r
283 var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,
\r
284 support = this.supportAttrs[ name ],
\r
286 if( !support ) return;
\r
288 if( name.indexOf( 'border' ) === 0 ){
\r
289 name = name.substr( 6 );
\r
290 return [ this.getAttr( 'borderTop' + name ), this.getAttr( 'borderRight' + name ), this.getAttr( 'borderBottom' + name ), this.getAttr( 'borderLeft' + name ) ];
\r
293 type = support[ 3 ];
\r
295 if( type & XUI_Attr_Type.QUARTET ){
\r
296 return [ this.getAttr( name + 'Top' ), this.getAttr( name + 'Right' ), this.getAttr( name + 'Bottom' ), this.getAttr( name + 'Left' ) ];
\r
298 if( type & XUI_Attr_Type.COMBI ) return [ v, data[ ++propID ] ];
\r
300 v = attrs[ support.No ];
\r
301 if( type & XUI_Attr_Type.AUTO && v === XUI_Attr_AUTO ) return 'auto';
\r
303 list = support[ 4 ];
\r
304 if( list ) return list[ v ];
\r
306 if( type & XUI_Attr_Type.COLOR && X_Type_isNumber( v ) ) return v;
\r
307 if( !( type & XUI_Attr_Type.NUMERICAL ) && X_Type_isNumber( v ) ) return v + 'em';
\r
312 getAttrWithUnit : function( prop, unit ){
\r
316 _remove : function(){
\r
317 switch( this.phase ){
\r
324 this.xnode[ 'kill' ]();
\r
327 delete this.rootData;
\r
328 delete this.parent;
\r
329 delete this.parentData;
\r
338 calculate : function( isNeedsDetection, x, y, allowedW, allowedH ){
\r
339 this.preMesure( allowedW, allowedH );
\r
341 this.noWidth = this.boxWidth === XUI_Attr_AUTO;
\r
342 this.noHeight = this.boxHeight === XUI_Attr_AUTO;
\r
344 if( this.noWidth || this.noHeight ){
\r
349 if( !isNeedsDetection ){
\r
356 * X_Node_BoxModel の情報を引きながら top,left,width,height,padding,border の設定
\r
358 updateLayout : function(){
\r
359 var x = this.boxX + ( this.parentData ? this.parentData.paddingL : 0 ),
\r
360 y = this.boxY + ( this.parentData ? this.parentData.paddingT : 0 ),
\r
361 w = X_UA[ 'IE5x' ] ? this.boxWidth : this.contentWidth,
\r
362 h = X_UA[ 'IE5x' ] ? this.boxHeight : this.contentHeight;
\r
365 [ 'css' ]( 'left', x ? x + 'em' : 0 ) // 親の padding 分ずらす
\r
366 [ 'css' ]( 'top', y ? y + 'em' : 0 ) // 親の padding 分ずらす
\r
367 [ 'css' ]( 'width', this.noWidth ? 'auto' : w ? w + 'em' : 0 )
\r
368 [ 'css' ]( 'height', this.noHeight ? 'auto' : h ? h + 'em' : 0 )
\r
369 [ 'css' ]( 'padding', XUI_AbstractUINode_createCssText( this, 'padding' ) )
\r
370 [ 'css' ]( 'borderWidth', XUI_AbstractUINode_createCssText( this, 'borderWidth' ) );
\r
374 * 親の サイズを元に自身のサイズを計算していく
\r
376 preMesure : function( allowedW, allowedH ){
\r
377 var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,
\r
378 box = attrs[ XUI_Attr_Support.sizing.No ],
\r
380 boxL, boxT, boxR, boxB,
\r
381 contentW, contentH, boxMinus,
\r
382 paddingT, paddingR, paddingB, paddingL,
\r
383 borderT, borderR, borderB, borderL;
\r
386 // 自身が constraintW の場合 親が AUTO ではない
\r
387 // 自身が constraintW でない場合自身が AUTO はなくかつ親 が AUTO の場合 or 自身は % でない
\r
389 paddingR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 1 ], allowedW );
\r
390 paddingL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 3 ], allowedW );
\r
391 borderR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 1 ], allowedW );
\r
392 borderL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 3 ], allowedW );
\r
395 case 3 : // border-box
\r
396 boxMinus -= borderR + borderL;
\r
397 case 2 : // padding-box
\r
398 boxMinus -= paddingR + paddingL;
\r
399 // case 1 : // content-box
\r
401 this.contentL = borderL + paddingL;
\r
402 this.contentR = borderR + paddingR;
\r
403 this.paddingL = paddingL;
\r
404 this.borderL = borderL;
\r
406 if( this.constraintW ? allowedW !== XUI_Attr_AUTO : !this.autoWidth && ( allowedW !== XUI_Attr_AUTO || !this.percentWidth ) ){
\r
407 if( this.constraintW ){ // 制約レイアウト
\r
408 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
410 contentW = XUI_AbstractUINode_calcFinalValue( attrs[ XUI_Attr_Support.width.No ], attrs[ XUI_Attr_Support.minWidth.No ], attrs[ XUI_Attr_Support.maxWidth.No ], allowedW );
\r
412 this.contentWidth = contentW + boxMinus;
\r
413 this.boxWidth = this.contentWidth + this.contentL + this.contentR;
\r
414 this.boxSizingOffsetLR = boxMinus;
\r
415 delete this.minContentWidth;
\r
416 delete this.maxContentWidth;
\r
417 delete this.minBoxWidth;
\r
418 delete this.maxBoxWidth;
\r
420 this.minContentWidth = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], allowedW ) + boxMinus );
\r
421 this.maxContentWidth = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], allowedW ) + boxMinus );
\r
422 this.minBoxWidth = this.minContentWidth + this.contentL + this.contentR;
\r
423 this.maxBoxWidth = this.maxContentWidth + this.contentL + this.contentR;
\r
424 this.contentWidth = this.minContentWidth;
\r
425 this.boxWidth = this.minBoxWidth;
\r
426 this.boxSizingOffsetLR = boxMinus;
\r
429 paddingT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 0 ], allowedH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
430 paddingB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 2 ], allowedH );
\r
431 borderT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 0 ], allowedH );
\r
432 borderB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 2 ], allowedH );
\r
435 case 3 : // border-box
\r
436 boxMinus -= borderT + borderB;
\r
437 case 2 : // padding-box
\r
438 boxMinus -= paddingT + paddingB;
\r
439 // case 1 : // content-box
\r
441 this.contentT = borderT + paddingT;
\r
442 this.contentB = borderB + paddingB;
\r
443 this.paddingT = paddingT;
\r
444 this.borderT = borderT;
\r
447 if( this.constraintH ? allowedH !== XUI_Attr_AUTO : !this.autoHeight && ( allowedH !== XUI_Attr_AUTO || !this.percentHeight ) ){
\r
448 if( this.constraintH ){ // 制約レイアウト
\r
449 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
451 contentH = XUI_AbstractUINode_calcFinalValue( attrs[ XUI_Attr_Support.height.No ], attrs[ XUI_Attr_Support.minHeight.No ], attrs[ XUI_Attr_Support.maxHeight.No ], allowedH );
\r
453 this.contentHeight = contentH + boxMinus;
\r
454 this.boxHeight = this.contentHeight + this.contentT + this.contentB; // padding-box の場合 border だけ足される
\r
455 this.boxSizingOffsetTB = boxMinus;
\r
456 delete this.minContentHeight;
\r
457 delete this.maxContentHeight;
\r
458 delete this.minBoxHeight;
\r
459 delete this.maxBoxHeight;
\r
461 this.minContentHeight = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], allowedH ) + boxMinus );
\r
462 this.maxContentHeight = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], allowedH ) + boxMinus );
\r
463 this.minBoxHeight = this.minContentHeight + this.contentT + this.contentB;
\r
464 this.maxBoxHeight = this.maxContentHeight + this.contentT + this.contentB;
\r
465 this.contentHeight = this.minContentHeight;
\r
466 this.boxHeight = this.minBoxHeight;
\r
467 this.boxSizingOffsetTB = boxMinus;
\r
470 if( this.parentData && this.parentData.layout.overrideAttrsForChild.left ){
\r
471 if( this.constraintW ){
\r
472 this.boxX = ( boxL || boxL === 0 ) ? boxL : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.left.No ], allowedW );
\r
474 if( attrs[ XUI_Attr_Support.right.No ] === null ){
\r
475 this.boxX = ( boxL || boxL === 0 ) ? boxL : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.left.No ], allowedW );
\r
477 this.boxX = alllowW - this.boxWidth - ( ( boxR || boxR === 0 ) ? boxR : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.right.No ], allowedW ) );
\r
483 if( this.parentData && this.parentData.layout.overrideAttrsForChild.top ){
\r
484 if( this.constraintH ){
\r
485 this.boxY = ( boxT || boxT === 0 ) ? boxT : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.top.No ], allowedH );
\r
487 if( attrs[ XUI_Attr_Support.bottom.No ] === null ){
\r
488 this.boxY = ( boxT || boxT === 0 ) ? boxT : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.top.No ], allowedH );
\r
490 this.boxY = allowedH - this.boxHeight - ( ( boxB || boxB === 0 ) ? boxB : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.bottom.No ], allowedH ) );
\r
498 * 描画・計測を行って、contentSize の決定
\r
500 mesure : function(){
\r
501 var dirty = this.dirty,
\r
502 //sup = X_UA[ 'Gecko' ] || ( X_UA[ 'Safari' ] && X_UA[ 'Windows' ] ) ? .01251 : 0,
\r
505 if( dirty === XUI_Dirty.CLEAN ){
\r
506 if( this.percentWidth || this.percentHeight ){
\r
513 case XUI_Dirty.CONTENT : // コンテンツが変更された
\r
514 case XUI_Dirty.FONT : // フォントサイズが変更された
\r
515 delete this.lastContentWidth;
\r
516 delete this.lastContentHeight;
\r
518 case XUI_Dirty.LAYOUT : // レイアウトの再計算が必要
\r
520 default : // TODO レイアウト崩れに対処 パフォーマンス悪い!
\r
522 w = this.contentWidth;
\r
523 h = this.contentHeight;
\r
524 xnode = this.xnode;
\r
526 /* http://web-designs.seesaa.net/article/188400668.html
\r
527 * min-width の値が max-width の値より大きい場合は、max-width の値は min-width の値に設定される。
\r
530 * 1. contentWidth === AUTO
\r
531 * style を更新して contentWidth の決定
\r
532 * min or max に引っかかったら style 更新
\r
533 * contentHeight === AUTO の場合
\r
535 * contentHeight !== AUTO の場合 scrollHeight のみ更新
\r
536 * 2. contentHeight === AUTO かつ
\r
537 * コンテンツの高さの再取得が必要( contentWidth が最終計測時の contentWidth と一致 かつ フォント・コンテンツに変更無し の場合再取得不要)
\r
538 * style を更新して contentHeight の決定
\r
540 * 3. content のサイズがすでに決定している
\r
544 if( xnode[ '_xnodes' ] && xnode[ '_xnodes' ].length ){
\r
545 if( w === XUI_Attr_AUTO ){
\r
547 w = _w = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'width', 'auto' )[ 'clientWidth' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
549 if( this.maxContentWidth < w - this.boxSizingOffsetLR ){
\r
550 this.noWidth = false;
\r
551 w = this.maxContentWidth + this.boxSizingOffsetLR;
\r
553 if( w - this.boxSizingOffsetLR < this.minContentWidth ){
\r
554 this.noWidth = false;
\r
555 w = this.minContentWidth + this.boxSizingOffsetLR;
\r
558 if( h === XUI_Attr_AUTO ){
\r
559 w !== _w && xnode[ 'css' ]( 'width', w + 'em' );
\r
560 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
561 w !== _w && xnode[ 'css' ]( 'width', 'auto' );
\r
564 this.lastContentWidth = this.contentWidth = w;
\r
567 if( h === XUI_Attr_AUTO ){
\r
568 if( w !== this.lastContentWidth ){
\r
569 xnode[ 'css' ]( 'width', w + 'em' );
\r
570 this.lastContentWidth = w;
\r
572 // ie8 clientHeight, ff scrollHeight & clientHeight
\r
573 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
575 h = this.lastContentHeight === -1 ?
\r
576 XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) ) :
\r
577 this.lastContentHeight;
\r
580 if( dirty !== XUI_Dirty.LAYOUT ){
\r
581 this.contentWidth = this.lastContentWidth = w;
\r
582 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
585 if( this.maxContentHeight < h - this.boxSizingOffsetTB ){
\r
586 this.noHeight = false;
\r
587 h = this.maxContentHeight + this.boxSizingOffsetTB;
\r
589 if( h - this.boxSizingOffsetTB < this.minContentHeight ){
\r
590 this.noHeight = false;
\r
591 h = this.minContentHeight + this.boxSizingOffsetTB;
\r
594 this.contentHeight = this.lastContentHeight = h;
\r
597 // コンテンツを持たないため基本のサイズは0
\r
598 if( w === XUI_Attr_AUTO ) this.contentWidth = w = 0 < this.minContentWidth ? this.minContentWidth : 0;
\r
599 if( h === XUI_Attr_AUTO ) this.contentHeight = h = 0 < this.minContentHeight ? this.minContentHeight : 0;
\r
600 this.noWidth = this.noHeight = false;
\r
605 //case XUI_Dirty.PAINT : // 再描画のみ必要
\r
610 * 自身の contentWidth, contentHeight を元に AUTO な width, height を確定していく
\r
612 postMesure : function(){
\r
613 var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,
\r
614 box = attrs[ XUI_Attr_Support.sizing.No ],
\r
615 contentW, contentH,
\r
617 paddingT, paddingR, paddingB, paddingL,
\r
618 borderT, borderR, borderB, borderL,
\r
622 if( this.boxWidth === XUI_Attr_AUTO ){
\r
623 contentW = this.contentWidth;
\r
624 paddingR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 1 ], contentW );
\r
625 paddingL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 3 ], contentW );
\r
626 borderR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 1 ], contentW );
\r
627 borderL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 3 ], contentW );
\r
630 case 1 : // content-box
\r
631 contentPlus = paddingR + paddingL;
\r
632 case 2 : // padding-box
\r
633 contentPlus += borderR + borderL;
\r
634 // case 3 : // border-box
\r
637 if( !this.constraintW ){
\r
638 contentW += contentPlus;
\r
639 min = this.minBoxWidth = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], contentW );
\r
640 max = this.maxBoxWidth = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], contentW );
\r
641 if( contentW < min && contentPlus < min ){
\r
642 this.contentWidth = min - contentPlus;
\r
644 if( max < contentW && contentPlus < max ){
\r
645 this.contentWidth = max - contentPlus;
\r
648 this.contentL = borderL + paddingL;
\r
649 this.contentR = borderR + paddingR;
\r
650 this.paddingL = paddingL;
\r
651 this.borderL = borderL;
\r
652 this.boxWidth = this.contentWidth + this.contentL + this.contentR;
\r
655 if( this.boxHeight === XUI_Attr_AUTO ){
\r
656 contentH = this.contentHeight;
\r
657 paddingT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 0 ], contentH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
658 paddingB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 2 ], contentH );
\r
659 borderT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 0 ], contentH );
\r
660 borderB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 2 ], contentH );
\r
663 case 1 : // content-box
\r
664 contentPlus = paddingT + paddingB;
\r
665 case 2 : // padding-box
\r
666 contentPlus += borderT + borderB;
\r
667 // case 3 : // border-box
\r
669 if( !this.constraintH ){
\r
670 contentH += contentPlus;
\r
671 min = this.minBoxHeight = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], contentH );
\r
672 max = this.maxBoxHeight = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], contentH );
\r
673 if( contentH < min && contentPlus < min ){
\r
674 this.contentHeight = min - contentPlus;
\r
676 if( max < contentH && contentPlus < max ){
\r
677 this.contentHeight = max - contentPlus;
\r
680 this.contentT = borderT + paddingT;
\r
681 this.contentB = borderB + paddingB;
\r
682 this.paddingT = paddingT;
\r
683 this.borderT = borderT;
\r
684 this.boxHeight = this.contentHeight + this.contentT + this.contentB;
\r
688 capcher : function( x, y ){
\r
689 if( this.pointerDisabled ) return false;
\r
694 if( 0 <= x && x < this.boxWidth && 0 <= y && y < this.boxHeight ){
\r
695 !this.hovering && ( this.rootData.hoverList[ this.rootData.hoverList.length ] = this );
\r
696 this.rootData.targetNodeData = this;
\r
702 * context を明示しない場合、User が context になる!
\r
704 listen : function( type, arg1, arg2, arg3 ){
\r
705 var root, events, counter, f;
\r
706 if( XUI_Event._START_POINTER <= type && type <= XUI_Event._END_POINTER ){
\r
707 if( this.phase < 3 ){
\r
708 if( !( events = this.reserveEvents ) ) this.reserveEvents = events = [];
\r
709 events[ events.length ] = [ type, arg1, arg2, arg3 ];
\r
712 if( XUI_Event._START_XUI_EVENT < type && type < XUI_Event._END_XUI_EVENT ){
\r
713 if( !this.gesture ){
\r
714 this.gesture = new Hammer( this.rootData, this, type );
\r
716 this.gesture[ 'listen' ]( type );
\r
719 //console.log( type );
\r
720 root = this.rootData;
\r
721 counter = root.eventCounter;
\r
722 if( counter[ type ] ){
\r
725 counter[ type ] = 1;
\r
726 root.xnodeInteractiveLayer[ 'listen' ]( XUI_Event.IdToName[ type ], X_UI_eventRellay );
\r
730 arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 ) );
\r
732 return X_EventDispatcher_listen.call( this, type, this.User, f );
\r
734 if( f.kind === X_Callback_FUNC_ONLY ){
\r
735 return X_EventDispatcher_listen.call( this, type, this.User, f.func, f.supplement );
\r
737 return X_EventDispatcher_listen.apply( this, arguments );
\r
739 unlisten : function( type, arg1, arg2, arg3 ){
\r
740 var root, events, i, ev, counter, f;
\r
741 if( XUI_Event._START_POINTER <= type && type <= XUI_Event._END_POINTER ){
\r
742 if( this.phase < 3 ){
\r
743 if( !( events = this.reserveEvents ) ) return this;
\r
744 for( i = events.length; i; ){
\r
745 ev = events[ --i ];
\r
746 if( ev[ 0 ] === type && ev[ 1 ] === arg1 && ev[ 2 ] === arg2 ){
\r
747 events.split( i, 1 );
\r
754 if( XUI_Event._START_XUI_EVENT < type && type < XUI_Event._END_XUI_EVENT ){
\r
755 this.gesture && this.gesture[ 'unlisten' ]( type );
\r
757 root = this.rootData;
\r
758 counter = root.eventCounter;
\r
759 if( !counter[ type ] ) return this;
\r
761 if( counter[ type ] === 0 ){
\r
762 root.xnodeInteractiveLayer[ 'unlisten' ]( XUI_Event.IdToName[ type ], X_UI_eventRellay );
\r
763 delete counter[ type ];
\r
767 arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 ) );
\r
769 return X_EventDispatcher_unlisten.apply( this, [ type, this.User, f ] );
\r
771 if( f.kind === X_Callback_FUNC_ONLY ){
\r
772 return X_EventDispatcher_unlisten.apply( this, [ type, this.User, f.func, f.supplement ] );
\r
774 return X_EventDispatcher_unlisten.apply( this, arguments );
\r
777 dispatch : function( e ){
\r
778 //console.log( e.type + ' ' + ( this[ '_listeners' ] && this[ '_listeners' ][ e.type ] ) );
\r
779 var xve = XUI_Event,
\r
780 ret = X_EventDispatcher_dispatch.call( this, e ),
\r
781 type = e.type || e;
\r
783 // TODO captureEvent PointerEvent
\r
784 if( ret & X_Callback_CAPTURE_POINTER && !this.hitChildData && XUI_Event._POINTER_MOVE === type ){
\r
785 this.rootData.monopolyNodeData = this;
\r
788 this.rootData.monopolyNodeData = null;
\r
789 if( xve._START_BUBLEUP < type && this.parentData && !( ret & X_Callback_STOP_PROPAGATION ) && !( ret & X_Callback_STOP_NOW ) ) return this.parentData[ 'dispatch' ]( e );
\r
796 function XUI_AbstractUINode_createCssText( that, name ){
\r
797 var attrs = that.attrObject || that.attrClass.prototype || XUI_AttrClass,
\r
798 def = that.supportAttrs[ name ],
\r
800 v = attrs[ def.No ],
\r
803 flag = !!( type & XUI_Attr_Type.BOOLEAN ),
\r
804 combi = !!( type & XUI_Attr_Type.COMBI ),
\r
805 quartet = !!( type & XUI_Attr_Type.QUARTET );
\r
808 if( attrs[ no + 1 ] === attrs[ no + 3 ] ){
\r
809 if( v === attrs[ no + 2 ] ){
\r
810 if( v === attrs[ no + 1 ] ){
\r
811 return XUI_AbstractUINode_createCssValue( v, type, list );
\r
814 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
815 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list )
\r
819 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
820 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list ),
\r
821 XUI_AbstractUINode_createCssValue( attrs[ no + 2 ], type, list )
\r
825 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
826 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list ),
\r
827 XUI_AbstractUINode_createCssValue( attrs[ no + 2 ], type, list ),
\r
828 XUI_AbstractUINode_createCssValue( attrs[ no + 3 ], type, list )
\r
833 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
834 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list )
\r
838 return v ? list : 'normal'; //
\r
840 return XUI_AbstractUINode_createCssValue( v, type, list );
\r
843 function XUI_AbstractUINode_createCssValue( v, type, list ){
\r
844 var length = !!( type & XUI_Attr_Type.LENGTH ),
\r
845 minusLen = !!( type & XUI_Attr_Type.MINUS_LENGTH ),
\r
846 percent = !!( type & XUI_Attr_Type.PERCENT ),
\r
847 minusPct = !!( type & XUI_Attr_Type.MINUS_PERCENT ),
\r
848 numerical = !!( type & XUI_Attr_Type.NUMERICAL ),
\r
849 auto = !!( type & XUI_Attr_Type.AUTO ),
\r
850 color = !!( type & XUI_Attr_Type.COLOR ),
\r
851 url = !!( type & XUI_Attr_Type.URL ),
\r
852 fontName = !!( type & XUI_Attr_Type.FONT_NAME );
\r
854 if( X_Type_isNumber( v ) ){
\r
855 if( auto && v === XUI_Attr_AUTO ) return 'auto';
\r
856 if( length || minusLen ) return v + 'em';
\r
857 if( numerical ) return v;
\r
858 if( list && list[ v ] ) return list[ v ];
\r
860 if( v < 0x100000 ){
\r
861 v = '00000' + v.toString( 16 );
\r
862 return '#' + v.substr( v.length - 6 );
\r
864 return '#' + v.toString( 16 );
\r
867 if( X_Type_isString( v ) ){
\r
868 if( percent || minusPct || url || fontName ) return v;
\r
872 function XUI_AbstractUINode_calcValue( styleValue, srcValue ){
\r
876 if( X_Type_isString( styleValue ) ){
\r
877 return srcValue * parseFloat( styleValue ) / 100;
\r
879 if( !X_Type_isNumber( styleValue ) ) return 0;
\r
883 function XUI_AbstractUINode_calcFinalValue( styleValue, styleMin, styleMax, srcValue ){
\r
884 var v = XUI_AbstractUINode_calcValue( styleValue, srcValue ),
\r
885 min = XUI_AbstractUINode_calcValue( styleMin, srcValue ),
\r
886 max = XUI_AbstractUINode_calcValue( styleMax, srcValue );
\r
887 return v <= min ? min : max <= v ? max : v;
\r
889 function XUI_AbstractUINode_ceil( v ){
\r
891 return ( v * 10 + 0.999 | 0 ) / 10;
\r
893 return ( -v * 10 + 0.999 | 0 ) / -10;
\r
896 X.UI.AbstractUINode = X_Class_create(
\r
900 parent : function(){
\r
901 return X_Pair_get( this ).parent;
\r
904 return X_Pair_get( this ).root;
\r
908 * unverifiedAttrs に全ての指定を控える
\r
909 * サポートされていない場合は無視される.親のレイアウトによって変わる
\r
911 attr : function( nameOrObject, valueOrUnit ){
\r
912 var p = X_Pair_get( this ),
\r
913 layout, k, def, attrs, v;
\r
914 if( nameOrObject && X_Type_isObject( nameOrObject ) ){
\r
916 layout = p.parentData && p.parentData.layout.overrideAttrsForChild; // root には parent がない
\r
917 for( k in nameOrObject ){
\r
918 if( X_EMPTY_OBJECT[ k ] ) continue;
\r
919 // 親のレイアウトマネージャの許可しない
\r
920 if( layout && !layout[ k ] ){
\r
923 if( def = p.supportAttrs[ k ] ){
\r
924 p.setAttr( k, def, nameOrObject[ k ] );
\r
928 if( X_Type_isString( nameOrObject ) ){
\r
929 if( valueOrUnit !== undefined ){
\r
930 if( 'em,%'.indexOf( valueOrUnit ) === -1 ){
\r
932 p.setAttr( nameOrObject, valueOrUnit );
\r
934 // getter with unit
\r
935 return p.getAttrWithUnit( nameOrObject, valueOrUnit );
\r
939 if( attrs = ( p.attrObject || p.attrClass.prototype || XUI_AttrClass ) ){
\r
940 def = p.supportAttrs[ nameOrObject ];
\r
941 return def && attrs[ def.No ];
\r
948 listen : function( type, arg1, arg2, arg3 ){
\r
949 X_Pair_get( this )[ 'listen' ]( type, arg1, arg2, arg3 );
\r
952 listenOnce : function( type, arg1, arg2, arg3 ){
\r
953 X_Pair_get( this )[ 'listenOnce' ]( type, arg1, arg2, arg3 );
\r
956 listening : function( type, arg1, arg2, arg3 ){
\r
957 return X_Pair_get( this )[ 'listening' ]( type, arg1, arg2, arg3 );
\r
959 unlisten : function( type, arg1, arg2, arg3 ){
\r
960 X_Pair_get( this )[ 'unlisten' ]( type, arg1, arg2, arg3 );
\r
963 dispatch : function( e ){
\r
964 return X_Pair_get( this )[ 'dispatch' ]( e );
\r
967 nextNode : function(){
\r
970 prevNode : function(){
\r
973 nodeIndex : function( v ){
\r
974 var data = X_Pair_get( this );
\r
975 if( typeof v === 'number' ){
\r
976 // data.nodeIndex( v );
\r
979 return data.parentData ? data.parentData.nodes.indexOf( data ) : 0;
\r
981 displayIndex : function(){
\r
985 // dirty の場合、rootData.calculate
\r
986 return X_Pair_get( this ).boxX;
\r
989 // dirty の場合、rootData.calculate
\r
990 return X_Pair_get( this ).boxY;
\r
992 getAbsoluteX : function(){
\r
993 // dirty の場合、rootData.calculate
\r
994 return X_Pair_get( this ).absoluteX;
\r
996 getAbsoluteY: function(){
\r
997 // dirty の場合、rootData.calculate
\r
998 return X_Pair_get( this ).absoluteY;
\r
1000 getWidth : function(){
\r
1001 // dirty の場合、rootData.calculate
\r
1002 return X_Pair_get( this ).boxWidth;
\r
1004 getHeight : function(){
\r
1005 // dirty の場合、rootData.calculate
\r
1006 return X_Pair_get( this ).boxHeight;
\r