1 // TODO -> Node[ 'inherits' ]
\r
2 var XUI_AbstractUINode = X_EventDispatcher[ 'inherits' ](
\r
3 'X.UI._AbstractUINode',
\r
9 dirty : XUI_Dirty.CLEAN,
\r
18 usableAttrs : XUI_Attr_Support,
\r
19 attrClass : XUI_AttrClass,
\r
21 unverifiedAttrs : null,
\r
24 pointerDisabled : false,
\r
25 hoverClassName : null,
\r
28 reserveEvents : null,
\r
36 boxWidth : XUI_Attr_AUTO,
\r
38 boxWidthMax : XUI_Attr_AUTO,
\r
39 boxHeight : XUI_Attr_AUTO,
\r
41 boxHeightMax : XUI_Attr_AUTO,
\r
50 boxSizingOffsetLR : 0,
\r
51 boxSizingOffsetTB : 0,
\r
52 contentWidth : XUI_Attr_AUTO,
\r
53 contentWidthMin : 0,
\r
54 contentWidthMax : XUI_Attr_AUTO,
\r
55 contentWidthLast : -1,
\r
56 contentHeight : XUI_Attr_AUTO,
\r
57 contentHeightMin : 0,
\r
58 contentHeightMax : XUI_Attr_AUTO,
\r
59 contentHeightLast : -1,
\r
61 constraintW : false,
\r
62 constraintH : false,
\r
67 percentWidth : false,
\r
68 percentHeight : false,
\r
69 // :hover, :focus, :disabled
\r
71 initialize : function( root, rootData, parent, parentData ){
\r
73 this.rootData = rootData;
\r
74 this.parent = parent;
\r
75 this.parentData = parentData;
\r
78 this[ 'dispatch' ]( XUI_Event.INIT );
\r
81 addToParent : function( xnodeParent ){
\r
82 var attr = this.attrObject || this.attrClass.prototype,
\r
83 usableAttrs = this.usableAttrs,
\r
84 i = 0, l = usableAttrs.length, def;
\r
86 xnodeParent && xnodeParent[ 'append' ]( this.xnode );
\r
89 for( k in usableAttrs ){
\r
90 def = usableAttrs[ k ];
\r
91 if( def[ 2 ] === XUI_Attr_USER.XNODE && X_Object_inObject( def.No, attr ) && attr[ k ] !== def[ 0 ] ){
\r
92 this.xnode[ 'css' ]( XUI_Attr_Rename[ k ] || k, XUI_AbstractUINode_createCssText( this, k ) );
\r
98 this[ 'dispatch' ]( XUI_Event.ADDED );
\r
101 creationComplete : function(){
\r
102 var events = this.reserveEvents,
\r
106 this.User[ 'dispatch' ]( XUI_Event.CREATION_COMPLETE );
\r
108 // html 要素が親に追加されるまで控えていたイベントの登録
\r
110 if( events && ( l = events.length ) ){
\r
111 for( i = 0; i < l; ++i ){
\r
112 this.listen.apply( this, events[ i ] );
\r
115 delete this.reserveEvents;
\r
120 * _UINode への setAttr の他、attrClass.prototype への setAttr にも対応する
\r
121 * 親要素が変化した場合、unverifiedAttrs を元に attrObject を再設定.
\r
123 setAttr : function( name, def, v ){
\r
124 var attrs = XUI_attrClassProto || this.attrObject,
\r
125 propID = def.No || def[ 5 ],
\r
126 defaultVal = XUI_attrClassProto ? attrs[ propID ] : this.attrClass.prototype[ propID ], // def[ 0 ],
\r
127 currentVal = attrs ? attrs[ propID ] : defaultVal,
\r
132 length = !!( type & XUI_Attr_Type.LENGTH ),
\r
133 minusLen = !!( type & XUI_Attr_Type.MINUS_LENGTH ),
\r
134 percent = !!( type & XUI_Attr_Type.PERCENT ),
\r
135 minusPct = !!( type & XUI_Attr_Type.MINUS_PERCENT ),
\r
136 numerical = !!( type & XUI_Attr_Type.NUMERICAL ),
\r
137 auto = !!( type & XUI_Attr_Type.AUTO ),
\r
138 color = !!( type & XUI_Attr_Type.COLOR ),
\r
139 url = !!( type & XUI_Attr_Type.URL ),
\r
140 fontName = !!( type & XUI_Attr_Type.FONT_NAME ),
\r
141 flag = !!( type & XUI_Attr_Type.BOOLEAN ),
\r
142 combi = !!( type & XUI_Attr_Type.COMBI ),
\r
143 quartet = !!( type & XUI_Attr_Type.QUARTET ),
\r
144 _v, i, l, nodes, root, roots;
\r
146 if( X_Type_isString( v ) ){
\r
147 //v = v.toLowercase();
\r
148 if( url || fontName ){
\r
151 if( auto && v === 'auto' ){
\r
154 if( list && ( _v = list[ v ] ) ){
\r
156 console.log( v + ' ' + _v );
\r
159 if( ( percent || minusPct ) && v.lastIndexOf( '%' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + '%' ){
\r
162 if( ( length || minusLen ) && v.lastIndexOf( 'em' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + 'em' ){
\r
165 if( v.indexOf( ' ' ) !== -1 ){
\r
166 v = v.split( ' ' );
\r
168 if( color && X_Type_isNumber( _v = X_Node_CSS_objToIEFilterText( v ) ) ){
\r
176 if( ( quartet || combi ) && !X_Type_isArray( v ) ){
\r
180 if( X_Type_isNumber( v ) ){
\r
182 ( length && ( 0 <= v ) ) ||
\r
183 ( minusLen && ( v <= 0 ) ) ||
\r
184 ( percent && 0 <= v && v <= 1 ) ||
\r
185 ( minusPct && -1 <= v && v < 0 ) ||
\r
186 ( numerical && 0 <= v ) ||
\r
187 ( auto && v === XUI_Attr_AUTO ) ||
\r
188 ( color && 0 <= v && v <= 0xFFFFFF ) ||
\r
189 ( list && list[ v ] )
\r
197 if( X_Type_isBoolean( v ) && !flag ){
\r
200 if( X_Type_isArray( v ) ){
\r
201 if( v.length <= 4 && quartet ){
\r
202 type &= ~XUI_Attr_Type.QUARTET;
\r
203 switch( v.length ){
\r
205 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
206 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
207 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
208 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
211 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
212 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
213 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
214 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
217 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
218 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
219 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\r
220 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
223 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
224 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
225 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\r
226 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 3 ] );
\r
230 if( v.length === 2 && combi ){
\r
231 type &= ~XUI_Attr_Type.COMBI;
\r
232 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
233 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
239 if( !XUI_attrClassProto && user === XUI_Attr_USER.XNODE && this.xnode ){
\r
240 this.xnode[ 'css' ]( XUI_Attr_Rename[ name ] || name, XUI_AbstractUINode_createCssText( this, name ) );
\r
241 //console.log( ( XUI_Attr_Rename[ name ] || name ) + ' ' + XUI_AbstractUINode_createCssText( this, name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
246 if( !v && v !== 0 ) v = defaultVal;
\r
248 // UIAttrClass の初期設定の場合、ここで終わる
\r
249 if( XUI_attrClassProto ){
\r
250 attrs[ propID ] = v;
\r
254 if( currentVal !== v ){
\r
256 case XUI_Attr_Support.left.No :
\r
257 this.constraintW = attrs[ XUI_Attr_Support.right.No ] !== null;
\r
259 case XUI_Attr_Support.right.No :
\r
260 this.constraintW = attrs[ XUI_Attr_Support.left.No ] !== null;
\r
262 case XUI_Attr_Support.top.No :
\r
263 this.constraintH = attrs[ XUI_Attr_Support.bottom.No ] !== null;
\r
265 case XUI_Attr_Support.bottom.No :
\r
266 this.constraintH = attrs[ XUI_Attr_Support.top.No ] !== null;
\r
268 case XUI_Attr_Support.width.No :
\r
269 this.autoWidth = v === XUI_Attr_AUTO;
\r
270 this.percentWidth = X_Type_isString( v );
\r
272 case XUI_Attr_Support.height.No :
\r
273 this.autoHeight = v === XUI_Attr_AUTO;
\r
274 this.percentHeight = X_Type_isString( v );
\r
278 if( defaultVal === v ){
\r
279 if( attrs ) delete attrs[ propID ];
\r
281 if( !attrs ) attrs = this.attrObject = new this.attrClass;
\r
282 attrs[ propID ] = v;
\r
285 if( name && user === XUI_Attr_USER.UINODE ){
\r
289 if( name && user === XUI_Attr_USER.XNODE && this.xnode ){
\r
290 this.xnode[ 'css' ]( XUI_Attr_Rename[ name ] || name, XUI_AbstractUINode_createCssText( this, name ) );
\r
291 //console.log( ( XUI_Attr_Rename[ name ] || name ) + ' ' + XUI_AbstractUINode_createCssText( this, name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
293 if( this.dirty < dirty ) this.dirty = dirty;
\r
297 getAttr : function( name ){
\r
298 var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,
\r
299 support = this.usableAttrs[ name ],
\r
301 if( !support ) return;
\r
303 if( name.indexOf( 'border' ) === 0 ){
\r
304 name = name.substr( 6 );
\r
305 return [ this.getAttr( 'borderTop' + name ), this.getAttr( 'borderRight' + name ), this.getAttr( 'borderBottom' + name ), this.getAttr( 'borderLeft' + name ) ];
\r
308 type = support[ 3 ];
\r
310 if( type & XUI_Attr_Type.QUARTET ){
\r
311 return [ this.getAttr( name + 'Top' ), this.getAttr( name + 'Right' ), this.getAttr( name + 'Bottom' ), this.getAttr( name + 'Left' ) ];
\r
313 if( type & XUI_Attr_Type.COMBI ) return [ v, data[ ++propID ] ];
\r
315 v = attrs[ support.No ];
\r
316 if( type & XUI_Attr_Type.AUTO && v === XUI_Attr_AUTO ) return 'auto';
\r
318 list = support[ 4 ];
\r
319 if( list ) return list[ v ];
\r
321 if( type & XUI_Attr_Type.COLOR && X_Type_isNumber( v ) ) return v;
\r
322 if( !( type & XUI_Attr_Type.NUMERICAL ) && X_Type_isNumber( v ) ) return v + 'em';
\r
327 getAttrWithUnit : function( prop, unit ){
\r
331 _remove : function(){
\r
332 switch( this.phase ){
\r
339 this.xnode[ 'kill' ]();
\r
342 delete this.rootData;
\r
343 delete this.parent;
\r
344 delete this.parentData;
\r
353 calculate : function( isNeedsDetection, x, y, allowedW, allowedH ){
\r
354 this.preMesure( allowedW, allowedH );
\r
356 this.noWidth = this.boxWidth === XUI_Attr_AUTO;
\r
357 this.noHeight = this.boxHeight === XUI_Attr_AUTO;
\r
359 if( this.noWidth || this.noHeight ){
\r
364 if( !isNeedsDetection ){
\r
371 * X_Node_BoxModel の情報を引きながら top,left,width,height,padding,border の設定
\r
373 updateLayout : function(){
\r
374 var x = this.boxX + ( this.parentData ? this.parentData.paddingL : 0 ),
\r
375 y = this.boxY + ( this.parentData ? this.parentData.paddingT : 0 ),
\r
376 w = X_UA[ 'IE5x' ] ? this.boxWidth : this.contentWidth, // IE6 の互換モードも
\r
377 h = X_UA[ 'IE5x' ] ? this.boxHeight : this.contentHeight;
\r
380 [ 'css' ]( 'left', x ? x + 'em' : 0 ) // 親の padding 分ずらす
\r
381 [ 'css' ]( 'top', y ? y + 'em' : 0 ) // 親の padding 分ずらす
\r
382 [ 'css' ]( 'width', this.noWidth ? 'auto' : w ? w + 'em' : 0 )
\r
383 [ 'css' ]( 'height', this.noHeight ? 'auto' : h ? h + 'em' : 0 )
\r
384 [ 'css' ]( 'padding', XUI_AbstractUINode_createCssText( this, 'padding' ) ) // TODO 不要? その分 w, h に足す
\r
385 [ 'css' ]( 'borderWidth', XUI_AbstractUINode_createCssText( this, 'borderWidth' ) );
\r
389 * 親の サイズを元に自身のサイズを計算していく
\r
391 preMesure : function( allowedW, allowedH ){
\r
392 var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,
\r
393 box = attrs[ XUI_Attr_Support.sizing.No ],
\r
395 boxL, boxT, boxR, boxB,
\r
396 contentW, contentH, boxMinus,
\r
397 paddingT, paddingR, paddingB, paddingL,
\r
398 borderT, borderR, borderB, borderL;
\r
401 // 自身が constraintW の場合 親が AUTO ではない
\r
402 // 自身が constraintW でない場合自身が AUTO はなくかつ親 が AUTO の場合 or 自身は % でない
\r
404 paddingR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 1 ], allowedW );
\r
405 paddingL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 3 ], allowedW );
\r
406 borderR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 1 ], allowedW );
\r
407 borderL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 3 ], allowedW );
\r
410 case 3 : // border-box
\r
411 boxMinus -= borderR + borderL;
\r
412 case 2 : // padding-box
\r
413 boxMinus -= paddingR + paddingL;
\r
414 // case 1 : // content-box
\r
416 this.contentL = borderL + paddingL;
\r
417 this.contentR = borderR + paddingR;
\r
418 this.paddingL = paddingL;
\r
419 this.borderL = borderL;
\r
421 if( this.constraintW ? allowedW !== XUI_Attr_AUTO : !this.autoWidth && ( allowedW !== XUI_Attr_AUTO || !this.percentWidth ) ){
\r
422 if( this.constraintW ){ // 制約レイアウト
\r
423 contentW = allowedW - ( boxL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.left.No ], allowedW ) ) - ( boxR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.right.No ], allowedW ) );
\r
425 contentW = XUI_AbstractUINode_calcFinalValue( attrs[ XUI_Attr_Support.width.No ], attrs[ XUI_Attr_Support.minWidth.No ], attrs[ XUI_Attr_Support.maxWidth.No ], allowedW );
\r
427 this.contentWidth = contentW + boxMinus;
\r
428 this.boxWidth = this.contentWidth + this.contentL + this.contentR;
\r
429 this.boxSizingOffsetLR = boxMinus;
\r
430 delete this.contentWidthMin;
\r
431 delete this.contentWidthMax;
\r
432 delete this.boxWidthMin;
\r
433 delete this.boxWidthMax;
\r
435 this.contentWidthMin = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], allowedW ) + boxMinus );
\r
436 this.contentWidthMax = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], allowedW ) + boxMinus );
\r
437 this.boxWidthMin = this.contentWidthMin + this.contentL + this.contentR;
\r
438 this.boxWidthMax = this.contentWidthMax + this.contentL + this.contentR;
\r
439 this.contentWidth = this.contentWidthMin;
\r
440 this.boxWidth = this.boxWidthMin;
\r
441 this.boxSizingOffsetLR = boxMinus;
\r
444 paddingT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 0 ], allowedH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
445 paddingB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 2 ], allowedH );
\r
446 borderT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 0 ], allowedH );
\r
447 borderB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 2 ], allowedH );
\r
450 case 3 : // border-box
\r
451 boxMinus -= borderT + borderB;
\r
452 case 2 : // padding-box
\r
453 boxMinus -= paddingT + paddingB;
\r
454 // case 1 : // content-box
\r
456 this.contentT = borderT + paddingT;
\r
457 this.contentB = borderB + paddingB;
\r
458 this.paddingT = paddingT;
\r
459 this.borderT = borderT;
\r
462 if( this.constraintH ? allowedH !== XUI_Attr_AUTO : !this.autoHeight && ( allowedH !== XUI_Attr_AUTO || !this.percentHeight ) ){
\r
463 if( this.constraintH ){ // 制約レイアウト
\r
464 contentH = allowedH - ( boxT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.top.No ], allowedH ) ) - ( boxB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.bottom.No ], allowedH ) );
\r
466 contentH = XUI_AbstractUINode_calcFinalValue( attrs[ XUI_Attr_Support.height.No ], attrs[ XUI_Attr_Support.minHeight.No ], attrs[ XUI_Attr_Support.maxHeight.No ], allowedH );
\r
468 this.contentHeight = contentH + boxMinus;
\r
469 this.boxHeight = this.contentHeight + this.contentT + this.contentB; // padding-box の場合 border だけ足される
\r
470 this.boxSizingOffsetTB = boxMinus;
\r
471 delete this.contentHeightMin;
\r
472 delete this.contentHeightMax;
\r
473 delete this.boxHeightMin;
\r
474 delete this.boxHeightMax;
\r
476 this.contentHeightMin = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], allowedH ) + boxMinus );
\r
477 this.contentHeightMax = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], allowedH ) + boxMinus );
\r
478 this.boxHeightMin = this.contentHeightMin + this.contentT + this.contentB;
\r
479 this.boxHeightMax = this.contentHeightMax + this.contentT + this.contentB;
\r
480 this.contentHeight = this.contentHeightMin;
\r
481 this.boxHeight = this.boxHeightMin;
\r
482 this.boxSizingOffsetTB = boxMinus;
\r
486 if( this.parentData && this.parentData.layout.overrideAttrsForChild.left ){
\r
487 if( this.constraintW || attrs[ XUI_Attr_Support.right.No ] === null ){
\r
488 this.boxX = ( boxL || boxL === 0 ) ? boxL : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.left.No ], allowedW );
\r
490 this.boxX = allowedW - this.boxWidth - ( ( boxR || boxR === 0 ) ? boxR : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.right.No ], allowedW ) );
\r
497 if( this.parentData && this.parentData.layout.overrideAttrsForChild.top ){
\r
498 if( this.constraintH || attrs[ XUI_Attr_Support.bottom.No ] === null ){
\r
499 this.boxY = ( boxT || boxT === 0 ) ? boxT : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.top.No ], allowedH );
\r
501 this.boxY = allowedH - this.boxHeight - ( ( boxB || boxB === 0 ) ? boxB : XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.bottom.No ], allowedH ) );
\r
509 * 描画・計測を行って、contentSize の決定
\r
511 mesure : function(){
\r
512 var dirty = this.dirty,
\r
515 if( dirty === XUI_Dirty.CLEAN ){
\r
516 if( this.percentWidth || this.percentHeight ){
\r
523 case XUI_Dirty.CONTENT : // コンテンツが変更された
\r
524 case XUI_Dirty.FONT : // フォントサイズが変更された
\r
525 delete this.contentWidthLast;
\r
526 delete this.contentHeightLast;
\r
528 case XUI_Dirty.LAYOUT : // レイアウトの再計算が必要
\r
530 default : // TODO レイアウト指定が不正な場合 bgcolor を変更、これ以下のレイアウトの中止
\r
532 w = this.contentWidth;
\r
533 h = this.contentHeight;
\r
534 xnode = this.xnode;
\r
536 /* http://web-designs.seesaa.net/article/188400668.html
\r
537 * min-width の値が max-width の値より大きい場合は、max-width の値は min-width の値に設定される。
\r
540 * 1. contentWidth === AUTO
\r
541 * style を更新して contentWidth の決定
\r
542 * min or max に引っかかったら style 更新
\r
543 * contentHeight === AUTO の場合
\r
545 * contentHeight !== AUTO の場合 scrollHeight のみ更新
\r
546 * 2. contentHeight === AUTO かつ
\r
547 * コンテンツの高さの再取得が必要( contentWidth が最終計測時の contentWidth と一致 かつ フォント・コンテンツに変更無し の場合再取得不要)
\r
548 * style を更新して contentHeight の決定
\r
550 * 3. content のサイズがすでに決定している
\r
554 if( xnode[ '_xnodes' ] && xnode[ '_xnodes' ].length ){
\r
555 if( w === XUI_Attr_AUTO ){
\r
557 w = _w = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'width', 'auto' )[ 'clientWidth' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
559 if( this.contentWidthMax < w - this.boxSizingOffsetLR ){
\r
560 this.noWidth = false;
\r
561 w = this.contentWidthMax + this.boxSizingOffsetLR;
\r
563 if( w - this.boxSizingOffsetLR < this.contentWidthMin ){
\r
564 this.noWidth = false;
\r
565 w = this.contentWidthMin + this.boxSizingOffsetLR;
\r
568 if( h === XUI_Attr_AUTO ){
\r
569 w !== _w && xnode[ 'css' ]( 'width', w + 'em' );
\r
570 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
571 w !== _w && xnode[ 'css' ]( 'width', 'auto' );
\r
574 this.contentWidthLast = this.contentWidth = w;
\r
577 if( h === XUI_Attr_AUTO ){
\r
578 if( w !== this.contentWidthLast ){
\r
579 xnode[ 'css' ]( 'width', w + 'em' );
\r
580 this.contentWidthLast = w;
\r
582 // ie8 clientHeight, ff scrollHeight & clientHeight
\r
583 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
585 h = this.contentHeightLast === -1 ?
\r
586 XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) ) :
\r
587 this.contentHeightLast;
\r
590 if( dirty !== XUI_Dirty.LAYOUT ){
\r
591 this.contentWidth = this.contentWidthLast = w;
\r
592 h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
595 if( this.contentHeightMax < h - this.boxSizingOffsetTB ){
\r
596 this.noHeight = false;
\r
597 h = this.contentHeightMax + this.boxSizingOffsetTB;
\r
599 if( h - this.boxSizingOffsetTB < this.contentHeightMin ){
\r
600 this.noHeight = false;
\r
601 h = this.contentHeightMin + this.boxSizingOffsetTB;
\r
604 this.contentHeight = this.contentHeightLast = h;
\r
607 // コンテンツを持たないため基本のサイズは0
\r
608 if( w === XUI_Attr_AUTO ) this.contentWidth = w = 0 < this.contentWidthMin ? this.contentWidthMin : 0;
\r
609 if( h === XUI_Attr_AUTO ) this.contentHeight = h = 0 < this.contentHeightMin ? this.contentHeightMin : 0;
\r
610 this.noWidth = this.noHeight = false;
\r
615 //case XUI_Dirty.PAINT : // 再描画のみ必要
\r
620 * 自身の contentWidth, contentHeight を元に AUTO な width, height を確定していく
\r
622 postMesure : function(){
\r
623 var attrs = this.attrObject || this.attrClass.prototype || XUI_AttrClass,
\r
624 box = attrs[ XUI_Attr_Support.sizing.No ],
\r
625 contentW, contentH,
\r
627 paddingT, paddingR, paddingB, paddingL,
\r
628 borderT, borderR, borderB, borderL,
\r
632 if( this.boxWidth === XUI_Attr_AUTO ){
\r
633 contentW = this.contentWidth;
\r
634 paddingR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 1 ], contentW );
\r
635 paddingL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 3 ], contentW );
\r
636 borderR = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 1 ], contentW );
\r
637 borderL = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 3 ], contentW );
\r
640 case 1 : // content-box
\r
641 contentPlus = paddingR + paddingL;
\r
642 case 2 : // padding-box
\r
643 contentPlus += borderR + borderL;
\r
644 // case 3 : // border-box
\r
647 if( !this.constraintW ){
\r
648 contentW += contentPlus;
\r
649 min = this.boxWidthMin = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minWidth.No ], contentW );
\r
650 max = this.boxWidthMax = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxWidth.No ], contentW );
\r
651 if( contentW < min && contentPlus < min ){
\r
652 this.contentWidth = min - contentPlus;
\r
654 if( max < contentW && contentPlus < max ){
\r
655 this.contentWidth = max - contentPlus;
\r
658 this.contentL = borderL + paddingL;
\r
659 this.contentR = borderR + paddingR;
\r
660 this.paddingL = paddingL;
\r
661 this.borderL = borderL;
\r
662 this.boxWidth = this.contentWidth + this.contentL + this.contentR;
\r
665 if( this.boxHeight === XUI_Attr_AUTO ){
\r
666 contentH = this.contentHeight;
\r
667 paddingT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 0 ], contentH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
668 paddingB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.padding.No + 2 ], contentH );
\r
669 borderT = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 0 ], contentH );
\r
670 borderB = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.borderWidth.No + 2 ], contentH );
\r
673 case 1 : // content-box
\r
674 contentPlus = paddingT + paddingB;
\r
675 case 2 : // padding-box
\r
676 contentPlus += borderT + borderB;
\r
677 // case 3 : // border-box
\r
679 if( !this.constraintH ){
\r
680 contentH += contentPlus;
\r
681 min = this.boxHeightMin = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.minHeight.No ], contentH );
\r
682 max = this.boxHeightMax = XUI_AbstractUINode_calcValue( attrs[ XUI_Attr_Support.maxHeight.No ], contentH );
\r
683 if( contentH < min && contentPlus < min ){
\r
684 this.contentHeight = min - contentPlus;
\r
686 if( max < contentH && contentPlus < max ){
\r
687 this.contentHeight = max - contentPlus;
\r
690 this.contentT = borderT + paddingT;
\r
691 this.contentB = borderB + paddingB;
\r
692 this.paddingT = paddingT;
\r
693 this.borderT = borderT;
\r
694 this.boxHeight = this.contentHeight + this.contentT + this.contentB;
\r
698 // TODO fontsize が変わることもある
\r
699 capcher : function( x, y ){
\r
700 if( this.pointerDisabled ) return false;
\r
705 if( 0 <= x && x < this.boxWidth && 0 <= y && y < this.boxHeight ){
\r
706 !this.hovering && ( this.rootData.hoverList[ this.rootData.hoverList.length ] = this );
\r
707 this.rootData.targetNodeData = this;
\r
713 * context を明示しない場合、User が context になる!
\r
715 listen : function( type, arg1, arg2, arg3 ){
\r
716 var root, events, counter, f;
\r
718 if( XUI_Event._START_POINTER <= type && type <= XUI_Event._END_POINTER ){
\r
719 if( this.phase < 3 ){
\r
720 if( !( events = this.reserveEvents ) ) this.reserveEvents = events = [];
\r
721 events[ events.length ] = [ type, arg1, arg2, arg3 ];
\r
724 if( XUI_Event._START_XUI_EVENT < type && type < XUI_Event._END_XUI_EVENT ){
\r
725 if( !this.gesture ){
\r
726 this.gesture = new Hammer( this.rootData, this, type );
\r
728 this.gesture[ 'listen' ]( type );
\r
731 //console.log( type );
\r
732 root = this.rootData;
\r
733 counter = root.eventCounter;
\r
734 if( counter[ type ] ){
\r
737 counter[ type ] = 1;
\r
738 root.xnodeInteractiveLayer[ 'listen' ]( XUI_Event.IdToName[ type ], X_UI_eventRellay );
\r
743 arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 ) );
\r
745 return X_EventDispatcher_listen.call( this, type, this.User, f );
\r
747 if( f.kind === X_Callback_FUNC_ONLY ){
\r
748 return X_EventDispatcher_listen.call( this, type, this.User, f.func, f.supplement );
\r
750 return X_EventDispatcher_listen.apply( this, arguments );
\r
752 unlisten : function( type, arg1, arg2, arg3 ){
\r
753 var root, events, i, ev, counter, f;
\r
754 if( XUI_Event._START_POINTER <= type && type <= XUI_Event._END_POINTER ){
\r
755 if( this.phase < 3 ){
\r
756 if( !( events = this.reserveEvents ) ) return this;
\r
757 for( i = events.length; i; ){
\r
758 ev = events[ --i ];
\r
759 if( ev[ 0 ] === type && ev[ 1 ] === arg1 && ev[ 2 ] === arg2 ){
\r
760 events.split( i, 1 );
\r
767 if( XUI_Event._START_XUI_EVENT < type && type < XUI_Event._END_XUI_EVENT ){
\r
768 this.gesture && this.gesture[ 'unlisten' ]( type );
\r
770 root = this.rootData;
\r
771 counter = root.eventCounter;
\r
772 if( !counter[ type ] ) return this;
\r
774 if( counter[ type ] === 0 ){
\r
775 root.xnodeInteractiveLayer[ 'unlisten' ]( XUI_Event.IdToName[ type ], X_UI_eventRellay );
\r
776 delete counter[ type ];
\r
780 arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 ) );
\r
782 return X_EventDispatcher_unlisten.apply( this, [ type, this.User, f ] );
\r
784 if( f.kind === X_Callback_FUNC_ONLY ){
\r
785 return X_EventDispatcher_unlisten.apply( this, [ type, this.User, f.func, f.supplement ] );
\r
787 return X_EventDispatcher_unlisten.apply( this, arguments );
\r
790 dispatch : function( e ){
\r
791 //console.log( e.type + ' ' + ( this[ '_listeners' ] && this[ '_listeners' ][ e.type ] ) );
\r
792 var xve = XUI_Event,
\r
793 ret = X_EventDispatcher_dispatch.call( this, e ),
\r
794 type = e.type || e;
\r
796 // TODO captureEvent PointerEvent
\r
797 if( ret & X_Callback_CAPTURE_POINTER && !this.hitChildData && XUI_Event._POINTER_MOVE === type ){
\r
798 this.rootData.monopolyNodeData = this;
\r
801 this.rootData.monopolyNodeData = null;
\r
802 if( xve._START_BUBLEUP < type && this.parentData && !( ret & X_Callback_STOP_PROPAGATION ) && !( ret & X_Callback_STOP_NOW ) ) return this.parentData[ 'dispatch' ]( e );
\r
806 setItemData : function( itemData ){
\r
807 if( this.itemData === itemData ) return;
\r
809 this.itemData = itemData;
\r
811 this[ 'dispatch' ]( { type : XUI_Event.ITEMDATA_CHANGED, itemData : itemData } );
\r
812 // itemData && itemData.listen( X_Event_CHANGED )
\r
813 // dataFeild dataFormatter dataValidator
\r
815 // itemData.listen( X_Event_CHANGED ) -> this[ 'dispatch' ]( UI_Event.ITEMDATA_UPDATED );
\r
821 function XUI_AbstractUINode_createCssText( that, name ){
\r
822 var attrs = that.attrObject || that.attrClass.prototype || XUI_AttrClass,
\r
823 def = that.usableAttrs[ name ],
\r
825 v = attrs[ def.No ],
\r
828 flag = !!( type & XUI_Attr_Type.BOOLEAN ),
\r
829 combi = !!( type & XUI_Attr_Type.COMBI ),
\r
830 quartet = !!( type & XUI_Attr_Type.QUARTET );
\r
833 if( attrs[ no + 1 ] === attrs[ no + 3 ] ){
\r
834 if( v === attrs[ no + 2 ] ){
\r
835 if( v === attrs[ no + 1 ] ){
\r
836 return XUI_AbstractUINode_createCssValue( v, type, list );
\r
839 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
840 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list )
\r
844 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
845 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list ),
\r
846 XUI_AbstractUINode_createCssValue( attrs[ no + 2 ], type, list )
\r
850 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
851 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list ),
\r
852 XUI_AbstractUINode_createCssValue( attrs[ no + 2 ], type, list ),
\r
853 XUI_AbstractUINode_createCssValue( attrs[ no + 3 ], type, list )
\r
858 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
859 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list )
\r
863 return v ? list : 'normal'; //
\r
865 return XUI_AbstractUINode_createCssValue( v, type, list );
\r
868 function XUI_AbstractUINode_createCssValue( v, type, list ){
\r
869 var length = !!( type & XUI_Attr_Type.LENGTH ),
\r
870 minusLen = !!( type & XUI_Attr_Type.MINUS_LENGTH ),
\r
871 percent = !!( type & XUI_Attr_Type.PERCENT ),
\r
872 minusPct = !!( type & XUI_Attr_Type.MINUS_PERCENT ),
\r
873 numerical = !!( type & XUI_Attr_Type.NUMERICAL ),
\r
874 auto = !!( type & XUI_Attr_Type.AUTO ),
\r
875 color = !!( type & XUI_Attr_Type.COLOR ),
\r
876 url = !!( type & XUI_Attr_Type.URL ),
\r
877 fontName = !!( type & XUI_Attr_Type.FONT_NAME );
\r
879 if( X_Type_isNumber( v ) ){
\r
880 if( auto && v === XUI_Attr_AUTO ) return 'auto';
\r
881 if( length || minusLen ) return v + 'em';
\r
882 if( numerical ) return v;
\r
883 if( list && list[ v ] ) return list[ v ];
\r
885 if( v < 0x100000 ){
\r
886 v = '00000' + v.toString( 16 );
\r
887 return '#' + v.substr( v.length - 6 );
\r
889 return '#' + v.toString( 16 );
\r
892 if( X_Type_isString( v ) ){
\r
893 if( percent || minusPct || url || fontName ) return v;
\r
897 function XUI_AbstractUINode_calcValue( styleValue, srcValue ){
\r
901 if( X_Type_isString( styleValue ) ){
\r
902 return srcValue * parseFloat( styleValue ) / 100;
\r
904 if( !X_Type_isNumber( styleValue ) ) return 0;
\r
908 function XUI_AbstractUINode_calcFinalValue( styleValue, styleMin, styleMax, srcValue ){
\r
909 var v = XUI_AbstractUINode_calcValue( styleValue, srcValue ),
\r
910 min = XUI_AbstractUINode_calcValue( styleMin, srcValue ),
\r
911 max = XUI_AbstractUINode_calcValue( styleMax, srcValue );
\r
912 return v <= min ? min : max <= v ? max : v;
\r
914 function XUI_AbstractUINode_ceil( v ){
\r
916 return ( v * 10 + 0.999 | 0 ) / 10;
\r
918 return ( -v * 10 + 0.999 | 0 ) / -10;
\r
921 X.UI.AbstractUINode = X_Class_create(
\r
925 parent : function(){
\r
926 return X_Pair_get( this ).parent;
\r
929 return X_Pair_get( this ).root;
\r
933 * unverifiedAttrs に全ての指定を控える
\r
934 * サポートされていない場合は無視される.親のレイアウトによって変わる
\r
936 attr : function( nameOrObject, valueOrUnit ){
\r
937 var p = X_Pair_get( this ),
\r
938 layout, k, def, attrs, v;
\r
939 if( nameOrObject && X_Type_isObject( nameOrObject ) ){
\r
941 layout = p.parentData && p.parentData.layout.overrideAttrsForChild; // root には parent がない
\r
942 for( k in nameOrObject ){
\r
943 if( X_EMPTY_OBJECT[ k ] ) continue;
\r
944 // 親のレイアウトマネージャの許可しない
\r
945 if( layout && !layout[ k ] ){
\r
948 if( def = p.usableAttrs[ k ] ){
\r
949 p.setAttr( k, def, nameOrObject[ k ] );
\r
953 if( X_Type_isString( nameOrObject ) && ( def = p.usableAttrs[ nameOrObject ] ) ){
\r
954 if( valueOrUnit !== undefined ){
\r
955 if( 'em,%'.indexOf( valueOrUnit ) === -1 ){
\r
957 p.setAttr( nameOrObject, def, valueOrUnit );
\r
959 // getter with unit
\r
960 return p.getAttrWithUnit( nameOrObject, valueOrUnit );
\r
964 if( attrs = ( p.attrObject || p.attrClass.prototype || XUI_AttrClass ) ){
\r
965 def = p.usableAttrs[ nameOrObject ];
\r
966 return def && attrs[ def.No ];
\r
973 listen : function( type, arg1, arg2, arg3 ){
\r
974 X_Pair_get( this )[ 'listen' ]( type, arg1, arg2, arg3 );
\r
977 listenOnce : function( type, arg1, arg2, arg3 ){
\r
978 X_Pair_get( this )[ 'listenOnce' ]( type, arg1, arg2, arg3 );
\r
981 listening : function( type, arg1, arg2, arg3 ){
\r
982 return X_Pair_get( this )[ 'listening' ]( type, arg1, arg2, arg3 );
\r
984 unlisten : function( type, arg1, arg2, arg3 ){
\r
985 X_Pair_get( this )[ 'unlisten' ]( type, arg1, arg2, arg3 );
\r
988 dispatch : function( e ){
\r
989 return X_Pair_get( this )[ 'dispatch' ]( e );
\r
992 nextNode : function(){
\r
995 prevNode : function(){
\r
998 nodeIndex : function( v ){
\r
999 var data = X_Pair_get( this );
\r
1000 if( typeof v === 'number' ){
\r
1001 // data.nodeIndex( v );
\r
1004 return data.parentData ? data.parentData.nodes.indexOf( data ) : 0;
\r
1006 displayIndex : function(){
\r
1009 getX : function(){
\r
1010 // dirty の場合、rootData.calculate
\r
1011 return X_Pair_get( this ).boxX;
\r
1013 getY : function(){
\r
1014 // dirty の場合、rootData.calculate
\r
1015 return X_Pair_get( this ).boxY;
\r
1017 getAbsoluteX : function(){
\r
1018 // dirty の場合、rootData.calculate
\r
1019 return X_Pair_get( this ).absoluteX;
\r
1021 getAbsoluteY: function(){
\r
1022 // dirty の場合、rootData.calculate
\r
1023 return X_Pair_get( this ).absoluteY;
\r
1025 getWidth : function(){
\r
1026 // dirty の場合、rootData.calculate
\r
1027 return X_Pair_get( this ).boxWidth;
\r
1029 getHeight : function(){
\r
1030 // dirty の場合、rootData.calculate
\r
1031 return X_Pair_get( this ).boxHeight;
\r
1035 * Repeater に於いて、繰り返されるアイテムの元(itemRenderer)からの複製に使用
\r
1037 clone : function( opt_cloneListener ){
\r
1039 //newPair = X_Pair_get( newNode ),
\r
1040 pair = X_Pair_get( this ),
\r
1041 attr, listeners, type, list, i, l;
\r
1044 if( pair.attrObject ){
\r
1046 for( k in pair.usableAttrs ){
\r
1047 def = pair.usableAttrs[ k ];
\r
1048 attr[ k ] = pair.attrObject[ def.No ];
\r
1050 newNode = this.constructor( attr );
\r
1053 // handleEvent 等の拡張されたオブジェクトもコピーする!
\r
1055 if( this[ k ] !== newNode[ k ] && !newNode[ k ] ) newNode[ k ] = this[ k ];
\r
1058 // User.UINODE な値は pair にコピーされているのでこれをコピー
\r
1060 //pair[ k ] !== newPair[ k ] && !newPair[ k ] && console.log( k );
\r
1061 //if( pair[ k ] !== newPair[ k ] && !newPair[ k ] && k !== 'attrObject' && k !== '_listeners' ){
\r
1062 //newPair[ k ] = pair[ k ];
\r
1063 //console.log( k );
\r
1069 // listener もコピーする!
\r
1070 if( opt_cloneListener && ( listeners = pair[ '_listeners' ] ) ){
\r
1071 for( type in listeners ){
\r
1072 list = listeners[ type ];
\r
1073 for( i = 0, l = list.length; i < l; ++i ){
\r
1076 case X_Callback_THIS_FUNC :
\r
1078 X_EventDispatcher_systemListen( newNode, type, f.context === this ? newNode : f.context, f.func, f.supplement );
\r
1080 newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.context === this ? newNode : f.context, f.func, f.supplement );
\r
1083 case X_Callback_HANDLEEVENT :
\r
1085 X_EventDispatcher_systemListen( newNode, type, f.context === this ? newNode : f.context, f.supplement );
\r
1087 newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.context === this ? newNode : f.context, f.supplement );
\r
1091 case X_Callback_FUNC_ONLY :
\r
1093 X_EventDispatcher_systemListen( newNode, type, f.func, f.supplement );
\r
1095 newNode[ f.once ? 'listenOnce' : 'listen' ]( type, f.func, f.supplement );
\r
1099 newNode[ 'listen' ]( type, f );
\r
1105 if( opt_cloneListener && ( list = this.reserveEvents ) ){
\r
1106 for( i = 0, l = list.length; i < l; ++i ){
\r
1108 newNode[ f.once ? 'listenOnce' : 'listen' ]( f[ 0 ], newNode, f[ 1 ], f[ 2 ] );
\r