From: dhrname Date: Sat, 8 Oct 2016 12:54:19 +0000 (+0900) Subject: Modify the updateState method X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=9619997183601656c5af59ec17bfc0ddd26f86c6;p=sie%2Fsie.git Modify the updateState method --- diff --git a/org/w3c/dom/smil.js b/org/w3c/dom/smil.js index 9b77118..e21f2d9 100644 --- a/org/w3c/dom/smil.js +++ b/org/w3c/dom/smil.js @@ -108,7 +108,7 @@ base("$frame").mix ( { /*開始時刻リスト (後述のupdateStateメソッドで使う)*/ beginList: { next: null, - value: 0 + value: Number.MAX_VALUE }, /*終了時刻リスト (後述のupdateStateメソッドで使う)*/ @@ -158,19 +158,20 @@ base("$frame").mix ( { return this; } var state = this.state, - wait = this.WAITING, - begin = this.BEGINNING, - play = this.PLAYING, - end = this.ENDING, - post = this.POSTWAITING, + wait = /*this.WAITING*/ 0, + begin = /*this.BEGINNING*/ 1, + play = /*this.PLAYING*/ 2, + end = /*this.ENDING*/ 3, + post = /*this.POSTWAITING*/ 4, isWait = (state === wait) || (state === post); /*beginListプロパティと、endListプロパティの中で、 * 現在フレーム数 f より大きい数値は、更新できる条件と無関係なので、除外しておく * また、f以下の値の中から、最大値を探して、 * それをbeginプロパティと比較する*/ var startTime = this.getMaxList(f, this.beginList), - endTime = this.getMaxList(f, this.endList); - if ( isWait && (startTime > this.begin) ) { + endTime = this.getMaxList(f, this.endList), + cacheBegin = this.begin; + if ( isWait && (startTime > cacheBegin) ) { this.state = begin; /*beginプロパティに開始時刻をキャッシュ用に保存*/ this.begin = startTime; @@ -182,17 +183,24 @@ base("$frame").mix ( { } else if (state === begin) { this.state = play; } else if (state === play) { - if ( (endTime >= this.begin) || (startTime > this.begin) ) { + if ( (endTime >= cacheBegin) || (startTime > cacheBegin) ) { /*終了時刻に到達したか、再び開始イベントが発火されたとき*/ this.state = end; } else { return this; } } else if (state === end) { - this.state = post; + if (endTime >= cacheBegin) { + this.state = post; + } else { + /*再生中に開始イベントが発火されて、終了状態となったとき*/ + this.state = begin; + this.begin = startTime; + } } else { this.state = begin; } + cacheBegin = startTime = endTime = void 0; return this; } } ); diff --git a/tool/Spec/spec/SvgDomSpec.js b/tool/Spec/spec/SvgDomSpec.js index 3ecbea6..5845a95 100644 --- a/tool/Spec/spec/SvgDomSpec.js +++ b/tool/Spec/spec/SvgDomSpec.js @@ -169,7 +169,7 @@ describe("SMIL Animation Spec", function() { expect(frame.beginList).toEqual({ next: null, - value: 0 + value: Number.MAX_VALUE }); expect(frame.endList).toEqual({ next: null, @@ -179,19 +179,15 @@ describe("SMIL Animation Spec", function() { expect(typeof frame.getMaxList).toBe("function"); expect(typeof frame.updateState).toBe("function"); - expect(frame.updateState(0).state).toBe(frame.BEGINNING); - expect(frame.state).toBe(frame.BEGINNING); - expect(frame.updateState(0).state).toBe(frame.PLAYING); - expect(frame.state).toBe(frame.PLAYING); - expect(frame.updateState(0).state).toBe(frame.PLAYING); - expect(frame.state).toBe(frame.PLAYING); - expect(frame.updateState(0).state).toBe(frame.PLAYING); - expect(frame.state).toBe(frame.PLAYING); - expect(frame.updateState(0).state).toBe(frame.PLAYING); - expect(frame.state).toBe(frame.PLAYING); + expect(frame.updateState(0).state).toBe(frame.WAITING); + expect(frame.state).toBe(frame.WAITING); + expect(frame.updateState(0).state).toBe(frame.WAITING); + expect(frame.state).toBe(frame.WAITING); + expect(frame.updateState(0).state).toBe(frame.WAITING); + expect(frame.state).toBe(frame.WAITING); + expect(frame.updateState(0).state).toBe(frame.WAITING); + expect(frame.state).toBe(frame.WAITING); - expect(frame.updateState(0).state).toBe(frame.PLAYING); - expect(frame.state).toBe(frame.PLAYING); frame.state = 100; expect(frame.updateState(0).state).toBe(frame.BEGINNING); expect(frame.state).toBe(frame.BEGINNING); @@ -200,38 +196,28 @@ describe("SMIL Animation Spec", function() { expect(frame.beginList).toEqual({ next: null, - value: 0 + value: Number.MAX_VALUE }); expect(frame.endList).toEqual({ next: null, value: Number.MAX_VALUE }); - expect(frame.getMaxList(0, frame.beginList)).toBe(0); + expect(frame.getMaxList(0, frame.beginList)).toBe(-1); expect(frame.getMaxList(0, frame.endList)).toBe(-1); } ); /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/ it("should be this for the value (the valid partion)", function() { - expect(frame.updateState(0).state).toBe(frame.BEGINNING); - expect(frame.state).toBe(frame.BEGINNING); - expect(frame.updateState(1).state).toBe(frame.PLAYING); - expect(frame.state).toBe(frame.PLAYING); - expect(frame.updateState(2).state).toBe(frame.PLAYING); - expect(frame.state).toBe(frame.PLAYING); - expect(frame.updateState(3).state).toBe(frame.PLAYING); - expect(frame.state).toBe(frame.PLAYING); - expect(frame.updateState(4).state).toBe(frame.PLAYING); - expect(frame.state).toBe(frame.PLAYING); function appendBegin(num) { frame.state = frame.WAITING; - frame.begin = num; frame.beginList = { value: num, next: frame.beginList }; }; appendBegin(0); + expect(frame.getMaxList(0, frame.beginList)).toBe(0); expect(frame.updateState(0).state).toBe(frame.BEGINNING); expect(frame.begin).toBe(0); expect(frame.updateState(0).state).toBe(frame.PLAYING); @@ -239,9 +225,24 @@ describe("SMIL Animation Spec", function() { expect(frame.updateState(0).state).toBe(frame.PLAYING); expect(frame.state).toBe(frame.PLAYING); + frame.state = frame.WAITING; + expect(frame.getMaxList(0, frame.beginList)).toBe(0); + expect(frame.updateState(0).state).toBe(frame.BEGINNING); + expect(frame.state).toBe(frame.BEGINNING); + expect(frame.updateState(1).state).toBe(frame.PLAYING); + expect(frame.state).toBe(frame.PLAYING); + expect(frame.updateState(2).state).toBe(frame.PLAYING); + expect(frame.state).toBe(frame.PLAYING); + expect(frame.updateState(3).state).toBe(frame.PLAYING); + expect(frame.state).toBe(frame.PLAYING); + expect(frame.updateState(4).state).toBe(frame.PLAYING); + expect(frame.state).toBe(frame.PLAYING); + appendBegin(1); + expect(frame.getMaxList(1, frame.beginList)).toBe(1); expect(frame.updateState(0).state).toBe(frame.BEGINNING); expect(frame.updateState(0).state).toBe(frame.PLAYING); + expect(frame.updateState(0).state).toBe(frame.PLAYING); expect(frame.updateState(1).state).toBe(frame.ENDING); expect(frame.updateState(1).state).toBe(frame.BEGINNING); expect(frame.state).toBe(frame.BEGINNING); @@ -266,6 +267,7 @@ describe("SMIL Animation Spec", function() { function appendEnd(num) { frame.state = frame.WAITING; + frame.begin = 0; frame.endList = { value: num, next: frame.endList