1 X.UI._AbstractUINode = X_EventDispatcher[ 'inherits' ](
\r
2 'X.UI._AbstractUINode',
\r
3 X_Class.ABSTRACT | X_Class.PRIVATE_DATA,
\r
6 dirty : X.UI.Dirty.CLEAN,
\r
15 supportAttrs : X.UI.Attr.Support,
\r
16 attrClass : X.UI.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 : X.UI.Attr.AUTO,
\r
37 maxBoxWidth : X.UI.Attr.AUTO,
\r
38 boxHeight : X.UI.Attr.AUTO,
\r
40 maxBoxHeight : X.UI.Attr.AUTO,
\r
45 boxSizingOffsetLR : 0,
\r
46 boxSizingOffsetTB : 0,
\r
47 contentWidth : X.UI.Attr.AUTO,
\r
48 minContentWidth : 0,
\r
49 maxContentWidth : X.UI.Attr.AUTO,
\r
50 lastContentWidth : -1,
\r
51 contentHeight : X.UI.Attr.AUTO,
\r
52 minContentHeight : 0,
\r
53 maxContentHeight : X.UI.Attr.AUTO,
\r
54 lastContentHeight : -1,
\r
56 constraintW : false,
\r
57 constraintH : false,
\r
60 percentWidth : false,
\r
61 percentHeight : false,
\r
62 // :hover, :focus, :disabled
\r
64 initialize : function( root, rootData, parent, parentData ){
\r
66 this.rootData = rootData;
\r
67 this.parent = parent;
\r
68 this.parentData = parentData;
\r
69 //this.xnode = X_Doc_create( 'div' );
\r
72 this[ 'dispatch' ]( X.UI.Event.INIT );
\r
75 addToParent : function( xnodeParent ){
\r
76 xnodeParent && xnodeParent[ 'append' ]( this.xnode );
\r
79 this[ 'dispatch' ]( X.UI.Event.ADDED );
\r
82 creationComplete : function(){
\r
83 var events = this.reserveEvents,
\r
87 this.User[ 'dispatch' ]( X.UI.Event.CREATION_COMPLETE );
\r
89 // html 要素が親に追加されるまで控えていたイベントの登録
\r
90 if( events && ( l = events.length ) ){
\r
91 for( i = 0; i < l; ++i ){
\r
92 this.listen.apply( this, events[ i ] );
\r
95 delete this.reserveEvents;
\r
100 * _UINode への setAttr の他、attrClass.prototype への setAttr にも対応する
\r
101 * 親要素が変化した場合、unverifiedAttrs を元に attrObject を再設定.
\r
103 setAttr : function( name, def, v ){
\r
104 var attrs = X.UI.attrClassProto || this.attrObject,
\r
105 propID = def.No || def[ 5 ],
\r
106 defaultVal = X.UI.attrClassProto ? attrs[ propID ] : this.attrClass.prototype[ propID ], // def[ 0 ],
\r
107 currentVal = attrs ? attrs[ propID ] : defaultVal,
\r
112 length = !!( type & X.UI.Attr.Type.LENGTH ),
\r
113 minusLen = !!( type & X.UI.Attr.Type.MINUS_LENGTH ),
\r
114 percent = !!( type & X.UI.Attr.Type.PERCENT ),
\r
115 minusPct = !!( type & X.UI.Attr.Type.MINUS_PERCENT ),
\r
116 numerical = !!( type & X.UI.Attr.Type.NUMERICAL ),
\r
117 auto = !!( type & X.UI.Attr.Type.AUTO ),
\r
118 color = !!( type & X.UI.Attr.Type.COLOR ),
\r
119 url = !!( type & X.UI.Attr.Type.URL ),
\r
120 fontName = !!( type & X.UI.Attr.Type.FONT_NAME ),
\r
121 flag = !!( type & X.UI.Attr.Type.BOOLEAN ),
\r
122 combi = !!( type & X.UI.Attr.Type.COMBI ),
\r
123 quartet = !!( type & X.UI.Attr.Type.QUARTET ),
\r
124 _v, i, l, nodes, root, roots;
\r
126 if( X_Type_isString( v ) ){
\r
127 //v = v.toLowercase();
\r
128 if( url || fontName ){
\r
131 if( auto && v === 'auto' ){
\r
132 v = X.UI.Attr.AUTO;
\r
134 if( list && ( _v = list[ v ] ) ){
\r
136 console.log( v + ' ' + _v );
\r
139 if( ( percent || minusPct ) && v.lastIndexOf( '%' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + '%' ){
\r
142 if( ( length || minusLen ) && v.lastIndexOf( 'em' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + 'em' ){
\r
145 if( v.indexOf( ' ' ) !== -1 ){
\r
146 v = v.split( ' ' );
\r
148 if( color && X_Type_isNumber( _v = X_Node_CSS_objToIEFilterText( v ) ) ){
\r
156 if( ( quartet || combi ) && !X_Type_isArray( v ) ){
\r
160 if( X_Type_isNumber( v ) ){
\r
162 ( length && ( 0 <= v ) ) ||
\r
163 ( minusLen && ( v <= 0 ) ) ||
\r
164 ( percent && 0 <= v && v <= 1 ) ||
\r
165 ( minusPct && -1 <= v && v < 0 ) ||
\r
166 ( numerical && 0 <= v ) ||
\r
167 ( auto && v === X.UI.Attr.AUTO ) ||
\r
168 ( color && 0 <= v && v <= 0xFFFFFF ) ||
\r
169 ( list && list[ v ] )
\r
177 if( X_Type_isBoolean( v ) && !flag ){
\r
180 if( X_Type_isArray( v ) ){
\r
181 if( v.length <= 4 && quartet ){
\r
182 type &= ~X.UI.Attr.Type.QUARTET;
\r
183 switch( v.length ){
\r
185 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
186 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
187 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
188 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[ 1 ] );
\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[ 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
199 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\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[ 3 ] );
\r
210 if( v.length === 2 && combi ){
\r
211 type &= ~X.UI.Attr.Type.COMBI;
\r
212 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
213 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
219 if( !X.UI.attrClassProto && user === X.UI.Attr.USER.XNODE && this.xnode ){
\r
220 this.xnode[ 'css' ]( X.UI.Attr.Rename[ name ] || name, XUI_AbstractUINode_createCssText( this, name ) );
\r
221 //console.log( ( X.UI.Attr.Rename[ name ] || name ) + ' ' + XUI_AbstractUINode_createCssText( this, name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
226 if( !v && v !== 0 ) v = defaultVal;
\r
228 if( X.UI.attrClassProto ){
\r
229 attrs[ propID ] = v;
\r
233 if( currentVal !== v ){
\r
235 case X.UI.Attr.Support.left.No :
\r
236 this.constraintW = attrs[ X.UI.Attr.Support.right.No ] !== null;
\r
238 case X.UI.Attr.Support.right.No :
\r
239 this.constraintW = attrs[ X.UI.Attr.Support.left.No ] !== null;
\r
241 case X.UI.Attr.Support.top.No :
\r
242 this.constraintH = attrs[ X.UI.Attr.Support.bottom.No ] !== null;
\r
244 case X.UI.Attr.Support.bottom.No :
\r
245 this.constraintH = attrs[ X.UI.Attr.Support.top.No ] !== null;
\r
247 case X.UI.Attr.Support.width.No :
\r
248 this.autoWidth = v === X.UI.Attr.AUTO;
\r
249 this.percentWidth = X_Type_isString( v );
\r
251 case X.UI.Attr.Support.height.No :
\r
252 this.autoHeight = v === X.UI.Attr.AUTO;
\r
253 this.percentHeight = X_Type_isString( v );
\r
257 if( defaultVal === v ){
\r
258 if( attrs ) delete attrs[ propID ];
\r
260 if( !attrs ) attrs = this.attrObject = new this.attrClass;
\r
261 attrs[ propID ] = v;
\r
264 if( name && user === X.UI.Attr.USER.UINODE ){
\r
268 if( name && user === X.UI.Attr.USER.XNODE && this.xnode ){
\r
269 this.xnode[ 'css' ]( X.UI.Attr.Rename[ name ] || name, XUI_AbstractUINode_createCssText( this, name ) );
\r
270 //console.log( ( X.UI.Attr.Rename[ name ] || name ) + ' ' + XUI_AbstractUINode_createCssText( this, name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
272 if( this.dirty < dirty ) this.dirty = dirty;
\r
276 getAttr : function( name ){
\r
277 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
278 support = this.supportAttrs[ name ],
\r
280 if( !support ) return;
\r
282 if( name.indexOf( 'border' ) === 0 ){
\r
283 name = name.substr( 6 );
\r
284 return [ this.getAttr( 'borderTop' + name ), this.getAttr( 'borderRight' + name ), this.getAttr( 'borderBottom' + name ), this.getAttr( 'borderLeft' + name ) ];
\r
287 type = support[ 3 ];
\r
289 if( type & X.UI.Attr.Type.QUARTET ){
\r
290 return [ this.getAttr( name + 'Top' ), this.getAttr( name + 'Right' ), this.getAttr( name + 'Bottom' ), this.getAttr( name + 'Left' ) ];
\r
292 if( type & X.UI.Attr.Type.COMBI ) return [ v, data[ ++propID ] ];
\r
294 v = attrs[ support.No ];
\r
295 if( type & X.UI.Attr.Type.AUTO && v === X.UI.Attr.AUTO ) return 'auto';
\r
297 list = support[ 4 ];
\r
298 if( list ) return list[ v ];
\r
300 if( type & X.UI.Attr.Type.COLOR && X_Type_isNumber( v ) ) return v;
\r
301 if( !( type & X.UI.Attr.Type.NUMERICAL ) && X_Type_isNumber( v ) ) return v + 'em';
\r
306 getAttrWithUnit : function( prop, unit ){
\r
310 _remove : function(){
\r
311 switch( this.phase ){
\r
318 this.xnode[ 'kill' ]();
\r
321 delete this.rootData;
\r
322 delete this.parent;
\r
323 delete this.parentData;
\r
332 calculate : function( isNeedsDetection, x, y, allowedW, allowedH ){
\r
333 this.preMesure( allowedW, allowedH );
\r
335 if( this.boxWidth === X.UI.Attr.AUTO || this.boxHeight === X.UI.Attr.AUTO ){
\r
340 !isNeedsDetection && this.updateLayout( x, y );
\r
344 * X_Node_BoxModel の情報を引きながら top,left,width,height,padding,border の設定
\r
346 updateLayout : function( x, y ){
\r
350 [ 'css' ]( 'left', x ? x + 'em' : 0 )
\r
351 [ 'css' ]( 'top', y ? y + 'em' : 0 )
\r
352 [ 'css' ]( 'width', this.contentWidth ? XUI_AbstractUINode_ceil( this.contentWidth ) + 'em' : 0 )
\r
353 [ 'css' ]( 'height', this.contentHeight ? XUI_AbstractUINode_ceil( this.contentHeight ) + 'em' : 0 )
\r
354 [ 'css' ]( 'padding', XUI_AbstractUINode_createCssText( this, 'padding' ) )
\r
355 [ 'css' ]( 'borderWidth', XUI_AbstractUINode_createCssText( this, 'borderWidth' ) );
\r
359 * 親の サイズを元に自身のサイズを計算していく
\r
361 preMesure : function( allowedW, allowedH ){
\r
362 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
363 box = attrs[ X.UI.Attr.Support.sizing.No ],
\r
365 boxL, boxT, boxR, boxB,
\r
366 contentW, contentH, boxMinus,
\r
367 paddingT, paddingR, paddingB, paddingL,
\r
368 borderT, borderR, borderB, borderL;
\r
371 // 自身が constraintW の場合 親が AUTO ではない
\r
372 // 自身が constraintW でない場合自身が AUTO はなくかつ親 が AUTO の場合 or 自身は % でない
\r
374 paddingR = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.padding.No + 1 ], allowedW );
\r
375 paddingL = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.padding.No + 3 ], allowedW );
\r
376 borderR = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.borderWidth.No + 1 ], allowedW );
\r
377 borderL = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.borderWidth.No + 3 ], allowedW );
\r
380 case 3 : // border-box
\r
381 boxMinus -= borderR + borderL;
\r
382 case 2 : // padding-box
\r
383 boxMinus -= paddingR + paddingL;
\r
384 // case 1 : // content-box
\r
386 this.contentL = borderL + paddingL;
\r
387 this.contentR = borderR + paddingR;
\r
389 if( this.constraintW ? allowedW !== X.UI.Attr.AUTO : !this.autoWidth && ( allowedW !== X.UI.Attr.AUTO || !this.percentWidth ) ){
\r
390 if( this.constraintW ){ // 制約レイアウト
\r
391 contentW = allowedW - ( boxL = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.left.No ], allowedW ) ) - ( boxR = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.right.No ], allowedW ) );
\r
393 contentW = XUI_AbstractUINode_calcFinalValue( attrs[ X.UI.Attr.Support.width.No ], attrs[ X.UI.Attr.Support.minWidth.No ], attrs[ X.UI.Attr.Support.maxWidth.No ], allowedW );
\r
395 this.contentWidth = contentW + boxMinus;
\r
396 //this.scrollWidth = this.contentWidth + this.contentL + this.contentR;
\r
397 this.boxWidth = contentW - boxMinus + this.contentL + this.contentR;
\r
398 this.boxSizingOffsetLR = boxMinus;
\r
399 delete this.minContentWidth;
\r
400 delete this.maxContentWidth;
\r
401 delete this.minBoxWidth;
\r
402 delete this.maxBoxWidth;
\r
404 this.minContentWidth = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.minWidth.No ], allowedW ) + boxMinus );
\r
405 this.maxContentWidth = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.maxWidth.No ], allowedW ) + boxMinus );
\r
406 //this.scrollWidth = this.contentWidth + this.contentL + this.contentR;
\r
407 this.minBoxWidth = this.minContentWidth - boxMinus + this.contentL + this.contentR;
\r
408 this.maxBoxWidth = this.maxContentWidth - boxMinus + this.contentL + this.contentR;
\r
409 //delete this.contentWidth;
\r
410 //delete this.scrollWidth;
\r
411 //delete this.boxWidth;
\r
412 //delete this.boxSizingOffsetLR;
\r
415 paddingT = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.padding.No + 0 ], allowedH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
416 paddingB = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.padding.No + 2 ], allowedH );
\r
417 borderT = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.borderWidth.No + 0 ], allowedH );
\r
418 borderB = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.borderWidth.No + 2 ], allowedH );
\r
421 case 3 : // border-box
\r
422 boxMinus -= borderT + borderB;
\r
423 case 2 : // padding-box
\r
424 boxMinus -= paddingT + paddingB;
\r
425 // case 1 : // content-box
\r
427 this.contentT = borderT + paddingT;
\r
428 this.contentB = borderB + paddingB;
\r
431 if( this.constraintH ? allowedH !== X.UI.Attr.AUTO : !this.autoHeight && ( allowedH !== X.UI.Attr.AUTO || !this.percentHeight ) ){
\r
432 if( this.constraintH ){ // 制約レイアウト
\r
433 contentH = allowedH - ( boxT = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.top.No ], allowedH ) ) - ( boxB = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.bottom.No ], allowedH ) );
\r
435 contentH = XUI_AbstractUINode_calcFinalValue( attrs[ X.UI.Attr.Support.height.No ], attrs[ X.UI.Attr.Support.minHeight.No ], attrs[ X.UI.Attr.Support.maxHeight.No ], allowedH );
\r
437 this.contentHeight = contentH + boxMinus;
\r
438 //this.scrollHeight = this.contentHeight + this.contentT + this.contentB;
\r
439 this.boxHeight = contentH - boxMinus + this.contentT + this.contentB; // padding-box の場合 border だけ足される
\r
440 this.boxSizingOffsetTB = boxMinus;
\r
441 delete this.minContentHeight;
\r
442 delete this.maxContentHeight;
\r
443 delete this.minBoxHeight;
\r
444 delete this.maxBoxHeight;
\r
446 this.minContentHeight = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.minHeight.No ], allowedH ) + boxMinus );
\r
447 this.maxContentHeight = XUI_AbstractUINode_ceil( XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.maxHeight.No ], allowedH ) + boxMinus );
\r
448 this.minBoxHeight = this.minContentHeight - boxMinus + this.contentT + this.contentB;
\r
449 this.maxBoxHeight = this.maxContentHeight - boxMinus + this.contentT + this.contentB;
\r
451 //delete this.contentHeight;
\r
452 //delete this.scrollHeight;
\r
453 //delete this.boxHeight;
\r
454 //delete this.boxSizingOffsetTB;
\r
457 if( this.parentData && this.parentData.layout.overrideAttrsForChild.left ){
\r
458 if( this.constraintW ){
\r
459 this.boxX = ( boxL || boxL === 0 ) ? boxL : XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.left.No ], allowedW );
\r
461 if( attrs[ X.UI.Attr.Support.right.No ] === null ){
\r
462 this.boxX = ( boxL || boxL === 0 ) ? boxL : XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.left.No ], allowedW );
\r
464 this.boxX = alllowW - this.boxWidth - ( ( boxR || boxR === 0 ) ? boxR : XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.right.No ], allowedW ) );
\r
470 if( this.parentData && this.parentData.layout.overrideAttrsForChild.top ){
\r
471 if( this.constraintH ){
\r
472 this.boxY = ( boxT || boxT === 0 ) ? boxT : XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.top.No ], allowedH );
\r
474 if( attrs[ X.UI.Attr.Support.bottom.No ] === null ){
\r
475 this.boxY = ( boxT || boxT === 0 ) ? boxT : XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.top.No ], allowedH );
\r
477 this.boxY = allowedH - this.boxHeight - ( ( boxB || boxB === 0 ) ? boxB : XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.bottom.No ], allowedH ) );
\r
485 * 描画・計測を行って、contentSize, scrollSize の決定
\r
487 mesure : function(){
\r
488 var dirty = this.dirty,
\r
491 if( dirty === X.UI.Dirty.CLEAN ){
\r
492 if( this.percentWidth || this.percentHeight ){
\r
499 case X.UI.Dirty.CONTENT : // コンテンツが変更された
\r
500 case X.UI.Dirty.FONT : // フォントサイズが変更された
\r
501 delete this.lastContentWidth;
\r
502 delete this.lastContentHeight;
\r
504 case X.UI.Dirty.LAYOUT : // レイアウトの再計算が必要
\r
506 default : // TODO レイアウト崩れに対処 パフォーマンス悪い!
\r
508 w = this.contentWidth;
\r
509 h = this.contentHeight;
\r
510 xnode = this.xnode;
\r
512 /* http://web-designs.seesaa.net/article/188400668.html
\r
513 * min-width の値が max-width の値より大きい場合は、max-width の値は min-width の値に設定される。
\r
516 * 1. contentWidth === AUTO
\r
517 * style を更新して contentWidth の決定
\r
518 * min or max に引っかかったら style 更新
\r
519 * contentHeight === AUTO の場合
\r
521 * contentHeight !== AUTO の場合 scrollHeight のみ更新
\r
522 * 2. contentHeight === AUTO かつ
\r
523 * コンテンツの高さの再取得が必要( contentWidth が最終計測時の contentWidth と一致 かつ フォント・コンテンツに変更無し の場合再取得不要)
\r
524 * style を更新して contentHeight の決定
\r
526 * 3. content のサイズがすでに決定している
\r
530 if( xnode[ '_xnodes' ] && xnode[ '_xnodes' ].length ){
\r
531 if( w === X.UI.Attr.AUTO ){
\r
532 w = this.contentWidth = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'width', 'auto' )[ 'width' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
533 console.log( 'chr ' + X_Node_CSS_getCharSize( xnode ) );
\r
535 //this.scrollWidth = w + this.contentL + this.contentR;
\r
536 if( this.maxContentWidth < w - this.boxSizingOffsetLR ) this.contentWidth = this.maxContentWidth + this.boxSizingOffsetLR;
\r
537 if( w - this.boxSizingOffsetLR < this.minContentWidth ) this.contentWidth = this.minContentWidth + this.boxSizingOffsetLR;
\r
538 this.lastContentWidth = this.contentWidth;
\r
540 w !== this.contentWidth && xnode[ 'css' ]( 'width', this.contentWidth + 'em' );
\r
542 if( h === X.UI.Attr.AUTO ){
\r
543 this.contentHeight = h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) ); // scrollHeight() ??
\r
544 //this.scrollHeight = h + this.contentT + this.contentB;
\r
545 if( this.maxContentHeight < h - this.boxSizingOffsetTB ) this.contentHeight = this.maxContentHeight + this.boxSizingOffsetTB;
\r
546 if( h - this.boxSizingOffsetTB < this.minContentHeight ) this.contentHeight = this.minContentHeight + this.boxSizingOffsetTB;
\r
548 //this.scrollHeight = h + this.contentT + this.contentB;
\r
551 this.lastContentHeight = h;
\r
553 if( h === X.UI.Attr.AUTO ){
\r
554 console.log( 'chr ' + X_Node_CSS_getCharSize( xnode ) );
\r
555 if( w !== this.lastContentWidth ){
\r
556 xnode[ 'css' ]( 'width', w + 'em' );
\r
558 this.lastContentWidth = w;
\r
559 this.contentHeight = h = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) ); // ie8 clientHeight, ff scrollHeight & clientHeight
\r
560 //this.scrollWidth = w + this.contentL + this.contentR;
\r
561 //this.scrollHeight = h + this.contentT + this.contentB;
\r
562 if( this.maxContentHeight < h - this.boxSizingOffsetTB ) this.contentHeight = this.maxContentHeight + this.boxSizingOffsetTB;
\r
563 if( h - this.boxSizingOffsetTB < this.minContentHeight ) this.contentHeight = this.minContentHeight + this.boxSizingOffsetTB;
\r
565 this.contentHeight = this.lastContentHeight = h =
\r
566 this.lastContentHeight === -1 ? XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) ) : this.lastContentHeight;
\r
567 //this.scrollWidth = w + this.contentL + this.contentR;
\r
568 //this.scrollHeight = h + this.contentT + this.contentB;
\r
571 if( dirty !== X.UI.Dirty.LAYOUT ){
\r
572 console.log( 'chr ' + X_Node_CSS_getCharSize( xnode ) );
\r
573 this.contentWidth = this.lastContentWidth = w;
\r
574 this.contentHeight = this.lastContentHeight = XUI_AbstractUINode_ceil( xnode[ 'css' ]( 'height', 'auto' )[ 'scrollHeight' ]() / X_Node_CSS_getCharSize( xnode ) );
\r
575 //this.scrollWidth = this.contentWidth + this.contentL + this.contentR;
\r
576 //this.scrollHeight = this.contentHeight + this.contentT + this.contentB;
\r
578 //this.scrollWidth = w + this.contentL + this.contentR;
\r
579 //this.scrollHeight = h + this.contentT + this.contentB;
\r
582 // コンテンツを持たないため基本のサイズは0
\r
583 if( w === X.UI.Attr.AUTO ) this.contentWidth = w = 0 < this.minContentWidth ? this.minContentWidth : 0;
\r
584 if( h === X.UI.Attr.AUTO ) this.contentHeight = h = 0 < this.minContentHeight ? this.minContentHeight : 0;
\r
585 //this.scrollWidth = w + this.contentL + this.contentR;
\r
586 //this.scrollHeight = h + this.contentT + this.contentB;
\r
591 //case X.UI.Dirty.PAINT : // 再描画のみ必要
\r
596 * 自身の contentWidth, contentHeight を元に AUTO な width, height を確定していく
\r
598 postMesure : function(){
\r
599 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
600 box = attrs[ X.UI.Attr.Support.sizing.No ],
\r
601 contentW, contentH,
\r
603 paddingT, paddingR, paddingB, paddingL,
\r
604 borderT, borderR, borderB, borderL,
\r
608 if( this.boxWidth === X.UI.Attr.AUTO ){
\r
609 contentW = this.contentWidth;
\r
610 paddingR = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.padding.No + 1 ], contentW );
\r
611 paddingL = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.padding.No + 3 ], contentW );
\r
612 borderR = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.borderWidth.No + 1 ], contentW );
\r
613 borderL = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.borderWidth.No + 3 ], contentW );
\r
616 case 3 : // border-box
\r
617 contentPlus = borderR + borderL;
\r
618 case 2 : // padding-box
\r
619 contentPlus += paddingR + paddingL;
\r
620 // case 1 : // content-box
\r
623 if( !this.constraintW ){
\r
624 contentW += contentPlus;
\r
625 min = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.minWidth.No ], contentW );
\r
626 max = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.maxWidth.No ], contentW );
\r
627 if( contentW < min && contentPlus < min ){
\r
628 this.contentWidth = min - contentPlus;
\r
630 if( max < contentW && contentPlus < max ){
\r
631 this.contentWidth = max - contentPlus;
\r
634 this.contentL = borderL + paddingL;
\r
635 this.contentR = borderR + paddingR;
\r
636 this.boxWidth = this.contentWidth + this.contentL + this.contentR;
\r
639 if( this.boxHeight === X.UI.Attr.AUTO ){
\r
640 contentH = this.contentHeight;
\r
641 paddingT = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.padding.No + 0 ], contentH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
642 paddingB = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.padding.No + 2 ], contentH );
\r
643 borderT = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.borderWidth.No + 0 ], contentH );
\r
644 borderB = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.borderWidth.No + 2 ], contentH );
\r
647 case 3 : // border-box
\r
648 contentPlus = borderT + borderB;
\r
649 case 2 : // padding-box
\r
650 contentPlus += paddingT + paddingB;
\r
651 // case 1 : // content-box
\r
653 if( !this.constraintH ){
\r
654 contentH += contentPlus;
\r
655 min = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.minHeight.No ], contentH );
\r
656 max = XUI_AbstractUINode_calcValue( attrs[ X.UI.Attr.Support.maxHeight.No ], contentH );
\r
657 if( contentH < min && contentPlus < min ){
\r
658 this.contentHeight = min - contentPlus;
\r
660 if( max < contentH && contentPlus < max ){
\r
661 this.contentHeight = max - contentPlus;
\r
664 this.contentT = borderT + paddingT;
\r
665 this.contentB = borderB + paddingB;
\r
666 this.boxHeight = this.contentHeight + this.contentT + this.contentB;
\r
670 capcher : function( x, y ){
\r
671 if( this.pointerDisabled ) return false;
\r
676 if( 0 <= x && x < this.boxWidth && 0 <= y && y < this.boxHeight ){
\r
677 !this.hovering && ( this.rootData.hoverList[ this.rootData.hoverList.length ] = this );
\r
678 this.rootData.targetNodeData = this;
\r
684 * context を明示しない場合、User が context になる!
\r
686 listen : function( type, arg1, arg2, arg3 ){
\r
687 var root, events, counter, f;
\r
688 if( X.UI.Event._START_POINTER <= type && type <= X.UI.Event._END_POINTER ){
\r
689 if( this.phase < 3 ){
\r
690 if( !( events = this.reserveEvents ) ) this.reserveEvents = events = [];
\r
691 events[ events.length ] = [ type, arg1, arg2, arg3 ];
\r
694 if( X.UI.Event._START_XUI_EVENT < type && type < X.UI.Event._END_XUI_EVENT ){
\r
695 if( !this.gesture ){
\r
696 this.gesture = new X.UI.Gesture( this.rootData, this, type );
\r
698 this.gesture[ 'listen' ]( type );
\r
701 //console.log( type );
\r
702 root = this.rootData;
\r
703 counter = root.eventCounter;
\r
704 if( counter[ type ] ){
\r
707 counter[ type ] = 1;
\r
708 root.xnodeInteractiveLayer[ 'listen' ]( X.UI.Event.IdToName[ type ], X_UI_eventRellay );
\r
712 arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 ) );
\r
714 return X_EventDispatcher_listen.call( this, type, this.User, f );
\r
716 if( f.kind === X_Callback_FUNC_ONLY ){
\r
717 return X_EventDispatcher_listen.call( this, type, this.User, f.func, f.supplement );
\r
719 return X_EventDispatcher_listen.apply( this, arguments );
\r
721 unlisten : function( type, arg1, arg2, arg3 ){
\r
722 var root, events, i, ev, counter, f;
\r
723 if( X.UI.Event._START_POINTER <= type && type <= X.UI.Event._END_POINTER ){
\r
724 if( this.phase < 3 ){
\r
725 if( !( events = this.reserveEvents ) ) return this;
\r
726 for( i = events.length; i; ){
\r
727 ev = events[ --i ];
\r
728 if( ev[ 0 ] === type && ev[ 1 ] === arg1 && ev[ 2 ] === arg2 ){
\r
729 events.split( i, 1 );
\r
736 if( X.UI.Event._START_XUI_EVENT < type && type < X.UI.Event._END_XUI_EVENT ){
\r
737 this.gesture && this.gesture[ 'unlisten' ]( type );
\r
739 root = this.rootData;
\r
740 counter = root.eventCounter;
\r
741 if( !counter[ type ] ) return this;
\r
743 if( counter[ type ] === 0 ){
\r
744 root.xnodeInteractiveLayer[ 'unlisten' ]( X.UI.Event.IdToName[ type ], X_UI_eventRellay );
\r
745 delete counter[ type ];
\r
749 arg1 && arg1.kind ? ( f = arg1 ) : ( f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 ) );
\r
751 return X_EventDispatcher_unlisten.apply( this, [ type, this.User, f ] );
\r
753 if( f.kind === X_Callback_FUNC_ONLY ){
\r
754 return X_EventDispatcher_unlisten.apply( this, [ type, this.User, f.func, f.supplement ] );
\r
756 return X_EventDispatcher_unlisten.apply( this, arguments );
\r
759 dispatch : function( e ){
\r
760 //console.log( e.type + ' ' + ( this[ '_listeners' ] && this[ '_listeners' ][ e.type ] ) );
\r
761 var xve = X.UI.Event,
\r
762 ret = X_EventDispatcher_dispatch.call( this, e ),
\r
763 type = e.type || e;
\r
765 // TODO captureEvent PointerEvent
\r
766 if( ret & X_Callback_MONOPOLY && !this.hitChildData && ( xve._POINTER_MOVE === type || xve._MOUSE_MOVE === type || xve.FILE_DRAG === type ) ){
\r
767 this.rootData.monopolyNodeData = this;
\r
770 this.rootData.monopolyNodeData = null;
\r
771 if( xve._START_BUBLEUP < type && this.parentData && !( ret & X_Callback_STOP_PROPAGATION ) && !( ret & X_Callback_STOP_NOW ) ) return this.parentData[ 'dispatch' ]( e );
\r
778 function XUI_AbstractUINode_createCssText( that, name ){
\r
779 var attrs = that.attrObject || that.attrClass.prototype || X.UI.AttrClass,
\r
780 def = that.supportAttrs[ name ],
\r
782 v = attrs[ def.No ],
\r
785 flag = !!( type & X.UI.Attr.Type.BOOLEAN ),
\r
786 combi = !!( type & X.UI.Attr.Type.COMBI ),
\r
787 quartet = !!( type & X.UI.Attr.Type.QUARTET );
\r
790 if( attrs[ no + 1 ] === attrs[ no + 3 ] ){
\r
791 if( v === attrs[ no + 2 ] ){
\r
792 if( v === attrs[ no + 1 ] ){
\r
793 return XUI_AbstractUINode_createCssValue( v, type, list );
\r
796 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
797 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list )
\r
801 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
802 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list ),
\r
803 XUI_AbstractUINode_createCssValue( attrs[ no + 2 ], type, list )
\r
807 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
808 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list ),
\r
809 XUI_AbstractUINode_createCssValue( attrs[ no + 2 ], type, list ),
\r
810 XUI_AbstractUINode_createCssValue( attrs[ no + 3 ], type, list )
\r
815 XUI_AbstractUINode_createCssValue( v, type, list ),
\r
816 XUI_AbstractUINode_createCssValue( attrs[ no + 1 ], type, list )
\r
820 return v ? list : 'normal'; //
\r
822 return XUI_AbstractUINode_createCssValue( v, type, list );
\r
825 function XUI_AbstractUINode_createCssValue( v, type, list ){
\r
826 var length = !!( type & X.UI.Attr.Type.LENGTH ),
\r
827 minusLen = !!( type & X.UI.Attr.Type.MINUS_LENGTH ),
\r
828 percent = !!( type & X.UI.Attr.Type.PERCENT ),
\r
829 minusPct = !!( type & X.UI.Attr.Type.MINUS_PERCENT ),
\r
830 numerical = !!( type & X.UI.Attr.Type.NUMERICAL ),
\r
831 auto = !!( type & X.UI.Attr.Type.AUTO ),
\r
832 color = !!( type & X.UI.Attr.Type.COLOR ),
\r
833 url = !!( type & X.UI.Attr.Type.URL ),
\r
834 fontName = !!( type & X.UI.Attr.Type.FONT_NAME );
\r
836 if( X_Type_isNumber( v ) ){
\r
837 if( auto && v === X.UI.Attr.AUTO ) return 'auto';
\r
838 if( length || minusLen ) return v + 'em';
\r
839 if( numerical ) return v;
\r
840 if( list && list[ v ] ) return list[ v ];
\r
842 if( v < 0x100000 ){
\r
843 v = '00000' + v.toString( 16 );
\r
844 return '#' + v.substr( v.length - 6 );
\r
846 return '#' + v.toString( 16 );
\r
849 if( X_Type_isString( v ) ){
\r
850 if( percent || minusPct || url || fontName ) return v;
\r
854 function XUI_AbstractUINode_calcValue( styleValue, srcValue ){
\r
858 if( X_Type_isString( styleValue ) ){
\r
859 return srcValue * parseFloat( styleValue ) / 100;
\r
861 if( !X_Type_isNumber( styleValue ) ) return 0;
\r
865 function XUI_AbstractUINode_calcFinalValue( styleValue, styleMin, styleMax, srcValue ){
\r
866 var v = XUI_AbstractUINode_calcValue( styleValue, srcValue ),
\r
867 min = XUI_AbstractUINode_calcValue( styleMin, srcValue ),
\r
868 max = XUI_AbstractUINode_calcValue( styleMax, srcValue );
\r
869 return v <= min ? min : max <= v ? max : v;
\r
871 function XUI_AbstractUINode_ceil( v ){
\r
873 return ( v * 10 + 0.999 | 0 ) / 10;
\r
875 return ( -v * 10 + 0.999 | 0 ) / -10;
\r
878 X.UI.AbstractUINode = X_Class_create(
\r
880 X_Class.ABSTRACT | X_Class.SUPER_ACCESS,
\r
882 parent : function(){
\r
883 return X_Class_getPrivate( this ).parent;
\r
886 return X_Class_getPrivate( this ).root;
\r
890 * unverifiedAttrs に全ての指定を控える
\r
891 * サポートされていない場合は無視される.親のレイアウトによって変わる
\r
893 attr : function( nameOrObject, valueOrUnit ){
\r
894 var p = X_Class_getPrivate( this ),
\r
895 layout, k, def, attrs, v;
\r
896 if( nameOrObject && X_Type_isObject( nameOrObject ) ){
\r
898 layout = p.parentData && p.parentData.layout.overrideAttrsForChild; // root には parent がない
\r
899 for( k in nameOrObject ){
\r
900 if( X_EMPTY_OBJECT[ k ] ) continue;
\r
901 // 親のレイアウトマネージャの許可しない
\r
902 if( layout && !layout[ k ] ){
\r
905 if( def = p.supportAttrs[ k ] ){
\r
906 p.setAttr( k, def, nameOrObject[ k ] );
\r
910 if( X_Type_isString( nameOrObject ) ){
\r
911 if( valueOrUnit !== undefined ){
\r
912 if( 'em,%'.indexOf( valueOrUnit ) === -1 ){
\r
914 p.setAttr( nameOrObject, valueOrUnit );
\r
916 // getter with unit
\r
917 return p.getAttrWithUnit( nameOrObject, valueOrUnit );
\r
921 if( attrs = ( p.attrObject || p.attrClass.prototype || X.UI.AttrClass ) ){
\r
922 def = p.supportAttrs[ nameOrObject ];
\r
923 return def && attrs[ def.No ];
\r
930 listen : function( type, arg1, arg2, arg3 ){
\r
931 X_Class_getPrivate( this )[ 'listen' ]( type, arg1, arg2, arg3 );
\r
934 listenOnce : function( type, arg1, arg2, arg3 ){
\r
935 X_Class_getPrivate( this )[ 'listenOnce' ]( type, arg1, arg2, arg3 );
\r
938 listening : function( type, arg1, arg2, arg3 ){
\r
939 return X_Class_getPrivate( this )[ 'listening' ]( type, arg1, arg2, arg3 );
\r
941 unlisten : function( type, arg1, arg2, arg3 ){
\r
942 X_Class_getPrivate( this )[ 'unlisten' ]( type, arg1, arg2, arg3 );
\r
945 dispatch : function( e ){
\r
946 return X_Class_getPrivate( this )[ 'dispatch' ]( e );
\r
949 nextNode : function(){
\r
952 prevNode : function(){
\r
955 nodeIndex : function( v ){
\r
956 var data = X_Class_getPrivate( this );
\r
957 if( typeof v === 'number' ){
\r
958 // data.nodeIndex( v );
\r
961 return data.parentData ? data.parentData.nodes.indexOf( data ) : 0;
\r
963 displayIndex : function(){
\r
967 // dirty の場合、rootData.calculate
\r
968 return X_Class_getPrivate( this ).boxX;
\r
971 // dirty の場合、rootData.calculate
\r
972 return X_Class_getPrivate( this ).boxY;
\r
974 getAbsoluteX : function(){
\r
975 // dirty の場合、rootData.calculate
\r
976 return X_Class_getPrivate( this ).absoluteX;
\r
978 getAbsoluteY: function(){
\r
979 // dirty の場合、rootData.calculate
\r
980 return X_Class_getPrivate( this ).absoluteY;
\r
982 getWidth : function(){
\r
983 // dirty の場合、rootData.calculate
\r
984 return X_Class_getPrivate( this ).boxWidth;
\r
986 getHeight : function(){
\r
987 // dirty の場合、rootData.calculate
\r
988 return X_Class_getPrivate( this ).boxHeight;
\r