svnno****@sourc*****
svnno****@sourc*****
2010年 9月 4日 (土) 23:10:02 JST
Revision: 1984
http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1984
Author: dhrname
Date: 2010-09-04 23:10:02 +0900 (Sat, 04 Sep 2010)
Log Message:
-----------
getOverrideStyleメソッドの実装を開始
Modified Paths:
--------------
branches/06x/061/org/w3c/dom/css.js
Modified: branches/06x/061/org/w3c/dom/css.js
===================================================================
--- branches/06x/061/org/w3c/dom/css.js 2010-09-04 14:00:32 UTC (rev 1983)
+++ branches/06x/061/org/w3c/dom/css.js 2010-09-04 14:10:02 UTC (rev 1984)
@@ -685,7 +685,122 @@
*/
/*function DocumentCSS : stylesheets::DocumentStyle {*/
/*CSSStyleDeclaration*/ Document.prototype.getOverrideStyle = function( /*Element*/ elt, /*string*/ pseudoElt) {
- var s = new CSSStyleDeclaration();
+ var tar = elt;
+ if (!!tar._runtimeStyle) {
+ return (tar._runtimeStyle);
+ } else {
+ var s = new CSSStyleDeclaration(), setProp = s.setProperty;
+ tar._runtimeStyle = s;
+ }
+ var style = this.defaultView.getComputedStyle(tar, "")
+ s.setProperty = function(propertyName, value, priority) {
+ var el = tar._tar;
+ if (!!!tar._fillElement) {
+ tar._fillElement = document.createElement("v:fill"); //キャッシュを作る
+ el.appendChild(tar._fillElement);
+ }
+ if (!!!tar._strokeElement) {
+ tar._strokeElement = document.createElement("v:stroke");
+ el.appendChild(tar._strokeElement);
+ }
+ var fillElement = tar._fillElementvar, strokeElement = tar._strokeElement;
+ setProp(propertyName, value, priority);
+ if (propertyName === "fill-opacity") {
+ var fillOpacity = parseFloat(value) * style._list._opacity; //opacityを掛け合わせる
+ if (fillOpacity < 1) {
+ fillElement.setAttribute("opacity", fillOpacity+"");
+ }
+ } else if (propertyName === "opacity") {
+ var fillOpacity = parseFloat(style.getPropertyValue("fill-opacity")) * parseFloat(value); //opacityを掛け合わせる
+ if (fillOpacity < 1) {
+ fillElement.setAttribute("opacity", fillOpacity+"");
+ }
+ var strokeOpacity = parseFloat(style.getPropertyValue("stroke-opacity")) * parseFloat(value);
+ if (strokeOpacity < 1) {
+ strokeElement.setAttribute("opacity", strokeOpacity+"");
+ }
+ fillOpacity = strokeOpacity = null;
+ } else if (propertyName === "fill") {
+ var fill = s.getPropertyCSSValue("fill");
+ if (value.indexOf("#") > -1) {
+ /*以下では、Gradation関連の要素に、イベントを渡すことで、
+ *この要素の、グラデーション描画を行う
+ */
+ var tod = tar.ownerDocument, t = tod.getElementById(fill.uri);
+ if (t) {
+ var evtt = tod.createEvent("MutationEvents");
+ evtt.initMutationEvent("DOMNodeInsertedIntoDocument", false, false, null, null, null, null, null);
+ evtt._tar = tar._fillElement;
+ evtt._style = style, evtt._ttar = tar;
+ t.dispatchEvent(evtt);
+ if (t.localName !== "radialGradient" && !!!tar._fillElement) {
+ el.appendChild(evtt._tar);
+ tar._fillElement = evtt._tar; //キャッシュを作る
+ }
+ t = evtt = null;
+ }
+ tod = null;
+ } else if (value === "none") {
+ tar.removeChild(tar._fillElment);
+ el.filled = "false";
+ } else {
+ var fc = fill.rgbColor, num = CSSPrimitiveValue.CSS_NUMBER;
+ fillElement.setAttribute("color", "rgb(" +fc.red.getFloatValue(num)+ "," +fc.green.getFloatValue(num)+ "," +fc.blue.getFloatValue(num)+ ")");
+ }
+ } else if (propertyName === "stroke") {
+ var stroke = style.getPropertyCSSValue("stroke");
+ if (value === "none") {
+ tar.removeChild(tar._strokeElment);
+ el.stroked = "false";
+ } else if (!stroke.uri) {
+ var fc = stroke.rgbColor, num = CSSPrimitiveValue.CSS_NUMBER;
+ strokeElement.setAttribute("color", "rgb(" +fc.red.getFloatValue(num)+ "," +fc.green.getFloatValue(num)+ "," +fc.blue.getFloatValue(num)+ ")");
+ }
+ } else if (propertyName === "stroke-opacity") {
+ var strokeOpacity = parseFloat(value) * parseFloat(style.getPropertyValue("opacity")); //opacityを掛け合わせる
+ if (strokeOpacity < 1) {
+ strokeElement.setAttribute("opacity", strokeOpacity);
+ }
+ fc = num = strokeOpacity = null;
+ } else if (propertyName === "stroke-width") {
+ var sgsw = s.getPropertyCSSValue("stroke-width"), tod = tar.ownerDocument, w = tod.documentElement.viewport.width, h = tod.documentElement.viewport.height;
+ sgsw._percent = Math.sqrt((w*w + h*h) / 2);
+ var swx = sgsw.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) * Math.sqrt(Math.abs(tar.getScreenCTM()._determinant()));
+ strokeElement.setAttribute("weight", swx + "px");
+ sgsw = w = h = null;
+ } else if (propertyName === "stroke-miterlimit") {
+ strokeElement.setAttribute("miterlimit", value);
+ } else if (propertyName === "stroke-linejoin") {
+ strokeElement.setAttribute("joinstyle", value);
+ } else if (propertyName === "stroke-linecap") {
+ if (value === "butt") {
+ strokeElement.setAttribute("endcap", "flat");
+ } else {
+ strokeElement.setAttribute("endcap", value);
+ }
+ } else if (propertyName === "stroke-dasharray") {
+ var tsd = value;
+ if (tsd !== "none") {
+ if (tsd.indexOf(",") > 0) { //コンマ区切りの文字列の場合
+ var strs = tsd.split(",");
+ for (var i = 0, sli = strs.length; i < sli; ++i) {
+ strs[i] = Math.ceil(parseFloat(strs[i]) / parseFloat(style.getPropertyValue("stroke-width"))); //精密ではないので注意
+ }
+ var strokedasharray = strs.join(" ");
+ if (strs.length % 2 === 1) {
+ strokedasharray += " " + strokedasharray;
+ }
+ }
+ strokeElement.setAttribute("dashstyle", strokedasharray);
+ tsd = strs = null;
+ }
+ } else if ((propertyName === "cursor") && (value !== "auto") && (value !== "")) {
+ el.style.cursor = value;
+ } else if (propertyName === "visibility") {
+ el.style.visibility = value;
+ }
+ el = fill = stroke = tar = value = propertyName = null;
+ }
return s;
};
/*createCSSStyleSheetメソッド