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,
178 if( isFinite( w ) === true ){
179 elm.css( 'width', w + 'px' );
182 if( isString( w ) === true ){
184 elm.css( 'width', w );
188 if( isFinite( h ) === true ){
189 elm.css( 'height', h + 'px' );
192 if( isString( h ) === true ){
194 elm.css( 'height', h );
199 if( isFinite( x ) === true ){
200 elm.css( 'left', x + 'px' );
203 if( isString( x ) === true ){
205 elm.css( 'left', x );
210 if( isFinite( y ) === true ){
211 elm.css( 'top', y + 'px' );
214 if( isString( y ) === true ){
220 x = isFinite( x ) === true ? x : data.x;
221 y = isFinite( y ) === true ? y : data.y;
222 w = isFinite( w ) === true ? w : data.w;
223 h = isFinite( h ) === true ? h : data.h;
224 if( data.x !== x || data.y !== y ){
227 ( parent = data.parentData ) && data.updateAbsoluteXY( parent.absoluteX, parent.absoluteY );
228 if( data.w === w && data.h === h ){
229 data.updateRectangle();
230 4 <= data.phase && data.rootData.reserveCalc();
234 if( data.w !== w || data.h !== h ){
237 data.updateRectangle();
238 4 <= data.phase && data.rootData.reserveCalc();
241 // ScrollBarManager.update( this );
245 * opt_unit は getter のみ
247 attr : function( prop, v, opt_unit ){
248 var update = prop[ 0 ],
252 length = !!( type & X.Css.Type.LENGTH ),
253 percent = !!( type & X.Css.Type.PERCENT ),
254 color = !!( type & X.Css.Type.COLOR ),
255 uDecimal = !!( type & X.Css.Type.U_DECIMAL ),
256 numerical = !!( type & X.Css.Type.NUMERICAL ),
257 flag = !!( type & X.Css.Type.BOOLEAN ),
258 quartet = !!( type & X.Css.Type.QUARTET ),
259 url = !!( type & X.Css.Type.URL ),
260 fontName = !!( type & X.Css.Type.FONT_NAME ),
261 //list = !!( type & X.Css.Type.LIST ),
262 combi = !!( type & X.Css.Type.COMBI ),
265 i, l, nodes, root, roots;
269 if( v !== undefined ){
270 if( Type.isNumber( v ) === true ){
271 if( numerical === false ){
272 if( uDecimal === false || v < 0 || 1 < v ){} //throw new Error( '' );
275 if( Type.isBoolean( v ) === true ){
276 if( flag === false ){} //throw new Error( '' );
278 if( Type.isString( v ) === true ){
279 if( url === false && fontName === false ){
280 if( v.indexOf( ' ' ) !== -1 ){
283 if( length === false && percent === false && color === false ){} //throw new Error( '' );
287 if( Type.isArray( v ) === true ){
288 if( v.length <= 4 && quartet === true ){
289 type ^= X.Css.Type.QUARTET;
291 if( v.length === 2 && combi === true ){
292 type ^= X.Css.Type.COMBI;
294 //throw new Error( '' );
298 this.attr( [ propID , type, list ], v[ 0 ] );
299 this.attr( [ ++propID, type, list ], v[ 0 ] );
300 this.attr( [ ++propID, type, list ], v[ 0 ] );
301 this.attr( [ ++propID, type, list ], v[ 0 ] );
304 this.attr( [ propID , type, list ], v[ 0 ] );
305 this.attr( [ ++propID, type, list ], v[ 1 ] );
306 this.attr( [ ++propID, type, list ], v[ 0 ] );
307 this.attr( [ ++propID, type, list ], v[ 1 ] );
310 this.attr( [ propID , type, list ], v[ 0 ] );
311 this.attr( [ ++propID, type, list ], v[ 1 ] );
312 this.attr( [ ++propID, type, list ], v[ 2 ] );
313 this.attr( [ ++propID, type, list ], v[ 1 ] );
316 this.attr( [ propID , type, list ], v[ 0 ] );
317 this.attr( [ ++propID, type, list ], v[ 1 ] );
318 this.attr( [ ++propID, type, list ], v[ 2 ] );
319 this.attr( [ ++propID, type, list ], v[ 3 ] );
326 case X.Css.Dirty.REFLOW :
327 delete this.layoutCssText;
329 case X.Css.Dirty.PAINT :
330 delete this.colorCssText;
332 case X.Css.Dirty.FONT :
333 delete this.fontCssText;
336 if( this.dirty < update ){
338 roots = this.rootList;
339 for( i = 0, l = roots.length; i < l; ++i ){
341 if( root.dirty < update ) root.dirty = update;
345 if( list ) _v = list.indexOf( v );
346 data[ propID ] = _v !== -1 ? _v : v;
349 case X.Css.AttrNo.left :
350 case X.Css.AttrNo.right :
351 this.constraintW = Type.isNumber( data[ X.Css.AttrNo.left ] ) || Type.isNumber( data[ X.Css.AttrNo.right ] );
353 case X.Css.AttrNo.top :
354 case X.Css.AttrNo.bottom :
355 this.constraintH = Type.isNumber( data[ X.Css.AttrNo.top ] ) || Type.isNumber( data[ X.Css.AttrNo.bottom ] );
357 case X.Css.AttrNo.width :
358 this.autoWidth = v === AUTO;
359 this.percentWidth = v === FULL || v < 1;
361 case X.Css.AttrNo.height :
362 this.autoHeight = v === AUTO;
363 this.percentHeight = v === FULL || v < 1;
373 if( quartet === true ) return [ v, data[ ++propID ], data[ ++propID ], data[ ++propID ] ];
374 if( combi === true ) return [ v, data[ ++propID ] ];
375 if( list && Type.isNumber( v ) === true ) return list[ v ];
378 __cssText : function(){
379 if( this.fontCssText === null ) this.fontCssText = this.createFontCssText();
380 if( this.layoutCssText === null ) this.layoutCssText = this.createLayoutCssText();
381 if( this.colorCssText === null ) this.colorCssText = this.createColorCssText();
382 return [ this.fontCssText, this.colorCssText, this.layoutCssText ].join( ';' );
384 createFontCssText : function(){
385 var data = this.data,
388 if( v = data[ X.Css.AttrNo.fontFamily ] ) css[ 0 ] = 'font-family:' + v;
389 if( v = data[ X.Css.AttrNo.fontSize ] ) css[ css.length ] = 'font-size:' + v;
390 if( v = data[ X.Css.AttrNo.bold ] ) css[ css.length ] = 'font-weight:bold';
391 if( v = data[ X.Css.AttrNo.italic ] ) css[ css.length ] = 'font-style:italic';
392 if( v = data[ X.Css.AttrNo.lineHeight ] ) css[ css.length ] = 'line-height:' + v;
393 if( v = data[ X.Css.AttrNo.letterSpacing ] ) css[ css.length ] = 'letter-spacing:' + v;
394 if( v = data[ X.Css.AttrNo.wordSpacing ] ) css[ css.length ] = 'word-spacing:' + v;
395 if( v = data[ X.Css.AttrNo.align ] ) css[ css.length ] = 'text-align:' + X.Css.Option.ALIGN[ v ];
396 if( v = data[ X.Css.AttrNo.transform ] ) css[ css.length ] = 'text-transform:' + X.Css.Option.TEXT_TRANSFORM[ v ];
397 return css.join( ';' );
399 createLayoutCssText : function(){
402 createColorCssText : function(){
403 var data = this.data,
406 if( v = data[ X.Css.AttrNo.borderColor ] ) css[ 0 ] = 'border-color:' + v;
407 if( v = data[ X.Css.AttrNo.borderStyle + 0 ] ) css[ css.length ] = 'border-top-style:' + X.Css.Option.BORDER_STYLE[ v ];
408 if( v = data[ X.Css.AttrNo.borderStyle + 1 ] ) css[ css.length ] = 'border-right-style:' + X.Css.Option.BORDER_STYLE[ v ];
409 if( v = data[ X.Css.AttrNo.borderStyle + 2 ] ) css[ css.length ] = 'border-bottom-style:' + X.Css.Option.BORDER_STYLE[ v ];
410 if( v = data[ X.Css.AttrNo.borderStyle + 3 ] ) css[ css.length ] = 'border-left-style:' + X.Css.Option.BORDER_STYLE[ v ];
411 if( v = data[ X.Css.AttrNo.cornerRadius + 0 ] ) css[ css.length ] = 'corner-radius-top:' + v;
412 if( v = data[ X.Css.AttrNo.cornerRadius + 1 ] ) css[ css.length ] = 'corner-radius-right:' + v;
413 if( v = data[ X.Css.AttrNo.cornerRadius + 2 ] ) css[ css.length ] = 'border-radius-bottom:' + v;
414 if( v = data[ X.Css.AttrNo.cornerRadius + 3 ] ) css[ css.length ] = 'border-radius-left:' + v;
415 if( v = data[ X.Css.AttrNo.bgColor ] ) css[ css.length ] = 'background-color:' + v;
416 // X.Css.AttrNo.bgAlpha
417 if( v = data[ X.Css.AttrNo.bgImgUrl ] ) css[ css.length ] = 'background-image:url(' + v + ')';
418 x = data[ X.Css.AttrNo.bgImgRepeatX ];
419 y = data[ X.Css.AttrNo.bgImgRepeatY ];
421 css[ css.length ] = 'background-repeat:repeat';
424 css[ css.length ] = 'background-repeat:repeat-x';
427 css[ css.length ] = 'background-repeat:repeat-y';
429 x = data[ X.Css.AttrNo.bgImgPositionX ];
430 y = data[ X.Css.AttrNo.bgImgPositionY ];
432 css[ css.length ] = 'background-position:' + x + ' ' + y;
435 css[ css.length ] = 'background-position:' + x + ' 0';
438 css[ css.length ] = 'background-position:0 ' + y;
440 if( v = data[ X.Css.AttrNo.color ] ) css[ css.length ] = 'color:' + v;
441 if( v = data[ X.Css.AttrNo.decoration ] ) css[ css.length ] = 'text-decoration:' + X.Css.Option.TEXT_DECORATION[ v ];
442 x = data[ X.Css.AttrNo.textShadowOffsetX ];
443 y = data[ X.Css.AttrNo.textShadowOffsetY ];
444 b = data[ X.Css.AttrNo.textShadowBlur ];
445 c = data[ X.Css.AttrNo.textShadowColor ];
446 if( c || x || y || b ){
447 css[ css.length ] = 'text-shadow:' + x + ' ' + y + ' ' + b + ' ' + c;
450 X.Css.AttrNo.shadowColor = [ X.Css.Dirty.PAINT, 23, X.Css.Type.COLOR ]; // color
451 X.Css.AttrNo.shadowAlpha = [ X.Css.Dirty.PAINT, 24, X.Css.Type.U_DECIMAL ]; // 0 - 1
452 X.Css.AttrNo.shadowOffsetX = [ X.Css.Dirty.PAINT, 25, X.Css.Type.LENGTH ]; // em
453 X.Css.AttrNo.shadowOffsetY = [ X.Css.Dirty.PAINT, 26, X.Css.Type.LENGTH ]; // em
454 X.Css.AttrNo.shadowBlur = [ X.Css.Dirty.PAINT, 27, X.Css.Type.LENGTH ]; // em
455 X.Css.AttrNo.shadowSpread = [ X.Css.Dirty.PAINT, 28, X.Css.Type.LENGTH ]; // em
456 X.Css.AttrNo.shadowInset = [ X.Css.Dirty.PAINT, 29, X.Css.Type.BOOLEAN ]; // true / false
458 return css.join( ';' );
469 var DisplayNodeStyle = X.Class.create(
474 Constructor : function( node, nodeData ){
475 X.Class._newPrivate( this, node, nodeData );
477 addName : function( names ){
478 return X.Class._getPrivate( this ).addName( names );
480 removeName : function( names ){
481 return X.Class._getPrivate( this ).removeName( names );
483 hasName : function( names ){
484 return X.Class._getPrivate( this ).hasName( names );
486 cssText : function( v ){
487 var data = X.Class._getPrivate( this );
492 return data._cssText;
495 var data = X.Class._getPrivate( this );
503 borderWidth : function( v ){
504 return X.Class._getPrivate( this ).attr( X.Css.Attr.borderWidth, v );
506 borderColor : function( v ){
507 return X.Class._getPrivate( this ).attr( X.Css.Attr.borderColor, v );
509 borderStyle : function( v ){
510 return X.Class._getPrivate( this ).attr( X.Css.Attr.borderStyle, v );
512 cornerRadius : function( v ){
513 return X.Class._getPrivate( this ).attr( X.Css.Attr.cornerRadius, v );
515 bgColor : function( v ){
516 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgColor, v );
518 bgAlpha : function( v ){
519 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgAlpha, v );
521 bgImgUrl : function( v ){
522 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgImgUrl, v );
524 bgImgRepeatX : function( v ){
525 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgImgRepeatX, v );
527 bgImgRepeatY : function( v ){
528 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgImgRepeatY, v );
530 bgImgPositionX : function( v ){
531 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgImgPositionX, v );
533 bgImgPositionY : function( v ){
534 return X.Class._getPrivate( this ).attr( X.Css.Attr.bgImgPositionY, v );
536 shadowColor : function( v ){
537 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowColor, v );
539 shadowAlpha : function( v ){
540 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowAlpha, v );
542 shadowOffsetX : function( v ){
543 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowOffsetX, v );
545 shadowOffsetY : function( v ){
546 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowOffsetY, v );
548 shadowBlur : function( v ){
549 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowBlur, v );
551 shadowSpread : function(){
552 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowSpread, v );
554 shadowInset : function(){
555 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowInset, v );
557 color : function( v ){
558 return X.Class._getPrivate( this ).attr( X.Css.Attr.color, v );
560 fontFamily : function( v ){
561 return X.Class._getPrivate( this ).attr( X.Css.Attr.fontFamily, v );
563 fontSize : function( v ){
564 return X.Class._getPrivate( this ).attr( X.Css.Attr.fontSize, v );
566 bold : function( v ){
567 return X.Class._getPrivate( this ).attr( X.Css.Attr.bold, v );
569 italic : function( v ){
570 return X.Class._getPrivate( this ).attr( X.Css.Attr.italic, v );
572 lineHeight : function( v ){
573 return X.Class._getPrivate( this ).attr( X.Css.Attr.lineHeight, v );
575 letterSpacing : function( v ){
576 return X.Class._getPrivate( this ).attr( X.Css.Attr.letterSpacing, v );
578 wordSpacing : function( v ){
579 return X.Class._getPrivate( this ).attr( X.Css.Attr.wordSpacing, v );
581 align : function( v ){
582 return X.Class._getPrivate( this ).attr( X.Css.Attr.align, v );
584 decoration : function( v ){
585 return X.Class._getPrivate( this ).attr( X.Css.Attr.decoration, v );
587 transform : function( v ){
588 return X.Class._getPrivate( this ).attr( X.Css.Attr.transform, v );
590 textShadowColor : function( v ){
591 return X.Class._getPrivate( this ).attr( X.Css.Attr.textShadowColor, v );
593 textShadowOffsetX : function( v ){
594 return X.Class._getPrivate( this ).attr( X.Css.Attr.textShadowOffsetX, v );
596 textShadowOffsetY : function( v ){
597 return X.Class._getPrivate( this ).attr( X.Css.Attr.textShadowOffsetY, v );
599 shadowBlur : function( v ){
600 return X.Class._getPrivate( this ).attr( X.Css.Attr.shadowBlur, v );