svnno****@sourc*****
svnno****@sourc*****
2010年 3月 22日 (月) 20:27:03 JST
Revision: 1747
http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1747
Author: dhrname
Date: 2010-03-22 20:27:03 +0900 (Mon, 22 Mar 2010)
Log Message:
-----------
CSSPrimitiveValueオブジェクトのメソッドなどを修正
Modified Paths:
--------------
branches/ufltima/dom/css.js
Modified: branches/ufltima/dom/css.js
===================================================================
--- branches/ufltima/dom/css.js 2010-03-22 11:26:28 UTC (rev 1746)
+++ branches/ufltima/dom/css.js 2010-03-22 11:27:03 UTC (rev 1747)
@@ -287,6 +287,7 @@
CSSValue.call(this, arguments);
this.cssValueType = CSSValue.CSS_PRIMITIVE_VALUE;
this.primitiveType = CSSPrimitiveValue.CSS_UNKNOWN;
+ this._value = 1;
this._n = [1, 0.01, 1, 1, 1, 35.43307, 3.543307, 90, 1.25, 15, 1, 180 / Math.PI, 90/100, 1, 1000, 1, 1000, 1]; //CSS_PX単位への変換値(なお、CSS_SはCSS_MSに、CSS_RADとCSS_GRADはCSS_DEGに、CSS_KHZはCSS_HZに統一)
return this;
};
@@ -324,7 +325,7 @@
throw new DOMException(DOMException.INVALID_ACCESS_ERR);
}
this.primitiveType = unitType;
- this.value = floatValue * this._n[unitType-1]; //値はあらかじめ、利用しやすいように変換しておく
+ this._value = floatValue * this._n[unitType-1]; //値はあらかじめ、利用しやすいように変換しておく
};
/*getFloatValueメソッド
*別の単位に変換可能。
@@ -333,37 +334,57 @@
if (CSSPrimitiveValue.CSS_UNKNOWN >= unitType && unitType >= CSSPrimitiveValue.CSS_STRING) { //浮動小数点数単位型をサポートしないCSS単位である場合
throw new DOMException(DOMException.INVALID_ACCESS_ERR);
}
- return (this.value / this._n[unitType-1]);
+ return (this._value / this._n[unitType-1]);
};
/*void*/ CSSPrimitiveValue.prototype.setStringValue = function(/*short*/ stringType, /*string*/ stringValue) {
if (CSSPrimitiveValue.CSS_DIMENSION >= stringType && stringType >= CSSPrimitiveValue.CSS_COUNTER) { //文字列型をサポートしないCSS単位である場合
throw new DOMException(DOMException.INVALID_ACCESS_ERR);
}
- this.value = stringValue;
+ this.cssText = stringValue;
};
/*string*/ CSSPrimitiveValue.prototype.getStringValue = function() {
if (CSSPrimitiveValue.CSS_DIMENSION >= stringType && stringType >= CSSPrimitiveValue.CSS_COUNTER) { //文字列型をサポートしないCSS単位である場合
throw new DOMException(DOMException.INVALID_ACCESS_ERR);
}
- return (this.value);
+ return (this.cssText);
};
/*Counter*/ CSSPrimitiveValue.prototype.getCounterValue = function() {
if (this.primitiveType !== CSSPrimitiveValue.CSS_COUNTER) { //Counter型ではないとき
throw new DOMException(DOMException.INVALID_ACCESS_ERR);
}
- return (this.value);
+ return (new Counter());
};
/*Rect*/ CSSPrimitiveValue.prototype.getRectValue = function() {
if (this.primitiveType !== CSSPrimitiveValue.CSS_RECT) { //Rect型ではないとき
throw new DOMException(DOMException.INVALID_ACCESS_ERR);
}
- return (this.value);
+ return (new Rect());
};
/*RGBColor*/ CSSPrimitiveValue.prototype.getRGBColorValue = function() {
if (this.primitiveType !== CSSPrimitiveValue.CSS_RGBCOLOR) { //RGBColor型ではないとき
throw new DOMException(DOMException.INVALID_ACCESS_ERR);
}
- return (this.value);
+ var s = new RGBColor();
+ var rgbColor = this.cssText;
+ var tkr = SVGColor.prototype._keywords[rgbColor];
+ if (tkr !== void 0) {
+ rgbColor = tkr;
+ }
+ if (rgbColor.indexOf("%", 5) > 0) { // %を含むrgb形式の場合
+ rgbColor = rgbColor.replace(/[\d.]+%/g, function(t) {
+ return Math.round((2.55 * parseFloat(t)));
+ });
+ } else if (rgbColor.indexOf("#") > 0) { //#を含む場合
+ rgbColor = rgbColor.replace(/[\dA-F][\dA-F]/g, function(t) {
+ return parseInt(t, 16);
+ });
+ }
+ var n = rgbColor.match(/\d+/g);
+ s.red.setFloatValue(CSSPrimitiveValue.CSS_NUMBER, parseFloat(n[0]));
+ s.green.setFloatValue(CSSPrimitiveValue.CSS_NUMBER, parseFloat(n[1]));
+ s.blue.setFloatValue(CSSPrimitiveValue.CSS_NUMBER, parseFloat(n[2]));
+ n = rgbColor = null;
+ return (s);
};
/*CSSValueList