svnno****@sourc*****
svnno****@sourc*****
2011年 9月 2日 (金) 20:55:49 JST
Revision: 2912 http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=2912 Author: dhrname Date: 2011-09-02 20:55:49 +0900 (Fri, 02 Sep 2011) Log Message: ----------- 0.84モジュール 結合 Modified Paths: -------------- branches/08x/sie.js Modified: branches/08x/sie.js =================================================================== --- branches/08x/sie.js 2011-09-02 11:53:29 UTC (rev 2911) +++ branches/08x/sie.js 2011-09-02 11:55:49 UTC (rev 2912) @@ -985,6 +985,8 @@ var evt = node.ownerDocument.createEvent("MouseEvents"); evt.initMouseEvent(type, true, true, node.ownerDocument.defaultView, 0); node.dispatchEvent(evt); + /*cancelBubbleプロパティについては、IEのMSDNなどを参照*/ + node.ownerDocument._window.event.cancelBubble = true; evt = null; }; })(that) @@ -995,7 +997,7 @@ /*void*/ Node.prototype.removeEventListener = function( /*string*/ type, /*EventListener*/ listener, /*boolean*/ useCapture) { var tce = this._capter; for (var i=0,tcli=tce.length;i<tcli;i++){ - if (tce[i].listener === listener) { //登録したリスナーと一致すれば + if (tce[i]._listener === listener) { //登録したリスナーと一致すれば tce[i] = null; } } @@ -1093,7 +1095,8 @@ EventListener.prototype = { /*void*/ handleEvent : function( /*Event*/ evt) { try { - var ph = evt.eventPhase, cap = this._cap; + var ph = evt.eventPhase, + cap = this._cap; if (ph === /*Event.CAPTURING_PHASE*/ 1) { //イベントフェーズが捕獲段階であることを示し cap = cap ? false : true; //このオブジェクト(EventListenr)が捕獲フェーズを指定するならば、リスナーを作動させる。指定しなければ、作動しない。 } @@ -1131,9 +1134,11 @@ this._stop = true; }, /*void*/ preventDefault : function(){ - this._default = false; - /*IEのみで使えるreturnValueプロパティ*/ - window.event.returnValue = false; + if (this.cancelable) { + this._default = false; + /*IEのみで使えるreturnValueプロパティ*/ + this.target.ownerDocument._window.event.returnValue = false; + } }, /*void*/ initEvent : function( /*string*/ eventTypeArg, /*boolean*/ canBubbleArg, /*boolean*/ cancelableArg) { this.type = eventTypeArg; @@ -3265,7 +3270,7 @@ this._instance = null; //埋め込みの場合に、読み込んだDOMツリーを結び付けておくプロパティ this._text = ""; this.addEventListener("DOMAttrModified", function(evt){ - if (evt.relatedNode.namespaceURI === "http://www.w3.org/1999/xlink" && evt.attrName === "xlink:href") { + if ((evt.relatedNode.namespaceURI === "http://www.w3.org/1999/xlink") && (evt.attrName === "xlink:href")) { evt.target.href.baseVal = evt.newValue; /*_svgload_limitedを+1とすることで、 *SVGLoadイベントは発火されなくなる。1を引く必要がある @@ -3335,18 +3340,23 @@ ele = doc.getElementById(id); tar._instance = ele; ev = doc.createEvent("SVGEvents"); - ev.initEvent("SVGLoad", false, false); + ev.initEvent("S_Load", false, false); tar.dispatchEvent(ev); + tar = xmlhttp = null; } else if (uri.indexOf("data:") > -1) { tar._tar.src = uri; + tar = xmlhttp = null; } else if ((uri.indexOf("http:") > -1) || (uri.indexOf(".") === 0)){ if (tar.localName === "image") { tar._tar.src = uri; + } else { + /*ここの_svgload_limitedは、リンクを読み込んだ後でSVGLoadイベントを実行させるという遅延処理で必要*/ + tar.ownerDocument.documentElement._svgload_limited++; } xmlhttp.open("GET", uri, false); xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest"); xmlhttp.onreadystatechange = function() { - if (xmlhttp.readyState === 4 && xmlhttp.status === 200) { + if ((xmlhttp.readyState === 4) && (xmlhttp.status === 200)) { var type = xmlhttp.getResponseHeader('Content-Type') || "text", doc, str, ele, ev; if ((type.indexOf("text") > -1) || (type.indexOf("xml") > -1) || (type.indexOf("script") > -1)) { //ファイルがtext形式である場合 @@ -3376,19 +3386,31 @@ } else if (!!tar._tar) { tar._tar.src = uri; } + /*S_LoadイベントとはSIE独自のイベント。 + *XLink言語によって、リンク先のコンテンツが読み込まれた時点で発火する + */ ev = tar.ownerDocument.createEvent("SVGEvents"); - ev.initEvent("SVGLoad", false, false); + ev.initEvent("S_Load", false, false); tar.dispatchEvent(ev); - type = doc = str = ev = null; + tar.ownerDocument.documentElement._svgload_limited--; + /*すべてのリンクが読み込みを終了した場合、SVGLoadイベントを発火*/ + if (tar.ownerDocument.documentElement._svgload_limited < 0) { + ev = tar.ownerDocument.createEvent("SVGEvents"); + ev.initEvent("SVGLoad", false, false); + tar.ownerDocument.documentElement.dispatchEvent(ev); + } + tar = type = doc = str = ev = null; /*IEのメモリリーク対策として、空関数を入力*/ xmlhttp.onreadystatechange = NAIBU.emptyFunction; + xmlhttp = null; } }; xmlhttp.send(null); } } + tar.ownerDocument.documentElement._svgload_limited--; } - evt = tar = base = href = egbase = ep = b = lh = uri = xmlhttp = ui = id = doc = ele = ev = show= null; + evt = base = href = egbase = ep = b = lh = uri = ui = id = doc = ele = ev = show= null; }, false); tar = evt = null; }, false); @@ -3539,21 +3561,44 @@ evt = name = tv = ovb = par = tp = sa = mos = null; }, false); this.addEventListener("SVGLoad", function(evt){ + /*以下のDOMAttrModifiedは浮上フェーズのときに、再描画をするように + *処理を書いたもの。属性が書き換わるたびに、再描画される + */ evt.target.addEventListener("DOMAttrModified", function(evt){ if (evt.eventPhase === /*Event.BUBBLING_PHASE*/ 3) { var tar = evt.target, - evtt; + evtt; if (tar.parentNode) { evtt = tar.ownerDocument.createEvent("MutationEvents"); evtt.initMutationEvent("DOMNodeInsertedIntoDocument", false, false, null, null, null, null, null); evtt.target = tar; - evtt.eventPhase = Event.AT_TARGET; + evtt.eventPhase = /*Event.AT_TARGET*/ 2; var tce = tar._capter; //tceは登録しておいたリスナーのリスト for (var j=0,tcli=tce.length;j<tcli;++j){ if (tce[j]) { tce[j].handleEvent(evtt); } } + if (((tar.localName === "g") || (tar.localName === "a")) && (tar.namespaceURI === "http://www.w3.org/2000/svg")) { + tar._currentStyle = tar._cacheMatrix = null; //キャッシュを消去 + if (tar.firstChild) { + var slist = tar.getElementsByTagNameNS("http://www.w3.org/2000/svg", "*"); + for (var i=0,sli=slist.length;i<sli;++i) { + tar = slist[i]; + tar._currentStyle = tar._cacheMatrix = null; + evtt = tar.ownerDocument.createEvent("MutationEvents"); + evtt.initMutationEvent("DOMNodeInsertedIntoDocument", false, false, null, null, null, null, null); + evtt.target = tar; + evtt.eventPhase = /*Event.AT_TARGET*/ 2; + var tce = tar._capter; //tceは登録しておいたリスナーのリスト + for (var j=0,tcli=tce.length;j<tcli;++j){ + if (tce[j]) { + tce[j].handleEvent(evtt); + } + } + } + } + } evtt = null; } tar = null; @@ -3561,7 +3606,7 @@ evt = null; }, false); evt = null; - }, true); + }, false); return this; }; SVGSVGElement.constructor = SVGElement; @@ -3756,28 +3801,7 @@ } else if (!tnext && tpar._tar) { tpar._tar.appendChild(tar._tar); } - tnext = tpar = isLast = null; - tar.addEventListener("DOMAttrModified", function(evt){ - if (evt.eventPhase === /*Event.BUBBLING_PHASE*/ 3) { - return; //強制終了させる - } - var tar = evt.target; - var s = tar.getElementsByTagNameNS("http://www.w3.org/2000/svg", "*"); - if (s) { - tar._currentStyle = tar._cacheMatrix = null; //キャッシュを消去 - var evtt = tar.ownerDocument.createEvent("MutationEvents"); - evtt.initMutationEvent("DOMNodeInsertedIntoDocument", false, false, null, null, null, null, null); - for (var i=0,sli=s.length;i<sli;++i) { - var di = s[i]; - di._currentStyle = di._cacheMatrix = null; - di.dispatchEvent(evtt); - di = null; - } - evtt = null; - } - evt = tar = s = null; - }, false); - evt = tar = null; + tnext = tpar = isLast = evt = tar = null; }, false); return this; }; @@ -3831,7 +3855,7 @@ } evt.target.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:show", "embed"); }, false); - this.addEventListener("SVGLoad", function(evt){ + this.addEventListener("S_Load", function(evt){ var tar = evt.target, style = tar.ownerDocument.defaultView.getComputedStyle(tar, ""), fontSize = parseFloat(style.getPropertyValue("font-size")), @@ -4014,19 +4038,19 @@ s = DOMImplementation.createDocument("http://www.w3.org/2000/svg", "svg"), tar = s.documentElement, tview = tar.viewport, - objw, objh, fi, n, attr, att, + objw, objh, fi, n, attr, att, w, h, sdt = tar._tar, sp = _doc.createElement("div"), dcp = _doc.createElement("v:group"), backr = _doc.createElement("v:rect"), - style, fontSize, sw, sh, trstyle, tpstyle, backrs, + style, fontSize, sw, sh, trstyle, tpstyle, backrs, viewWidth, viewHeight, backdown, backright, bfl, bft, bl, text, _parseFloat = parseFloat, ndoc = NAIBU.doc, oba = _doc.createElement("div"); //obaはradialGradient要素で使う oba.setAttribute("id","_NAIBU_outline"); _doc.body.appendChild(oba); - sp.style.margin = "-1px,-0px,0px,-1px" + sp.style.margin = "-1px,0px,0px,-1px" if (ifcw) { _doc.body.style.backgroundColor = objei.parentNode.currentStyle.backgroundColor; } @@ -4103,6 +4127,10 @@ fi = fi.nextSibling; } fi = null; + /*dom/event.jsのaddEventListenerメソッドなどで、iframe要素のwindowオブジェクトを利用する必要があるため、 + *ドキュメントにそのオブジェクトを結び付けておく + */ + s._window = ifcw; /*以下では、VMLの要素とHTMLのCSSのプロパティを用いて、背景を *作り出す作業を行う。これは必須 */ @@ -4115,8 +4143,10 @@ sw = tar.width.baseVal.value; sh = tar.height.baseVal.value; backr.style.position = "absolute"; - backr.style.width = tview.width+ "px"; - backr.style.height = tview.height+ "px"; + w = tview.width; + h = tview.height; + backr.style.width = w+ "px"; + backr.style.height = h+ "px"; backr.style.zIndex = -1; backr.stroked = "false"; backr.filled = "false"; @@ -4125,7 +4155,11 @@ tpstyle = objei.style; trstyle.visibility = "visible"; trstyle.position = "absolute"; + /*以下、画像を切り取り*/ trstyle.overflow = "hidden"; + /*ウィンドウ枠の長さを決定する*/ + viewWidth = w > sw ? sw : w; + viewHeight = h > sh ? sh : h; backrs = backr.currentStyle; bfl = _parseFloat(backrs.left); bft = _parseFloat(backrs.top); @@ -4139,7 +4173,9 @@ bt = bft; dcp.style.top = -bt+ "px"; } - this._document = s; + backright = bl + viewWidth + 1; + backdown = bt + viewHeight + 1; + trstyle.clip = "rect(" +bt+ "px " +backright+ "px " +backdown+ "px " +bl+ "px)"; this._document = s; if ("_svgload_limited" in s.documentElement) { /*_svgload_limitedプロパティはXlink言語が使われていない限り、0である。 *xlink:href属性が指定されるたびに+1となる。 @@ -4168,7 +4204,7 @@ } s.defaultView._cache = s.defaultView._cache_ele = null; oba = _doc = evt = _doc = objei = tar = tview = objw = objh = n = att = sdt = sp = dcp = backr = sw = sh = style = fontSize = null; - trstyle = tpstyle = backrs = text = texti = i = bfl = bft = bl = bt = text = _parseFloat = null; + trstyle = tpstyle = backrs = text = texti = i = bfl = bft = bl = bt = text = _parseFloat = w = h = viewWidth = viewHeight = backdown = backright = null; /*IEのメモリリーク対策として、空関数を入力*/ this.xmlhttp.onreadystatechange = NAIBU.emptyFunction; if (this._next) { @@ -4248,7 +4284,7 @@ } evt = null; }, false); - this.addEventListener("SVGLoad", function(evt){ + this.addEventListener("S_Load", function(evt){ var tar = evt.target, sheet = tar.sheet, styleText = tar._text, @@ -4273,7 +4309,6 @@ } sheet.cssRules[sheet.cssRules.length] = scri; } - tod.documentElement._svgload_limited--; tod.documentElement.addEventListener("DOMNodeInsertedIntoDocument", function(evt) { var tar = evt.target, doc = tar.ownerDocument, @@ -4291,11 +4326,6 @@ } tar = doc = rules = null; }, true); - if (tod.documentElement._svgload_limited < 0) { - evt = tod.createEvent("SVGEvents"); - evt.initEvent("SVGLoad", false, false); - tod.documentElement.dispatchEvent(evt); - } tar = evt = style = sheet = styleText = tod = i = rules = rli = null; }, false); this.addEventListener("DOMNodeInserted", function(evt){ @@ -4310,7 +4340,7 @@ var tar = evt.target; if ((evt.eventPhase === Event.AT_TARGET) && !tar.getAttributeNodeNS("http://www.w3.org/1999/xlink", "xlink:href")) { var evtt = tar.ownerDocument.createEvent("SVGEvents"); - evtt.initEvent("SVGLoad", false, false); + evtt.initEvent("S_Load", false, false); evt.currentTarget.dispatchEvent(evtt); } tar = evt = null; @@ -6768,14 +6798,8 @@ grad = ele = t = grad2 = href = stops = length = color = colors = opacity = null; return; } - while (grad2 && !grad2.hasChildNodes()) { //stopを子要素に持つgradient要素を探す - href = grad2.getAttributeNS("http://www.w3.org/1999/xlink", "href"); - if (href) { - href.match(/#(.+)/); - grad2 = grad2.ownerDocument.getElementById(RegExp.$1); - } else { - break; - } + if (grad._instance) { //xlink言語で呼び出されたノードが_instanceに収納されているならば + grad2 = grad._instance; } stops = grad2.getElementsByTagNameNS("http://www.w3.org/2000/svg", "stop"); if (!stops) { @@ -6804,6 +6828,10 @@ ele["o:opacity2"] = opacity[0]+ ""; /*SVGRadialGradientElementインターフェースで利用する*/ grad._color = color; + var gt = grad2.getAttributeNS(null, "gradientTransform"); + if (gt) { + grad.setAttributeNS(null, "transform", gt); + } grad = grad2 = ele = stops = length = color = colors = opacity = evt = t = href = stop = sstyle = ci = null; }, false); return this; @@ -6888,10 +6916,6 @@ cx = cx*wid + nx; cy = cy*hei + ny; rx = r*wid; ry = r*hei; nx = ny = wid = hei = null; } - var gt = grad.getAttributeNS(null, "gradientTransform"); - if (gt) { - grad.setAttributeNS(null, "transform", gt); - } var matrix = tar.getScreenCTM().multiply(grad.getCTM()); el = cx - rx; et = cy - ry; er = cx + rx; eb = cy + ry; var rrx = rx * 0.55228, rry = ry * 0.55228; @@ -7107,26 +7131,11 @@ st = "new"; } tar.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:show", st); - tar.addEventListener("DOMAttrModified", function(evt){ - var tar = evt.target; - var s = tar.getElementsByTagNameNS("http://www.w3.org/2000/svg", "*"); - if (s) { - var evtt = tar.ownerDocument.createEvent("MutationEvents"); - evtt.initMutationEvent("DOMNodeInsertedIntoDocument", false, false, null, null, null, null, null); - for (var i=0,sli=s.length;i<sli;++i) { - var di = s[i]; - di.dispatchEvent(evtt); - di = null; - } - evtt = null; - } - evt = tar = s = null; - }, false); tar = evt = null; }, false); this.addEventListener("DOMNodeInsertedIntoDocument", function(evt){ var tar = evt.target; - if (!!tar._tar && (tar.nodeType === Node.ELEMENT_NODE)) { + if (!!tar._tar && (tar.nodeType === /*Node.ELEMENT_NODE*/ 1)) { var txts = tar._tar.style; txts.cursor = "hand"; txts.textDecoration = "none"; @@ -7168,19 +7177,13 @@ } evt = null; }, false); - this.addEventListener("SVGLoad", function(evt){ + this.addEventListener("S_Load", function(evt){ var tar = evt.target, script = tar._text; var tod = tar.ownerDocument; NAIBU._temp_doc = tod; script = script.replace(/function\s+(\w+)/g, "$1 = function"); script = "(function(document){" +script+ "})(NAIBU._temp_doc);" eval(script); - tod.documentElement._svgload_limited--; - if (tod.documentElement._svgload_limited < 0) { - evt = tod.createEvent("SVGEvents"); - evt.initEvent("SVGLoad", false, false); - tod.documentElement.dispatchEvent(evt); - } tar = evt = script = null; }, false); this.addEventListener("DOMNodeInserted", function(evt){ @@ -7195,7 +7198,7 @@ var tar = evt.target; if (evt.eventPhase === Event.AT_TARGET && !tar.getAttributeNodeNS("http://www.w3.org/1999/xlink", "xlink:href")) { var evtt = tar.ownerDocument.createEvent("SVGEvents"); - evtt.initEvent("SVGLoad", false, false); + evtt.initEvent("S_Load", false, false); evt.currentTarget.dispatchEvent(evtt); } tar = evt = null; @@ -8139,7 +8142,7 @@ evt.target.ownerDocument.documentElement._svgload_limited-- evt.target.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:show", "embed"); }, false); - this.addEventListener("SVGLoad", function(evt){ + this.addEventListener("S_Load", function(evt){ var tar = evt.target, tpp = tar.parentNode.parentNode.parentNode; if (tpp.localName === "defs") { tpp = tar.parentNode.parentNode; //tppをfont-face要素としておく @@ -8545,42 +8548,32 @@ } else { //IE6-8ならば var ob = _doc.getElementsByTagName("object"), em = _doc.getElementsByTagName("embed"), - i = 0, s=[], - ifr, obi, n; - for (;ob[i];++i) { - obi = ob[i]; - s[s.length] = new GetSVGDocument(obi); - ifr = _doc.createElement("iframe"); - ifr.style.background = "black"; - n = obi.getAttribute("width"); - n && ifr.setAttribute("width", n); - n = obi.getAttribute("height"); - n && ifr.setAttribute("height", n); - ifr.marginWidth = ifr.marginHeight = "0px"; //このマージン設定がないと、全体がずれてしまう - ifr.scrolling = "no"; - ifr.frameBorder = "0"; - /*iframe要素を使って、描画のプロセスを分離する - *したがって、_docはdocumentとは別のオブジェクトとなる - */ - obi.parentNode.insertBefore(ifr, obi); - } - for (i=0;em[i];++i) { - obi = em[i]; - s[s.length] = new GetSVGDocument(obi); - ifr = _doc.createElement("iframe"); - ifr.style.background = "black"; - n = obi.getAttribute("width"); - n && ifr.setAttribute("width", n); - n = obi.getAttribute("height"); - n && ifr.setAttribute("height", n); - ifr.marginWidth = ifr.marginHeight = "0px"; //このマージン設定がないと、全体がずれてしまう - ifr.scrolling = "no"; - ifr.frameBorder = "0"; - obi.parentNode.insertBefore(ifr, obi); - } - ob = em = i = obi = ifr = null; - for (i=0;i<s.length;++i) { + _search = function(_ob) { + var ifr, obi, n; + for (var i=0;_ob[i];++i) { + obi = _ob[i]; + s[s.length] = new GetSVGDocument(obi); + ifr = _doc.createElement("iframe"); + ifr.style.background = "black"; + n = obi.getAttribute("width"); + n && ifr.setAttribute("width", n); + n = obi.getAttribute("height"); + n && ifr.setAttribute("height", n); + ifr.marginWidth = ifr.marginHeight = "0px"; //このマージン設定がないと、全体がずれてしまう + ifr.scrolling = "no"; + ifr.frameBorder = "0"; + /*iframe要素を使って、描画のプロセスを分離する + *したがって、_docはdocumentとは別のオブジェクトとなる + */ + obi.parentNode.insertBefore(ifr, obi); + } + i = obi = ifr = _ob = null; + }; + _search(ob); + _search(em); + ob = em = _search = null; + for (var i=0;i<s.length;++i) { if (i < s.length-1) { s[i]._next = s[i+1] }