svnno****@sourc*****
svnno****@sourc*****
2011年 8月 13日 (土) 20:59:22 JST
Revision: 2870
http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=2870
Author: dhrname
Date: 2011-08-13 20:59:22 +0900 (Sat, 13 Aug 2011)
Log Message:
-----------
CSSPrimitiveValueインターフェースのsetFloatvalueメソッドを実装して、それを使用しながら軽量化
(備考:Stringのmatchメソッドの使用回数を減らせることができたので、軽量化した)
Modified Paths:
--------------
branches/08x/083/org/w3c/dom/css.js
branches/08x/083/org/w3c/dom/svg.js
Modified: branches/08x/083/org/w3c/dom/css.js
===================================================================
--- branches/08x/083/org/w3c/dom/css.js 2011-08-13 11:28:39 UTC (rev 2869)
+++ branches/08x/083/org/w3c/dom/css.js 2011-08-13 11:59:22 UTC (rev 2870)
@@ -426,7 +426,7 @@
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に統一)
this.cssValueType = CSSValue.CSS_PRIMITIVE_VALUE;
this.primitiveType = CSSPrimitiveValue.CSS_UNKNOWN;
- this._value = 1;
+ this._value = null;
this._percent = 0; //単位に%が使われていた場合、このプロパティの数値を1%として使う
this._empercent = 0;
/*void*/ this.setFloatValue = function(/*short*/ unitType, /*float*/ floatValue) {
@@ -444,41 +444,45 @@
if ((/*CSSPrimitiveValue.CSS_UNKNOWN*/ 0 >= unitType) && (unitType >= /*CSSPrimitiveValue.CSS_STRING*/ 19)) { //浮動小数点数単位型をサポートしないCSS単位である場合
throw new DOMException(DOMException.INVALID_ACCESS_ERR);
}
- var tc = this.cssText,
- n = tc.charAt(tc.length-1),
- type = 0,
- s = +(tc.match(this._regd));
- s = isNaN(s) ? 0 : s;
- if (n >= "0" && n <= "9") {
- type = /*CSSPrimitiveValue.CSS_NUMBER*/ 1;
- if (unitType === 1) {
- unitType = tc = n = type = null;
- return s;
+ if (this._value || (this._value === 0)) { //すでに、setFloatValueメソッドによって_valueプロパティが設定されていた場合
+ return (this._value / this._n[unitType-1]);
+ } else {
+ var tc = this.cssText,
+ n = tc.charAt(tc.length-1),
+ type = 0,
+ s = +(tc.match(this._regd));
+ s = isNaN(s) ? 0 : s;
+ if (n >= "0" && n <= "9") {
+ type = /*CSSPrimitiveValue.CSS_NUMBER*/ 1;
+ if (unitType === 1) {
+ unitType = tc = n = type = null;
+ return s;
+ }
+ } else if (n === "%") {
+ s *= this._percent;
+ type = /*CSSPrimitiveValue.CSS_PERCENTAGE*/ 2;
+ } else if ((n === "m") && (tc.charAt(tc.length-2) === "e")) {
+ s *= this._empercent;
+ type = /*CSSPrimitiveValue.CSS_EMS*/ 3;
+ } else if ((n === "x") && (tc.charAt(tc.length-2) === "e")) {
+ type = /*CSSPrimitiveValue.CSS_EXS*/ 4;
+ } else if ((n === "x") && (tc.charAt(tc.length-2) === "p")) {
+ type = /*CSSPrimitiveValue.CSS_PX*/ 5;
+ } else if ((n === "m") && (tc.charAt(tc.length-2) === "c")) {
+ type = /*CSSPrimitiveValue.CSS_CM*/ 6;
+ } else if ((n === "m") && (tc.charAt(tc.length-2) === "m")) {
+ type = /*CSSPrimitiveValue.CSS_MM*/ 7;
+ } else if (n === "n") {
+ type = /*CSSPrimitiveValue.CSS_IN*/ 8;
+ } else if (n === "t") {
+ type = /*CSSPrimitiveValue.CSS_PT*/ 9;
+ } else if (n === "c") {
+ type = /*CSSPrimitiveValue.CSS_PC*/ 10;
}
- } else if (n === "%") {
- s *= this._percent;
- type = /*CSSPrimitiveValue.CSS_PERCENTAGE*/ 2;
- } else if ((n === "m") && (tc.charAt(tc.length-2) === "e")) {
- s *= this._empercent;
- type = /*CSSPrimitiveValue.CSS_EMS*/ 3;
- } else if ((n === "x") && (tc.charAt(tc.length-2) === "e")) {
- type = /*CSSPrimitiveValue.CSS_EXS*/ 4;
- } else if ((n === "x") && (tc.charAt(tc.length-2) === "p")) {
- type = /*CSSPrimitiveValue.CSS_PX*/ 5;
- } else if ((n === "m") && (tc.charAt(tc.length-2) === "c")) {
- type = /*CSSPrimitiveValue.CSS_CM*/ 6;
- } else if ((n === "m") && (tc.charAt(tc.length-2) === "m")) {
- type = /*CSSPrimitiveValue.CSS_MM*/ 7;
- } else if (n === "n") {
- type = /*CSSPrimitiveValue.CSS_IN*/ 8;
- } else if (n === "t") {
- type = /*CSSPrimitiveValue.CSS_PT*/ 9;
- } else if (n === "c") {
- type = /*CSSPrimitiveValue.CSS_PC*/ 10;
+ s = s * this._n[type-1] / this._n[unitType-1];
+ tc = n = type = unitType = null;
+ return s;
}
- this._value = s * this._n[type-1]; //値はあらかじめ、利用しやすいように変換しておく
- tc = n = type = s = null;
- return (this._value / this._n[unitType-1]);
};
/*void*/ this.setStringValue = function(/*short*/ stringType, /*string*/ stringValue) {
if (CSSPrimitiveValue.CSS_DIMENSION >= stringType && stringType >= CSSPrimitiveValue.CSS_COUNTER) { //文字列型をサポートしないCSS単位である場合
Modified: branches/08x/083/org/w3c/dom/svg.js
===================================================================
--- branches/08x/083/org/w3c/dom/svg.js 2011-08-13 11:28:39 UTC (rev 2869)
+++ branches/08x/083/org/w3c/dom/svg.js 2011-08-13 11:59:22 UTC (rev 2870)
@@ -751,9 +751,9 @@
throw new SVGException(SVGException.SVG_INVALID_VALUE_ERR);
}
}
- this.rgbColor.red.cssText = s[0];
- this.rgbColor.green.cssText = s[1];
- this.rgbColor.blue.cssText = s[2];
+ this.rgbColor.red.setFloatValue(/*CSSPrimitiveValue.CSS_NUMBER*/ 1, s[0]);
+ this.rgbColor.green.setFloatValue(1, s[1]);
+ this.rgbColor.blue.setFloatValue(1, s[2]);
rgbColor = s = _parseInt = null;
};
@@ -4495,7 +4495,7 @@
/*再度、設定。css.jsのsetPropertyを参照*/
sstyle.setProperty("color", sstyle.getPropertyValue("color"));
}
- color[i] = "rgb(" +ci.rgbColor.red.cssText+ "," +ci.rgbColor.green.cssText+ "," +ci.rgbColor.blue.cssText+ ")";
+ color[i] = "rgb(" +ci.rgbColor.red.getFloatValue(1)+ "," +ci.rgbColor.green.getFloatValue(1)+ "," +ci.rgbColor.blue.getFloatValue(1)+ ")";
colors[i] = stop.offset.baseVal + " " + color[i];
opacity[i] = (sstyle.getPropertyValue("stop-opacity") || 1) * t.getPropertyValue("fill-opacity") * t.getPropertyValue("opacity");
}