4 * style 値の変更は、enterFrame 後にまとめて適用
5 * width(), height(), x(), y() 1em の取得時にも適用
6 * css3 の ie用 fix は X.UI レベルで行う
30 AUTO : Number.POSITIVE_INFINITY,
31 FULL : X.Dom // something unigue value; 100%
52 /* font-size -> fontSize */
53 _DICTIONARY_CAMELIZE : {},
55 camelize : function( cssProp ){
57 parts, l, i, camelized;
59 if( camelized = me._DICTIONARY_CAMELIZE[ cssProp ] ) return camelized;
60 parts = cssProp.split( ' ' ).join( '' ).split( '-' );
62 if( l === 1 ) return parts[ 0 ];
64 camelized = cssProp.charAt(0) === '-'
65 ? parts[ 0 ].charAt( 0 ).toUpperCase() + parts[ 0 ].substring( 1 )
68 for( i = 1; i < l; ++i ){
69 camelized += parts[ i ].charAt( 0 ).toUpperCase() + parts[ i ].substring( 1 );
71 return me._DICTIONARY_CAMELIZE[ cssProp ] = camelized;
74 /* fontSize -> font-size */
77 uncamelize: function( str ){
78 return str.split( ' ' ).join( '' ).replace( X.Dom.Style.REG_LARGE, '-$&' ).toLowerCase();
81 CHAR_CODE_A : 'A'.charCodeAt( 0 ),
83 _DICTIONARY_UNCAMELIZE : {},
85 uncamelize : function( str ){
89 uncamelized, l, chr, code;
90 str = str.split( ' ' ).join( '' );
91 if( uncamelized = me._DICTIONARY_UNCAMELIZE[ str ] ) return uncamelized;
93 for( i = 0, l = str.length; i < l; ++i ){
94 chr = str.charAt( i );
95 code = chr.charCodeAt( 0 );
96 uncamelized += ( A <= code && code <= Z ) ? '-' + chr : chr;
98 return me._DICTIONARY_UNCAMELIZE[ str ] = uncamelized.toLowerCase();
102 * CSS における display, position, float プロパティの相互関係
103 * http://d.hatena.ne.jp/elm200/20080201/1201874740
105 * CSS21:9.7 Relationships between ’display’, ’position’, and ’float’
106 * http://www.w3.org/TR/CSS21/visuren.html#dis-pos-flo
108 * display:none? -yes-> 非表示
110 * position:absolute? -yes-> float:none,display:block;
112 * float:none? -no-> display:block;
117 display position float
118 block static|relative none
119 block static|relative right|left
121 inline static|relative none
128 objToCssText : function( obj ){
131 uncamelize = me.uncamelize,
132 VENDER_PREFIX = me.VENDER_PREFIX,
133 FIX_PROP = me.SPECIAL_FIX_PROP,
134 SPECIAL_FIX = me.SPECIAL_FIX,
138 name = uncamelize( p );
139 if( FIX_PROP[ name ] ){
142 css[ ++n ] = [ VENDER_PREFIX[ name ] || name, obj[ p ] ].join( ':' );
145 sp && ( css[ ++n ] = 'filter:' + SPECIAL_FIX( obj ) );
146 return css.join( ';' );
150 X.UA.IE && X.UA.IE < 9 ?
155 9 <= X.UA.IE && X.UA.IE < 10 ? // == 9
160 _FONT_SIZE_RATIO : null,
162 // https://developer.mozilla.org/en-US/docs/Web/CSS/transform
163 // Firefox 3.5, ie9, Opera 10.5, Safari 3.1, Chrome
164 // 3D support Firefox 10, ie10, Safari 4.0, Chrome 12.0
165 // transform : void 0,
167 // https://developer.mozilla.org/ja/docs/Web/Guide/CSS/Using_CSS_transitions
168 // Chrome 1.0, Firefox 4.0, ie10, Opera 10.5, Safari 3.2
169 // Android 2.1, Firefox Android 4.0, Opera Mobile 10, Safari Mobile 3.2
170 // transition : void 0
172 // ブラウザ毎の getComputedStyle の戻り値 http://d.hatena.ne.jp/uupaa/20080928/1222543331
194 SLATEGRAY : 0x708090,
196 GAINSBORO : 0xDCDCDC,
197 MIDNIGHTBLUE : 0x191970,
198 SLATEBLUE : 0x6A5ACD,
199 MEDIUMBLUE : 0x0000CD,
200 ROYALBLUE : 0x4169E1,
201 DODGERBLUE : 0x1E90FF,
203 STEELBLUE : 0x4682B4,
204 LIGHTBLUE : 0xADD8E6,
205 PALETURQUOISE : 0xAFEEEE,
206 TURQUOISE : 0x40E0D0,
207 LIGHTCYAN : 0xE0FFFF,
208 AQUAMARINE : 0x7FFFD4,
209 DARKGREEN : 0x006400,
211 LIGHTGREEN : 0x90EE90,
212 CHARTREUSE : 0x7FFF00,
213 GREENYELLOW : 0xADFF2F,
214 LIMEGREEN : 0x32CD32,
215 YELLOWGREEN : 0x9ACD32,
216 OLIVEDRAB : 0x6B8E23,
217 DARKKHAKI : 0xBCB76B,
218 PALEGOLDENROD : 0xEEE8AA,
219 LIGHTYELLOW : 0xFFFFE0,
221 GOLDENROD : 0xDAA520,
222 DARKGOLDENROD : 0xB8860B,
223 ROSYBROWN : 0xBC8F8F,
224 INDIANRED : 0xCD5C5C,
225 SADDLEBROWN : 0x8B4513,
228 BURLYWOOD : 0xDEB887,
231 SANDYBROWN : 0xF4A460,
233 CHOCOLATE : 0xD2691E,
234 FIREBRICK : 0xB22222,
243 PALEVIOLETRED : 0xDB7093,
247 DARKVIOLET : 0x9400D3,
248 BLUEVIOLET : 0x8A2BE2,
249 MEDIUMPURPLE : 0x9370DB,
252 MISTYROSE : 0xFFE4E1,
254 LEMONCHIFFON : 0xFFFACD
257 PARAMS : ( function(){
259 register( ret.percent = {},
260 'marginBottom,marginLeft,marginRight,marginTop,paddingBottom,paddingLeft,paddingRight,paddingTop,fontSize,textIndent'
262 register( ret.offset = {},
263 'height,width,bottom,left,right,top'
265 register( ret.size = {},
266 'borderBottomWidth,borderLeftWidth,borderRightWidth,borderTopWidth,letterSpacing,wordSpacing'
268 register( ret.color = {},
269 'backgroundColor,borderBottomColor,borderLeftColor,borderRightColor,borderTopColor,color'
271 register( ret.region = {},
272 'margin,padding,borderWidth,borderColor'
274 register( ret.special = {},
275 'clip,backgroundPosition,backgroundPositionX,backgroundPositionY,opacity,lineHeight,zIndex'
277 register( ret.unit = {}, 'px,cm,mm,in,pt,pc,em,%' );
279 register( ret.margin = {}, 'marginBottom,marginLeft,marginRight,marginTop,paddingBottom' );
280 register( ret.padding = {}, 'paddingBottom,paddingLeft,paddingRight,paddingTop' );
281 register( ret.borderWidth = {}, 'borderBottomWidth,borderLeftWidth,borderRightWidth,borderTopWidth' );
282 register( ret.borderColor = {}, 'borderBottomColor,borderLeftColor,borderRightColor,borderTopColor' );
284 function register( obj, params ){
285 params = params.split( ',' );
286 for( var i = params.length; i; ) obj[ params[ --i ] ] = true;
291 _CLIP_SEPARATOR : X.UA.IE && X.UA.IE < 8 ? ' ' : ',',
296 Property : X.Class.create(
300 Constructor : function( name, value, unit, xnode ){
310 equal : function( prop ){
311 if( this.unit === prop.unit ){
312 return this.value === prop.value;
314 return Math.abs( this.toPx() - prop.toPx() ) < 1;
316 convert: function( prop ){
317 var u = prop.unit, v;
318 if( this.unit === u ) return;
319 this.value = v = this.toPx();
322 // bgpX, bgpY の場合 X.Dom.Image.getActualDimension( backgroundImage url を使用 )
326 v / this.xnode._getCharSize() :
327 v / ( X.Dom.Style._UNIT_RATIO[ u ] || 1 );
330 setValue: function( v ){
333 getValue: function(){
336 getOffset: function( prop ){
337 return prop.value - this.value;
342 getValueText: function(){
343 return this.value === 0 ? '0' : this.value + this.unit;
346 var v = this.value, u = this.unit;
350 ( u === 'em' || ( u === '' && this.name === 'lineHeight' ) ) ?
351 v * this.xnode._getCharSize() :
353 v / ( X.Dom.Style._UNIT_RATIO[ u ] || 1 );
356 var p = X.Dom.Style.PARAMS,
360 z = u !== '' ? true : v === 0;
361 if( p.percent[ n ] === true ) return z;
362 if( p.offset[ n ] === true ) return z;
363 if( p.size[ n ] === true ) return z && u !== '%';
364 if( p.special[ n ] === true ){
365 if( n === 'lineHeight' ) return true;
366 if( n === 'opacity' ) return 0 <= v && v <= 1 && u === '';
367 if( n === 'zIndex' ) return u === '';
375 * backgroundPosition, clip
377 PropertyGroup : X.Class.create(
381 Constructor : function( name ){
384 for( var i = 1, l = arguments.length; i<l; ++i ){
385 this.props[ this.props.length ] = arguments[ i ];
389 equal : function( prop ){
390 var ps = this.props, i = ps.length;
393 if( ps[ i ].equal( prop[ i ] ) === false ) return false;
397 convert : function( prop ){
398 var ps = this.props, i = ps.length;
401 ps[ i ].convert( prop[ i ] );
404 setValue : function( ary ){
405 var ps = this.props, i = 0, l = ps.length;
407 ps[ i ].setValue( ary[ i ] );
410 getValue : function(){
411 var ret = [], ps = this.props, i = 0, l = ps.length;
413 ret[ ret.length ] = ps[ i ].getValue();
417 getOffset : function( prop ){
424 ret[ ret.length ] = ps[ i ].getOffset( _ps[ i ] );
428 getUnit : function(){
429 var ret = [], ps = this.props, i = 0, l = ps.length;
431 ret[ ret.length ] = ps[ i ].getUnit();
435 getValueText : function(){
436 var ret = [], ps = this.props, i = 0, l = ps.length;
438 ret[ ret.length ] = ps[ i ].getValueText();
440 if( this.name === 'clip' ){
441 return 'rect(' + ret.join( X.Dom.Style._CLIP_SEPARATOR ) + ')';
443 return ret.join( ' ' );
446 var ps = this.props, i = ps.length;
451 isValid : function( t ){
453 var ps = t.props, i = ps.length;
455 if( ps[ --i ].isValid() === false ) return false;
463 * http://css-eblog.com/ie-css-problems/rgba-pe.html
464 * ie67 では rgb() は background-color で反応しない、、、
467 ColorProperty : X.Class.create(
469 X.Class.POOL_OBJECT, {
470 Constructor : function( name, x ){
477 if( X.Type.isNumber( rgb = x ) || X.Type.isNumber( rgb = X.Dom.Style.COLOR[ x.toUpperCase() ] ) ){
478 r = ( rgb & 0xff0000 ) >> 16;
479 g = ( rgb & 0xff00 ) >> 8;
482 if( x.charAt( 0 ) === '#' ){
483 if( x.length === 7 ){
484 r = parseInt( x.charAt( 1 ) + x.charAt( 2 ), 16 );
485 g = parseInt( x.charAt( 3 ) + x.charAt( 4 ), 16 );
486 b = parseInt( x.charAt( 5 ) + x.charAt( 6 ), 16 );
488 if( x.length === 4 ){
489 r = parseInt( x.charAt( 1 ) + x.charAt( 1 ), 16 );
490 g = parseInt( x.charAt( 2 ) + x.charAt( 2 ), 16 );
491 b = parseInt( x.charAt( 3 ) + x.charAt( 3 ), 16 );
493 if( x.length === 2 ){
494 r = parseInt( x.charAt( 1 ) + x.charAt( 1 ), 16 );
495 g = parseInt( x.charAt( 1 ) + x.charAt( 1 ), 16 );
496 b = parseInt( x.charAt( 1 ) + x.charAt( 1 ), 16 );
499 if( x.indexOf( 'rgb(' ) === 0 ){
500 rgb = x.substr( 4 ).split( ',' );
501 r = parseFloat( rgb[ 0 ] );
502 g = parseFloat( rgb[ 1 ] );
503 b = parseFloat( rgb[ 2 ] );
504 if( x.indexOf( '%' ) !== -1 ) pct = true;
506 if( x.indexOf( 'rgba(' ) === 0 ){
507 rgb = x.substr( 5 ).split( ',' );
508 r = parseFloat( rgb[ 0 ] );
509 g = parseFloat( rgb[ 1 ] );
510 b = parseFloat( rgb[ 2 ] );
511 a = parseFloat( rgb[ 3 ] );
512 if( x.indexOf( '%' ) !== -1 ) pct = true;
532 equal : function( prop ){
533 if( this.pct === prop.pct ){
534 return this.r === prop.r && this.g === prop.g && this.b === prop.b;
536 var rgb = this._toPct(),
537 _rgb = prop._toPct(),
541 if( Math.abs( rgb[ i ] - _rgb[ i ] ) > 1 ) return false;
545 convert : function( prop ){
547 if( this.pct === u ) return;
548 x = u === true ? 100 / 255 : 2.55;
554 setValue : function( rgb ){
559 getValue : function(){
560 return [ this.r, this.g, this.b ];
562 getOffset : function( prop ){
563 return [ prop.r - this.r, prop.g - this.g, prop.b - this.b ];
565 getUnit : function(){
566 return this.pct === true ? '%' : '';
568 getValueText : function(){
569 if( this.pct === true ){
570 return [ 'rgb(', this.r, '%,', this.g, '%,', this.b, '%)' ].join( '' );
572 var round = Math.round;
574 var rgb = '00000' + ( ( round( this.r ) << 16 ) + ( round( this.g ) << 8 ) + round( this.b ) ).toString( 16 );
575 return '#' + rgb.substr( rgb.length - 6 );
578 if( this.pct === true ) return [ this.r, this.g, this.b ];
579 return [ this.r / 2.55, this.g / 2.55, this.b / 2.55 ];
581 isValid : function( t ){
582 var isFinite = window.isFinite;
583 if( !isFinite( this.r ) || !isFinite( this.g ) || !isFinite( this.b ) ) return false;
584 if( 0 > this.r || 0 > this.g || 0 > this.b ) return false;
585 if( this.pct === true ) return this.r <= 100 && this.g <= 100 && this.b <= 100;
586 return this.r <= 255 && this.g <= 255 && this.b <= 255;
591 _getProperty : function( xnode, css, unit, p ){
593 var XDomStyle = X.Dom.Style,
594 me = XDomStyle._getProperty,
595 PARAMS = XDomStyle.PARAMS,
596 PropertyGroup = XDomStyle.PropertyGroup,
597 Property = XDomStyle.Property,
598 ColorProperty = XDomStyle.ColorProperty,
601 if( PARAMS.special[ p ] === true || PARAMS.region[ p ] === true ){
604 // rect(...) クリップします。<top>, <bottom> は上端からの、 <right>, <left> は左端からのオフセットで指定します。Internet Explorer 4~7 では、カンマの代わりにスペースで区切る必要があります。
605 // position:absolute または position:fixed を適用した要素に対してのみ有効です。
606 var top = me( p + 'Top' ),
607 right = me( p + 'Right' ),
608 bottom = me( p + 'Bottom' ),
609 left = me( p + 'Left' ),
610 ret = new PropertyGroup( p, top, right, bottom, left ),
612 if( ret.isValid() === true ) return ret;
614 all = css[ p ].split( '(' )[ 1 ].split( ')' )[ 0 ].split( XDomStyle._CLIP_SEPARATOR );
618 new Property( p + 'Top', all[ 0 ], 'px', xnode ),
619 new Property( p + 'Right', all[ 1 ], 'px', xnode ),
620 new Property( p + 'Bottom', all[ 2 ], 'px', xnode ),
621 new Property( p + 'Left', all[ 3 ], 'px', xnode )
629 var props = '$1Top$2,$1Right$2,$1Bottom$2,$1Left$2'.split( '$1' ).join( name || 'border' ).split( '$2' ).join( width || 'Width' ).split( ',' ),
630 top = me( props[ 0 ] ),
631 right = me( props[ 1 ] ),
632 bottom = me( props[ 2 ] ),
633 left = me( props[ 3 ] ),
634 ret = new PropertyGroup( p, top, right, bottom, left ),
635 all, _0, _1, _2, _3, vu, v, u;
636 if( ret.isValid() === true ) return ret;
638 all = css[ p ].split( ' ' );
643 vu = XDomStyle._Util._splitValueAndUnit( _0 );
646 switch( all.length ){
648 top = new Property( props[ 0 ], v, u, xnode );
649 right = new Property( props[ 1 ], v, u, xnode );
650 bottom = new Property( props[ 2 ], v, u, xnode );
651 left = new Property( props[ 3 ], v, u, xnode );
654 top = new Property( props[ 0 ], v, u, xnode );
655 bottom = new Property( props[ 2 ], v, u, xnode );
656 vu = XDomStyle._Util._splitValueAndUnit( _1 );
659 right = new Property( props[ 1 ], v, u, xnode );
660 left = new Property( props[ 3 ], v, u, xnode );
663 top = new Property( props[ 0 ], v, u, xnode );
664 vu = XDomStyle._Util._splitValueAndUnit( _1 );
667 right = new Property( props[ 1 ], v, u, xnode );
668 left = new Property( props[ 3 ], v, u, xnode );
669 vu = XDomStyle._Util._splitValueAndUnit( _2 );
672 bottom = new Property( props[ 2 ], v, u, xnode );
675 top = new Property( props[ 0 ], v, u, xnode );
676 vu = XDomStyle._Util._splitValueAndUnit( _1 );
679 right = new Property( props[ 1 ], v, u, xnode );
680 vu = XDomStyle._Util._splitValueAndUnit( _2 );
683 bottom = new Property( props[ 2 ], v,u, xnode );
684 vu = XDomStyle._Util._splitValueAndUnit( _3 );
687 left = new Property( props[ 3 ], v, u, xnode );
690 return new PropertyGroup( p, top, right, bottom, left );
693 var props = 'borderTopColor,borderRightColor,borderBottomColor,borderLeftColor'.split( ',' ),
694 top = me( props[ 0 ] ),
695 right = me( props[ 1 ] ),
696 bottom = me( props[ 2 ] ),
697 left = me( props[ 3 ] ),
698 ret = new PropertyGroup( p, top, right, bottom, left ),
700 if( ret.isValid() === true ) return ret;
702 all = css[ p ].split( ' ' );
705 switch( all.length ){
707 top = new ColorProperty( props[ 0 ], _0 );
708 right = new ColorProperty( props[ 1 ], _0 );
709 bottom = new ColorProperty( props[ 2 ], _0 );
710 left = new ColorProperty( props[ 3 ], _0 );
713 top = new ColorProperty( props[ 0 ], _0 );
714 right = new ColorProperty( props[ 1 ], _1 );
715 bottom = new ColorProperty( props[ 2 ], _0 );
716 left = new ColorProperty( props[ 3 ], _1 );
719 top = new ColorProperty( props[ 0 ], _0 );
720 right = new ColorProperty( props[ 1 ], _1 );
721 bottom = new ColorProperty( props[ 2 ], all[ 2 ] );
722 left = new ColorProperty( props[ 3 ], _1 );
725 top = new ColorProperty( props[ 0 ], _0 );
726 right = new ColorProperty( props[ 1 ], _1 );
727 bottom = new ColorProperty( props[ 2 ], all[ 2 ] );
728 left = new ColorProperty( props[ 3 ], all[ 3 ] );
731 return new PropertyGroup( p, top, right, bottom, left );
733 case 'backgroundPosition' :
734 var x = me( p + 'X' ),
736 ret = new PropertyGroup( p, x, y ),
738 if( ret.isValid() === true ) return ret;
740 xy = css[ p ].split( ' ' );
741 x = XDomStyle._Util._splitValueAndUnit( xy[ 0 ] );
742 y = XDomStyle._Util._splitValueAndUnit( xy[ 1 ] );
746 new Property( p + 'X', x[ 0 ], x[ 1 ], xnode ),
747 new Property( p + 'Y', y[ 0 ], y[ 1 ], xnode )
750 // opacity, zindex, lineHeight
751 vu = XDomStyle._Util._splitValueAndUnit( css[ p ] );
752 return new Property( p, vu[ 0 ], vu[ 1 ], xnode );
754 var x = css[ p ], e, v, u;
756 if( PARAMS.offset[ p ] === true ){
757 return new Property( p, vu[ 0 ], vu[ 1 ], xnode );
760 if( p === 'width' ) v = e.offsetWidth;
761 if( p === 'height' ) v = e.offsetHeight;
762 if( p === 'top' ) v = e.offsetTop;
763 if( p === 'bottom' ) v = e.offsetBottom;
764 if( p === 'left' ) v = e.offsetLeft;
765 if( p === 'right' ) v = e.offsetRight;
766 u = _getUnit( x, p );
767 // alert( p + XDomStyle._Util.pxTo( v, u ) + u )
768 return new Property( p, XDomStyle._Util.pxTo( v, u ), u, xnode );
770 if( p === 'fontSize' && ( v = XDomStyle._FONT_SIZE_RATIO[ x ] ) ){ // xx-small 等
771 return new Property( p, v, 'px', xnode );
773 if( PARAMS.offset[ p ] || PARAMS.percent[ p ] || PARAMS.size[ p ] ){
774 vu = XDomStyle._Util._splitValueAndUnit( x );
775 return new Property( p, vu[ 0 ], vu[ 1 ], xnode );
778 if( PARAMS.color[ p ] ) return new ColorProperty( p, x );
783 getValue: function( x ){
784 return X.Type.isString( x ) ? parseInt( x ) :
785 X.Type.isNumber( x ) ? x : 0;
787 getUnit: function( x, p ){
790 var REG_UINIT = /.*\d(\w{1,2})?/,
795 if( X.Type.isString( x ) === true ){
796 u = x.replace( REG_UINIT, $1 );
797 if( p === 'lineHeight' ) return u;
798 if( PARAMS.unit[ u ] !== true ) return 'px';
803 _splitValueAndUnit : function( v ){
805 if( X.Type.isNumber( v ) ) return [ v || 0, '' ];
806 if( isNaN( num = parseInt( v ) ) ) return [ 0, '' ];
808 i = v.indexOf( _num ) + _num.length;
810 return [ num, X.Dom.Style.UNIT[ u ] ? u : 'px' ];
815 X.Dom.Style._GET_VALUE_WITH_UNIT = {
816 borderWidth : X.Dom.Style.Type.QUARTET | X.Dom.Style.Type.LENGTH,
817 //borderStyle : X.Dom.Style.Type.QUARTET,
818 borderRadius : X.Dom.Style.Type.QUARTET | X.Dom.Style.Type.LENGTH,
819 margin : X.Dom.Style.Type.QUARTET | X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
820 padding : X.Dom.Style.Type.QUARTET | X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
821 clip : X.Dom.Style.Type.QUARTET | X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
823 backgroundColor : X.Dom.Style.Type.COLOR,
824 backgroundPosition : X.Dom.Style.Type.COMBI,
828 fontSize : X.Dom.Style.Type.LENGTH,
829 lineHeight : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT | X.Dom.Style.Type.NUMERICAL,
830 textIndent : X.Dom.Style.Type.LENGTH,
831 letterSpacing : X.Dom.Style.Type.LENGTH,
832 wordSpacing : X.Dom.Style.Type.LENGTH,
834 textShadowColor : X.Dom.Style.Type.COLOR,
835 textShadowOffsetX : X.Dom.Style.Type.LENGTH,
836 textShadowOffsetY : X.Dom.Style.Type.LENGTH,
837 textShadowBlur : X.Dom.Style.Type.LENGTH, */
839 width : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
840 height : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
842 left : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
843 top : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
844 bottom : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
845 right : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
848 borderSpacing : X.Dom.Style.Type.LENGTH
852 X.Dom.Style.SPECIAL_FIX =
854 X.UA.IE && X.UA.IE < 9 ?
856 var test = X.Dom.Style.SPECIAL_FIX_PROP,
861 if( !( id = test[ p ] ) ) continue;
864 case 1 : //'filter' :
867 case 2 : //'opacity' :
868 filters[ ++n ] = 'alpha(opacity=' + v * 100 +')';
870 case 3 : //'boxShadow' :
871 // box-shadow: 10px 10px 10px 10px rgba(0,0,0,0.4) inset;
872 // スペース区切りで、水平方向の距離 垂直方向の距離 ぼかし距離 広がり距離 影の色 insetキーワードを指定する。 ぼかし距離 広がり距離 影の色 insetキーワードは省略可
873 // shadow(color=#cccccc, strength=10, direction=135);
874 v = X.Dom.Style._getProperty( this, css, 'px', 'boxShadow' );
875 dir = Math.atan2( v[ 1 ], v[ 0 ] ) * 180 / Math.PI + 90;
876 dir += dir < 0 ? 360 : 0;
877 filters[ ++n ] = 'shadow(color=' + v[ 4 ] + ',strength=' + v[ 3 ] + ',direction=' + dir + ')';
879 case 4 : //'textShadow' :
880 //text-shadow: 5px 5px 2px blue; 水平方向の距離 垂直方向の距離 影のぼかし半径 影の色 none
881 //glow(Color=yellow,Strength=10);
882 //どうやらCSSのbackgroundプロパティと同時に使えないようです。
886 case 5 : //'backgroundImage' :
890 return filters.join( ' ' );
892 // IE9 textShadow に filter を使用
893 X.UA.IE && 9 <= X.UA.IE && X.UA.IE < 10 ?
895 var test = X.Dom.Style.SPECIAL_FIX_PROP,
896 filters = [], p, id, v;
898 if( !( id = test[ p ] ) ) continue;
901 case 1 : //'filter' :
902 filters[ filters.length ] = v;
906 if( filters ) return filters.join( ' ' );
909 var test = X.Dom.Style.SPECIAL_FIX_PROP,
912 if( !( id = test[ p ] ) ) continue;
915 case 1 : //'backgroundPositionX' :
918 case 2 : //'backgroundPositionY' :
921 case 3 : //'backgroundPositionX' :
924 case 4 : //'backgroundPositionX' :
927 case 5 : //'backgroundPositionX' :
930 case 6 : //'backgroundPositionX' :
935 if( bgpX || bgpY ) ret[ ret.length ] = 'background-position:';
936 if( clipT || clipB || clipL || clipR ){
937 ret[ ret.length ] = 'clip:rect(';
939 return ret.join( ';' );
947 // unitID, name 単位指定のプロパティ取得 geter
949 // name, value setter
951 X.Dom.Node.prototype.css = function( nameOrObj /* orUnitID, valuOrUnitOrName */ ){
952 var XDomStyle = X.Dom.Style,
955 p, name, v, camelize, unit, ieFix;
956 if( this._xnodeType !== 1 ) return this;
958 if( X.Type.isObject( nameOrObj ) ){
959 if( !css ) css = this._css = {};
960 camelize = XDomStyle.camelize;
961 ieFix = X.Dom.Style.IE_FILTER_FIX;
962 for( p in nameOrObj ){
964 this._dirty |= X.Dom.Dirty.IE_FILTER;
967 v || v === 0 ? css[ camelize( p ) ] = v : delete css[ camelize( p ) ];
968 if( p === 'display' ){
969 v === 'none' ? ( this._state |= X.Dom.State.IE5_DISPLAY_NONE_FIX ) : ( this._state &= ~X.Dom.State.IE5_DISPLAY_NONE_FIX );
970 v === 'none' ? ( this._state |= X.Dom.State.DISPLAY_NONE ) : ( this._state &= ~X.Dom.State.DISPLAY_NONE );
973 this._dirty |= X.Dom.Dirty.CSS;
974 this.parent && this._reserveUpdate();
975 delete this._cssText;
978 if( 1 < args.length ){
979 if( !( unit = XDomStyle.UNIT[ nameOrObj ] ) ){
980 // setter name, value
981 if( !css ) css = this._css = {};
982 name = XDomStyle.camelize( nameOrObj );
984 if( css[ name ] === v ) return this;
985 if( X.Dom.Style.IE_FILTER_FIX[ name ] ){
986 this._dirty |= X.Dom.Dirty.IE_FILTER;
993 delete this._cssText;
994 this._dirty |= X.Dom.Dirty.CSS;
995 if( name === 'display' ){
996 v === 'none' ? ( this._state |= X.Dom.State.IE5_DISPLAY_NONE_FIX ) : ( this._state &= ~X.Dom.State.IE5_DISPLAY_NONE_FIX );
997 v === 'none' ? ( this._state |= X.Dom.State.DISPLAY_NONE ) : ( this._state &= ~X.Dom.State.DISPLAY_NONE );
999 // parent でなく this._root! でなくて this._state & in tree
1000 this.parent && this._reserveUpdate();
1004 // unit 付の値取得は fontSize と 画像サイズが確定していないと正確に取れない。内部のみにする?
1006 if( !XDomStyle._GET_VALUE_WITH_UNIT[ name = XDomStyle.camelize( args[ 1 ] ) ] ) return null;
1007 p = XDomStyle._getProperty( this, css, unit, name );
1014 // 集計 border, padding, margin, backgroundPosition, clip
1015 // border で正確なデータを返せない時は、null を返す
1016 return css[ XDomStyle.camelize( nameOrObj ) ];
1019 X.Dom.Node.prototype.cssText = function( v ){
1020 var obj, i, l, attr, name;
1021 if( X.Type.isString( v ) ){
1025 for( i = 0, l = v.length; i < l; ++i ){
1026 attr = v[ i ].split( ':' );
1027 ( name = attr[ 0 ] ) && ( obj[ name ] = attr[ 1 ] || true );
1029 return this.css( obj );
1032 if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){
1033 delete this._cssText;
1035 return this._cssText;
1039 * ここでは HTMLElement のチャックは行わない!
1041 X.Dom.Node.prototype._getCharSize =
1042 window.getComputedStyle ?
1044 return parseInt( getComputedStyle( this._rawNode, null ).fontSize );
1046 document.defaultView && document.defaultView.getComputedStyle ?
1048 return parseInt( document.defaultView.getComputedStyle( this._rawNode, null ).fontSize );
1050 X.UA.IE && 5.5 <= X.UA.IE ?
1052 if( this === Node.root && X.Dom.Event._lastFontSize ) return X.Dom.Event._lastFontSize;
1053 var font = this._rawNode.currentStyle.fontSize,
1054 vu = X.Dom.Style._Util._splitValueAndUnit( font ),
1059 if( v = X.Dom.Style._FONT_SIZE_RATIO[ font ] ) return v;
1061 if( u = X.Dom.Style._UNIT_RATIO[ u ] ) return v / u;
1067 // body まで辿ってしまった場合は?
1068 if( this.parent ) return this.parent._getCharSize() * v;
1071 // body まで辿ってしまった場合は?
1072 if( this.parent ) return this.parent._getCharSize() * v / 100;
1075 elm = document.createElement( 'div' );
1076 Node._systemNode._rawNode.appendChild( elm );
1077 elm.style.cssText = 'position:absolute;top:0;left:0;overflow:hidden;line-height:1;height:1em;';
1078 elm.innerText = 'X';
1079 v = elm.offsetHeight;
1080 Node._systemNode._rawNode.removeChild( elm );
1083 document.getElementById ?
1085 var elm = document.createElement( 'span' ),
1087 this._rawNode.appendChild( elm );
1088 elm.style.cssText = 'display:block;position:absolute;top:0;left:0;visivility:hidden;line-height:1;height:1em;';
1089 elm.innerHTML = 'X';
1090 v = elm.offsetHeight;
1091 this._rawNode.removeChild( elm );
1096 var elm = this._rawNode || this._ie4getRawNode(), v;
1097 elm.insertAdjacentHTML( 'BeforeEnd', '<span style="visivility:hidden;line-height:1;">X</span>' );
1098 elm = elm.children[ elm.children.length - 1 ];
1099 v = elm.offsetHeight;
1107 X.Dom.listenOnce( X.Dom.Event.DOM_PRE_INIT, function(){
1108 var testStyle = X.Dom._root;//.style;
1110 X.Dom.Style.VENDER_PREFIX = (function(){
1112 vendors = 'webkit,Webkit,Moz,moz,ms,Ms,O,o,khtml,Khtml'.split( ',' ),
1114 'opacity,boxSizing,' +
1115 'transform,transformOrigin,perspective,' +
1116 'transisiton,transitionDelay,transitionProperty,transitionDuration,transitionTimingFunction,' +
1117 'userSelect,touchAction,touchCallout,contentZooming,userDrag,tapHighlightColor'.split( ',' ),
1118 vendor, i, search, prop;
1120 vendors.unshift( '' );
1122 function findVenderPrefix( prop ){
1123 var v, i = vendors.length;
1127 if( testStyle[ v + prop ] !== undefined ){
1134 for( i = searches.length; i; ){
1135 search = searches[ --i ];
1136 prop = findVenderPrefix( search );
1137 if( search === 'transform' ) ret.transVender = vendor;
1138 if( prop ) ret[ search ] = prop;
1143 X.Dom.Style.SPECIAL_FIX_PROP =
1145 X.UA.IE && X.UA.IE < 9 ?
1148 opacity : 2//, uinode ChromeNode で行う
1151 //backgroundImage : 5
1154 X.UA.IE && 9 <= X.UA.IE && X.UA.IE < 10 ?
1160 backgroundPositionX : testStyle.backgroundPositionX === undefined ? 3 : 0,
1161 backgroundPosiitonY : testStyle.backgroundPositionX === undefined ? 3 : 0,
1162 clipTop : testStyle.clipTop === undefined && testStyle[ 'clip-top' ] === undefined ? 3 : 0,
1163 clipBottom : testStyle.clipTop === undefined && testStyle[ 'clip-top' ] === undefined ? 4 : 0,
1164 clipLeft : testStyle.clipTop === undefined && testStyle[ 'clip-top' ] === undefined ? 5 : 0,
1165 clipRight : testStyle.clipTop === undefined && testStyle[ 'clip-top' ] === undefined ? 6 : 0
1169 X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
1170 var xnode = Node._systemNode,
1171 output = X.Dom.Style._UNIT_RATIO = {},
1172 list = 'em,cm,mm,in,pt,pc'.split( ',' ),
1175 for( i = list.length; i; ){
1177 output[ unit ] = xnode.css( 'width', 100 + unit ).width() / 100;
1180 output = X.Dom.Style._FONT_SIZE_RATIO = {},
1181 list = 'xx-large,x-large,large,larger,medium,small,smaller,x-small,xx-small'.split( ',' );
1182 xnode.css( { lineHeight : '100%', height : '1em' } ).text( 'X' );
1184 for( i = list.length; i; ){
1186 output[ size ] = xnode.css( 'fontSize', size ).height();// / base;
1189 xnode.cssText( '' ).empty();