3 var _DisplayNodeStyle = X.Class.create(
7 Constructor : function( node, nodeData ){
9 this.nodeData= nodeData;
11 nodeData.style= this.User;
12 nodeData.styleData= this;
16 if( nodeData.tmpCss ){
17 if( nodeData.tmpCss.role === 'container' ) nodeData.forContainer = true;
18 if( nodeData.tmpCss.role === 'chrome' ) nodeData.forChrome = true;
21 initialize : function(){
22 if( this.nodeData.layout ){
23 this.allow = this.nodeData.layout.allowForSelf; // これに加えて親の allowForChild を合成
25 if( this.nodeData.parentData.layout ){
26 this.allow = this.nodeData.parentData.layout.allowForChild;
31 if( this.nodeData.tmpCss ){
32 this.css( this.nodeData.tmpCss );
33 delete this.nodeData.tmpCss;
37 afterAddition : function(){
38 var elm = this.nodeData.rawElement;
41 elm.className( this._name );
45 elm.cssText( this._cssText );
51 var sp = ' ', sp2 = ' ', elm;
52 if( this._name !== v ){
58 while( v.indexOf( sp2 ) !== -1 ){ v = v.split( sp2 ).join( sp ); };
59 while( 0 < v.length && v.charAt( 0 ) === sp ){ v = v.substr( 1 ); };
60 while( 0 < v.length && v.lastIndexOf( sp ) === 0 ){ --v.length; };
69 if( elm = this.nodeData.rawElement ){
76 addName : function( _names ){
79 if( !this._name || !this._name.length ) return this.name( _names );
80 _names = _names.split( sp );
81 for( i = _names.length; i; ){
82 if( ( _name = _names[ --i ] ) !== '' && this.hasName( _name ) === false ){
83 if( !names ) names = this._name.split( sp );
84 names[ names.length ] = _name;
87 return this.name( names.join( sp ) );
89 removeName : function( _names ){
93 if( !names || !names.length ) return this.User;
94 names = names.split( sp );
95 _names = _names.split( sp );
96 for( i = _names.length; i; ){
97 ( index = names.indexOf( _names[ --i ] ) ) !== -1 && names.splice( index, 1 );
99 return this.name( names.join( sp ) );
101 hasName : function( _names ){
102 var names = this._name, i;
103 if( !names || !names.length ) return false;
104 names = names.split( ' ' );
105 _names = _names.split( ' ' );
106 for( i = _names.length; i; ){
107 if( names.indexOf( _names[ --i ] ) === -1 ) return false;
111 cssText : function( v ){
113 if( this._cssText !== v ){
115 //if( style = this.nodeData.rawStyle ){
116 // style.cssText = v;
118 if( elm = this.nodeData.rawElement ) elm.cssText( v );
122 var css = this._cssObj,
132 if( REMOVE[ p ] === 0 ) continue;
134 switch( p = TRANS[ p ] || p ){
136 this.addName( v[ p ] );
138 case 'hoverStyleName' :
139 this.nodeData.hoverStyleName = v[ p ];
140 this.nodeData.hover = !!( v[ p ] && v[ p ].length );
143 if( allow.x === false ) continue;
146 if( allow.y === false ) continue;
149 if( allow.w === false ) continue;
152 if( allow.h === false ) continue;
155 if( allow.gapX === false ) continue;
158 if( allow.gapY === false ) continue;
161 if( allow.padding === false ) continue;
166 this.cssText( X.Dom.Style.objToCssText( css ) );
168 layout : function( x, y, w, h ){
169 var isFinite = X.Type.isFinite,
170 isString = X.Type.isString,
172 data = this.nodeData,
173 elm = data.rawElement,
174 //style = data.rawStyle,
179 if( isFinite( w ) === true ){
180 elm.css( { width : w + 'px' } );
181 //style.width = w + 'px';
184 if( isString( w ) === true ){
186 elm.css( { width : w } );
187 w = elm.width();// elm.offsetWidth;
190 if( isFinite( h ) === true ){
191 //style.height = h + 'px';
192 elm.css( { height : h + 'px' } );
195 if( isString( h ) === true ){
197 elm.css( { height : h } );
198 h = elm.height(); //elm.offsetHeight;
202 if( isFinite( x ) === true ){
203 //style.left = x + 'px';
204 elm.css( { left : x + 'px' } );
207 if( isString( x ) === true ){
209 elm.css( { left : x } );
210 x = elm.x(); // elm.offsetLeft;
214 if( isFinite( y ) === true ){
215 //style.top = y + 'px';
216 elm.css( { top : y + 'px' } );
219 if( isString( y ) === true ){
221 elm.css( { top : y } );
222 y = elm.y(); // elm.offsetTop;
225 x = isFinite( x ) === true ? x : data.x;
226 y = isFinite( y ) === true ? y : data.y;
227 w = isFinite( w ) === true ? w : data.w;
228 h = isFinite( h ) === true ? h : data.h;
229 if( data.x !== x || data.y !== y ){
232 ( parent = data.parentData ) && data.updateAbsoluteXY( parent.absoluteX, parent.absoluteY );
233 if( data.w === w && data.h === h ){
234 data.updateRectangle();
235 4 <= data.phase && data.rootData.reserveCalc();
239 if( data.w !== w || data.h !== h ){
242 data.updateRectangle();
243 4 <= data.phase && data.rootData.reserveCalc();
246 // ScrollBarManager.update( this );
250 * opt_unit は getter のみ
252 attr : function( prop, v, opt_unit ){
253 var update = prop[ 0 ],
257 length = !!( type & X.Css.Type.LENGTH ),
258 percent = !!( type & X.Css.Type.PERCENT ),
259 color = !!( type & X.Css.Type.COLOR ),
260 uDecimal = !!( type & X.Css.Type.U_DECIMAL ),
261 numerical = !!( type & X.Css.Type.NUMERICAL ),
262 flag = !!( type & X.Css.Type.BOOLEAN ),
263 quartet = !!( type & X.Css.Type.QUARTET ),
264 url = !!( type & X.Css.Type.URL ),
265 fontName = !!( type & X.Css.Type.FONT_NAME ),
266 //list = !!( type & X.Css.Type.LIST ),
267 combi = !!( type & X.Css.Type.COMBI ),
270 i, l, nodes, root, roots;
274 if( v !== undefined ){
275 if( Type.isNumber( v ) === true ){
276 if( numerical === false ){
277 if( uDecimal === false || v < 0 || 1 < v ){} //throw new Error( '' );
280 if( Type.isBoolean( v ) === true ){
281 if( flag === false ){} //throw new Error( '' );
283 if( Type.isString( v ) === true ){
284 if( url === false && fontName === false ){
285 if( v.indexOf( ' ' ) !== -1 ){
288 if( length === false && percent === false && color === false ){} //throw new Error( '' );
292 if( Type.isArray( v ) === true ){
293 if( v.length <= 4 && quartet === true ){
294 type ^= X.Css.Type.QUARTET;
296 if( v.length === 2 && combi === true ){
297 type ^= X.Css.Type.COMBI;
299 //throw new Error( '' );
303 this.attr( [ propID , type, list ], v[ 0 ] );
304 this.attr( [ ++propID, type, list ], v[ 0 ] );
305 this.attr( [ ++propID, type, list ], v[ 0 ] );
306 this.attr( [ ++propID, type, list ], v[ 0 ] );
309 this.attr( [ propID , type, list ], v[ 0 ] );
310 this.attr( [ ++propID, type, list ], v[ 1 ] );
311 this.attr( [ ++propID, type, list ], v[ 0 ] );
312 this.attr( [ ++propID, type, list ], v[ 1 ] );
315 this.attr( [ propID , type, list ], v[ 0 ] );
316 this.attr( [ ++propID, type, list ], v[ 1 ] );
317 this.attr( [ ++propID, type, list ], v[ 2 ] );
318 this.attr( [ ++propID, type, list ], v[ 1 ] );
321 this.attr( [ propID , type, list ], v[ 0 ] );
322 this.attr( [ ++propID, type, list ], v[ 1 ] );
323 this.attr( [ ++propID, type, list ], v[ 2 ] );
324 this.attr( [ ++propID, type, list ], v[ 3 ] );
331 case X.Css.Dirty.REFLOW :
332 delete this.layoutCssText;
334 case X.Css.Dirty.PAINT :
335 delete this.colorCssText;
337 case X.Css.Dirty.FONT :
338 delete this.fontCssText;
341 if( this.dirty < update ){
343 roots = this.rootList;
344 for( i = 0, l = roots.length; i < l; ++i ){
346 if( root.dirty < update ) root.dirty = update;
350 if( list ) _v = list.indexOf( v );
351 data[ propID ] = _v !== -1 ? _v : v;
354 case X.Css.AttrNo.left :
355 case X.Css.AttrNo.right :
356 this.constraintW = Type.isNumber( data[ X.Css.AttrNo.left ] ) || Type.isNumber( data[ X.Css.AttrNo.right ] );
358 case X.Css.AttrNo.top :
359 case X.Css.AttrNo.bottom :
360 this.constraintH = Type.isNumber( data[ X.Css.AttrNo.top ] ) || Type.isNumber( data[ X.Css.AttrNo.bottom ] );
362 case X.Css.AttrNo.width :
363 this.autoWidth = v === AUTO;
364 this.percentWidth = v === FULL || v < 1;
366 case X.Css.AttrNo.height :
367 this.autoHeight = v === AUTO;
368 this.percentHeight = v === FULL || v < 1;
378 if( quartet === true ) return [ v, data[ ++propID ], data[ ++propID ], data[ ++propID ] ];
379 if( combi === true ) return [ v, data[ ++propID ] ];
380 if( list && Type.isNumber( v ) === true ) return list[ v ];
383 __cssText : function(){
384 if( this.fontCssText === null ) this.fontCssText = this.createFontCssText();
385 if( this.layoutCssText === null ) this.layoutCssText = this.createLayoutCssText();
386 if( this.colorCssText === null ) this.colorCssText = this.createColorCssText();
387 return [ this.fontCssText, this.colorCssText, this.layoutCssText ].join( ';' );
389 createFontCssText : function(){
390 var data = this.data,
393 if( v = data[ X.Css.AttrNo.fontFamily ] ) css[ 0 ] = 'font-family:' + v;
394 if( v = data[ X.Css.AttrNo.fontSize ] ) css[ css.length ] = 'font-size:' + v;
395 if( v = data[ X.Css.AttrNo.bold ] ) css[ css.length ] = 'font-weight:bold';
396 if( v = data[ X.Css.AttrNo.italic ] ) css[ css.length ] = 'font-style:italic';
397 if( v = data[ X.Css.AttrNo.lineHeight ] ) css[ css.length ] = 'line-height:' + v;
398 if( v = data[ X.Css.AttrNo.letterSpacing ] ) css[ css.length ] = 'letter-spacing:' + v;
399 if( v = data[ X.Css.AttrNo.wordSpacing ] ) css[ css.length ] = 'word-spacing:' + v;
400 if( v = data[ X.Css.AttrNo.align ] ) css[ css.length ] = 'text-align:' + X.Css.Option.ALIGN[ v ];
401 if( v = data[ X.Css.AttrNo.transform ] ) css[ css.length ] = 'text-transform:' + X.Css.Option.TEXT_TRANSFORM[ v ];
402 return css.join( ';' );
404 createLayoutCssText : function(){
407 createColorCssText : function(){
408 var data = this.data,
411 if( v = data[ X.Css.AttrNo.borderColor ] ) css[ 0 ] = 'border-color:' + v;
412 if( v = data[ X.Css.AttrNo.borderStyle + 0 ] ) css[ css.length ] = 'border-top-style:' + X.Css.Option.BORDER_STYLE[ v ];
413 if( v = data[ X.Css.AttrNo.borderStyle + 1 ] ) css[ css.length ] = 'border-right-style:' + X.Css.Option.BORDER_STYLE[ v ];
414 if( v = data[ X.Css.AttrNo.borderStyle + 2 ] ) css[ css.length ] = 'border-bottom-style:' + X.Css.Option.BORDER_STYLE[ v ];
415 if( v = data[ X.Css.AttrNo.borderStyle + 3 ] ) css[ css.length ] = 'border-left-style:' + X.Css.Option.BORDER_STYLE[ v ];
416 if( v = data[ X.Css.AttrNo.cornerRadius + 0 ] ) css[ css.length ] = 'corner-radius-top:' + v;
417 if( v = data[ X.Css.AttrNo.cornerRadius + 1 ] ) css[ css.length ] = 'corner-radius-right:' + v;
418 if( v = data[ X.Css.AttrNo.cornerRadius + 2 ] ) css[ css.length ] = 'border-radius-bottom:' + v;
419 if( v = data[ X.Css.AttrNo.cornerRadius + 3 ] ) css[ css.length ] = 'border-radius-left:' + v;
420 if( v = data[ X.Css.AttrNo.bgColor ] ) css[ css.length ] = 'background-color:' + v;
421 // X.Css.AttrNo.bgAlpha
422 if( v = data[ X.Css.AttrNo.bgImgUrl ] ) css[ css.length ] = 'background-image:url(' + v + ')';
423 x = data[ X.Css.AttrNo.bgImgRepeatX ];
424 y = data[ X.Css.AttrNo.bgImgRepeatY ];
426 css[ css.length ] = 'background-repeat:repeat';
429 css[ css.length ] = 'background-repeat:repeat-x';
432 css[ css.length ] = 'background-repeat:repeat-y';
434 x = data[ X.Css.AttrNo.bgImgPositionX ];
435 y = data[ X.Css.AttrNo.bgImgPositionY ];
437 css[ css.length ] = 'background-position:' + x + ' ' + y;
440 css[ css.length ] = 'background-position:' + x + ' 0';
443 css[ css.length ] = 'background-position:0 ' + y;
445 if( v = data[ X.Css.AttrNo.color ] ) css[ css.length ] = 'color:' + v;
446 if( v = data[ X.Css.AttrNo.decoration ] ) css[ css.length ] = 'text-decoration:' + X.Css.Option.TEXT_DECORATION[ v ];
447 x = data[ X.Css.AttrNo.textShadowOffsetX ];
448 y = data[ X.Css.AttrNo.textShadowOffsetY ];
449 b = data[ X.Css.AttrNo.textShadowBlur ];
450 c = data[ X.Css.AttrNo.textShadowColor ];
451 if( c || x || y || b ){
452 css[ css.length ] = 'text-shadow:' + x + ' ' + y + ' ' + b + ' ' + c;
455 X.Css.AttrNo.shadowColor = [ X.Css.Dirty.PAINT, 23, X.Css.Type.COLOR ]; // color
456 X.Css.AttrNo.shadowAlpha = [ X.Css.Dirty.PAINT, 24, X.Css.Type.U_DECIMAL ]; // 0 - 1
457 X.Css.AttrNo.shadowOffsetX = [ X.Css.Dirty.PAINT, 25, X.Css.Type.LENGTH ]; // em
458 X.Css.AttrNo.shadowOffsetY = [ X.Css.Dirty.PAINT, 26, X.Css.Type.LENGTH ]; // em
459 X.Css.AttrNo.shadowBlur = [ X.Css.Dirty.PAINT, 27, X.Css.Type.LENGTH ]; // em
460 X.Css.AttrNo.shadowSpread = [ X.Css.Dirty.PAINT, 28, X.Css.Type.LENGTH ]; // em
461 X.Css.AttrNo.shadowInset = [ X.Css.Dirty.PAINT, 29, X.Css.Type.BOOLEAN ]; // true / false
463 return css.join( ';' );
474 var DisplayNodeStyle = X.Class.create(
479 Constructor : function( node, nodeData ){
480 X.Class._newPrivate( this, node, nodeData );
482 addName : function( names ){
483 return X.Class._getPrivate( this ).addName( names );
485 removeName : function( names ){
486 return X.Class._getPrivate( this ).removeName( names );
488 hasName : function( names ){
489 return X.Class._getPrivate( this ).hasName( names );
491 cssText : function( v ){
492 var data = X.Class._getPrivate( this );
497 return data._cssText;
500 var data = X.Class._getPrivate( this );
508 borderWidth : function( v ){
509 return X.Class._getPrivate( this ).attr( X.Css.Attr.borderWidth, v );
511 borderColor : function( v ){
512 return X.Class._getPrivate( this ).attr( X.Css.Attr.borderColor, v );
514 borderStyle : function( v ){
515 return X.Class._getPrivate( this ).attr( X.Css.Attr.borderStyle, v );
517 cornerRadius : function( v ){
518 return X.Class._getPrivate( this ).attr( X.Css.Attr.cornerRadius, v );
520 bgColor : function( v ){
521 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgColor, v );
523 bgAlpha : function( v ){
524 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgAlpha, v );
526 bgImgUrl : function( v ){
527 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgImgUrl, v );
529 bgImgRepeatX : function( v ){
530 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgImgRepeatX, v );
532 bgImgRepeatY : function( v ){
533 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgImgRepeatY, v );
535 bgImgPositionX : function( v ){
536 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgImgPositionX, v );
538 bgImgPositionY : function( v ){
539 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgImgPositionY, v );
541 shadowColor : function( v ){
542 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowColor, v );
544 shadowAlpha : function( v ){
545 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowAlpha, v );
547 shadowOffsetX : function( v ){
548 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowOffsetX, v );
550 shadowOffsetY : function( v ){
551 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowOffsetY, v );
553 shadowBlur : function( v ){
554 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowBlur, v );
556 shadowSpread : function(){
557 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowSpread, v );
559 shadowInset : function(){
560 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowInset, v );
562 color : function( v ){
563 return X.Class._getPrivate( this ).attr( X.Css.Attr.color, v );
565 fontFamily : function( v ){
566 return X.Class._getPrivate( this ).attr( X.Css.Attr.fontFamily, v );
568 fontSize : function( v ){
569 return X.Class._getPrivate( this ).attr( X.Css.Attr.fontSize, v );
571 bold : function( v ){
572 return X.Class._getPrivate( this ).attr( X.Css.Attr.bold, v );
574 italic : function( v ){
575 return X.Class._getPrivate( this ).attr( X.Css.Attr.italic, v );
577 lineHeight : function( v ){
578 return X.Class._getPrivate( this ).attr( X.Css.Attr.lineHeight, v );
580 letterSpacing : function( v ){
581 return X.Class._getPrivate( this ).attr( X.Css.Attr.letterSpacing, v );
583 wordSpacing : function( v ){
584 return X.Class._getPrivate( this ).attr( X.Css.Attr.wordSpacing, v );
586 align : function( v ){
587 return X.Class._getPrivate( this ).attr( X.Css.Attr.align, v );
589 decoration : function( v ){
590 return X.Class._getPrivate( this ).attr( X.Css.Attr.decoration, v );
592 transform : function( v ){
593 return X.Class._getPrivate( this ).attr( X.Css.Attr.transform, v );
595 textShadowColor : function( v ){
596 return X.Class._getPrivate( this ).attr( X.Css.Attr.textShadowColor, v );
598 textShadowOffsetX : function( v ){
599 return X.Class._getPrivate( this ).attr( X.Css.Attr.textShadowOffsetX, v );
601 textShadowOffsetY : function( v ){
602 return X.Class._getPrivate( this ).attr( X.Css.Attr.textShadowOffsetY, v );
604 shadowBlur : function( v ){
605 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowBlur, v );