OSDN Git Service

SVGTextContentElementのgetNumberOfCharsメソッドの修正とSpecの追加
authordhrname <dhrname@users.sourceforge.jp>
Tue, 10 Apr 2012 14:35:36 +0000 (23:35 +0900)
committerdhrname <dhrname@users.sourceforge.jp>
Tue, 10 Apr 2012 14:35:36 +0000 (23:35 +0900)
org/w3c/dom/svg.js
tool/Spec/spec/SvgDomSpec.js

index bed6660..d5eb50d 100644 (file)
@@ -3844,7 +3844,7 @@ function SVGTextContentElement(_doc) {
       /*a要素の場合はtarをすりかえておく*/
       tar = tar.firstChild;
     }
-    if ((eph === /*Event.CAPTURING_PHASE*/ 1) && (tar.nodeType === /*Node.TEXT_NODE*/ 3) && !!!tar._tars) {
+    if ((eph === /*Event.CAPTURING_PHASE*/ 1) && (tar.nodeType === /*Node.TEXT_NODE*/ 3) && !tar._tars) {
       /*Textノードにdiv要素を格納したリストをプロパティとして蓄えておく*/
       tar._tars = [];
       var data = tar.data.replace(/^\s+/, "").replace(/\s+$/, "");
@@ -3860,12 +3860,16 @@ function SVGTextContentElement(_doc) {
         tar._tars[tar._tars.length] = d;
       }
       data = void 0;
-      cur._length += tar._tars.length;
-    } else if ((eph === /*Event.CAPTURING_PHASE*/ 1) && (tar instanceof SVGTextContentElement) && !!!tar._tars) {
-      cur._length += tar._length;
     }
     evt = tar = cur = eph = void 0;
   }, true);
+  this.addEventListener("DOMNodeRemoved", function(evt){
+    var tar = evt.target;
+    if ((evt.eventPhase === /*Event.BUBBLING_PHASE*/ 3) && (tar.nodeType === /*Node.TEXT_NODE*/ 3)) {
+      delete evt.currentTarget._length;
+      tar = evt = void 0;
+    }
+  }, false);
  return this;
 };
 
@@ -3876,12 +3880,28 @@ t.prototype = new SVGElement();
   /*unsigned short*/ t.LENGTHADJUST_SPACING           = 1;
   /*unsigned short*/ t.LENGTHADJUST_SPACINGANDGLYPHS  = 2;
   t.prototype._list = null;         //文字の位置を格納しておくリストのキャッシュ
-  t.prototype._length = 0;          //全文字数
+  t.prototype._length = null;       //全文字数のキャッシュ
   t.prototype._stx = t.prototype._sty = 0; //初めの文字の位置
   t.prototype._chars = 0;           //tspan (tref)要素が全体の何文字目から始まっているか
-  t.prototype._isYokogaki = true;          //横書きかどうか
+  t.prototype._isYokogaki = true;   //横書きかどうか
 /*long*/     t.prototype.getNumberOfChars = function() {
-  return (this._length);
+  if (this._length) {
+    return (this._length);
+  } else {
+    var t = this.firstChild,
+        s = 0;
+    while (t) {
+      if (t.length && (t.nodeType === /*Node.TEXT_NODE*/ 3)) {
+        s += t.length;
+      } else if (t.getNumberOfChars) { //tspan要素などであれば
+        s += t.getNumberOfChars();
+      }
+      t = t.nextSibling;
+    }
+    this._length = s;
+    t = void 0;
+    return s;
+  }
 };
 /*float*/    t.prototype.getComputedTextLength = function() {
   var l = this.textLength.baseVal;
index b523c39..49fb7ee 100644 (file)
@@ -1310,7 +1310,7 @@ describe("SVG Spec in JavaScript", function() {
           str += "nん";
         }
         s.appendChild(s.ownerDocument.createTextNode(str));
-        expect(s.getNumberOfChars()).toEqual(str.length);
+        expect(s.getNumberOfChars()).toEqual(s.firstChild.length);
         s.removeChild(s.firstChild);
         str = "";
       }