svnno****@sourc*****
svnno****@sourc*****
2010年 3月 6日 (土) 19:32:01 JST
Revision: 1699 http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1699 Author: dhrname Date: 2010-03-06 19:32:01 +0900 (Sat, 06 Mar 2010) Log Message: ----------- 1, コードの整形 2, style属性の解析を行う処理をした 3, getScreenCTMメソッドの修正 4, マップの名前を修正 Modified Paths: -------------- branches/ufltima/dom/svg.js Modified: branches/ufltima/dom/svg.js =================================================================== --- branches/ufltima/dom/svg.js 2010-03-04 14:48:34 UTC (rev 1698) +++ branches/ufltima/dom/svg.js 2010-03-06 10:32:01 UTC (rev 1699) @@ -140,11 +140,13 @@ */ function SVGElement() { Element.call(this, arguments); - /*String*/ this.id = null; //id属性の値 - /*String*/ this.xmlbase = null; //xml:base属性の値 - /*SVGSVGElement*/ this.ownerSVGElement; //ルート要素であるsvg要素 + /*String*/ this.id = null; //id属性の値 + /*String*/ this.xmlbase = null; //xml:base属性の値 + /*SVGSVGElement*/ this.ownerSVGElement; //ルート要素であるsvg要素 /*readonly SVGElement*/ this.viewportElement; //ビューポートを形成する要素(多くはsvg要素) SVGStylable.call(this, arguments); //ElementCSSInlineStyleのインタフェースを継承 + /*readonly attribute SVGElement*/ this.nearestViewportElement = null; + /*readonly attribute SVGElement*/ this.farthestViewportElement = null; /*interface SVGTransformable : SVGLocatable *TransformListはtransform属性を行列で表現したあとのリスト構造 */ @@ -157,9 +159,9 @@ /*interface SVGLocatable*/ /*SVGRect*/ SVGElement.prototype.getBBox = function(){ var s = new SVGRect(); - s.x = this._tar.clientLeft; - s.y = this._tar.clientTop; - s.width = this._tar.clientWidth; + s.x = this._tar.clientLeft; + s.y = this._tar.clientTop; + s.width = this._tar.clientWidth; s.height = this._tar.clientHeight; return s; }; @@ -181,6 +183,9 @@ }; /*SVGMatrix*/ SVGElement.prototype.getScreenCTM = function(){ + if (this.parentNode) { + return null; + } var s = this.getCTM.multiply(this.ownerDocument.currentView.transform.consolidate()); return s; }; @@ -317,7 +322,7 @@ */ SVGLength.prototype.newValueSpecifiedUnits = function (/*unsigned short*/ unitType, /*float*/ valueInSpecifiedUnits) { this.value = 1; - this.convertToSpecifiedUnits((unitType); + this.convertToSpecifiedUnits(unitType); this.value = valueInSpecifiedUnits * this.valueInSpecifiedUnits; this.valueInSpecifiedUnits = valueInSpecifiedUnits; this.valuAsString = valueInSpecifiedUnits + this._s; @@ -369,8 +374,8 @@ function SVGColor() { CSSValue.call(this, arguments); /*readonly unsigned short*/ this.colorType = SVGColor.SVG_COLORTYPE_UNKNOWN; - /*readonly css::RGBColor*/ this.rgbColor = new RGBColor(); - /*readonly SVGICCColor*/ this.iccColor; + /*readonly css::RGBColor*/ this.rgbColor = new RGBColor(); + /*readonly SVGICCColor*/ this.iccColor; return this; }; @@ -547,11 +552,11 @@ }; function SVGRect() { - /*float*/ this.x = 0; + /*float*/ this.x = 0; // raises DOMException on setting - /*float*/ this.y = 0; + /*float*/ this.y = 0; // raises DOMException on setting - /*float*/ this.width = 0; + /*float*/ this.width = 0; // raises DOMException on setting /*float*/ this.height = 0; // raises DOMException on setting @@ -574,6 +579,27 @@ /*readonly attribute css::CSSStyleDeclaration*/ this.style = new CSSStyleDeclaration(); this._runtimeStyle = new CSSStyleDeclaration(); //getOverrideStyleメソッドで利用する this._attributeStyle = new CSSStyleDeclaration(); //プレゼンテーション属性の値を格納する + //styleのcssTextプロパティを解析するリスナーを登録しておく + this.addEventListener("DOMNodeInsertedIntoDocument", function(evt) { + var style = evt.target.style, n = false; + for (var i=0, sli=style.length;i<sli;++i) { + var s = style.getPropertyCSSValue(style.item(i)); + if (!!!s.cssText._rewrite) { + n = true; + s.cssText._rewrite = 1; + break; + } + } + if (n) { //CSSValueのcssTextが書き換えられていれば + style.cssText = ""; + for (var i=0, sli=style.length;i<sli;++i) { + var s = style.getPropertyCSSValue(style.item(i)); + style.cssText += s.cssText; + } + } + if (!!!style.cssText._rewrite) { + } + }, false) }; /*getPresentationAttributeメソッド *プレゼンテーション属性の値をCSSValueとして得る。これはCSSのスタイルの設定値を定めるときや、内部の動的処理に役立つ @@ -609,10 +635,10 @@ */ function SVGDocument(){ Document.apply(this, arguments); - /*readonly DOMString*/ this.title = ""; + /*readonly DOMString*/ this.title = ""; /*readonly DOMString*/ this.referrer = document.referrer; - /*readonly DOMString*/ this.domain = document.domain; - /*readonly DOMString*/ this.URL = document.location; + /*readonly DOMString*/ this.domain = document.domain; + /*readonly DOMString*/ this.URL = document.location; /*readonly SVGSVGElement*/ this.rootElement; return this; }; @@ -640,20 +666,20 @@ *それぞれ、svg要素の同名属性に対応。たとえば、xならば、x属性に対応している *1000というのは、W3Cで触れていないため、独自の初期値を採用 */ - /*readonly SVGAnimatedLength*/ this.x = new SVGAnimatedLength(); - /*readonly SVGAnimatedLength*/ this.y = new SVGAnimatedLength(); - /*readonly SVGAnimatedLength*/ this.width = new SVGAnimatedLength(); + /*readonly SVGAnimatedLength*/ this.x = new SVGAnimatedLength(); + /*readonly SVGAnimatedLength*/ this.y = new SVGAnimatedLength(); + /*readonly SVGAnimatedLength*/ this.width = new SVGAnimatedLength(); /*readonly SVGAnimatedLength*/ this.height = new SVGAnimatedLength(); /*DOMString*/ this.contentScriptType = "application/ecmascript"; //古い仕様では、text/ecmascript - /*DOMString*/ this.contentStyleType = "text/css"; - /*readonly SVGRect*/ this.viewport = this.createSVGRect(); - /*boolean*/ this.useCurrentView = false; //ズームなど加工がされていれば、true - /*readonly SVGViewSpec*/ this.currentView = new SVGViewSpec(); + /*DOMString*/ this.contentStyleType = "text/css"; + /*readonly SVGRect*/ this.viewport = this.createSVGRect(); + /*boolean*/ this.useCurrentView = false; //ズームなど加工がされていれば、true + /*readonly SVGViewSpec*/ this.currentView = new SVGViewSpec(); /*もし、画像をズームやパンしたとき、どのような倍率になるかを *以下のプロパティを使って次の行列で示すことができる *2x3 行列 [a b c d e f] = [currentScale 0 0 currentScale currentTranslate.x currentTranslate.y] */ - /*float*/ this.currentScale = 1; + /*float*/ this.currentScale = 1; /*readonly SVGPoint*/ this.currentTranslate = this.createSVGPoint(); this.currentTranslate.x = 0; this.currentTranslate.y = 0; @@ -669,8 +695,34 @@ var tar = evt.target, ea = evt.attrName, _parseFloat = parseFloat; if (!!tar[ea]) { var tea = tar[ea]; + if (evt.attrChange === MutationEvent.ADDITION) { + var n = evt.newValue.match(/\D+$/), type = 0; + if (!n) { + type = SVGLength.SVG_LENGTHTYPE_NUMBER; + } else if (n === "%") { + type = SVGLength.SVG_LENGTHTYPE_PERCENTAGE; + } else if (n === "em") { + type = SVGLength.SVG_LENGTHTYPE_EMS; + } else if (n === "ex") { + type = SVGLength.SVG_LENGTHTYPE_EXS; + } else if (n === "px") { + type = SVGLength.SVG_LENGTHTYPE_PX; + } else if (n === "cm") { + type = SVGLength.SVG_LENGTHTYPE_CM; + } else if (n === "mm") { + type = SVGLength.SVG_LENGTHTYPE_MM; + } else if (n === "in") { + type = SVGLength.SVG_LENGTHTYPE_IN; + } else if (n === "pt") { + type = SVGLength.SVG_LENGTHTYPE_PT; + } else if (n === "pc") { + type = SVGLength.SVG_LENGTHTYPE_PC; + } + } else { + var type = tea.unitType; + } if (tea instanceof SVGAnimatedLength) { - tea.baseVal.newValueSpecified(te.unitType, _parseFloat(evt.newValue)); + tea.baseVal.newValueSpecified(type, _parseFloat(evt.newValue)); } } }, true); @@ -916,15 +968,19 @@ var name = evt.attrName, tar = evt.target; if (!!CSS2Properties[name] || name.indexOf("-") > -1) { tar._attributeStyle.setProperty(name, evt.newValue, ""); + } else if (evt.relatedNode.localName === "id") { //xml:idあるいはid属性ならば } else if (name === "transform") { } else if (name === "style") { + tar.style.cssText = evt.newValue; } else if (name === "class") { - } else if (evt.relatedNode.localName === "id") { //xml:idあるいはid属性ならば + tar.className = evt.newValue; } else if (name.indexOf("on") === 0) { //event属性ならば + var s = eval("(function(){" +evt.newValue+ "})"); + tar.addEventListener(name.substring(2, name.length-1), s, false); } evt.initMutationEvent("DOMNodeInsertedIntoDocument", false, false, null, null, null, null, null); tar.dispatchEvent(evt); //描画を開始するために、dispatchEventメソッドを使う - evt = name = null; + evt = name = tar = null; }, false); return this; }; @@ -1607,7 +1663,7 @@ *SVGのd属性をVMLに変換していく処理である。 */ var tar = evt.target, matrix = tar.getScreenCTM(), tlist = tar.normalizedPathSegList, _parseInt = parseInt; - var dat = "", ma = matrix.a, mb = matrix.b, mc = matrix.c, md = matrix.d, me = matrix.e, mf = matrix.f,; + var dat = "", ma = matrix.a, mb = matrix.b, mc = matrix.c, md = matrix.d, me = matrix.e, mf = matrix.f; for (var i=0, tli=tlist.numberOfItems;i<tli;++i) { var ti = tlist.getItem(i), tps = ti.pathSegTypeAsLetter; if (tps === "z" || tps === "Z") { @@ -2498,24 +2554,24 @@ stop: SVGStopElement, rect: SVGRectElement, circle: SVGCircleElement, - ellipse: SSVGEllipseElement, - polyline: SSVGPolylineElement, + ellipse: SVGEllipseElement, + polyline: SVGPolylineElement, polygon: SVGPolygonElement, text: SVGTextElement, - tspan: SVGTspanElement, + tspan: SVGTSpanElement, image: SVGImageElement, line: SVGLineElement, a: SVGAElement, altGlyphDef: SVGAltGlyphDefElement, altGlyph: SVGAltGlyphElement, - altGlyphItem: SVGAltGlypItem, + altGlyphItem: SVGAltGlyphItemElement, animateColor: SVGAnimateColorElement, animate: SVGAnimateElement, animateMotion: SVGAnimateMotionElement, - animateTransform:SVGAniamteTranformElement, + animateTransform:SVGAnimateTransformElement, clipPath: SVGClipPathElement, colorProfile: SVGColorProfileElement, - cursor: SVGCurosrElement, + cursor: SVGCursorElement, definitionSrc: SVGDefinitionSrcElement, feBlend: SVGFEBlendElement, feGaussianBlur: SVGFEGaussianBlurElement, @@ -2539,8 +2595,8 @@ set: SVGSetElement, style: SVGStyleElement, "switch": SVGSwitchElement, - textPath: SVGTextPatElement, - tref: SVGTrefElement, + textPath: SVGTextPathElement, + tref: SVGTRefElement, use: SVGUseElement, view: SVGViewElement, vkern: SVGVKernElement