OSDN Git Service

New the beginList and the endList property
authordhrname <dhrname@users.sourceforge.jp>
Sat, 1 Oct 2016 14:06:09 +0000 (23:06 +0900)
committerdhrname <dhrname@users.sourceforge.jp>
Sat, 1 Oct 2016 14:06:09 +0000 (23:06 +0900)
org/w3c/dom/smil.js
tool/Spec/spec/SvgDomSpec.js

index 1935197..e85e06c 100644 (file)
@@ -33,7 +33,7 @@ base("$frame").mix ( {
   /*タイムラインのリスト (時間区間の設定ができる)*/\r
   timelines: [],\r
 \r
-  /*開始フレーム数。アニメーションの開始条件となる\r
+  /*é\96\8bå§\8bã\83\95ã\83¬ã\83¼ã\83 æ\95°ã\81®å\80\99è£\9cã\80\82ã\82¢ã\83\8bã\83¡ã\83¼ã\82·ã\83§ã\83³ã\81®é\96\8bå§\8bæ\9d¡ä»¶ã\81¨ã\81ªã\82\8b\r
    * 単位はフレーム数であって、秒数ではない*/\r
   begin: 0,\r
 \r
@@ -44,6 +44,18 @@ base("$frame").mix ( {
   /*現在のフレーム数*/\r
   currentFrame: 0,\r
   \r
+  /*開始時刻リスト (後述のupdateStateメソッドで使う)*/\r
+  beginList: { \r
+    next: null,\r
+    value: 0\r
+  },\r
+  \r
+  /*終了時刻リスト (後述のupdateStateメソッドで使う)*/\r
+  endList: {\r
+     next: null,\r
+     value: Number.MAX_VALUE\r
+  },\r
+    \r
   /*現在の要素の状態を数値で示す(マジックナンバーは後述の大文字プロパティを使う)*/\r
   state: 0,\r
   \r
@@ -64,17 +76,28 @@ base("$frame").mix ( {
   \r
   /*引数で指定されたフレーム数に応じて、stateプロパティを更新するメソッド*/\r
   updateState: function( /*number*/ f) {\r
-    var state = this.state;\r
-    if (f == 0) {\r
-      /*フレーム数が更新できる条件を満たさなかったときは、stateプロパティを更新させない*/\r
-      return state;\r
-    }\r
-    var wait = this.WAITING,\r
+    var state = this.state,\r
+        wait = this.WAITING,\r
         begin = this.BEGINNING,\r
         play = this.PLAYING,\r
         end = this.ENDING,\r
         post = this.POSTWAITING;\r
-    if ( (state == wait) || (state == post) ) {\r
+    var list = this.beginList,\r
+        startTime = list.value; /*本当の開始時刻*/\r
+    while( list ) {\r
+      var v = list.value;\r
+      /*f以下の開始リスト値のうち、最大値をstartTimeに代入*/\r
+      if ( (v <= f)\r
+           && (startTime <= v) ) {\r
+        startTime = f;\r
+      }\r
+      list = list.next;\r
+    }\r
+    if ( (f !== void 0)\r
+         && (startTime < this.begin) ) {\r
+      /*フレーム数が更新できる条件を満たさなかったときは、stateプロパティを更新させない*/\r
+      return state;\r
+    } else if ( (state == wait) || (state == post) ) {\r
       return (this.state = begin);\r
     } else if (state == begin) {\r
       return (this.state = play);\r
@@ -82,6 +105,8 @@ base("$frame").mix ( {
       return (this.state = end);\r
     } else if (state == end) {\r
       return (this.state = post);\r
+    } else {\r
+      return begin;\r
     }\r
   },\r
   \r
index bb61c0c..3a2c522 100644 (file)
@@ -72,6 +72,15 @@ describe("SMIL Animation Spec", function() {
       expect(frame.ENDING).toBe(3);\r
       expect(frame.POSTWAITING).toBe(4);\r
       expect(frame.state).toBe(frame.WAITING);\r
+      \r
+      expect(frame.beginList).toEqual({\r
+              next: null,\r
+              value: 0\r
+            });\r
+      expect(frame.endList).toEqual({\r
+              next: null,\r
+              value: Number.MAX_VALUE\r
+            });\r
     });\r
     /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
     it("should be this for the value (the valid partion)", function() {\r
@@ -142,7 +151,7 @@ describe("SMIL Animation Spec", function() {
         begin: 1,\r
         activeTime: 2\r
       } );\r
-      expect(frame.timelines[2].activeTime).toBe(2)\r
+      expect(frame.timelines[2].activeTime).toBe(2);\r
     });\r
     /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
     it("should be this for the value (the invalid partion)", function() {\r
@@ -152,11 +161,12 @@ describe("SMIL Animation Spec", function() {
       frame.setFrame(0);\r
     });\r
       describe("the updateState method on $frame object", function() {\r
-        var frame = base("$frame");\r
+        var frame = base("$frame").up("$2");\r
         beforeEach( function() {\r
             frame.timelines = [];\r
             frame.isPaused = false;\r
             frame.state = frame.WAITING;\r
+            frame.begin = 0;\r
         } );\r
         afterEach( function() {\r
             frame.timelines = [];\r
@@ -175,6 +185,43 @@ describe("SMIL Animation Spec", function() {
           expect(frame.updateState()).toBe(frame.BEGINNING);\r
           expect(frame.state).toBe(frame.BEGINNING);\r
           \r
+          expect(frame.updateState(0)).toBe(frame.PLAYING);\r
+          expect(frame.state).toBe(frame.PLAYING);\r
+          frame.state = 100;\r
+          expect(frame.updateState()).toBe(frame.BEGINNING);\r
+          expect(frame.state).toBe(100);\r
+          \r
+          expect(frame.beginList).toEqual({\r
+              next: null,\r
+              value: 0\r
+            });\r
+          expect(frame.endList).toEqual({\r
+              next: null,\r
+              value: Number.MAX_VALUE\r
+            });\r
+        \r
+        } );\r
+        /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
+        it("should be this for the value (the valid partion)", function() {\r
+          expect(frame.updateState(0)).toBe(frame.BEGINNING);\r
+          expect(frame.state).toBe(frame.BEGINNING);\r
+          expect(frame.updateState(1)).toBe(frame.PLAYING);\r
+          expect(frame.state).toBe(frame.PLAYING);\r
+          expect(frame.updateState(2)).toBe(frame.ENDING);\r
+          expect(frame.state).toBe(frame.ENDING);\r
+          expect(frame.updateState(3)).toBe(frame.POSTWAITING);\r
+          expect(frame.state).toBe(frame.POSTWAITING);\r
+          expect(frame.updateState(4)).toBe(frame.BEGINNING);\r
+          expect(frame.state).toBe(frame.BEGINNING);\r
+          \r
+          function appendBegin(num) {\r
+            frame.state = frame.WAITING;\r
+            frame.beginList = {\r
+              value: num,\r
+              next: frame.beginList\r
+            };\r
+          };\r
+          appendBegin(0);\r
           expect(frame.updateState(0)).toBe(frame.BEGINNING);\r
           expect(frame.state).toBe(frame.BEGINNING);\r
         } );\r