1 var _AbstractUINode = X.EventDispatcher.inherits(
\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
42 boxWidth : X.UI.Attr.AUTO,
\r
44 maxBoxWidth : X.UI.Attr.AUTO,
\r
45 boxHeight : X.UI.Attr.AUTO,
\r
47 maxBoxHeight : X.UI.Attr.AUTO,
\r
52 boxSizingOffsetLR : 0,
\r
53 boxSizingOffsetTB : 0,
\r
54 contentWidth : X.UI.Attr.AUTO,
\r
55 minContentWidth : 0,
\r
56 maxContentWidth : X.UI.Attr.AUTO,
\r
57 lastContentWidth : -1,
\r
58 contentHeight : X.UI.Attr.AUTO,
\r
59 minContentHeight : 0,
\r
60 maxContentHeight : X.UI.Attr.AUTO,
\r
62 constraintW : false,
\r
63 constraintH : false,
\r
66 percentWidth : false,
\r
67 percentHeight : false,
\r
68 // :hover, :focus, :disabled
\r
70 initialize : function( root, rootData, parent, parentData ){
\r
71 var events = this.reserveEvents,
\r
75 this.rootData = rootData;
\r
76 this.hoverList = rootData.hoverList;
\r
77 this.parent = parent;
\r
78 this.parentData = parentData;
\r
79 //this.xnode = X.Dom.Node.create( 'div' );
\r
82 this.dispatch( { type : X.UI.Event.INIT } );
\r
84 // html 要素が親に追加されるまで控えていたイベントの登録
\r
85 if( events && ( l = events.length ) ){
\r
86 for( i = 0; i < l; ++i ){
\r
87 this.listen.apply( this, events[ i ] );
\r
90 delete this.reserveEvents;
\r
94 addToParent : function( parentElement ){
\r
95 parentElement && parentElement.append( this.xnode );
\r
98 this.dispatch( { type : X.UI.Event.ADDED } );
\r
101 creationComplete : function(){
\r
103 this.User.dispatch( { type : X.UI.Event.CREATION_COMPLETE } );
\r
107 * _UINode への setAttr の他、attrClass.prototype への setAttr にも対応する
\r
108 * 親要素が変化した場合、unverifiedAttrs を元に attrObject を再設定.
\r
110 setAttr : function( name, def, v ){
\r
111 var attrs = X.UI.attrClassProto || this.attrObject,
\r
112 propID = def.No || def[ 5 ],
\r
113 defaultVal = X.UI.attrClassProto ? attrs[ propID ] : this.attrClass.prototype[ propID ], // def[ 0 ],
\r
114 currentVal = attrs ? attrs[ propID ] : defaultVal,
\r
119 length = !!( type & X.UI.Attr.Type.LENGTH ),
\r
120 minusLen = !!( type & X.UI.Attr.Type.MINUS_LENGTH ),
\r
121 percent = !!( type & X.UI.Attr.Type.PERCENT ),
\r
122 minusPct = !!( type & X.UI.Attr.Type.MINUS_PERCENT ),
\r
123 numerical = !!( type & X.UI.Attr.Type.NUMERICAL ),
\r
124 auto = !!( type & X.UI.Attr.Type.AUTO ),
\r
125 color = !!( type & X.UI.Attr.Type.COLOR ),
\r
126 url = !!( type & X.UI.Attr.Type.URL ),
\r
127 fontName = !!( type & X.UI.Attr.Type.FONT_NAME ),
\r
128 flag = !!( type & X.UI.Attr.Type.BOOLEAN ),
\r
129 combi = !!( type & X.UI.Attr.Type.COMBI ),
\r
130 quartet = !!( type & X.UI.Attr.Type.QUARTET ),
\r
131 _v, i, l, nodes, root, roots;
\r
133 if( X.Type.isString( v ) ){
\r
134 //v = v.toLowercase();
\r
135 if( url || fontName ){
\r
138 if( auto && v === 'auto' ){
\r
139 v = X.UI.Attr.AUTO;
\r
141 if( list && ( _v = list[ v ] ) ){
\r
145 if( ( percent || minusPct ) && v.lastIndexOf( '%' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + '%' ){
\r
148 if( ( length || minusLen ) && v.lastIndexOf( 'em' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + 'em' ){
\r
151 if( v.indexOf( ' ' ) !== -1 ){
\r
152 v = v.split( ' ' );
\r
154 if( color && X.Type.isNumber( _v = X.Dom.Style.parseColor( v ) ) ){
\r
162 if( ( quartet || combi ) && !X.Type.isArray( v ) ){
\r
166 if( X.Type.isNumber( v ) ){
\r
168 ( length && ( 0 <= v ) ) ||
\r
169 ( minusLen && ( v <= 0 ) ) ||
\r
170 ( percent && 0 <= v && v <= 1 ) ||
\r
171 ( minusPct && -1 <= v && v < 0 ) ||
\r
172 ( numerical && 0 <= v ) ||
\r
173 ( auto && v === X.UI.Attr.AUTO ) ||
\r
174 ( color && 0 <= v && v <= 0xFFFFFF ) ||
\r
175 ( list && list[ v ] )
\r
183 if( X.Type.isBoolean( v ) && !flag ){
\r
186 if( X.Type.isArray( v ) ){
\r
187 if( v.length <= 4 && quartet ){
\r
188 type &= ~X.UI.Attr.Type.QUARTET;
\r
189 switch( v.length ){
\r
191 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
192 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
193 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
194 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
197 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
198 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
199 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
200 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
203 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
204 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
205 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\r
206 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
209 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
210 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
211 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\r
212 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 3 ] );
\r
216 if( v.length === 2 && combi ){
\r
217 type &= ~X.UI.Attr.Type.COMBI;
\r
218 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
219 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
225 if( !X.UI.attrClassProto && user === X.UI.Attr.USER.XNODE && this.xnode ){
\r
226 this.xnode.css( X.UI.Attr.Rename[ name ] || name, this._createCssText( name ) );
\r
227 //console.log( ( X.UI.Attr.Rename[ name ] || name ) + ' ' + this._createCssText( name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
232 if( !v && v !== 0 ) v = defaultVal;
\r
234 if( X.UI.attrClassProto ){
\r
235 attrs[ propID ] = v;
\r
239 if( currentVal !== v ){
\r
241 case X.UI.Attr.Support.left.No :
\r
242 this.constraintW = attrs[ X.UI.Attr.Support.right.No ] !== null;
\r
244 case X.UI.Attr.Support.right.No :
\r
245 this.constraintW = attrs[ X.UI.Attr.Support.left.No ] !== null;
\r
247 case X.UI.Attr.Support.top.No :
\r
248 this.constraintH = attrs[ X.UI.Attr.Support.bottom.No ] !== null;
\r
250 case X.UI.Attr.Support.bottom.No :
\r
251 this.constraintH = attrs[ X.UI.Attr.Support.top.No ] !== null;
\r
253 case X.UI.Attr.Support.width.No :
\r
254 this.autoWidth = v === X.UI.Attr.AUTO;
\r
255 this.percentWidth = X.Type.isString( v );
\r
257 case X.UI.Attr.Support.height.No :
\r
258 this.autoHeight = v === X.UI.Attr.AUTO;
\r
259 this.percentHeight = X.Type.isString( v );
\r
263 if( defaultVal === v ){
\r
264 if( attrs ) delete attrs[ propID ];
\r
266 if( !attrs ) attrs = this.attrObject = new this.attrClass;
\r
267 attrs[ propID ] = v;
\r
270 if( name && user === X.UI.Attr.USER.XNODE && this.xnode ){
\r
271 this.xnode.css( X.UI.Attr.Rename[ name ] || name, this._createCssText( name ) );
\r
272 //console.log( ( X.UI.Attr.Rename[ name ] || name ) + ' ' + this._createCssText( name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
274 if( this.dirty < dirty ) this.dirty = dirty;
\r
278 _createCssText : function( name ){
\r
279 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
280 def = this.supportAttrs[ name ],
\r
282 v = attrs[ def.No ],
\r
285 flag = !!( type & X.UI.Attr.Type.BOOLEAN ),
\r
286 combi = !!( type & X.UI.Attr.Type.COMBI ),
\r
287 quartet = !!( type & X.UI.Attr.Type.QUARTET );
\r
290 if( attrs[ no + 1 ] === attrs[ no + 3 ] ){
\r
291 if( v === attrs[ no + 2 ] ){
\r
292 if( v === attrs[ no + 1 ] ){
\r
293 return this._createCssValue( v, type, list );
\r
296 this._createCssValue( v, type, list ),
\r
297 this._createCssValue( attrs[ no + 1 ], type, list )
\r
301 this._createCssValue( v, type, list ),
\r
302 this._createCssValue( attrs[ no + 1 ], type, list ),
\r
303 this._createCssValue( attrs[ no + 2 ], type, list )
\r
307 this._createCssValue( v, type, list ),
\r
308 this._createCssValue( attrs[ no + 1 ], type, list ),
\r
309 this._createCssValue( attrs[ no + 2 ], type, list ),
\r
310 this._createCssValue( attrs[ no + 3 ], type, list )
\r
315 this._createCssValue( v, type, list ),
\r
316 this._createCssValue( attrs[ no + 1 ], type, list )
\r
320 return v ? list : 'normal'; //
\r
322 return this._createCssValue( v, type, list );
\r
325 _createCssValue : function( v, type, list ){
\r
326 var length = !!( type & X.UI.Attr.Type.LENGTH ),
\r
327 minusLen = !!( type & X.UI.Attr.Type.MINUS_LENGTH ),
\r
328 percent = !!( type & X.UI.Attr.Type.PERCENT ),
\r
329 minusPct = !!( type & X.UI.Attr.Type.MINUS_PERCENT ),
\r
330 numerical = !!( type & X.UI.Attr.Type.NUMERICAL ),
\r
331 auto = !!( type & X.UI.Attr.Type.AUTO ),
\r
332 color = !!( type & X.UI.Attr.Type.COLOR ),
\r
333 url = !!( type & X.UI.Attr.Type.URL ),
\r
334 fontName = !!( type & X.UI.Attr.Type.FONT_NAME );
\r
336 if( X.Type.isNumber( v ) ){
\r
337 if( auto && v === X.UI.Attr.AUTO ) return 'auto';
\r
338 if( length || minusLen ) return v + 'em';
\r
339 if( numerical ) return v;
\r
340 if( list && list[ v ] ) return list[ v ];
\r
342 if( v < 0x100000 ){
\r
343 v = '00000' + v.toString( 16 );
\r
344 return '#' + v.substr( v.length - 6 );
\r
346 return '#' + v.toString( 16 );
\r
349 if( X.Type.isString( v ) ){
\r
350 if( percent || minusPct || url || fontName ) return v;
\r
354 getAttr : function( name ){
\r
355 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
356 support = this.supportAttrs[ name ],
\r
358 if( !support ) return;
\r
360 if( name.indexOf( 'border' ) === 0 ){
\r
361 name = name.substr( 6 );
\r
362 return [ this.getAttr( 'borderTop' + name ), this.getAttr( 'borderRight' + name ), this.getAttr( 'borderBottom' + name ), this.getAttr( 'borderLeft' + name ) ];
\r
365 type = support[ 3 ];
\r
367 if( type & X.UI.Attr.Type.QUARTET ){
\r
368 return [ this.getAttr( name + 'Top' ), this.getAttr( name + 'Right' ), this.getAttr( name + 'Bottom' ), this.getAttr( name + 'Left' ) ];
\r
370 if( type & X.UI.Attr.Type.COMBI ) return [ v, data[ ++propID ] ];
\r
372 v = attrs[ support.No ];
\r
373 if( type & X.UI.Attr.Type.AUTO && v === X.UI.Attr.AUTO ) return 'auto';
\r
375 list = support[ 4 ];
\r
376 if( list ) return list[ v ];
\r
378 if( type & X.UI.Attr.Type.COLOR && X.Type.isNumber( v ) ) return v;
\r
379 if( !( type & X.UI.Attr.Type.NUMERICAL ) && X.Type.isNumber( v ) ) return v + 'em';
\r
384 getAttrWithUnit : function( prop, unit ){
\r
388 _remove : function(){
\r
389 switch( this.phase ){
\r
396 this.xnode.destroy();
\r
399 delete this.rootData;
\r
400 delete this.parent;
\r
401 delete this.parentData;
\r
410 calculate : function( isNeedsDetection, x, y, allowedW, allowedH ){
\r
411 this.preMesure( allowedW, allowedH );
\r
413 if( this.boxWidth === X.UI.Attr.AUTO || this.boxHeight === X.UI.Attr.AUTO ){
\r
418 !isNeedsDetection && this.updateLayout( x, y );
\r
422 * X.Dom.BoxModel の情報を引きながら top,left,width,height,padding,border の設定
\r
424 updateLayout : function( x, y ){
\r
428 .css( 'left', x ? x + 'em' : 0 )
\r
429 .css( 'top', y ? y + 'em' : 0 )
\r
430 .css( 'width', this.contentWidth ? _AbstractUINode.ceil( this.contentWidth ) + 'em' : 0 )
\r
431 .css( 'height', this.contentHeight ? _AbstractUINode.ceil( this.contentHeight ) + 'em' : 0 )
\r
432 .css( 'padding', this._createCssText( 'padding' ) )
\r
433 .css( 'borderWidth', this._createCssText( 'borderWidth' ) );
\r
437 * 親の サイズを元に自身のサイズを計算していく
\r
439 preMesure : function( allowedW, allowedH ){
\r
440 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
441 calc = _AbstractUINode.calcValue,
\r
442 box = attrs[ X.UI.Attr.Support.sizing.No ],
\r
444 boxL, boxT, boxR, boxB,
\r
445 contentW, contentH, boxMinus,
\r
446 paddingT, paddingR, paddingB, paddingL,
\r
447 borderT, borderR, borderB, borderL;
\r
450 // 自身が constraintW の場合 親が AUTO ではない
\r
451 // 自身が constraintW でない場合自身が AUTO はなくかつ親 が AUTO の場合 or 自身は % でない
\r
453 paddingR = calc( attrs[ X.UI.Attr.Support.padding.No + 1 ], allowedW );
\r
454 paddingL = calc( attrs[ X.UI.Attr.Support.padding.No + 3 ], allowedW );
\r
455 borderR = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 1 ], allowedW );
\r
456 borderL = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 3 ], allowedW );
\r
459 case 3 : // border-box
\r
460 boxMinus -= borderR + borderL;
\r
461 case 2 : // padding-box
\r
462 boxMinus -= paddingR + paddingL;
\r
463 // case 1 : // content-box
\r
465 this.contentL = borderL + paddingL;
\r
466 this.contentR = borderR + paddingR;
\r
468 if( this.constraintW ? allowedW !== X.UI.Attr.AUTO : !this.autoWidth && ( allowedW !== X.UI.Attr.AUTO || !this.percentWidth ) ){
\r
469 if( this.constraintW ){ // 制約レイアウト
\r
470 contentW = allowedW - ( boxL = calc( attrs[ X.UI.Attr.Support.left.No ], allowedW ) ) - ( boxR = calc( attrs[ X.UI.Attr.Support.right.No ], allowedW ) );
\r
472 contentW = _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
474 this.contentWidth = contentW + boxMinus;
\r
475 this.scrollWidth = this.contentWidth + this.contentL + this.contentR;
\r
476 this.boxWidth = contentW - boxMinus + this.contentL + this.contentR;
\r
477 this.boxSizingOffsetLR = boxMinus;
\r
478 delete this.minContentWidth;
\r
479 delete this.maxContentWidth;
\r
480 delete this.minBoxWidth;
\r
481 delete this.maxBoxWidth;
\r
483 this.minContentWidth = calc( attrs[ X.UI.Attr.Support.minWidth.No ], allowedW ) + boxMinus;
\r
484 this.maxContentWidth = calc( attrs[ X.UI.Attr.Support.maxWidth.No ], allowedW ) + boxMinus;
\r
485 this.scrollWidth = this.contentWidth + this.contentL + this.contentR;
\r
486 this.minBoxWidth = this.minContentWidth - boxMinus + this.contentL + this.contentR;
\r
487 this.maxBoxWidth = this.maxContentWidth - boxMinus + this.contentL + this.contentR;
\r
488 //delete this.contentWidth;
\r
489 //delete this.scrollWidth;
\r
490 //delete this.boxWidth;
\r
491 //delete this.boxSizingOffsetLR;
\r
494 paddingT = calc( attrs[ X.UI.Attr.Support.padding.No + 0 ], allowedH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
495 paddingB = calc( attrs[ X.UI.Attr.Support.padding.No + 2 ], allowedH );
\r
496 borderT = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 0 ], allowedH );
\r
497 borderB = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 2 ], allowedH );
\r
500 case 3 : // border-box
\r
501 boxMinus -= borderT + borderB;
\r
502 case 2 : // padding-box
\r
503 boxMinus -= paddingT + paddingB;
\r
504 // case 1 : // content-box
\r
506 this.contentT = borderT + paddingT;
\r
507 this.contentB = borderB + paddingB;
\r
510 if( this.constraintH ? allowedH !== X.UI.Attr.AUTO : !this.autoHeight && ( allowedH !== X.UI.Attr.AUTO || !this.percentHeight ) ){
\r
511 if( this.constraintH ){ // 制約レイアウト
\r
512 contentH = allowedH - ( boxT = calc( attrs[ X.UI.Attr.Support.top.No ], allowedH ) ) - ( boxB = calc( attrs[ X.UI.Attr.Support.bottom.No ], allowedH ) );
\r
514 contentH = _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
516 this.contentHeight = contentH + boxMinus;
\r
517 this.scrollHeight = this.contentHeight + this.contentT + this.contentB;
\r
518 this.boxHeight = contentH - boxMinus + this.contentT + this.contentB; // padding-box の場合 border だけ足される
\r
519 this.boxSizingOffsetTB = boxMinus;
\r
520 delete this.minContentHeight;
\r
521 delete this.maxContentHeight;
\r
522 delete this.minBoxHeight;
\r
523 delete this.maxBoxHeight;
\r
525 this.minContentHeight = calc( attrs[ X.UI.Attr.Support.minHeight.No ], allowedH ) + boxMinus;
\r
526 this.maxContentHeight = calc( attrs[ X.UI.Attr.Support.maxHeight.No ], allowedH ) + boxMinus;
\r
527 this.minBoxHeight = this.minContentHeight - boxMinus + this.contentT + this.contentB;
\r
528 this.maxBoxHeight = this.maxContentHeight - boxMinus + this.contentT + this.contentB;
\r
530 //delete this.contentHeight;
\r
531 //delete this.scrollHeight;
\r
532 //delete this.boxHeight;
\r
533 //delete this.boxSizingOffsetTB;
\r
536 if( this.parentData && this.parentData.layout.overrideAttrsForChild.left ){
\r
537 if( this.constraintW ){
\r
538 this.boxX = ( boxL || boxL === 0 ) ? boxL : calc( attrs[ X.UI.Attr.Support.left.No ], allowedW );
\r
540 if( attrs[ X.UI.Attr.Support.right.No ] === null ){
\r
541 this.boxX = ( boxL || boxL === 0 ) ? boxL : calc( attrs[ X.UI.Attr.Support.left.No ], allowedW );
\r
543 this.boxX = alllowW - this.boxWidth - ( ( boxR || boxR === 0 ) ? boxR : calc( attrs[ X.UI.Attr.Support.right.No ], allowedW ) );
\r
549 if( this.parentData && this.parentData.layout.overrideAttrsForChild.top ){
\r
550 if( this.constraintH ){
\r
551 this.boxY = ( boxT || boxT === 0 ) ? boxT : calc( attrs[ X.UI.Attr.Support.top.No ], allowedH );
\r
553 if( attrs[ X.UI.Attr.Support.bottom.No ] === null ){
\r
554 this.boxY = ( boxT || boxT === 0 ) ? boxT : calc( attrs[ X.UI.Attr.Support.top.No ], allowedH );
\r
556 this.boxY = allowedH - this.boxHeight - ( ( boxB || boxB === 0 ) ? boxB : calc( attrs[ X.UI.Attr.Support.bottom.No ], allowedH ) );
\r
564 * 描画・計測を行って、contentSize, scrollSize の決定
\r
566 mesure : function(){
\r
567 var dirty = this.dirty,
\r
570 if( dirty === X.UI.Dirty.CLEAN ){
\r
571 if( this.percentWidth || this.percentHeight ){
\r
578 case X.UI.Dirty.CONTENT : // コンテンツが変更された
\r
579 case X.UI.Dirty.FONT : // フォントサイズが変更された
\r
580 delete this.lastContentWidth;
\r
582 case X.UI.Dirty.LAYOUT : // レイアウトの再計算が必要
\r
584 default : // TODO レイアウト崩れに対処 パフォーマンス悪い!
\r
586 w = this.contentWidth;
\r
587 h = this.contentHeight;
\r
588 xnode = this.xnode;
\r
590 /* http://web-designs.seesaa.net/article/188400668.html
\r
591 * min-width の値が max-width の値より大きい場合は、max-width の値は min-width の値に設定される。
\r
594 * 1. contentWidth === AUTO
\r
595 * style を更新して contentWidth の決定
\r
596 * min or max に引っかかったら style 更新
\r
597 * contentHeight === AUTO の場合
\r
599 * contentHeight !== AUTO の場合 scrollHeight のみ更新
\r
600 * 2. contentHeight === AUTO かつ
\r
601 * コンテンツの高さの再取得が必要( contentWidth が最終計測時の contentWidth と一致 かつ フォント・コンテンツに変更無し の場合再取得不要)
\r
602 * style を更新して contentHeight の決定
\r
604 * 3. content のサイズがすでに決定している
\r
608 if( xnode._xnodes && xnode._xnodes.length ){
\r
609 if( w === X.UI.Attr.AUTO ){
\r
610 w = this.contentWidth = xnode.css( 'width', 'auto' ).width() / xnode._getCharSize();
\r
611 console.log( xnode.width() + ' ' + xnode._getCharSize() + ' > ' + w );
\r
613 this.scrollWidth = w + this.contentL + this.contentR;
\r
614 if( this.maxContentWidth < w - this.boxSizingOffsetLR ) this.contentWidth = this.maxContentWidth + this.boxSizingOffsetLR;
\r
615 if( w - this.boxSizingOffsetLR < this.minContentWidth ) this.contentWidth = this.minContentWidth + this.boxSizingOffsetLR;
\r
616 this.lastContentWidth = this.contentWidth;
\r
618 w !== this.contentWidth && xnode.css( 'width', _AbstractUINode.ceil( this.contentWidth ) + 'em' );
\r
620 if( h === X.UI.Attr.AUTO ){
\r
621 this.contentHeight = h = xnode.scrollHeight() / xnode._getCharSize(); // scrollHeight() ??
\r
622 this.scrollHeight = h + this.contentT + this.contentB;
\r
623 if( this.maxContentHeight < h - this.boxSizingOffsetTB ) this.contentHeight = this.maxContentHeight + this.boxSizingOffsetTB;
\r
624 if( h - this.boxSizingOffsetTB < this.minContentHeight ) this.contentHeight = this.minContentHeight + this.boxSizingOffsetTB;
\r
626 this.scrollHeight = xnode.height() / xnode._getCharSize() + this.contentT + this.contentB;
\r
629 if( h === X.UI.Attr.AUTO ){
\r
630 if( w !== this.lastContentWidth ){
\r
631 xnode.css( 'width', _AbstractUINode.ceil( w ) + 'em' );
\r
633 this.lastContentWidth = w;
\r
634 this.contentHeight = h = xnode.scrollHeight() / xnode._getCharSize();
\r
635 this.scrollWidth = w + this.contentL + this.contentR;
\r
636 this.scrollHeight = h + this.contentT + this.contentB;
\r
637 if( this.maxContentHeight < h - this.boxSizingOffsetTB ) this.contentHeight = this.maxContentHeight + this.boxSizingOffsetTB;
\r
638 if( h - this.boxSizingOffsetTB < this.minContentHeight ) this.contentHeight = this.minContentHeight + this.boxSizingOffsetTB;
\r
640 this.scrollWidth = w + this.contentL + this.contentR;
\r
641 this.scrollHeight = h + this.contentT + this.contentB;
\r
644 if( dirty !== X.UI.Dirty.LAYOUT ){
\r
645 this.contentWidth = this.lastContentWidth = w; //xnode.width();
\r
646 this.contentHeight = xnode.height() / xnode._getCharSize();
\r
647 this.scrollWidth = this.contentWidth + this.contentL + this.contentR;
\r
648 this.scrollHeight = this.contentHeight + this.contentT + this.contentB;
\r
650 this.scrollWidth = w + this.contentL + this.contentR;
\r
651 this.scrollHeight = h + this.contentT + this.contentB;
\r
654 // コンテンツを持たないため基本のサイズは0
\r
655 if( w === X.UI.Attr.AUTO ) this.contentWidth = w = 0 < this.minContentWidth ? this.minContentWidth : 0;
\r
656 if( h === X.UI.Attr.AUTO ) this.contentHeight = h = 0 < this.minContentHeight ? this.minContentHeight : 0;
\r
657 this.scrollWidth = w + this.contentL + this.contentR;
\r
658 this.scrollHeight = h + this.contentT + this.contentB;
\r
663 //case X.UI.Dirty.PAINT : // 再描画のみ必要
\r
668 * 自身の contentWidth, contentHeight を元に AUTO な width, height を確定していく
\r
670 postMesure : function(){
\r
671 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
672 calc = _AbstractUINode.calcValue,
\r
673 box = attrs[ X.UI.Attr.Support.sizing.No ],
\r
674 contentW, contentH,
\r
676 paddingT, paddingR, paddingB, paddingL,
\r
677 borderT, borderR, borderB, borderL,
\r
681 if( this.boxWidth === X.UI.Attr.AUTO ){
\r
682 contentW = this.contentWidth;
\r
683 paddingR = calc( attrs[ X.UI.Attr.Support.padding.No + 1 ], contentW );
\r
684 paddingL = calc( attrs[ X.UI.Attr.Support.padding.No + 3 ], contentW );
\r
685 borderR = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 1 ], contentW );
\r
686 borderL = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 3 ], contentW );
\r
689 case 3 : // border-box
\r
690 contentPlus = borderR + borderL;
\r
691 case 2 : // padding-box
\r
692 contentPlus += paddingR + paddingL;
\r
693 // case 1 : // content-box
\r
696 if( !this.constraintW ){
\r
697 contentW += contentPlus;
\r
698 min = calc( attrs[ X.UI.Attr.Support.minWidth.No ], contentW );
\r
699 max = calc( attrs[ X.UI.Attr.Support.maxWidth.No ], contentW );
\r
700 if( contentW < min && contentPlus < min ){
\r
701 this.contentWidth = min - contentPlus;
\r
703 if( max < contentW && contentPlus < max ){
\r
704 this.contentWidth = max - contentPlus;
\r
707 this.contentL = borderL + paddingL;
\r
708 this.contentR = borderR + paddingR;
\r
709 this.boxWidth = this.contentWidth + this.contentL + this.contentR;
\r
712 if( this.boxHeight === X.UI.Attr.AUTO ){
\r
713 contentH = this.contentHeight;
\r
714 paddingT = calc( attrs[ X.UI.Attr.Support.padding.No + 0 ], contentH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
715 paddingB = calc( attrs[ X.UI.Attr.Support.padding.No + 2 ], contentH );
\r
716 borderT = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 0 ], contentH );
\r
717 borderB = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 2 ], contentH );
\r
720 case 3 : // border-box
\r
721 contentPlus = borderT + borderB;
\r
722 case 2 : // padding-box
\r
723 contentPlus += paddingT + paddingB;
\r
724 // case 1 : // content-box
\r
726 if( !this.constraintH ){
\r
727 contentH += contentPlus;
\r
728 min = calc( attrs[ X.UI.Attr.Support.minHeight.No ], contentH );
\r
729 max = calc( attrs[ X.UI.Attr.Support.maxHeight.No ], contentH );
\r
730 if( contentH < min && contentPlus < min ){
\r
731 this.contentHeight = min - contentPlus;
\r
733 if( max < contentH && contentPlus < max ){
\r
734 this.contentHeight = max - contentPlus;
\r
737 this.contentT = borderT + paddingT;
\r
738 this.contentB = borderB + paddingB;
\r
739 this.boxHeight = this.contentHeight + this.contentT + this.contentB;
\r
743 capcher : function( x, y ){
\r
744 if( this.pointerDisabled ) return false;
\r
749 if( 0 <= x && x < this.boxWidth && 0 <= y && y < this.boxHeight ){
\r
750 !this.hovering && ( this.hoverList[ this.hoverList.length ] = this );
\r
751 this.rootData.targetNodeData = this;
\r
757 listen : function( type, arg1, arg2, arg3 ){
\r
758 var root, events, counter;
\r
759 if( X.UI.Event._START_POINTER <= type && type <= X.UI.Event._END_POINTER ){
\r
760 if( this.phase < 3 ){
\r
761 if( !( events = this.reserveEvents ) ) this.reserveEvents = events = [];
\r
762 events[ events.length ] = [ type, arg1, arg2, arg3 ];
\r
765 if( X.UI.Event._START_XUI_EVENT < type && type < X.UI.Event._END_XUI_EVENT ){
\r
766 if( !this.gesture ){
\r
767 this.gesture = new X.UI.Gesture( this.root, this, type );
\r
769 this.gesture.listen( type );
\r
772 root = this.rootData;
\r
773 counter = root.eventCounter;
\r
774 if( counter[ type ] ){
\r
777 counter[ type ] = 1;
\r
778 root.elmMouseCatch.listen( X.UI.Event.IdToName[ type ], eventRellay );
\r
782 if( typeof arg1 === 'function' ){
\r
783 return X.EventDispatcher.prototype.listen.apply( this, [ type, this.User, arg1, arg2 ] );
\r
785 return X.EventDispatcher.prototype.listen.apply( this, [ type, arg1 || this.User, arg2 || arg1, arg3 || arg2 ] );
\r
787 unlisten : function( type, arg1, arg2, arg3 ){
\r
788 var root, events, i, ev, counter;
\r
789 if( X.UI.Event._START_POINTER <= type && type <= X.UI.Event._END_POINTER ){
\r
790 if( this.phase < 3 ){
\r
791 if( !( events = this.reserveEvents ) ) return this;
\r
792 for( i = events.length; i; ){
\r
793 ev = events[ --i ];
\r
794 if( ev[ 0 ] === type && ev[ 1 ] === arg1 && ev[ 2 ] === arg2 ){
\r
795 events.split( i, 1 );
\r
802 if( X.UI.Event._START_XUI_EVENT < type && type < X.UI.Event._END_XUI_EVENT ){
\r
803 this.gesture && this.gesture.unlisten( type );
\r
805 root = this.rootData;
\r
806 counter = root.eventCounter;
\r
807 if( !counter[ type ] ) return this;
\r
809 if( counter[ type ] === 0 ){
\r
810 X.Dom.Event.remove( root.elmMouseCatch, X.UI.Event.IdToName[ type ], eventRellay );
\r
811 delete counter[ type ];
\r
815 if( typeof arg1 === 'function' ){
\r
816 return X.EventDispatcher.prototype.unlisten.apply( this, [ type, this.User, arg1, arg2 ] );
\r
818 return X.EventDispatcher.prototype.unlisten.apply( this, [ type, arg1 || this.User, arg2 || arg1, arg3 || arg2 ] );
\r
821 dispatch : function( e ){
\r
822 var xve = X.UI.Event,
\r
823 ret = X.EventDispatcher.prototype.dispatch.call( this, e ),
\r
825 if( ret & X.Callback.MONOPOLY && !this.hitChildData && ( xve._POINTER_MOVE === type || xve._MOUSE_MOVE === type || xve.FILE_DRAG === type ) ){
\r
826 this.rootData.monopolyNodeData = this;
\r
829 this.rootData.monopolyNodeData = null;
\r
830 if( xve._START_BUBLEUP < type && this.parentData && ret & X.Callback.STOP_PROPAGATION === 0 && ret & X.Callback.STOP_NOW === 0 ) return this.parentData.dispatch( e );
\r
837 _AbstractUINode.calcValue = function( styleValue, srcValue ){
\r
841 if( X.Type.isString( styleValue ) ){
\r
842 return srcValue * parseFloat( styleValue ) / 100;
\r
844 if( !X.Type.isNumber( styleValue ) ) return 0;
\r
848 _AbstractUINode.finalValue = function( styleValue, styleMin, styleMax, srcValue ){
\r
849 var calc = _AbstractUINode.calcValue,
\r
850 v = calc( styleValue, srcValue ),
\r
851 min = calc( styleMin, srcValue ),
\r
852 max = calc( styleMax, srcValue );
\r
853 return v <= min ? min : max <= v ? max : v;
\r
855 _AbstractUINode.ceil = function( v ){
\r
857 return ( v * 10 + 0.999 | 0 ) / 10;
\r
859 return ( -v * 10 + 0.999 | 0 ) / -10;
\r
862 var AbstractUINode = X.Class.create(
\r
864 X.Class.ABSTRACT | X.Class.SUPER_ACCESS,
\r
866 parent : function(){
\r
867 return X.Class._getPrivate( this ).parent;
\r
870 return X.Class._getPrivate( this ).root;
\r
874 * unverifiedAttrs に全ての指定を控える
\r
875 * サポートされていない場合は無視される.親のレイアウトによって変わる
\r
877 attr : function( nameOrObject, valueOrUnit ){
\r
878 var p = X.Class._getPrivate( this ),
\r
879 layout, k, def, attrs, v;
\r
880 if( nameOrObject && X.Type.isObject( nameOrObject ) ){
\r
882 layout = p.parentData && p.parentData.layout.overrideAttrsForChild; // root には parent がない
\r
883 for( k in nameOrObject ){
\r
884 // 親のレイアウトマネージャの許可しない
\r
885 if( layout && !layout[ k ] ){
\r
888 if( def = p.supportAttrs[ k ] ){
\r
889 p.setAttr( k, def, nameOrObject[ k ] );
\r
893 if( X.Type.isString( nameOrObject ) ){
\r
894 if( valueOrUnit !== undefined ){
\r
895 if( 'em,%'.indexOf( valueOrUnit ) === -1 ){
\r
897 p.setAttr( nameOrObject, valueOrUnit );
\r
899 // getter with unit
\r
900 return p.getAttrWithUnit( nameOrObject, valueOrUnit );
\r
904 if( attrs = ( p.attrObject || p.attrClass.prototype || X.UI.AttrClass ) ){
\r
905 def = p.supportAttrs[ nameOrObject ];
\r
906 return def && attrs[ def.No ];
\r
913 listen : function( type, arg1, arg2, arg3 ){
\r
914 X.Class._getPrivate( this ).listen( type, arg1, arg2, arg3 );
\r
917 listenOnce : function( type, arg1, arg2, arg3 ){
\r
918 X.Class._getPrivate( this ).listenOnce( type, arg1, arg2, arg3 );
\r
921 unlisten : function( type, arg1, arg2, arg3 ){
\r
922 X.Class._getPrivate( this ).unlisten( type, arg1, arg2, arg3 );
\r
925 dispatch : function( e ){
\r
926 return X.Class._getPrivate( this ).dispatch( e );
\r
929 getNextNode : function(){
\r
932 getPrevNode : function(){
\r
935 nodeIndex : function( v ){
\r
936 var data = X.Class._getPrivate( this );
\r
937 if( typeof v === 'number' ){
\r
938 // data.nodeIndex( v );
\r
941 return data.parentData ? data.parentData.nodes.indexOf( data ) : 0;
\r
943 displayIndex : function(){
\r
947 // dirty の場合、rootData.calculate
\r
948 return X.Class._getPrivate( this ).x;
\r
951 // dirty の場合、rootData.calculate
\r
952 return X.Class._getPrivate( this ).y;
\r
954 getAbsoluteX : function(){
\r
955 // dirty の場合、rootData.calculate
\r
956 return X.Class._getPrivate( this ).absoluteX;
\r
958 getAbsoluteY: function(){
\r
959 // dirty の場合、rootData.calculate
\r
960 return X.Class._getPrivate( this ).absoluteY;
\r
962 getWidth : function(){
\r
963 // dirty の場合、rootData.calculate
\r
964 return X.Class._getPrivate( this ).boxWidth;
\r
966 getHeight : function(){
\r
967 // dirty の場合、rootData.calculate
\r
968 return X.Class._getPrivate( this ).boxHeight;
\r
970 scrollTo : function( x, y ){
\r
971 X.Class._getPrivate( this ).scrollTo( x, y );
\r
973 getScrollX : function( v ){
\r
974 // dirty の場合、rootData.calculate
\r
975 return X.Class._getPrivate( this ).scrollX( v );
\r
977 getScrollY : function( v ){
\r
978 // dirty の場合、rootData.calculate
\r
979 return X.Class._getPrivate( this ).scrollY( v );
\r
981 disabled : function( v ){
\r
982 return X.Class._getPrivate( this ).disabled( v );
\r
984 cursor : function( v ){
\r
985 return X.Class._getPrivate( this ).cursor( v );
\r