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
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
138 if( ( percent || minusPct ) && v.lastIndexOf( '%' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + '%' ){
\r
141 if( ( length || minusLen ) && v.lastIndexOf( 'em' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + 'em' ){
\r
144 if( v.indexOf( ' ' ) !== -1 ){
\r
145 v = v.split( ' ' );
\r
147 if( color && X.Type.isNumber( _v = X_Node_CSS_objToIEFilterText( v ) ) ){
\r
155 if( ( quartet || combi ) && !X.Type.isArray( v ) ){
\r
159 if( X.Type.isNumber( v ) ){
\r
161 ( length && ( 0 <= v ) ) ||
\r
162 ( minusLen && ( v <= 0 ) ) ||
\r
163 ( percent && 0 <= v && v <= 1 ) ||
\r
164 ( minusPct && -1 <= v && v < 0 ) ||
\r
165 ( numerical && 0 <= v ) ||
\r
166 ( auto && v === X.UI.Attr.AUTO ) ||
\r
167 ( color && 0 <= v && v <= 0xFFFFFF ) ||
\r
168 ( list && list[ v ] )
\r
176 if( X.Type.isBoolean( v ) && !flag ){
\r
179 if( X.Type.isArray( v ) ){
\r
180 if( v.length <= 4 && quartet ){
\r
181 type &= ~X.UI.Attr.Type.QUARTET;
\r
182 switch( v.length ){
\r
184 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\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
190 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
191 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\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[ 1 ] );
\r
196 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
197 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
198 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\r
199 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
202 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
203 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
204 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\r
205 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 3 ] );
\r
209 if( v.length === 2 && combi ){
\r
210 type &= ~X.UI.Attr.Type.COMBI;
\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
218 if( !X.UI.attrClassProto && user === X.UI.Attr.USER.XNODE && this.xnode ){
\r
219 this.xnode.css( X.UI.Attr.Rename[ name ] || name, this._createCssText( name ) );
\r
220 //console.log( ( X.UI.Attr.Rename[ name ] || name ) + ' ' + this._createCssText( name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
225 if( !v && v !== 0 ) v = defaultVal;
\r
227 if( X.UI.attrClassProto ){
\r
228 attrs[ propID ] = v;
\r
232 if( currentVal !== v ){
\r
234 case X.UI.Attr.Support.left.No :
\r
235 this.constraintW = attrs[ X.UI.Attr.Support.right.No ] !== null;
\r
237 case X.UI.Attr.Support.right.No :
\r
238 this.constraintW = attrs[ X.UI.Attr.Support.left.No ] !== null;
\r
240 case X.UI.Attr.Support.top.No :
\r
241 this.constraintH = attrs[ X.UI.Attr.Support.bottom.No ] !== null;
\r
243 case X.UI.Attr.Support.bottom.No :
\r
244 this.constraintH = attrs[ X.UI.Attr.Support.top.No ] !== null;
\r
246 case X.UI.Attr.Support.width.No :
\r
247 this.autoWidth = v === X.UI.Attr.AUTO;
\r
248 this.percentWidth = X.Type.isString( v );
\r
250 case X.UI.Attr.Support.height.No :
\r
251 this.autoHeight = v === X.UI.Attr.AUTO;
\r
252 this.percentHeight = X.Type.isString( v );
\r
256 if( defaultVal === v ){
\r
257 if( attrs ) delete attrs[ propID ];
\r
259 if( !attrs ) attrs = this.attrObject = new this.attrClass;
\r
260 attrs[ propID ] = v;
\r
263 if( name && user === X.UI.Attr.USER.XNODE && this.xnode ){
\r
264 this.xnode.css( X.UI.Attr.Rename[ name ] || name, this._createCssText( name ) );
\r
265 //console.log( ( X.UI.Attr.Rename[ name ] || name ) + ' ' + this._createCssText( name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
267 if( this.dirty < dirty ) this.dirty = dirty;
\r
271 _createCssText : function( name ){
\r
272 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
273 def = this.supportAttrs[ name ],
\r
275 v = attrs[ def.No ],
\r
278 flag = !!( type & X.UI.Attr.Type.BOOLEAN ),
\r
279 combi = !!( type & X.UI.Attr.Type.COMBI ),
\r
280 quartet = !!( type & X.UI.Attr.Type.QUARTET );
\r
283 if( attrs[ no + 1 ] === attrs[ no + 3 ] ){
\r
284 if( v === attrs[ no + 2 ] ){
\r
285 if( v === attrs[ no + 1 ] ){
\r
286 return this._createCssValue( v, type, list );
\r
289 this._createCssValue( v, type, list ),
\r
290 this._createCssValue( attrs[ no + 1 ], type, list )
\r
294 this._createCssValue( v, type, list ),
\r
295 this._createCssValue( attrs[ no + 1 ], type, list ),
\r
296 this._createCssValue( attrs[ no + 2 ], type, list )
\r
300 this._createCssValue( v, type, list ),
\r
301 this._createCssValue( attrs[ no + 1 ], type, list ),
\r
302 this._createCssValue( attrs[ no + 2 ], type, list ),
\r
303 this._createCssValue( attrs[ no + 3 ], type, list )
\r
308 this._createCssValue( v, type, list ),
\r
309 this._createCssValue( attrs[ no + 1 ], type, list )
\r
313 return v ? list : 'normal'; //
\r
315 return this._createCssValue( v, type, list );
\r
318 _createCssValue : function( v, type, list ){
\r
319 var length = !!( type & X.UI.Attr.Type.LENGTH ),
\r
320 minusLen = !!( type & X.UI.Attr.Type.MINUS_LENGTH ),
\r
321 percent = !!( type & X.UI.Attr.Type.PERCENT ),
\r
322 minusPct = !!( type & X.UI.Attr.Type.MINUS_PERCENT ),
\r
323 numerical = !!( type & X.UI.Attr.Type.NUMERICAL ),
\r
324 auto = !!( type & X.UI.Attr.Type.AUTO ),
\r
325 color = !!( type & X.UI.Attr.Type.COLOR ),
\r
326 url = !!( type & X.UI.Attr.Type.URL ),
\r
327 fontName = !!( type & X.UI.Attr.Type.FONT_NAME );
\r
329 if( X.Type.isNumber( v ) ){
\r
330 if( auto && v === X.UI.Attr.AUTO ) return 'auto';
\r
331 if( length || minusLen ) return v + 'em';
\r
332 if( numerical ) return v;
\r
333 if( list && list[ v ] ) return list[ v ];
\r
335 if( v < 0x100000 ){
\r
336 v = '00000' + v.toString( 16 );
\r
337 return '#' + v.substr( v.length - 6 );
\r
339 return '#' + v.toString( 16 );
\r
342 if( X.Type.isString( v ) ){
\r
343 if( percent || minusPct || url || fontName ) return v;
\r
347 getAttr : function( name ){
\r
348 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
349 support = this.supportAttrs[ name ],
\r
351 if( !support ) return;
\r
353 if( name.indexOf( 'border' ) === 0 ){
\r
354 name = name.substr( 6 );
\r
355 return [ this.getAttr( 'borderTop' + name ), this.getAttr( 'borderRight' + name ), this.getAttr( 'borderBottom' + name ), this.getAttr( 'borderLeft' + name ) ];
\r
358 type = support[ 3 ];
\r
360 if( type & X.UI.Attr.Type.QUARTET ){
\r
361 return [ this.getAttr( name + 'Top' ), this.getAttr( name + 'Right' ), this.getAttr( name + 'Bottom' ), this.getAttr( name + 'Left' ) ];
\r
363 if( type & X.UI.Attr.Type.COMBI ) return [ v, data[ ++propID ] ];
\r
365 v = attrs[ support.No ];
\r
366 if( type & X.UI.Attr.Type.AUTO && v === X.UI.Attr.AUTO ) return 'auto';
\r
368 list = support[ 4 ];
\r
369 if( list ) return list[ v ];
\r
371 if( type & X.UI.Attr.Type.COLOR && X.Type.isNumber( v ) ) return v;
\r
372 if( !( type & X.UI.Attr.Type.NUMERICAL ) && X.Type.isNumber( v ) ) return v + 'em';
\r
377 getAttrWithUnit : function( prop, unit ){
\r
381 _remove : function(){
\r
382 switch( this.phase ){
\r
389 this.xnode.destroy();
\r
392 delete this.rootData;
\r
393 delete this.parent;
\r
394 delete this.parentData;
\r
403 calculate : function( isNeedsDetection, x, y, allowedW, allowedH ){
\r
404 this.preMesure( allowedW, allowedH );
\r
406 if( this.boxWidth === X.UI.Attr.AUTO || this.boxHeight === X.UI.Attr.AUTO ){
\r
411 !isNeedsDetection && this.updateLayout( x, y );
\r
415 * X_Node_BoxModel の情報を引きながら top,left,width,height,padding,border の設定
\r
417 updateLayout : function( x, y ){
\r
421 .css( 'left', x ? x + 'em' : 0 )
\r
422 .css( 'top', y ? y + 'em' : 0 )
\r
423 .css( 'width', this.contentWidth ? X.UI._AbstractUINode.ceil( this.contentWidth ) + 'em' : 0 )
\r
424 .css( 'height', this.contentHeight ? X.UI._AbstractUINode.ceil( this.contentHeight ) + 'em' : 0 )
\r
425 .css( 'padding', this._createCssText( 'padding' ) )
\r
426 .css( 'borderWidth', this._createCssText( 'borderWidth' ) );
\r
430 * 親の サイズを元に自身のサイズを計算していく
\r
432 preMesure : function( allowedW, allowedH ){
\r
433 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
434 calc = X.UI._AbstractUINode.calcValue,
\r
435 box = attrs[ X.UI.Attr.Support.sizing.No ],
\r
437 boxL, boxT, boxR, boxB,
\r
438 contentW, contentH, boxMinus,
\r
439 paddingT, paddingR, paddingB, paddingL,
\r
440 borderT, borderR, borderB, borderL;
\r
443 // 自身が constraintW の場合 親が AUTO ではない
\r
444 // 自身が constraintW でない場合自身が AUTO はなくかつ親 が AUTO の場合 or 自身は % でない
\r
446 paddingR = calc( attrs[ X.UI.Attr.Support.padding.No + 1 ], allowedW );
\r
447 paddingL = calc( attrs[ X.UI.Attr.Support.padding.No + 3 ], allowedW );
\r
448 borderR = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 1 ], allowedW );
\r
449 borderL = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 3 ], allowedW );
\r
452 case 3 : // border-box
\r
453 boxMinus -= borderR + borderL;
\r
454 case 2 : // padding-box
\r
455 boxMinus -= paddingR + paddingL;
\r
456 // case 1 : // content-box
\r
458 this.contentL = borderL + paddingL;
\r
459 this.contentR = borderR + paddingR;
\r
461 if( this.constraintW ? allowedW !== X.UI.Attr.AUTO : !this.autoWidth && ( allowedW !== X.UI.Attr.AUTO || !this.percentWidth ) ){
\r
462 if( this.constraintW ){ // 制約レイアウト
\r
463 contentW = allowedW - ( boxL = calc( attrs[ X.UI.Attr.Support.left.No ], allowedW ) ) - ( boxR = calc( attrs[ X.UI.Attr.Support.right.No ], allowedW ) );
\r
465 contentW = X.UI._AbstractUINode.finalValue( attrs[ X.UI.Attr.Support.width.No ], attrs[ X.UI.Attr.Support.minWidth.No ], attrs[ X.UI.Attr.Support.maxWidth.No ], allowedW );
\r
467 this.contentWidth = contentW + boxMinus;
\r
468 this.scrollWidth = this.contentWidth + this.contentL + this.contentR;
\r
469 this.boxWidth = contentW - boxMinus + this.contentL + this.contentR;
\r
470 this.boxSizingOffsetLR = boxMinus;
\r
471 delete this.minContentWidth;
\r
472 delete this.maxContentWidth;
\r
473 delete this.minBoxWidth;
\r
474 delete this.maxBoxWidth;
\r
476 this.minContentWidth = calc( attrs[ X.UI.Attr.Support.minWidth.No ], allowedW ) + boxMinus;
\r
477 this.maxContentWidth = calc( attrs[ X.UI.Attr.Support.maxWidth.No ], allowedW ) + boxMinus;
\r
478 this.scrollWidth = this.contentWidth + this.contentL + this.contentR;
\r
479 this.minBoxWidth = this.minContentWidth - boxMinus + this.contentL + this.contentR;
\r
480 this.maxBoxWidth = this.maxContentWidth - boxMinus + this.contentL + this.contentR;
\r
481 //delete this.contentWidth;
\r
482 //delete this.scrollWidth;
\r
483 //delete this.boxWidth;
\r
484 //delete this.boxSizingOffsetLR;
\r
487 paddingT = calc( attrs[ X.UI.Attr.Support.padding.No + 0 ], allowedH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
488 paddingB = calc( attrs[ X.UI.Attr.Support.padding.No + 2 ], allowedH );
\r
489 borderT = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 0 ], allowedH );
\r
490 borderB = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 2 ], allowedH );
\r
493 case 3 : // border-box
\r
494 boxMinus -= borderT + borderB;
\r
495 case 2 : // padding-box
\r
496 boxMinus -= paddingT + paddingB;
\r
497 // case 1 : // content-box
\r
499 this.contentT = borderT + paddingT;
\r
500 this.contentB = borderB + paddingB;
\r
503 if( this.constraintH ? allowedH !== X.UI.Attr.AUTO : !this.autoHeight && ( allowedH !== X.UI.Attr.AUTO || !this.percentHeight ) ){
\r
504 if( this.constraintH ){ // 制約レイアウト
\r
505 contentH = allowedH - ( boxT = calc( attrs[ X.UI.Attr.Support.top.No ], allowedH ) ) - ( boxB = calc( attrs[ X.UI.Attr.Support.bottom.No ], allowedH ) );
\r
507 contentH = X.UI._AbstractUINode.finalValue( attrs[ X.UI.Attr.Support.height.No ], attrs[ X.UI.Attr.Support.minHeight.No ], attrs[ X.UI.Attr.Support.maxHeight.No ], allowedH );
\r
509 this.contentHeight = contentH + boxMinus;
\r
510 this.scrollHeight = this.contentHeight + this.contentT + this.contentB;
\r
511 this.boxHeight = contentH - boxMinus + this.contentT + this.contentB; // padding-box の場合 border だけ足される
\r
512 this.boxSizingOffsetTB = boxMinus;
\r
513 delete this.minContentHeight;
\r
514 delete this.maxContentHeight;
\r
515 delete this.minBoxHeight;
\r
516 delete this.maxBoxHeight;
\r
518 this.minContentHeight = calc( attrs[ X.UI.Attr.Support.minHeight.No ], allowedH ) + boxMinus;
\r
519 this.maxContentHeight = calc( attrs[ X.UI.Attr.Support.maxHeight.No ], allowedH ) + boxMinus;
\r
520 this.minBoxHeight = this.minContentHeight - boxMinus + this.contentT + this.contentB;
\r
521 this.maxBoxHeight = this.maxContentHeight - boxMinus + this.contentT + this.contentB;
\r
523 //delete this.contentHeight;
\r
524 //delete this.scrollHeight;
\r
525 //delete this.boxHeight;
\r
526 //delete this.boxSizingOffsetTB;
\r
529 if( this.parentData && this.parentData.layout.overrideAttrsForChild.left ){
\r
530 if( this.constraintW ){
\r
531 this.boxX = ( boxL || boxL === 0 ) ? boxL : calc( attrs[ X.UI.Attr.Support.left.No ], allowedW );
\r
533 if( attrs[ X.UI.Attr.Support.right.No ] === null ){
\r
534 this.boxX = ( boxL || boxL === 0 ) ? boxL : calc( attrs[ X.UI.Attr.Support.left.No ], allowedW );
\r
536 this.boxX = alllowW - this.boxWidth - ( ( boxR || boxR === 0 ) ? boxR : calc( attrs[ X.UI.Attr.Support.right.No ], allowedW ) );
\r
542 if( this.parentData && this.parentData.layout.overrideAttrsForChild.top ){
\r
543 if( this.constraintH ){
\r
544 this.boxY = ( boxT || boxT === 0 ) ? boxT : calc( attrs[ X.UI.Attr.Support.top.No ], allowedH );
\r
546 if( attrs[ X.UI.Attr.Support.bottom.No ] === null ){
\r
547 this.boxY = ( boxT || boxT === 0 ) ? boxT : calc( attrs[ X.UI.Attr.Support.top.No ], allowedH );
\r
549 this.boxY = allowedH - this.boxHeight - ( ( boxB || boxB === 0 ) ? boxB : calc( attrs[ X.UI.Attr.Support.bottom.No ], allowedH ) );
\r
557 * 描画・計測を行って、contentSize, scrollSize の決定
\r
559 mesure : function(){
\r
560 var dirty = this.dirty,
\r
563 if( dirty === X.UI.Dirty.CLEAN ){
\r
564 if( this.percentWidth || this.percentHeight ){
\r
571 case X.UI.Dirty.CONTENT : // コンテンツが変更された
\r
572 case X.UI.Dirty.FONT : // フォントサイズが変更された
\r
573 delete this.lastContentWidth;
\r
574 delete this.lastContentHeight;
\r
576 case X.UI.Dirty.LAYOUT : // レイアウトの再計算が必要
\r
578 default : // TODO レイアウト崩れに対処 パフォーマンス悪い!
\r
580 w = this.contentWidth;
\r
581 h = this.contentHeight;
\r
582 xnode = this.xnode;
\r
584 /* http://web-designs.seesaa.net/article/188400668.html
\r
585 * min-width の値が max-width の値より大きい場合は、max-width の値は min-width の値に設定される。
\r
588 * 1. contentWidth === AUTO
\r
589 * style を更新して contentWidth の決定
\r
590 * min or max に引っかかったら style 更新
\r
591 * contentHeight === AUTO の場合
\r
593 * contentHeight !== AUTO の場合 scrollHeight のみ更新
\r
594 * 2. contentHeight === AUTO かつ
\r
595 * コンテンツの高さの再取得が必要( contentWidth が最終計測時の contentWidth と一致 かつ フォント・コンテンツに変更無し の場合再取得不要)
\r
596 * style を更新して contentHeight の決定
\r
598 * 3. content のサイズがすでに決定している
\r
602 if( xnode._xnodes && xnode._xnodes.length ){
\r
603 if( w === X.UI.Attr.AUTO ){
\r
604 w = this.contentWidth = xnode.css( 'width', 'auto' ).width() / X_Node_CSS_getCharSize( xnode );
\r
606 this.scrollWidth = w + this.contentL + this.contentR;
\r
607 if( this.maxContentWidth < w - this.boxSizingOffsetLR ) this.contentWidth = this.maxContentWidth + this.boxSizingOffsetLR;
\r
608 if( w - this.boxSizingOffsetLR < this.minContentWidth ) this.contentWidth = this.minContentWidth + this.boxSizingOffsetLR;
\r
609 this.lastContentWidth = this.contentWidth;
\r
611 w !== this.contentWidth && xnode.css( 'width', X.UI._AbstractUINode.ceil( this.contentWidth ) + 'em' );
\r
613 if( h === X.UI.Attr.AUTO ){
\r
614 this.contentHeight = h = xnode.css( 'height', 'auto' ).scrollHeight() / X_Node_CSS_getCharSize( xnode ); // scrollHeight() ??
\r
615 this.scrollHeight = h + this.contentT + this.contentB;
\r
616 if( this.maxContentHeight < h - this.boxSizingOffsetTB ) this.contentHeight = this.maxContentHeight + this.boxSizingOffsetTB;
\r
617 if( h - this.boxSizingOffsetTB < this.minContentHeight ) this.contentHeight = this.minContentHeight + this.boxSizingOffsetTB;
\r
619 this.scrollHeight = h + this.contentT + this.contentB;
\r
622 this.lastContentHeight = h;
\r
624 if( h === X.UI.Attr.AUTO ){
\r
625 if( w !== this.lastContentWidth ){
\r
626 xnode.css( 'width', X.UI._AbstractUINode.ceil( w ) + 'em' );
\r
628 this.lastContentWidth = w;
\r
629 this.contentHeight = h = xnode.css( 'height', 'auto' ).scrollHeight() / X_Node_CSS_getCharSize( xnode );
\r
630 this.scrollWidth = w + this.contentL + this.contentR;
\r
631 this.scrollHeight = h + this.contentT + this.contentB;
\r
632 if( this.maxContentHeight < h - this.boxSizingOffsetTB ) this.contentHeight = this.maxContentHeight + this.boxSizingOffsetTB;
\r
633 if( h - this.boxSizingOffsetTB < this.minContentHeight ) this.contentHeight = this.minContentHeight + this.boxSizingOffsetTB;
\r
635 this.contentHeight = this.lastContentHeight = h =
\r
636 this.lastContentHeight === -1 ? xnode.css( 'height', 'auto' ).scrollHeight() / X_Node_CSS_getCharSize( xnode ) : this.lastContentHeight;
\r
637 this.scrollWidth = w + this.contentL + this.contentR;
\r
638 this.scrollHeight = h + this.contentT + this.contentB;
\r
641 if( dirty !== X.UI.Dirty.LAYOUT ){
\r
642 this.contentWidth = this.lastContentWidth = w; //xnode.width();
\r
643 this.contentHeight = this.lastContentHeight = xnode.css( 'height', 'auto' ).scrollHeight() / X_Node_CSS_getCharSize( xnode );
\r
644 this.scrollWidth = this.contentWidth + this.contentL + this.contentR;
\r
645 this.scrollHeight = this.contentHeight + this.contentT + this.contentB;
\r
647 this.scrollWidth = w + this.contentL + this.contentR;
\r
648 this.scrollHeight = h + this.contentT + this.contentB;
\r
651 // コンテンツを持たないため基本のサイズは0
\r
652 if( w === X.UI.Attr.AUTO ) this.contentWidth = w = 0 < this.minContentWidth ? this.minContentWidth : 0;
\r
653 if( h === X.UI.Attr.AUTO ) this.contentHeight = h = 0 < this.minContentHeight ? this.minContentHeight : 0;
\r
654 this.scrollWidth = w + this.contentL + this.contentR;
\r
655 this.scrollHeight = h + this.contentT + this.contentB;
\r
660 //case X.UI.Dirty.PAINT : // 再描画のみ必要
\r
665 * 自身の contentWidth, contentHeight を元に AUTO な width, height を確定していく
\r
667 postMesure : function(){
\r
668 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
669 calc = X.UI._AbstractUINode.calcValue,
\r
670 box = attrs[ X.UI.Attr.Support.sizing.No ],
\r
671 contentW, contentH,
\r
673 paddingT, paddingR, paddingB, paddingL,
\r
674 borderT, borderR, borderB, borderL,
\r
678 if( this.boxWidth === X.UI.Attr.AUTO ){
\r
679 contentW = this.contentWidth;
\r
680 paddingR = calc( attrs[ X.UI.Attr.Support.padding.No + 1 ], contentW );
\r
681 paddingL = calc( attrs[ X.UI.Attr.Support.padding.No + 3 ], contentW );
\r
682 borderR = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 1 ], contentW );
\r
683 borderL = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 3 ], contentW );
\r
686 case 3 : // border-box
\r
687 contentPlus = borderR + borderL;
\r
688 case 2 : // padding-box
\r
689 contentPlus += paddingR + paddingL;
\r
690 // case 1 : // content-box
\r
693 if( !this.constraintW ){
\r
694 contentW += contentPlus;
\r
695 min = calc( attrs[ X.UI.Attr.Support.minWidth.No ], contentW );
\r
696 max = calc( attrs[ X.UI.Attr.Support.maxWidth.No ], contentW );
\r
697 if( contentW < min && contentPlus < min ){
\r
698 this.contentWidth = min - contentPlus;
\r
700 if( max < contentW && contentPlus < max ){
\r
701 this.contentWidth = max - contentPlus;
\r
704 this.contentL = borderL + paddingL;
\r
705 this.contentR = borderR + paddingR;
\r
706 this.boxWidth = this.contentWidth + this.contentL + this.contentR;
\r
709 if( this.boxHeight === X.UI.Attr.AUTO ){
\r
710 contentH = this.contentHeight;
\r
711 paddingT = calc( attrs[ X.UI.Attr.Support.padding.No + 0 ], contentH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
712 paddingB = calc( attrs[ X.UI.Attr.Support.padding.No + 2 ], contentH );
\r
713 borderT = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 0 ], contentH );
\r
714 borderB = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 2 ], contentH );
\r
717 case 3 : // border-box
\r
718 contentPlus = borderT + borderB;
\r
719 case 2 : // padding-box
\r
720 contentPlus += paddingT + paddingB;
\r
721 // case 1 : // content-box
\r
723 if( !this.constraintH ){
\r
724 contentH += contentPlus;
\r
725 min = calc( attrs[ X.UI.Attr.Support.minHeight.No ], contentH );
\r
726 max = calc( attrs[ X.UI.Attr.Support.maxHeight.No ], contentH );
\r
727 if( contentH < min && contentPlus < min ){
\r
728 this.contentHeight = min - contentPlus;
\r
730 if( max < contentH && contentPlus < max ){
\r
731 this.contentHeight = max - contentPlus;
\r
734 this.contentT = borderT + paddingT;
\r
735 this.contentB = borderB + paddingB;
\r
736 this.boxHeight = this.contentHeight + this.contentT + this.contentB;
\r
740 capcher : function( x, y ){
\r
741 if( this.pointerDisabled ) return false;
\r
746 if( 0 <= x && x < this.boxWidth && 0 <= y && y < this.boxHeight ){
\r
747 !this.hovering && ( this.rootData.hoverList[ this.rootData.hoverList.length ] = this );
\r
748 this.rootData.targetNodeData = this;
\r
754 listen : function( type, arg1, arg2, arg3 ){
\r
755 var root, events, counter, f;
\r
756 if( X.UI.Event._START_POINTER <= type && type <= X.UI.Event._END_POINTER ){
\r
757 if( this.phase < 3 ){
\r
758 if( !( events = this.reserveEvents ) ) this.reserveEvents = events = [];
\r
759 events[ events.length ] = [ type, arg1, arg2, arg3 ];
\r
762 if( X.UI.Event._START_XUI_EVENT < type && type < X.UI.Event._END_XUI_EVENT ){
\r
763 if( !this.gesture ){
\r
764 this.gesture = new X.UI.Gesture( this.rootData, this, type );
\r
766 this.gesture.listen( type );
\r
769 //console.log( type );
\r
770 root = this.rootData;
\r
771 counter = root.eventCounter;
\r
772 if( counter[ type ] ){
\r
775 counter[ type ] = 1;
\r
776 root.xnodeInteractiveLayer.listen( X.UI.Event.IdToName[ type ], X.UI._eventRellay );
\r
780 f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 );
\r
782 return X_EventDispatcher_listen.call( this, type, this.User, f );
\r
784 if( f.k === X_Callback_FUNC_ONLY ){
\r
785 return X_EventDispatcher_listen.call( this, type, this.User, f.f, f.s );
\r
787 return X_EventDispatcher_listen.apply( this, arguments );
\r
789 unlisten : function( type, arg1, arg2, arg3 ){
\r
790 var root, events, i, ev, counter, f;
\r
791 if( X.UI.Event._START_POINTER <= type && type <= X.UI.Event._END_POINTER ){
\r
792 if( this.phase < 3 ){
\r
793 if( !( events = this.reserveEvents ) ) return this;
\r
794 for( i = events.length; i; ){
\r
795 ev = events[ --i ];
\r
796 if( ev[ 0 ] === type && ev[ 1 ] === arg1 && ev[ 2 ] === arg2 ){
\r
797 events.split( i, 1 );
\r
804 if( X.UI.Event._START_XUI_EVENT < type && type < X.UI.Event._END_XUI_EVENT ){
\r
805 this.gesture && this.gesture.unlisten( type );
\r
807 root = this.rootData;
\r
808 counter = root.eventCounter;
\r
809 if( !counter[ type ] ) return this;
\r
811 if( counter[ type ] === 0 ){
\r
812 root.xnodeInteractiveLayer.unlisten( X.UI.Event.IdToName[ type ], X.UI._eventRellay );
\r
813 delete counter[ type ];
\r
817 f = X_Callback_classifyCallbackArgs( arg1, arg2, arg3 );
\r
819 return X.EventDispatcher.prototype.unlisten.apply( this, [ type, this.User, f ] );
\r
821 if( f.k === X_Callback_FUNC_ONLY ){
\r
822 return X.EventDispatcher.prototype.unlisten.apply( this, [ type, this.User, f.f, f.s ] );
\r
824 return X.EventDispatcher.prototype.unlisten.apply( this, arguments );
\r
827 dispatch : function( e ){
\r
828 //console.log( e.type + ' ' + ( this._listeners && this._listeners[ e.type ] ) );
\r
829 var xve = X.UI.Event,
\r
830 ret = X_EventDispatcher_dispatch.call( this, e ),
\r
831 type = e.type || e;
\r
833 // TODO captureEvent PointerEvent
\r
834 if( ret & X.Callback.MONOPOLY && !this.hitChildData && ( xve._POINTER_MOVE === type || xve._MOUSE_MOVE === type || xve.FILE_DRAG === type ) ){
\r
835 this.rootData.monopolyNodeData = this;
\r
838 this.rootData.monopolyNodeData = null;
\r
839 if( xve._START_BUBLEUP < type && this.parentData && !( ret & X.Callback.STOP_PROPAGATION ) && !( ret & X.Callback.STOP_NOW ) ) return this.parentData.dispatch( e );
\r
846 X.UI._AbstractUINode.calcValue = function( styleValue, srcValue ){
\r
850 if( X.Type.isString( styleValue ) ){
\r
851 return srcValue * parseFloat( styleValue ) / 100;
\r
853 if( !X.Type.isNumber( styleValue ) ) return 0;
\r
857 X.UI._AbstractUINode.finalValue = function( styleValue, styleMin, styleMax, srcValue ){
\r
858 var calc = X.UI._AbstractUINode.calcValue,
\r
859 v = calc( styleValue, srcValue ),
\r
860 min = calc( styleMin, srcValue ),
\r
861 max = calc( styleMax, srcValue );
\r
862 return v <= min ? min : max <= v ? max : v;
\r
864 X.UI._AbstractUINode.ceil = function( v ){
\r
866 return ( v * 10 + 0.999 | 0 ) / 10;
\r
868 return ( -v * 10 + 0.999 | 0 ) / -10;
\r
871 X.UI.AbstractUINode = X.Class.create(
\r
873 X.Class.ABSTRACT | X.Class.SUPER_ACCESS,
\r
875 parent : function(){
\r
876 return X_Class_getPrivate( this ).parent;
\r
879 return X_Class_getPrivate( this ).root;
\r
883 * unverifiedAttrs に全ての指定を控える
\r
884 * サポートされていない場合は無視される.親のレイアウトによって変わる
\r
886 attr : function( nameOrObject, valueOrUnit ){
\r
887 var p = X_Class_getPrivate( this ),
\r
888 layout, k, def, attrs, v;
\r
889 if( nameOrObject && X.Type.isObject( nameOrObject ) ){
\r
891 layout = p.parentData && p.parentData.layout.overrideAttrsForChild; // root には parent がない
\r
892 for( k in nameOrObject ){
\r
893 if( X_EMPTY_OBJECT[ k ] ) continue;
\r
894 // 親のレイアウトマネージャの許可しない
\r
895 if( layout && !layout[ k ] ){
\r
898 if( def = p.supportAttrs[ k ] ){
\r
899 p.setAttr( k, def, nameOrObject[ k ] );
\r
903 if( X.Type.isString( nameOrObject ) ){
\r
904 if( valueOrUnit !== undefined ){
\r
905 if( 'em,%'.indexOf( valueOrUnit ) === -1 ){
\r
907 p.setAttr( nameOrObject, valueOrUnit );
\r
909 // getter with unit
\r
910 return p.getAttrWithUnit( nameOrObject, valueOrUnit );
\r
914 if( attrs = ( p.attrObject || p.attrClass.prototype || X.UI.AttrClass ) ){
\r
915 def = p.supportAttrs[ nameOrObject ];
\r
916 return def && attrs[ def.No ];
\r
923 listen : function( type, arg1, arg2, arg3 ){
\r
924 X_Class_getPrivate( this ).listen( type, arg1, arg2, arg3 );
\r
927 listenOnce : function( type, arg1, arg2, arg3 ){
\r
928 X_Class_getPrivate( this ).listenOnce( type, arg1, arg2, arg3 );
\r
931 listening : function( type, arg1, arg2, arg3 ){
\r
932 return X_Class_getPrivate( this ).listening( type, arg1, arg2, arg3 );
\r
934 unlisten : function( type, arg1, arg2, arg3 ){
\r
935 X_Class_getPrivate( this ).unlisten( type, arg1, arg2, arg3 );
\r
938 dispatch : function( e ){
\r
939 return X_Class_getPrivate( this ).dispatch( e );
\r
942 getNextNode : function(){
\r
945 getPrevNode : function(){
\r
948 nodeIndex : function( v ){
\r
949 var data = X_Class_getPrivate( this );
\r
950 if( typeof v === 'number' ){
\r
951 // data.nodeIndex( v );
\r
954 return data.parentData ? data.parentData.nodes.indexOf( data ) : 0;
\r
956 displayIndex : function(){
\r
960 // dirty の場合、rootData.calculate
\r
961 return X_Class_getPrivate( this ).boxX;
\r
964 // dirty の場合、rootData.calculate
\r
965 return X_Class_getPrivate( this ).boxY;
\r
967 getAbsoluteX : function(){
\r
968 // dirty の場合、rootData.calculate
\r
969 return X_Class_getPrivate( this ).absoluteX;
\r
971 getAbsoluteY: function(){
\r
972 // dirty の場合、rootData.calculate
\r
973 return X_Class_getPrivate( this ).absoluteY;
\r
975 getWidth : function(){
\r
976 // dirty の場合、rootData.calculate
\r
977 return X_Class_getPrivate( this ).boxWidth;
\r
979 getHeight : function(){
\r
980 // dirty の場合、rootData.calculate
\r
981 return X_Class_getPrivate( this ).boxHeight;
\r
983 scrollTo : function( x, y ){
\r
984 X_Class_getPrivate( this ).scrollTo( x, y );
\r
986 getScrollX : function( v ){
\r
987 // dirty の場合、rootData.calculate
\r
988 return X_Class_getPrivate( this ).scrollX( v );
\r
990 getScrollY : function( v ){
\r
991 // dirty の場合、rootData.calculate
\r
992 return X_Class_getPrivate( this ).scrollY( v );
\r
994 disabled : function( v ){
\r
995 return X_Class_getPrivate( this ).disabled( v );
\r
997 cursor : function( v ){
\r
998 return X_Class_getPrivate( this ).cursor( v );
\r