1 var _AbstractUINode = X.EventDispatcher.inherits(
\r
3 X.Class.ABSTRACT | X.Class.PRIVATE_DATA,
\r
13 supportAttrs : X.UI.Attr.Support,
\r
14 attrClass : X.UI.AttrClass,
\r
16 unverifiedAttrs : null,
\r
19 pointerDisabled : false,
\r
20 hoverClassName : null,
\r
23 reserveEvents : null,
\r
40 boxWidth : X.UI.Attr.AUTO,
\r
42 maxBoxWidth : X.UI.Attr.AUTO,
\r
43 boxHeight : X.UI.Attr.AUTO,
\r
45 maxBoxHeight : X.UI.Attr.AUTO,
\r
50 boxSizingOffsetLR : 0,
\r
51 boxSizingOffsetTB : 0,
\r
52 contentWidth : X.UI.Attr.AUTO,
\r
53 minContentWidth : 0,
\r
54 maxContentWidth : X.UI.Attr.AUTO,
\r
55 lastContentWidth : -1,
\r
56 contentHeight : X.UI.Attr.AUTO,
\r
57 minContentHeight : 0,
\r
58 maxContentHeight : X.UI.Attr.AUTO,
\r
60 constraintW : false,
\r
61 constraintH : false,
\r
64 percentWidth : false,
\r
65 percentHeight : false,
\r
66 // :hover, :focus, :disabled
\r
68 initialize : function( root, rootData, parent, parentData ){
\r
69 var events = this.reserveEvents,
\r
73 this.rootData = rootData;
\r
74 this.hoverList = rootData.hoverList;
\r
75 this.parent = parent;
\r
76 this.parentData = parentData;
\r
77 //this.xnode = X.Dom.Node.create( 'div' );
\r
80 this.dispatch( { type : X.UI.Event.INIT } );
\r
82 // html 要素が親に追加されるまで控えていたイベントの登録
\r
83 if( events && ( l = events.length ) ){
\r
84 for( i = 0; i < l; ++i ){
\r
85 this.listen.apply( this, events[ i ] );
\r
88 delete this.reserveEvents;
\r
92 addToParent : function( parentElement ){
\r
93 parentElement && parentElement.append( this.xnode );
\r
96 this.dispatch( { type : X.UI.Event.ADDED } );
\r
99 creationComplete : function(){
\r
101 this.User.dispatch( { type : X.UI.Event.CREATION_COMPLETE } );
\r
105 * _UINode への setAttr の他、attrClass.prototype への setAttr にも対応する
\r
106 * 親要素が変化した場合、unverifiedAttrs を元に attrObject を再設定.
\r
108 setAttr : function( name, def, v ){
\r
109 var attrs = X.UI.attrClassProto || this.attrObject,
\r
110 propID = def.No || def[ 5 ],
\r
111 defaultVal = X.UI.attrClassProto ? attrs[ propID ] : this.attrClass.prototype[ propID ], // def[ 0 ],
\r
112 currentVal = attrs ? attrs[ propID ] : defaultVal,
\r
117 length = !!( type & X.UI.Attr.Type.LENGTH ),
\r
118 minusLen = !!( type & X.UI.Attr.Type.MINUS_LENGTH ),
\r
119 percent = !!( type & X.UI.Attr.Type.PERCENT ),
\r
120 minusPct = !!( type & X.UI.Attr.Type.MINUS_PERCENT ),
\r
121 numerical = !!( type & X.UI.Attr.Type.NUMERICAL ),
\r
122 auto = !!( type & X.UI.Attr.Type.AUTO ),
\r
123 color = !!( type & X.UI.Attr.Type.COLOR ),
\r
124 url = !!( type & X.UI.Attr.Type.URL ),
\r
125 fontName = !!( type & X.UI.Attr.Type.FONT_NAME ),
\r
126 flag = !!( type & X.UI.Attr.Type.BOOLEAN ),
\r
127 combi = !!( type & X.UI.Attr.Type.COMBI ),
\r
128 quartet = !!( type & X.UI.Attr.Type.QUARTET ),
\r
129 _v, i, l, nodes, root, roots;
\r
131 if( X.Type.isString( v ) ){
\r
132 //v = v.toLowercase();
\r
133 if( url || fontName ){
\r
136 if( auto && v === 'auto' ){
\r
137 v = X.UI.Attr.AUTO;
\r
139 if( list && ( _v = list[ v ] ) ){
\r
143 if( ( percent || minusPct ) && v.lastIndexOf( '%' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + '%' ){
\r
146 if( ( length || minusLen ) && v.lastIndexOf( 'em' ) !== -1 && isFinite( _v = parseFloat( v ) ) && v === _v + 'em' ){
\r
149 if( v.indexOf( ' ' ) !== -1 ){
\r
150 v = v.split( ' ' );
\r
152 if( color && X.Type.isNumber( _v = X.Dom.Style.parseColor( v ) ) ){
\r
160 if( ( quartet || combi ) && !X.Type.isArray( v ) ){
\r
164 if( X.Type.isNumber( v ) ){
\r
166 ( length && ( 0 <= v ) ) ||
\r
167 ( minusLen && ( v <= 0 ) ) ||
\r
168 ( percent && 0 <= v && v <= 1 ) ||
\r
169 ( minusPct && -1 <= v && v < 0 ) ||
\r
170 ( numerical && 0 <= v ) ||
\r
171 ( auto && v === X.UI.Attr.AUTO ) ||
\r
172 ( color && 0 <= v && v <= 0xFFFFFF ) ||
\r
173 ( list && list[ v ] )
\r
181 if( X.Type.isBoolean( v ) && !flag ){
\r
184 if( X.Type.isArray( v ) ){
\r
185 if( v.length <= 4 && quartet ){
\r
186 type &= ~X.UI.Attr.Type.QUARTET;
\r
187 switch( v.length ){
\r
189 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[ 0 ] );
\r
192 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 0 ] );
\r
195 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
196 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
201 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
202 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
203 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\r
204 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
207 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
208 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
209 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 2 ] );
\r
210 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 3 ] );
\r
214 if( v.length === 2 && combi ){
\r
215 type &= ~X.UI.Attr.Type.COMBI;
\r
216 this.setAttr( false, [ defaultVal, user, dirty, type, list, propID ], v[ 0 ] );
\r
217 this.setAttr( false, [ defaultVal, user, dirty, type, list, ++propID ], v[ 1 ] );
\r
223 if( !X.UI.attrClassProto && user === X.UI.Attr.USER.XNODE && this.xnode ){
\r
224 this.xnode.css( X.UI.Attr.Rename[ name ] || name, this._createCssText( name ) );
\r
225 //console.log( ( X.UI.Attr.Rename[ name ] || name ) + ' ' + this._createCssText( name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
230 if( !v && v !== 0 ) v = defaultVal;
\r
232 if( X.UI.attrClassProto ){
\r
233 attrs[ propID ] = v;
\r
237 if( currentVal !== v ){
\r
239 case X.UI.Attr.Support.left.No :
\r
240 this.constraintW = attrs[ X.UI.Attr.Support.right.No ] !== null;
\r
242 case X.UI.Attr.Support.right.No :
\r
243 this.constraintW = attrs[ X.UI.Attr.Support.left.No ] !== null;
\r
245 case X.UI.Attr.Support.top.No :
\r
246 this.constraintH = attrs[ X.UI.Attr.Support.bottom.No ] !== null;
\r
248 case X.UI.Attr.Support.bottom.No :
\r
249 this.constraintH = attrs[ X.UI.Attr.Support.top.No ] !== null;
\r
251 case X.UI.Attr.Support.width.No :
\r
252 this.autoWidth = v === X.UI.Attr.AUTO;
\r
253 this.percentWidth = X.Type.isString( v );
\r
255 case X.UI.Attr.Support.height.No :
\r
256 this.autoHeight = v === X.UI.Attr.AUTO;
\r
257 this.percentHeight = X.Type.isString( v );
\r
261 if( defaultVal === v ){
\r
262 if( attrs ) delete attrs[ propID ];
\r
264 if( !attrs ) attrs = this.attrObject = new this.attrClass;
\r
265 attrs[ propID ] = v;
\r
268 if( name && user === X.UI.Attr.USER.XNODE && this.xnode ){
\r
269 this.xnode.css( X.UI.Attr.Rename[ name ] || name, this._createCssText( name ) );
\r
270 //console.log( ( X.UI.Attr.Rename[ name ] || name ) + ' ' + this._createCssText( name ) + ' ' + propID + ' ' + attrs[ propID ] );
\r
272 if( this.dirty < dirty ) this.dirty = dirty;
\r
276 _createCssText : function( name ){
\r
277 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
278 def = this.supportAttrs[ name ],
\r
280 v = attrs[ def.No ],
\r
283 flag = !!( type & X.UI.Attr.Type.BOOLEAN ),
\r
284 combi = !!( type & X.UI.Attr.Type.COMBI ),
\r
285 quartet = !!( type & X.UI.Attr.Type.QUARTET );
\r
288 if( attrs[ no + 1 ] === attrs[ no + 3 ] ){
\r
289 if( v === attrs[ no + 2 ] ){
\r
290 if( v === attrs[ no + 1 ] ){
\r
291 return this._createCssValue( v, type, list );
\r
294 this._createCssValue( v, type, list ),
\r
295 this._createCssValue( attrs[ no + 1 ], type, list )
\r
299 this._createCssValue( v, type, list ),
\r
300 this._createCssValue( attrs[ no + 1 ], type, list ),
\r
301 this._createCssValue( attrs[ no + 2 ], type, list )
\r
305 this._createCssValue( v, type, list ),
\r
306 this._createCssValue( attrs[ no + 1 ], type, list ),
\r
307 this._createCssValue( attrs[ no + 2 ], type, list ),
\r
308 this._createCssValue( attrs[ no + 3 ], type, list )
\r
313 this._createCssValue( v, type, list ),
\r
314 this._createCssValue( attrs[ no + 1 ], type, list )
\r
318 return v ? list : 'normal'; //
\r
320 return this._createCssValue( v, type, list );
\r
323 _createCssValue : function( v, type, list ){
\r
324 var length = !!( type & X.UI.Attr.Type.LENGTH ),
\r
325 minusLen = !!( type & X.UI.Attr.Type.MINUS_LENGTH ),
\r
326 percent = !!( type & X.UI.Attr.Type.PERCENT ),
\r
327 minusPct = !!( type & X.UI.Attr.Type.MINUS_PERCENT ),
\r
328 numerical = !!( type & X.UI.Attr.Type.NUMERICAL ),
\r
329 auto = !!( type & X.UI.Attr.Type.AUTO ),
\r
330 color = !!( type & X.UI.Attr.Type.COLOR ),
\r
331 url = !!( type & X.UI.Attr.Type.URL ),
\r
332 fontName = !!( type & X.UI.Attr.Type.FONT_NAME );
\r
334 if( X.Type.isNumber( v ) ){
\r
335 if( auto && v === X.UI.Attr.AUTO ) return 'auto';
\r
336 if( length || minusLen ) return v + 'em';
\r
337 if( numerical ) return v;
\r
338 if( list && list[ v ] ) return list[ v ];
\r
340 return '#' + v.toString( 16 );
\r
343 if( X.Type.isString( v ) ){
\r
344 if( percent || minusPct || url || fontName ) return v;
\r
348 getAttr : function( name ){
\r
349 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
350 support = this.supportAttrs[ name ],
\r
352 if( !support ) return;
\r
354 if( name.indexOf( 'border' ) === 0 ){
\r
355 name = name.substr( 6 );
\r
356 return [ this.getAttr( 'borderTop' + name ), this.getAttr( 'borderRight' + name ), this.getAttr( 'borderBottom' + name ), this.getAttr( 'borderLeft' + name ) ];
\r
359 type = support[ 3 ];
\r
361 if( type & X.UI.Attr.Type.QUARTET ){
\r
362 return [ this.getAttr( name + 'Top' ), this.getAttr( name + 'Right' ), this.getAttr( name + 'Bottom' ), this.getAttr( name + 'Left' ) ];
\r
364 if( type & X.UI.Attr.Type.COMBI ) return [ v, data[ ++propID ] ];
\r
366 v = attrs[ support.No ];
\r
367 if( type & X.UI.Attr.Type.AUTO && v === X.UI.Attr.AUTO ) return 'auto';
\r
369 list = support[ 4 ];
\r
370 if( list ) return list[ v ];
\r
372 if( type & X.UI.Attr.Type.COLOR && X.Type.isNumber( v ) ) return v;
\r
373 if( !( type & X.UI.Attr.Type.NUMERICAL ) && X.Type.isNumber( v ) ) return v + 'em';
\r
378 getAttrWithUnit : function( prop, unit ){
\r
382 _remove : function(){
\r
383 switch( this.phase ){
\r
388 this.xnode.destroy();
\r
391 delete this.rootData;
\r
392 delete this.parent;
\r
393 delete this.parentData;
\r
402 calculate : function( isNeedsDetection, x, y, allowW, allowH ){
\r
403 this.preMesure( allowW, allowH );
\r
405 if( this.boxWidth === X.UI.Attr.AUTO || this.boxHeight === X.UI.Attr.AUTO ){
\r
410 !isNeedsDetection && this.updateLayout( x, y );
\r
414 * X.Dom.BoxModel の情報を引きながら top,left,width,height,padding,border の設定
\r
416 updateLayout : function( x, y ){
\r
420 .css( 'left', x ? x + 'em' : 0 )
\r
421 .css( 'top', y ? y + 'em' : 0 )
\r
422 .css( 'width', this.contentWidth ? this.contentWidth + 'em' : 0 )
\r
423 .css( 'height', this.contentHeight ? this.contentHeight + 'em' : 0 )
\r
424 .css( 'padding', this._createCssText( 'padding' ) )
\r
425 .css( 'borderWidth', this._createCssText( 'borderWidth' ) );
\r
429 * 親の サイズを元に自身のサイズを計算していく
\r
431 preMesure : function( allowW, allowH ){
\r
432 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
433 calc = _AbstractUINode.calcValue,
\r
434 box = attrs[ X.UI.Attr.Support.sizing.No ],
\r
436 boxL, boxT, boxR, boxB,
\r
437 contentW, contentH, boxMinus,
\r
438 paddingT, paddingR, paddingB, paddingL,
\r
439 borderT, borderR, borderB, borderL;
\r
442 // 自身が constraintW の場合 親が AUTO ではない
\r
443 // 自身が constraintW でない場合自身が AUTO はなくかつ親 が AUTO の場合 or 自身は % でない
\r
445 paddingR = calc( attrs[ X.UI.Attr.Support.padding.No + 1 ], allowW );
\r
446 paddingL = calc( attrs[ X.UI.Attr.Support.padding.No + 3 ], allowW );
\r
447 borderR = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 1 ], allowW );
\r
448 borderL = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 3 ], allowW );
\r
451 case 3 : // border-box
\r
452 boxMinus -= borderR + borderL;
\r
453 case 2 : // padding-box
\r
454 boxMinus -= paddingR + paddingL;
\r
455 // case 1 : // content-box
\r
457 this.contentL = borderL + paddingL;
\r
458 this.contentR = borderR + paddingR;
\r
460 if( this.constraintW ? allowW !== X.UI.Attr.AUTO : !this.autoWidth && ( allowW !== X.UI.Attr.AUTO || !this.percentWidth ) ){
\r
461 if( this.constraintW ){ // 制約レイアウト
\r
462 contentW = allowW - ( boxL = calc( attrs[ X.UI.Attr.Support.left.No ], allowW ) ) - ( boxR = calc( attrs[ X.UI.Attr.Support.right.No ], allowW ) );
\r
464 contentW = _AbstractUINode.finalValue( attrs[ X.UI.Attr.Support.width.No ], attrs[ X.UI.Attr.Support.minWidth.No ], attrs[ X.UI.Attr.Support.maxWidth.No ], allowW );
\r
466 this.contentWidth = contentW + boxMinus;
\r
467 this.scrollWidth = this.contentWidth + this.contentL + this.contentR;
\r
468 this.boxWidth = contentW - boxMinus + this.contentL + this.contentR;
\r
469 this.boxSizingOffsetLR = boxMinus;
\r
470 delete this.minContentWidth;
\r
471 delete this.maxContentWidth;
\r
472 delete this.minBoxWidth;
\r
473 delete this.maxBoxWidth;
\r
475 this.minContentWidth = calc( attrs[ X.UI.Attr.Support.minWidth.No ], allowW ) + boxMinus;
\r
476 this.maxContentWidth = calc( attrs[ X.UI.Attr.Support.maxWidth.No ], allowW ) + boxMinus;
\r
477 this.scrollWidth = this.contentWidth + this.contentL + this.contentR;
\r
478 this.minBoxWidth = this.minContentWidth - boxMinus + this.contentL + this.contentR;
\r
479 this.maxBoxWidth = this.maxContentWidth - boxMinus + this.contentL + this.contentR;
\r
480 delete this.contentWidth;
\r
481 delete this.scrollWidth;
\r
482 delete this.boxWidth;
\r
483 delete this.boxSizingOffsetLR;
\r
486 paddingT = calc( attrs[ X.UI.Attr.Support.padding.No + 0 ], allowH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
487 paddingB = calc( attrs[ X.UI.Attr.Support.padding.No + 2 ], allowH );
\r
488 borderT = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 0 ], allowH );
\r
489 borderB = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 2 ], allowH );
\r
492 case 3 : // border-box
\r
493 boxMinus -= borderT + borderB;
\r
494 case 2 : // padding-box
\r
495 boxMinus -= paddingT + paddingB;
\r
496 // case 1 : // content-box
\r
498 this.contentT = borderT + paddingT;
\r
499 this.conetntB = borderB + paddingB;
\r
502 if( this.constraintH ? allowH !== X.UI.Attr.AUTO : !this.autoHeight && ( allowH !== X.UI.Attr.AUTO || !this.percentHeight ) ){
\r
503 if( this.constraintH ){ // 制約レイアウト
\r
504 contentH = allowH - ( boxT = calc( attrs[ X.UI.Attr.Support.top.No ], allowH ) ) - ( boxB = calc( attrs[ X.UI.Attr.Support.bottom.No ], allowH ) );
\r
506 contentH = _AbstractUINode.finalValue( attrs[ X.UI.Attr.Support.height.No ], attrs[ X.UI.Attr.Support.minHeight.No ], attrs[ X.UI.Attr.Support.maxHeight.No ], allowH );
\r
508 this.contentHeight = contentH + boxMinus;
\r
509 this.scrollHeight = this.contentHeight + this.contentT + this.contentB;
\r
510 this.boxHeight = contentH - boxMinus + this.contentT + this.conetntB; // padding-box の場合 border だけ足される
\r
511 this.boxSizingOffsetTB = boxMinus;
\r
512 delete this.minContentHeight;
\r
513 delete this.maxContentHeight;
\r
514 delete this.minBoxHeight;
\r
515 delete this.maxBoxHeight;
\r
517 this.minContentHeight = calc( attrs[ X.UI.Attr.Support.minHeight.No ], allowH ) + boxMinus;
\r
518 this.maxContentHeight = calc( attrs[ X.UI.Attr.Support.maxHeight.No ], allowH ) + boxMinus;
\r
519 this.minBoxHeight = this.minContentHeight - boxMinus + this.contentT + this.conetntB;
\r
520 this.maxBoxHeight = this.maxContentHeight - boxMinus + this.contentT + this.conetntB;
\r
522 delete this.contentHeight;
\r
523 delete this.scrollHeight;
\r
524 delete this.boxHeight;
\r
525 delete this.boxSizingOffsetTB;
\r
528 if( this.parentData && this.parentData.layout.overrideAttrsForChild.left ){
\r
529 if( this.constraintW ){
\r
530 this.boxX = ( boxL || boxL === 0 ) ? boxL : calc( attrs[ X.UI.Attr.Support.left.No ], allowW );
\r
532 if( attrs[ X.UI.Attr.Support.right.No ] === null ){
\r
533 this.boxX = ( boxL || boxL === 0 ) ? boxL : calc( attrs[ X.UI.Attr.Support.left.No ], allowW );
\r
535 this.boxX = alllowW - this.boxWidth - ( ( boxR || boxR === 0 ) ? boxR : calc( attrs[ X.UI.Attr.Support.right.No ], allowW ) );
\r
541 if( this.parentData && this.parentData.layout.overrideAttrsForChild.top ){
\r
542 if( this.constraintH ){
\r
543 this.boxY = ( boxT || boxT === 0 ) ? boxT : calc( attrs[ X.UI.Attr.Support.top.No ], allowH );
\r
545 if( attrs[ X.UI.Attr.Support.bottom.No ] === null ){
\r
546 this.boxY = ( boxT || boxT === 0 ) ? boxT : calc( attrs[ X.UI.Attr.Support.top.No ], allowH );
\r
548 this.boxY = allowH - this.boxHeight - ( ( boxB || boxB === 0 ) ? boxB : calc( attrs[ X.UI.Attr.Support.bottom.No ], allowH ) );
\r
556 * 描画・計測を行って、contentSize, scrollSize の決定
\r
558 mesure : function(){
\r
559 var dirty = this.dirty,
\r
563 case X.UI.Dirty.CONTENT : // コンテンツが変更された
\r
564 case X.UI.Dirty.FONT : // フォントサイズが変更された
\r
565 delete this.lastContentWidth;
\r
566 case X.UI.Dirty.LAYOUT : // レイアウトの再計算が必要
\r
567 w = this.contentWidth;
\r
568 h = this.contentHeight;
\r
569 xnode = this.xnode;
\r
571 /* http://web-designs.seesaa.net/article/188400668.html
\r
572 * min-width の値が max-width の値より大きい場合は、max-width の値は min-width の値に設定される。
\r
575 * 1. contentWidth === AUTO
\r
576 * style を更新して contentWidth の決定
\r
577 * min or max に引っかかったら style 更新
\r
578 * contentHeight === AUTO の場合
\r
580 * contentHeight !== AUTO の場合 scrollHeight のみ更新
\r
581 * 2. contentHeight === AUTO かつ
\r
582 * コンテンツの高さの再取得が必要( contentWidth が最終計測時の contentWidth と一致 かつ フォント・コンテンツに変更無し の場合再取得不要)
\r
583 * style を更新して contentHeight の決定
\r
585 * 3. content のサイズがすでに決定している
\r
589 if( xnode._xnodes && xnode._xnodes.length ){
\r
590 if( w === X.UI.Attr.AUTO ){
\r
591 w = this.contentWidth = xnode.width() / xnode._getCharSize();
\r
592 this.scrollWidth = w + this.contentL + this.contentR;
\r
593 if( this.maxContentWidth < w - this.boxSizingOffsetLR ) this.contentWidth = this.maxContentWidth + this.boxSizingOffsetLR;
\r
594 if( w - this.boxSizingOffsetLR < this.minContentWidth ) this.contentWidth = this.minContentWidth + this.boxSizingOffsetLR;
\r
595 this.lastContentWidth = this.contentWidth;
\r
597 w !== this.contentWidth && xnode.css( 'width', this.contentWidth + 'em' );
\r
599 if( h === X.UI.Attr.AUTO ){
\r
600 this.conetntHeight = h = xnode.height() / xnode._getCharSize();
\r
601 this.scrollHeight = h + this.contentT + this.contentB;
\r
602 if( this.maxContentHeight < h - this.boxSizingOffsetTB ) this.contentHeight = this.maxContentHeight + this.boxSizingOffsetTB;
\r
603 if( h - this.boxSizingOffsetTB < this.minContentHeight ) this.contentHeight = this.minContentHeight + this.boxSizingOffsetTB;
\r
605 this.scrollHeight = xnode.height() / xnode._getCharSize() + this.contentT + this.contentB;
\r
608 if( h === X.UI.Attr.AUTO ){
\r
609 if( w !== this.lastContentWidth ){
\r
610 xnode.css( 'width', w + 'em' );
\r
611 this.lastContentWidth = w;
\r
612 this.conetntHeight = h = xnode.height() / xnode._getCharSize();
\r
613 this.scrollWidth = w + this.contentL + this.contentR;
\r
614 this.scrollHeight = h + this.contentT + this.contentB;
\r
615 if( this.maxContentHeight < h - this.boxSizingOffsetTB ) this.contentHeight = this.maxContentHeight + this.boxSizingOffsetTB;
\r
616 if( h - this.boxSizingOffsetTB < this.minContentHeight ) this.contentHeight = this.minContentHeight + this.boxSizingOffsetTB;
\r
618 this.scrollWidth = w + this.contentL + this.contentR;
\r
619 this.scrollHeight = h + this.contentT + this.contentB;
\r
622 if( dirty !== X.UI.Dirty.LAYOUT ){
\r
623 this.contentWidth = this.lastContentWidth = w; //xnode.width();
\r
624 this.contentHeight = xnode.height() / xnode._getCharSize();
\r
625 this.scrollWidth = this.contentWidth + this.contentL + this.contentR;
\r
626 this.scrollHeight = this.contentHeight + this.contentT + this.contentB;
\r
628 this.scrollWidth = w + this.contentL + this.contentR;
\r
629 this.scrollHeight = h + this.contentT + this.contentB;
\r
632 // コンテンツを持たないため基本のサイズは0
\r
633 if( w === X.UI.Attr.AUTO ) this.contentWidth = w = 0 < this.minContentWidth ? this.minContentWidth : 0;
\r
634 if( h === X.UI.Attr.AUTO ) this.contentHeight = h = 0 < this.minContentHeight ? this.minContentHeight : 0;
\r
635 this.scrollWidth = w + this.contentL + this.contentR;
\r
636 this.scrollHeight = h + this.contentT + this.contentB;
\r
639 //case X.UI.Dirty.PAINT : // 再描画のみ必要
\r
644 * 自身の contentWidth, contentHeight を元に AUTO な width, height を確定していく
\r
646 postMesure : function(){
\r
647 var attrs = this.attrObject || this.attrClass.prototype || X.UI.AttrClass,
\r
648 calc = _AbstractUINode.calcValue,
\r
649 box = attrs[ X.UI.Attr.Support.sizing.No ],
\r
650 contentW, contentH,
\r
652 paddingT, paddingR, paddingB, paddingL,
\r
653 borderT, borderR, borderB, borderL,
\r
657 if( this.boxWidth === X.UI.Attr.AUTO ){
\r
658 contentW = this.contentWidth;
\r
659 paddingR = calc( attrs[ X.UI.Attr.Support.padding.No + 1 ], contentW );
\r
660 paddingL = calc( attrs[ X.UI.Attr.Support.padding.No + 3 ], contentW );
\r
661 borderR = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 1 ], contentW );
\r
662 borderL = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 3 ], contentW );
\r
665 case 3 : // border-box
\r
666 contentPlus = borderR + borderL;
\r
667 case 2 : // padding-box
\r
668 contentPlus += paddingR + paddingL;
\r
669 // case 1 : // content-box
\r
672 if( !this.constraintW ){
\r
673 contentW += contentPlus;
\r
674 min = calc( attrs[ X.UI.Attr.Support.minWidth.No ], contentW );
\r
675 max = calc( attrs[ X.UI.Attr.Support.maxWidth.No ], contentW );
\r
676 if( contentW < min && contentPlus < min ){
\r
677 this.contentWidth = min - contentPlus;
\r
679 if( max < contentW && contentPlus < max ){
\r
680 this.contentWidth = max - contentPlus;
\r
683 this.contentL = borderL + paddingL;
\r
684 this.contentR = borderR + paddingR;
\r
685 this.boxWidth = this.contentWidth + this.contentL + this.contentR;
\r
688 if( this.boxHeight === X.UI.Attr.AUTO ){
\r
689 contentH = this.contentHeight;
\r
690 paddingT = calc( attrs[ X.UI.Attr.Support.padding.No + 0 ], contentH );// paddingTRBL の % 指定は 最大幅に対して TB でも幅に対して
\r
691 paddingB = calc( attrs[ X.UI.Attr.Support.padding.No + 2 ], contentH );
\r
692 borderT = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 0 ], contentH );
\r
693 borderB = calc( attrs[ X.UI.Attr.Support.borderWidth.No + 2 ], contentH );
\r
696 case 3 : // border-box
\r
697 contentPlus = borderT + borderB;
\r
698 case 2 : // padding-box
\r
699 contentPlus += paddingT + paddingB;
\r
700 // case 1 : // content-box
\r
702 if( !this.constraintH ){
\r
703 contentH += contentPlus;
\r
704 min = calc( attrs[ X.UI.Attr.Support.minHeight.No ], contentH );
\r
705 max = calc( attrs[ X.UI.Attr.Support.maxHeight.No ], contentH );
\r
706 if( contentH < min && contentPlus < min ){
\r
707 this.contentHeight = min - contentPlus;
\r
709 if( max < contentH && contentPlus < max ){
\r
710 this.contentHeight = max - contentPlus;
\r
713 this.contentT = borderT + paddingT;
\r
714 this.contentB = borderB + paddingB;
\r
715 this.boxHeight = this.contentHeight + this.contentT + this.contentB;
\r
719 capcher : function( x, y ){
\r
720 if( this.pointerDisabled ) return false;
\r
725 if( 0 <= x && x < this.boxWidth && 0 <= y && y < this.boxHeight ){
\r
726 !this.hovering && ( this.hoverList[ this.hoverList.length ] = this );
\r
727 this.rootData.targetNodeData = this;
\r
733 listen : function( type, arg1, arg2, arg3 ){
\r
734 var root, events, counter;
\r
735 if( X.UI.Event._START_POINTER <= type && type <= X.UI.Event._END_POINTER ){
\r
736 if( this.phase < 3 ){
\r
737 if( !( events = this.reserveEvents ) ) this.reserveEvents = events = [];
\r
738 events[ events.length ] = [ type, arg1, arg2, arg3 ];
\r
741 if( X.UI.Event._START_XUI_EVENT < type && type < X.UI.Event._END_XUI_EVENT ){
\r
742 if( !this.gesture ){
\r
743 this.gesture = new X.UI.Gesture( this.root, this, type );
\r
745 this.gesture.listen( type );
\r
748 root = this.rootData;
\r
749 counter = root.eventCounter;
\r
750 if( counter[ type ] ){
\r
753 counter[ type ] = 1;
\r
754 root.elmMouseCatch.listen( X.UI.Event.IdToName[ type ], eventRellay );
\r
758 if( typeof arg1 === 'function' ){
\r
759 return X.EventDispatcher.prototype.listen.apply( this, [ type, this.User, arg1, arg2 ] );
\r
761 return X.EventDispatcher.prototype.listen.apply( this, [ type, arg1 || this.User, arg2 || arg1, arg3 || arg2 ] );
\r
763 unlisten : function( type, arg1, arg2, arg3 ){
\r
764 var root, events, i, ev, counter;
\r
765 if( X.UI.Event._START_POINTER <= type && type <= X.UI.Event._END_POINTER ){
\r
766 if( this.phase < 3 ){
\r
767 if( !( events = this.reserveEvents ) ) return this;
\r
768 for( i = events.length; i; ){
\r
769 ev = events[ --i ];
\r
770 if( ev[ 0 ] === type && ev[ 1 ] === arg1 && ev[ 2 ] === arg2 ){
\r
771 events.split( i, 1 );
\r
778 if( X.UI.Event._START_XUI_EVENT < type && type < X.UI.Event._END_XUI_EVENT ){
\r
779 this.gesture && this.gesture.unlisten( type );
\r
781 root = this.rootData;
\r
782 counter = root.eventCounter;
\r
783 if( !counter[ type ] ) return this;
\r
785 if( counter[ type ] === 0 ){
\r
786 X.Dom.Event.remove( root.elmMouseCatch, X.UI.Event.IdToName[ type ], eventRellay );
\r
787 delete counter[ type ];
\r
791 if( typeof arg1 === 'function' ){
\r
792 return X.EventDispatcher.prototype.unlisten.apply( this, [ type, this.User, arg1, arg2 ] );
\r
794 return X.EventDispatcher.prototype.unlisten.apply( this, [ type, arg1 || this.User, arg2 || arg1, arg3 || arg2 ] );
\r
797 dispatch : function( e ){
\r
798 var xve = X.UI.Event,
\r
799 ret = X.EventDispatcher.prototype.dispatch.call( this, e ),
\r
801 if( ret & X.Callback.MONOPOLY && !this.hitChildData && ( xve._POINTER_MOVE === type || xve._MOUSE_MOVE === type || xve.FILE_DRAG === type ) ){
\r
802 this.rootData.monopolyNodeData = this;
\r
805 this.rootData.monopolyNodeData = null;
\r
806 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
813 _AbstractUINode.calcValue = function( styleValue, srcValue ){
\r
817 if( X.Type.isString( styleValue ) ){
\r
818 return srcValue * parseFloat( styleValue ) / 100;
\r
820 if( !X.Type.isNumber( styleValue ) ) return 0;
\r
824 _AbstractUINode.finalValue = function( styleValue, styleMin, styleMax, srcValue ){
\r
825 var calc = _AbstractUINode.calcValue,
\r
826 v = calc( styleValue, srcValue ),
\r
827 min = calc( styleMin, srcValue ),
\r
828 max = calc( styleMax, srcValue );
\r
829 return v <= min ? min : max <= v ? max : v;
\r
832 var AbstractUINode = X.Class.create(
\r
834 X.Class.ABSTRACT | X.Class.SUPER_ACCESS,
\r
836 parent : function(){
\r
837 return X.Class._getPrivate( this ).parent;
\r
840 return X.Class._getPrivate( this ).root;
\r
844 * unverifiedAttrs に全ての指定を控える
\r
845 * サポートされていない場合は無視される.親のレイアウトによって変わる
\r
847 attr : function( nameOrObject, valueOrUnit ){
\r
848 var p = X.Class._getPrivate( this ),
\r
849 layout, k, def, attrs, v;
\r
850 if( nameOrObject && X.Type.isObject( nameOrObject ) ){
\r
852 layout = p.parentData && p.parentData.layout.overrideAttrsForChild; // root には parent がない
\r
853 for( k in nameOrObject ){
\r
854 // 親のレイアウトマネージャの許可しない
\r
855 if( layout && !layout[ k ] ){
\r
858 if( def = p.supportAttrs[ k ] ){
\r
859 p.setAttr( k, def, nameOrObject[ k ] );
\r
863 if( X.Type.isString( nameOrObject ) ){
\r
864 if( valueOrUnit !== undefined ){
\r
865 if( 'em,%'.indexOf( valueOrUnit ) === -1 ){
\r
867 p.setAttr( nameOrObject, valueOrUnit );
\r
869 // getter with unit
\r
870 return p.getAttrWithUnit( nameOrObject, valueOrUnit );
\r
874 if( attrs = ( p.attrObject || p.attrClass.prototype || X.UI.AttrClass ) ){
\r
875 def = p.supportAttrs[ nameOrObject ];
\r
876 return def && attrs[ def.No ];
\r
883 listen : function( type, arg1, arg2, arg3 ){
\r
884 X.Class._getPrivate( this ).listen( type, arg1, arg2, arg3 );
\r
887 listenOnce : function( type, arg1, arg2, arg3 ){
\r
888 X.Class._getPrivate( this ).listenOnce( type, arg1, arg2, arg3 );
\r
891 unlisten : function( type, arg1, arg2, arg3 ){
\r
892 X.Class._getPrivate( this ).unlisten( type, arg1, arg2, arg3 );
\r
895 dispatch : function( e ){
\r
896 return X.Class._getPrivate( this ).dispatch( e );
\r
899 getNextNode : function(){
\r
902 getPrevNode : function(){
\r
905 nodeIndex : function( v ){
\r
906 var data = X.Class._getPrivate( this );
\r
907 if( typeof v === 'number' ){
\r
908 // data.nodeIndex( v );
\r
911 return data.parentData ? data.parentData.nodes.indexOf( data ) : 0;
\r
913 displayIndex : function(){
\r
917 // dirty の場合、rootData.calculate
\r
918 return X.Class._getPrivate( this ).x;
\r
921 // dirty の場合、rootData.calculate
\r
922 return X.Class._getPrivate( this ).y;
\r
924 getAbsoluteX : function(){
\r
925 // dirty の場合、rootData.calculate
\r
926 return X.Class._getPrivate( this ).absoluteX;
\r
928 getAbsoluteY: function(){
\r
929 // dirty の場合、rootData.calculate
\r
930 return X.Class._getPrivate( this ).absoluteY;
\r
932 getWidth : function(){
\r
933 // dirty の場合、rootData.calculate
\r
934 return X.Class._getPrivate( this ).boxWidth;
\r
936 getHeight : function(){
\r
937 // dirty の場合、rootData.calculate
\r
938 return X.Class._getPrivate( this ).boxHeight;
\r
940 scrollTo : function( x, y ){
\r
941 X.Class._getPrivate( this ).scrollTo( x, y );
\r
943 getScrollX : function( v ){
\r
944 // dirty の場合、rootData.calculate
\r
945 return X.Class._getPrivate( this ).scrollX( v );
\r
947 getScrollY : function( v ){
\r
948 // dirty の場合、rootData.calculate
\r
949 return X.Class._getPrivate( this ).scrollY( v );
\r
951 disabled : function( v ){
\r
952 return X.Class._getPrivate( this ).disabled( v );
\r
954 cursor : function( v ){
\r
955 return X.Class._getPrivate( this ).cursor( v );
\r