TextTrack modes are strings
authorannacc@chromium.org <annacc@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Aug 2012 20:12:39 +0000 (20:12 +0000)
committerannacc@chromium.org <annacc@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Aug 2012 20:12:39 +0000 (20:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=85050

Reviewed by Eric Carlson.

The spec recently changed away from enumeration to string for the type
of TextTrack mode.
http://dev.w3.org/html5/spec/media-elements.html#texttrackmode

Source/WebCore:

No new tests. Updates to existing tests.

* html/HTMLMediaElement.cpp:

Use the new string mode rather than the old enum.  Also, TextTrack::setMode()
no longer requires an ExceptionCode:
(WebCore::HTMLMediaElement::loadInternal):
(WebCore::HTMLMediaElement::textTrackModeChanged):
(WebCore::HTMLMediaElement::textTrackKindChanged):
(WebCore::HTMLMediaElement::addTextTrack):
(WebCore::HTMLMediaElement::showingTrackWithSameKind):
(WebCore::HTMLMediaElement::configureTextTrackGroup):
(WebCore::HTMLMediaElement::configureNewTextTracks):
(WebCore::HTMLMediaElement::configureTextTrackDisplay):

* html/track/TextTrack.cpp:

Update these methods to use ConstructFromLiteral for efficiency:
(WebCore::TextTrack::subtitlesKeyword):
(WebCore::TextTrack::captionsKeyword):
(WebCore::TextTrack::descriptionsKeyword):
(WebCore::TextTrack::chaptersKeyword):
(WebCore::TextTrack::metadataKeyword):

New methods to use for the mode string (replacing the enum):
(WebCore::TextTrack::disabledKeyword):
(WebCore::TextTrack::hiddenKeyword):
(WebCore::TextTrack::showingKeyword):

(WebCore::TextTrack::TextTrack): Initialize mode to disabled.
(WebCore::TextTrack::setMode): Remove ExceptionCode and no longer throw an
INVALID_ACCESS_ERR.
(WebCore::TextTrack::mode): Return a keyword string instead of an enum.

Use the new string mode rather than the old enum:
(WebCore::TextTrack::cues):
(WebCore::TextTrack::activeCues):
(WebCore::TextTrack::isRendered):

* html/track/TextTrack.h: Remove old enum, add new string keyword methods,
and update mode() and setMode() accordingly.

* html/track/TextTrack.idl: Remove old enum and make mode attribute be a string.

Use the new string mode rather than the old enum:
* html/track/TextTrackCue.cpp:
(WebCore::TextTrackCue::dispatchEvent):
(WebCore::TextTrackCue::isActive):

LayoutTests:

Remove check for mode constants as we are no longer using an enum:
* media/track/track-constants-expected.txt:
* media/track/track-constants.html:

Update tests to use the new strings rather than the enums:
* media/track/track-delete-during-setup-expected.txt:
* media/track/track-delete-during-setup.html:
* media/track/track-element-dom-change-crash-expected.txt:
* media/track/track-element-dom-change-crash.html:
* media/track/track-load-from-src-readyState.html:
* media/track/track-mode-expected.txt:
* media/track/track-mode-not-changed-by-new-track-expected.txt:
* media/track/track-mode-not-changed-by-new-track.html:
* media/track/track-mode-triggers-loading-expected.txt:
* media/track/track-mode-triggers-loading.html:
* media/track/track-mode.html:
* media/track/track-texttracks-expected.txt:
* media/track/track-texttracks.html:
* media/video-test.js:
(enableAllTextTracks):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@126786 268f45cc-cd09-0410-ab3c-d52691b4dbfc

23 files changed:
LayoutTests/ChangeLog
LayoutTests/media/track/track-constants-expected.txt
LayoutTests/media/track/track-constants.html
LayoutTests/media/track/track-delete-during-setup-expected.txt
LayoutTests/media/track/track-delete-during-setup.html
LayoutTests/media/track/track-element-dom-change-crash-expected.txt
LayoutTests/media/track/track-element-dom-change-crash.html
LayoutTests/media/track/track-load-from-src-readyState.html
LayoutTests/media/track/track-mode-expected.txt
LayoutTests/media/track/track-mode-not-changed-by-new-track-expected.txt
LayoutTests/media/track/track-mode-not-changed-by-new-track.html
LayoutTests/media/track/track-mode-triggers-loading-expected.txt
LayoutTests/media/track/track-mode-triggers-loading.html
LayoutTests/media/track/track-mode.html
LayoutTests/media/track/track-texttracks-expected.txt
LayoutTests/media/track/track-texttracks.html
LayoutTests/media/video-test.js
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/track/TextTrack.cpp
Source/WebCore/html/track/TextTrack.h
Source/WebCore/html/track/TextTrack.idl
Source/WebCore/html/track/TextTrackCue.cpp

index eb042c4..0974b1e 100644 (file)
@@ -1,3 +1,35 @@
+2012-08-27  Anna Cavender  <annacc@chromium.org>
+
+        TextTrack modes are strings
+        https://bugs.webkit.org/show_bug.cgi?id=85050
+
+        Reviewed by Eric Carlson.
+
+        The spec recently changed away from enumeration to string for the type
+        of TextTrack mode.
+        http://dev.w3.org/html5/spec/media-elements.html#texttrackmode
+
+        Remove check for mode constants as we are no longer using an enum:
+        * media/track/track-constants-expected.txt:
+        * media/track/track-constants.html:
+
+        Update tests to use the new strings rather than the enums:
+        * media/track/track-delete-during-setup-expected.txt:
+        * media/track/track-delete-during-setup.html:
+        * media/track/track-element-dom-change-crash-expected.txt:
+        * media/track/track-element-dom-change-crash.html:
+        * media/track/track-load-from-src-readyState.html:
+        * media/track/track-mode-expected.txt:
+        * media/track/track-mode-not-changed-by-new-track-expected.txt:
+        * media/track/track-mode-not-changed-by-new-track.html:
+        * media/track/track-mode-triggers-loading-expected.txt:
+        * media/track/track-mode-triggers-loading.html:
+        * media/track/track-mode.html:
+        * media/track/track-texttracks-expected.txt:
+        * media/track/track-texttracks.html:
+        * media/video-test.js:
+        (enableAllTextTracks):
+
 2012-08-27  Mike West  <mkwst@chromium.org>
 
         'self' in a CSP directive should match blob: and filesystem: URLs.
index 83ac544..e5b0940 100644 (file)
@@ -4,9 +4,5 @@ EXPECTED (HTMLTrackElement.NONE == '0') OK
 EXPECTED (HTMLTrackElement.LOADING == '1') OK
 EXPECTED (HTMLTrackElement.LOADED == '2') OK
 EXPECTED (HTMLTrackElement.ERROR == '3') OK
-
-EXPECTED (TextTrack.DISABLED == '0') OK
-EXPECTED (TextTrack.HIDDEN == '1') OK
-EXPECTED (TextTrack.SHOWING == '2') OK
 END OF TEST
 
index 42305cf..e55e2f8 100644 (file)
@@ -9,11 +9,6 @@
             testExpected("HTMLTrackElement.LOADING", 1);
             testExpected("HTMLTrackElement.LOADED", 2);
             testExpected("HTMLTrackElement.ERROR", 3);
-            consoleWrite("");
-
-            testExpected("TextTrack.DISABLED", 0);
-            testExpected("TextTrack.HIDDEN", 1);
-            testExpected("TextTrack.SHOWING", 2);
         
             endTest();
         }
index 6859137..75f353c 100644 (file)
@@ -1,7 +1,7 @@
 >
 
 EXPECTED (track1.readyState == '0') OK
-EXPECTED (track1.track.mode == '0') OK
+EXPECTED (track1.track.mode == 'disabled') OK
 
 END OF TEST
 
index b7a7527..c249bbf 100644 (file)
@@ -19,7 +19,7 @@
 
             function canplaythrough()
             {
-                track1.track.mode = TextTrack.HIDDEN;
+                track1.track.mode = "hidden";
                 setTimeout("endTest()", 100);
             }
 
@@ -30,7 +30,7 @@
 
                 track1 = document.querySelectorAll('track')[0]; 
                 testExpected("track1.readyState", HTMLTrackElement.NONE);
-                testExpected("track1.track.mode", TextTrack.DISABLED);
+                testExpected("track1.track.mode", "disabled");
 
                 video.src = findMediaFile("video", "../content/test");
                 consoleWrite("");
index cb4d305..45156c7 100644 (file)
@@ -2,7 +2,7 @@ Tests that the browser handles properly simple DOM mutations.
 
 ** Create video and text track element **
 ** Append the track element to the video element **
-** Set the mode of the text track to SHOWING **
+** Set the mode of the text track to "showing" **
 
 No crash. PASS.
 
index dd6e518..d38711c 100644 (file)
@@ -15,8 +15,8 @@
                 consoleWrite("** Append the track element to the video element **");
                 video.appendChild(track);
 
-                consoleWrite("** Set the mode of the text track to SHOWING **");
-                track.track.mode = 2;
+                consoleWrite("** Set the mode of the text track to \"showing\" **");
+                track.track.mode = "showing";
 
                 consoleWrite("");
                 consoleWrite("No crash. PASS.");
index 5cc4a06..e2d9086 100644 (file)
@@ -24,7 +24,7 @@
             testExpected("track.readyState", HTMLTrackElement.NONE);
             track.addEventListener("load", function () { trackLoaded(); }, true);
             track.src = "captions-webvtt/tc004-webvtt-file.vtt";   
-            track.mode = TextTrack.HIDDEN;
+            track.mode = "hidden";
 
         </script>
     </body>
index b4d5d90..19edc96 100644 (file)
@@ -2,36 +2,36 @@ Tests that the TextTrack mode attribute is appropriately set.
 
 
 ++ Test default attribute value
-EXPECTED (textTrack.mode == '2') OK
-EXPECTED (video.textTracks[0].mode == '2') OK
+EXPECTED (textTrack.mode == 'showing') OK
+EXPECTED (video.textTracks[0].mode == 'showing') OK
 
 *** Set to bogus value, should return default
-TEST(textTrack.mode = '37') THROWS(DOMException.INVALID_ACCESS_ERR) OK
-EXPECTED (textTrack.mode == '2') OK
-EXPECTED (video.textTracks[0].mode == '2') OK
+RUN(textTrack.mode = 'bogus')
+EXPECTED (textTrack.mode == 'showing') OK
+EXPECTED (video.textTracks[0].mode == 'showing') OK
 
 *** Set to known values
-++ 'TextTrack.DISABLED'
-RUN(textTrack.mode = '0')
-EXPECTED (textTrack.mode == '0') OK
-EXPECTED (video.textTracks[0].mode == '0') OK
+++ 'disabled'
+RUN(textTrack.mode = 'disabled')
+EXPECTED (textTrack.mode == 'disabled') OK
+EXPECTED (video.textTracks[0].mode == 'disabled') OK
 EXPECTED (textTrack.cues == 'null') OK
 
-++ 0 events expected while mode = TextTrack.DISABLED
+++ 0 events expected while mode = disabled
 
-++ 'TextTrack.HIDDEN'
-RUN(textTrack.mode = '1')
-EXPECTED (textTrack.mode == '1') OK
-EXPECTED (video.textTracks[0].mode == '1') OK
+++ 'hidden'
+RUN(textTrack.mode = 'hidden')
+EXPECTED (textTrack.mode == 'hidden') OK
+EXPECTED (video.textTracks[0].mode == 'hidden') OK
 EXPECTED (textTrack.cues.length == '3') OK
 
-++ 'TextTrack.SHOWING'
-RUN(textTrack.mode = '2')
-EXPECTED (textTrack.mode == '2') OK
-EXPECTED (video.textTracks[0].mode == '2') OK
+++ 'showing'
+RUN(textTrack.mode = 'showing')
+EXPECTED (textTrack.mode == 'showing') OK
+EXPECTED (video.textTracks[0].mode == 'showing') OK
 EXPECTED (textTrack.cues.length == '3') OK
 
-++ at least 3 events expected while mode = TextTrack.SHOWING
+++ at least 3 events expected while mode = showing
 EVENT(cuechange)
 EVENT(cuechange)
 EVENT(cuechange)
index 84c4922..66a3d66 100644 (file)
@@ -3,19 +3,19 @@ Tests that a track appended after the initial track configuration does not chang
 
 EVENT(load) -- <body>
 EXPECTED (track1.readyState == '0') OK
-EXPECTED (track1.track.mode == '0') OK
+EXPECTED (track1.track.mode == 'disabled') OK
 
 EVENT(canplaythrough) -- <video>
 **check initial metadata track state
 EXPECTED (track1.readyState == '0') OK
-EXPECTED (track1.track.mode == '0') OK
+EXPECTED (track1.track.mode == 'disabled') OK
 EXPECTED (track1.track.cues == 'null') OK
-RUN(track1.track.mode = TextTrack.HIDDEN)
+RUN(track1.track.mode = 'hidden')
 
 EVENT(load) -- <track kind='metadata' >
 **check metadata track state
 EXPECTED (track1.readyState == '2') OK
-EXPECTED (track1.track.mode == '1') OK
+EXPECTED (track1.track.mode == 'hidden') OK
 EXPECTED (track1.track.cues.length == '12') OK
 EXPECTED (track1.track.cues[11].startTime == '22') OK
 **add a caption track, configured to load automatically
@@ -29,10 +29,10 @@ RUN(video.appendChild(track2))
 EVENT(load) -- <track kind='captions' >
 **check that metadata track state has not changed
 EXPECTED (track1.readyState == '2') OK
-EXPECTED (track1.track.mode == '1') OK
+EXPECTED (track1.track.mode == 'hidden') OK
 **and that the captions track state is correct
 EXPECTED (track2.readyState == '2') OK
-EXPECTED (track2.track.mode == '2') OK
+EXPECTED (track2.track.mode == 'showing') OK
 
 END OF TEST
 
index 40e9bb8..6b7d8a8 100644 (file)
                 consoleWrite("EVENT(load) -- &lt;track kind='captions' &gt;");
                 consoleWrite("<i>**check that metadata track state has not changed<" + "/i>");
                 testExpected("track1.readyState", HTMLTrackElement.LOADED);
-                testExpected("track1.track.mode", TextTrack.HIDDEN);
+                testExpected("track1.track.mode", "hidden");
                 consoleWrite("<i>**and that the captions track state is correct<" + "/i>");
                 testExpected("track2.readyState", HTMLTrackElement.LOADED);
-                testExpected("track2.track.mode", TextTrack.SHOWING);
+                testExpected("track2.track.mode", "showing");
                 consoleWrite("");
                 endTest();
             }
@@ -25,7 +25,7 @@
                 consoleWrite("EVENT(load) -- &lt;track kind='metadata' &gt;");
                 consoleWrite("<i>**check metadata track state<" + "/i>");
                 testExpected("track1.readyState", HTMLTrackElement.LOADED);
-                testExpected("track1.track.mode", TextTrack.HIDDEN);
+                testExpected("track1.track.mode", "hidden");
                 testExpected("track1.track.cues.length", 12);
                 testExpected("track1.track.cues[11].startTime", 22);
 
@@ -45,9 +45,9 @@
                 consoleWrite("EVENT(canplaythrough) -- &lt;video&gt;");
                 consoleWrite("<i>**check initial metadata track state<" + "/i>");
                 testExpected("track1.readyState", HTMLTrackElement.NONE);
-                testExpected("track1.track.mode", TextTrack.DISABLED);
+                testExpected("track1.track.mode", "disabled");
                 testExpected("track1.track.cues", null);
-                run("track1.track.mode = TextTrack.HIDDEN");
+                run("track1.track.mode = 'hidden'");
                 consoleWrite("");
             }
 
@@ -58,7 +58,7 @@
 
                 track1 = document.querySelectorAll('track')[0]; 
                 testExpected("track1.readyState", HTMLTrackElement.NONE);
-                testExpected("track1.track.mode", TextTrack.DISABLED);
+                testExpected("track1.track.mode", "disabled");
 
                 video.src = findMediaFile("video", "../content/test");
                 consoleWrite("");
index 195f946..03a0eb3 100644 (file)
@@ -4,19 +4,19 @@ Tests that a 'metadata' track does not load automatically, but does load when th
 EVENT(load) -- <body>
 **check initial metadata track state
 EXPECTED (track.readyState == '0') OK
-EXPECTED (video.textTracks[0].mode == '0') OK
+EXPECTED (video.textTracks[0].mode == 'disabled') OK
 
 EVENT(canplaythrough) -- <video>
 **change metadata track mode so it loads
 EXPECTED (track.readyState == '0') OK
-EXPECTED (video.textTracks[0].mode == '0') OK
+EXPECTED (video.textTracks[0].mode == 'disabled') OK
 EXPECTED (video.textTracks[0].cues == 'null') OK
-RUN(video.textTracks[0].mode = TextTrack.HIDDEN)
+RUN(video.textTracks[0].mode = 'hidden')
 
 EVENT(load) -- <track>
 **check metadata track state
 EXPECTED (track.readyState == '2') OK
-EXPECTED (track.track.mode == '1') OK
+EXPECTED (track.track.mode == 'hidden') OK
 EXPECTED (video.textTracks[0].cues.length == '12') OK
 EXPECTED (video.textTracks[0].cues[11].startTime == '22') OK
 
index 94e116c..64e68f3 100644 (file)
@@ -12,7 +12,7 @@
                 consoleWrite("EVENT(load) -- &lt;track&gt;");
                 consoleWrite("<i>**check metadata track state<" + "/i>");
                 testExpected("track.readyState", HTMLTrackElement.LOADED);
-                testExpected("track.track.mode", TextTrack.HIDDEN);
+                testExpected("track.track.mode", "hidden");
                 testExpected("video.textTracks[0].cues.length", 12);
                 testExpected("video.textTracks[0].cues[11].startTime", 22);
                 consoleWrite("");
@@ -24,9 +24,9 @@
                 consoleWrite("EVENT(canplaythrough) -- &lt;video&gt;");
                 consoleWrite("<i>**change metadata track mode so it loads<" + "/i>");
                 testExpected("track.readyState", HTMLTrackElement.NONE);
-                testExpected("video.textTracks[0].mode", TextTrack.DISABLED);
+                testExpected("video.textTracks[0].mode", "disabled");
                 testExpected("video.textTracks[0].cues", null);
-                run("video.textTracks[0].mode = TextTrack.HIDDEN");
+                run("video.textTracks[0].mode = 'hidden'");
                 consoleWrite("");
             }
 
@@ -38,7 +38,7 @@
                 consoleWrite("<i>**check initial metadata track state<" + "/i>");
                 track = document.querySelectorAll('track')[0]; 
                 testExpected("track.readyState", HTMLTrackElement.NONE);
-                testExpected("video.textTracks[0].mode", TextTrack.DISABLED);
+                testExpected("video.textTracks[0].mode", "disabled");
 
                 video.src = findMediaFile("video", "../content/test");
                 consoleWrite("");
index 8467b04..82e35bd 100644 (file)
@@ -14,7 +14,7 @@
                 run("textTrack.mode = '" + value + "'");
                 testExpected("textTrack.mode", value);
                 testExpected("video.textTracks[0].mode", value);
-                if (value == TextTrack.DISABLED)
+                if (value == "disabled")
                     testExpected("textTrack.cues", null);
                 else
                     testExpected("textTrack.cues.length", textTrack.cues.length);
                 textTrack = document.getElementById('track_1').track;
 
                 consoleWrite("<b>++ Test default attribute value</b>");
-                testExpected("textTrack.mode", TextTrack.SHOWING);
-                testExpected("video.textTracks[0].mode", TextTrack.SHOWING);
+                testExpected("textTrack.mode", "showing");
+                testExpected("video.textTracks[0].mode", "showing");
                 consoleWrite("");
 
                 consoleWrite("<b>*** Set to bogus value, should return default</b>");
-                var value = 37;
-                testException("textTrack.mode = '" + value + "'", "DOMException.INVALID_ACCESS_ERR");
-                testExpected("textTrack.mode", TextTrack.SHOWING);
-                testExpected("video.textTracks[0].mode", TextTrack.SHOWING);
+                var value = "bogus";
+                run("textTrack.mode = '" + value + "'");
+                testExpected("textTrack.mode", "showing");
+                testExpected("video.textTracks[0].mode", "showing");
                 consoleWrite("");
 
                 consoleWrite("<b>*** Set to known values</b>");
-                consoleWrite("<b>++ 'TextTrack.DISABLED'</b>");
-                setMode(TextTrack.DISABLED);
+                consoleWrite("<b>++ 'disabled'</b>");
+                setMode("disabled");
 
                 video.src = findMediaFile("video", "../content/test");
                 video.play();
                 // Wait for end of first cue (no events should fire while track is disabled).
                 setTimeout(testHiddenAndShowing, 400);
-                consoleWrite("++ 0 events expected while mode = TextTrack.DISABLED");
+                consoleWrite("++ 0 events expected while mode = disabled");
                 consoleWrite("");
             }
             
             function testHiddenAndShowing()
             {
-                consoleWrite("<b>++ 'TextTrack.HIDDEN'</b>");
-                setMode(TextTrack.HIDDEN);
+                consoleWrite("<b>++ 'hidden'</b>");
+                setMode("hidden");
 
-                consoleWrite("<b>++ 'TextTrack.SHOWING'</b>");
-                setMode(TextTrack.SHOWING);
+                consoleWrite("<b>++ 'showing'</b>");
+                setMode("showing");
 
-                consoleWrite("++ at least " + textTrack.cues.length + " events expected while mode = TextTrack.SHOWING");
+                consoleWrite("++ at least " + textTrack.cues.length + " events expected while mode = showing");
             }
             
             waitForEvent('cuechange',
index ac5e4d1..4dd61e6 100644 (file)
@@ -15,7 +15,7 @@ EXPECTED (video.textTracks[1].kind == 'chapters') OK
 EXPECTED (video.textTracks[2].kind == 'descriptions') OK
 
 ** Verify the default parameters of the text track object returned by addTextTrack(). **
-EXPECTED (video.textTracks[2].mode == TextTrack.HIDDEN == 'true') OK
+EXPECTED (video.textTracks[2].mode == 'hidden' == 'true') OK
 EXPECTED (video.textTracks[2].cues != null == 'true') OK
 EXPECTED (video.textTracks[2].cues.length == 0 == 'true') OK
 
index 5cf4036..f257185 100644 (file)
@@ -28,7 +28,7 @@
                 testExpected("video.textTracks[2].kind", "descriptions");
 
                 consoleWrite("<br>** Verify the default parameters of the text track object returned by addTextTrack(). **");
-                testExpected("video.textTracks[2].mode == TextTrack.HIDDEN", true);
+                testExpected("video.textTracks[2].mode == 'hidden'", true);
                 testExpected("video.textTracks[2].cues != null", true);
                 testExpected("video.textTracks[2].cues.length == 0", true);
 
index edfddbb..0f28486 100644 (file)
@@ -314,8 +314,8 @@ function enableAllTextTracks()
 {
     findMediaElement();
     for (var i = 0; i < video.textTracks.length; i++) {
-        if (video.textTracks[i].mode == TextTrack.DISABLED)
-            video.textTracks[i].mode = TextTrack.HIDDEN;
+        if (video.textTracks[i].mode == "disabled")
+            video.textTracks[i].mode = "hidden";
     }
 }
 
index bc975e6..771575c 100644 (file)
@@ -1,3 +1,63 @@
+2012-08-27  Anna Cavender  <annacc@chromium.org>
+
+        TextTrack modes are strings
+        https://bugs.webkit.org/show_bug.cgi?id=85050
+
+        Reviewed by Eric Carlson.
+
+        The spec recently changed away from enumeration to string for the type
+        of TextTrack mode.
+        http://dev.w3.org/html5/spec/media-elements.html#texttrackmode
+
+        No new tests. Updates to existing tests.
+
+        * html/HTMLMediaElement.cpp:
+
+        Use the new string mode rather than the old enum.  Also, TextTrack::setMode()
+        no longer requires an ExceptionCode:
+        (WebCore::HTMLMediaElement::loadInternal):
+        (WebCore::HTMLMediaElement::textTrackModeChanged):
+        (WebCore::HTMLMediaElement::textTrackKindChanged):
+        (WebCore::HTMLMediaElement::addTextTrack):
+        (WebCore::HTMLMediaElement::showingTrackWithSameKind):
+        (WebCore::HTMLMediaElement::configureTextTrackGroup):
+        (WebCore::HTMLMediaElement::configureNewTextTracks):
+        (WebCore::HTMLMediaElement::configureTextTrackDisplay):
+
+        * html/track/TextTrack.cpp:
+
+        Update these methods to use ConstructFromLiteral for efficiency:
+        (WebCore::TextTrack::subtitlesKeyword):
+        (WebCore::TextTrack::captionsKeyword):
+        (WebCore::TextTrack::descriptionsKeyword):
+        (WebCore::TextTrack::chaptersKeyword):
+        (WebCore::TextTrack::metadataKeyword):
+
+        New methods to use for the mode string (replacing the enum):
+        (WebCore::TextTrack::disabledKeyword):
+        (WebCore::TextTrack::hiddenKeyword):
+        (WebCore::TextTrack::showingKeyword):
+
+        (WebCore::TextTrack::TextTrack): Initialize mode to disabled.
+        (WebCore::TextTrack::setMode): Remove ExceptionCode and no longer throw an
+        INVALID_ACCESS_ERR.
+        (WebCore::TextTrack::mode): Return a keyword string instead of an enum.
+
+        Use the new string mode rather than the old enum:
+        (WebCore::TextTrack::cues):
+        (WebCore::TextTrack::activeCues):
+        (WebCore::TextTrack::isRendered):
+
+        * html/track/TextTrack.h: Remove old enum, add new string keyword methods,
+        and update mode() and setMode() accordingly.
+
+        * html/track/TextTrack.idl: Remove old enum and make mode attribute be a string.
+
+        Use the new string mode rather than the old enum:
+        * html/track/TextTrackCue.cpp:
+        (WebCore::TextTrackCue::dispatchEvent):
+        (WebCore::TextTrackCue::isActive):
+
 2012-08-27  Mike West  <mkwst@chromium.org>
 
         'self' in a CSP directive should match blob: and filesystem: URLs.
index 02a5645..d4603fd 100644 (file)
@@ -777,7 +777,7 @@ void HTMLMediaElement::loadInternal()
         if (m_textTracks) {
             for (unsigned i = 0; i < m_textTracks->length(); ++i) {
                 TextTrack* track = m_textTracks->item(i);
-                if (track->mode() != TextTrack::DISABLED)
+                if (track->mode() != TextTrack::disabledKeyword())
                     m_textTracksWhenResourceSelectionBegan.append(track);
             }
         }
@@ -1295,7 +1295,7 @@ void HTMLMediaElement::textTrackModeChanged(TextTrack* track)
             
             // Mark this track as "configured" so configureNewTextTracks won't change the mode again.
             trackElement->setHasBeenConfigured(true);
-            if (track->mode() != TextTrack::DISABLED) {
+            if (track->mode() != TextTrack::disabledKeyword()) {
                 if (trackElement->readyState() == HTMLTrackElement::LOADED)
                     textTrackAddCues(track, track->cues());
                 else if (trackElement->readyState() == HTMLTrackElement::NONE)
@@ -1314,8 +1314,8 @@ void HTMLMediaElement::textTrackModeChanged(TextTrack* track)
 
 void HTMLMediaElement::textTrackKindChanged(TextTrack* track)
 {
-    if (track->kind() != TextTrack::captionsKeyword() && track->kind() != TextTrack::subtitlesKeyword() && track->mode() == TextTrack::SHOWING)
-        track->setMode(TextTrack::HIDDEN, ASSERT_NO_EXCEPTION);
+    if (track->kind() != TextTrack::captionsKeyword() && track->kind() != TextTrack::subtitlesKeyword() && track->mode() == TextTrack::showingKeyword())
+        track->setMode(TextTrack::hiddenKeyword());
 }
 
 void HTMLMediaElement::textTrackAddCues(TextTrack*, const TextTrackCueList* cues) 
@@ -2688,7 +2688,7 @@ PassRefPtr<TextTrack> HTMLMediaElement::addTextTrack(const String& kind, const S
     textTrack->setReadinessState(TextTrack::Loaded);
 
     // ... its text track mode to the text track hidden mode, and its text track list of cues to an empty list ...
-    textTrack->setMode(TextTrack::HIDDEN, ec);
+    textTrack->setMode(TextTrack::hiddenKeyword());
 
     return textTrack.release();
 }
@@ -2713,7 +2713,7 @@ HTMLTrackElement* HTMLMediaElement::showingTrackWithSameKind(HTMLTrackElement* t
             continue;
 
         HTMLTrackElement* showingTrack = static_cast<HTMLTrackElement*>(node);
-        if (showingTrack->kind() == trackElement->kind() && showingTrack->track()->mode() == TextTrack::SHOWING)
+        if (showingTrack->kind() == trackElement->kind() && showingTrack->track()->mode() == TextTrack::showingKeyword())
             return showingTrack;
     }
     
@@ -2864,10 +2864,9 @@ void HTMLMediaElement::configureTextTrackGroup(const TrackGroup& group) const
     for (size_t i = 0; i < group.tracks.size(); ++i) {
         HTMLTrackElement* trackElement = group.tracks[i];
         RefPtr<TextTrack> textTrack = trackElement->track();
-        ExceptionCode unusedException;
         
         if (trackElementToEnable == trackElement) {
-            textTrack->setMode(TextTrack::SHOWING, unusedException);
+            textTrack->setMode(TextTrack::showingKeyword());
             if (defaultTrack == trackElement)
                 textTrack->setShowingByDefault(true);
         } else {
@@ -2876,18 +2875,17 @@ void HTMLMediaElement::configureTextTrackGroup(const TrackGroup& group) const
                 // mode is showing by default, the user agent must furthermore change that text track's
                 // text track mode to hidden.
                 textTrack->setShowingByDefault(false);
-                textTrack->setMode(TextTrack::HIDDEN, unusedException);
+                textTrack->setMode(TextTrack::hiddenKeyword());
             } else
-                textTrack->setMode(TextTrack::DISABLED, unusedException);
+                textTrack->setMode(TextTrack::disabledKeyword());
         }
     }
 
     if (trackElementToEnable && group.defaultTrack && group.defaultTrack != trackElementToEnable) {
         RefPtr<TextTrack> textTrack = group.defaultTrack->track();
         if (textTrack && textTrack->showingByDefault()) {
-            ExceptionCode unusedException;
             textTrack->setShowingByDefault(false);
-            textTrack->setMode(TextTrack::HIDDEN, unusedException);
+            textTrack->setMode(TextTrack::hiddenKeyword());
         }
     }
 }
@@ -2922,7 +2920,7 @@ void HTMLMediaElement::configureNewTextTracks()
         else
             currentGroup = &otherTracks;
 
-        if (!currentGroup->visibleTrack && textTrack->mode() == TextTrack::SHOWING)
+        if (!currentGroup->visibleTrack && textTrack->mode() == TextTrack::showingKeyword())
             currentGroup->visibleTrack = trackElement;
         if (!currentGroup->defaultTrack && trackElement->isDefault())
             currentGroup->defaultTrack = trackElement;
@@ -4093,7 +4091,7 @@ void HTMLMediaElement::configureTextTrackDisplay()
 
     bool haveVisibleTextTrack = false;
     for (unsigned i = 0; i < m_textTracks->length(); ++i) {
-        if (m_textTracks->item(i)->mode() == TextTrack::SHOWING) {
+        if (m_textTracks->item(i)->mode() == TextTrack::showingKeyword()) {
             haveVisibleTextTrack = true;
             break;
         }
index addc875..6abcacc 100644 (file)
@@ -48,41 +48,59 @@ static const int invalidTrackIndex = -1;
 
 const AtomicString& TextTrack::subtitlesKeyword()
 {
-    DEFINE_STATIC_LOCAL(const AtomicString, subtitles, ("subtitles"));
+    DEFINE_STATIC_LOCAL(const AtomicString, subtitles, ("subtitles", AtomicString::ConstructFromLiteral));
     return subtitles;
 }
 
 const AtomicString& TextTrack::captionsKeyword()
 {
-    DEFINE_STATIC_LOCAL(const AtomicString, captions, ("captions"));
+    DEFINE_STATIC_LOCAL(const AtomicString, captions, ("captions", AtomicString::ConstructFromLiteral));
     return captions;
 }
 
 const AtomicString& TextTrack::descriptionsKeyword()
 {
-    DEFINE_STATIC_LOCAL(const AtomicString, descriptions, ("descriptions"));
+    DEFINE_STATIC_LOCAL(const AtomicString, descriptions, ("descriptions", AtomicString::ConstructFromLiteral));
     return descriptions;
 }
 
 const AtomicString& TextTrack::chaptersKeyword()
 {
-    DEFINE_STATIC_LOCAL(const AtomicString, chapters, ("chapters"));
+    DEFINE_STATIC_LOCAL(const AtomicString, chapters, ("chapters", AtomicString::ConstructFromLiteral));
     return chapters;
 }
 
 const AtomicString& TextTrack::metadataKeyword()
 {
-    DEFINE_STATIC_LOCAL(const AtomicString, metadata, ("metadata"));
+    DEFINE_STATIC_LOCAL(const AtomicString, metadata, ("metadata", AtomicString::ConstructFromLiteral));
     return metadata;
 }
 
+const AtomicString& TextTrack::disabledKeyword()
+{
+    DEFINE_STATIC_LOCAL(const AtomicString, open, ("disabled", AtomicString::ConstructFromLiteral));
+    return open;
+}
+
+const AtomicString& TextTrack::hiddenKeyword()
+{
+    DEFINE_STATIC_LOCAL(const AtomicString, closed, ("hidden", AtomicString::ConstructFromLiteral));
+    return closed;
+}
+
+const AtomicString& TextTrack::showingKeyword()
+{
+    DEFINE_STATIC_LOCAL(const AtomicString, ended, ("showing", AtomicString::ConstructFromLiteral));
+    return ended;
+}
+
 TextTrack::TextTrack(ScriptExecutionContext* context, TextTrackClient* client, const String& kind, const String& label, const String& language, TextTrackType type)
     : TrackBase(context, TrackBase::TextTrack)
     , m_cues(0)
     , m_mediaElement(0)
     , m_label(label)
     , m_language(language)
-    , m_mode(TextTrack::DISABLED)
+    , m_mode(disabledKeyword())
     , m_client(client)
     , m_trackType(type)
     , m_readinessState(NotLoaded)
@@ -128,41 +146,39 @@ void TextTrack::setKind(const String& kind)
         m_client->textTrackKindChanged(this);
 }
 
-void TextTrack::setMode(unsigned short mode, ExceptionCode& ec)
+void TextTrack::setMode(const String& mode)
 {
-    // 4.8.10.12.5 On setting the mode, if the new value is not either 0, 1, or 2,
-    // the user agent must throw an INVALID_ACCESS_ERR exception.
-    if (mode > TextTrack::SHOWING) {
-        ec = INVALID_ACCESS_ERR;
+    // On setting, if the new value isn't equal to what the attribute would currently
+    // return, the new value must be processed as follows ...
+    if (mode != disabledKeyword() && mode != hiddenKeyword() && mode != showingKeyword())
         return;
-    }
 
-    if (m_mode == static_cast<Mode>(mode))
+    if (m_mode == mode)
         return;
 
     // If mode changes to disabled, remove this track's cues from the client
     // because they will no longer be accessible from the cues() function.
-    if (mode == TextTrack::DISABLED && m_client && m_cues)
+    if (mode == disabledKeyword() && m_client && m_cues)
         m_client->textTrackRemoveCues(this, m_cues.get());
          
-    if (mode != TextTrack::SHOWING && m_cues)
+    if (mode != showingKeyword() && m_cues)
         for (size_t i = 0; i < m_cues->length(); ++i)
             m_cues->item(i)->removeDisplayTree();
 
     //  ... Note: If the mode had been showing by default, this will change it to showing, 
     // even though the value of mode would appear not to change.
-    m_mode = static_cast<Mode>(mode);
+    m_mode = mode;
     setShowingByDefault(false);
 
     if (m_client)
         m_client->textTrackModeChanged(this);
 }
 
-TextTrack::Mode TextTrack::mode() const
+String TextTrack::mode() const
 {
-    // The text track "showing" and "showing by default" modes return SHOWING (numeric value 2)
+    // The text track "showing" and "showing by default" modes return the string "showing".
     if (m_showingByDefault)
-        return SHOWING;
+        return showingKeyword();
     return m_mode;
 }
 
@@ -173,7 +189,7 @@ TextTrackCueList* TextTrack::cues()
     // Otherwise, it must return null. When an object is returned, the
     // same object must be returned each time.
     // http://www.whatwg.org/specs/web-apps/current-work/#dom-texttrack-cues
-    if (m_mode != TextTrack::DISABLED)
+    if (m_mode != disabledKeyword())
         return ensureTextTrackCueList();
     return 0;
 }
@@ -186,7 +202,7 @@ TextTrackCueList* TextTrack::activeCues() const
     // order. Otherwise, it must return null. When an object is returned, the
     // same object must be returned each time.
     // http://www.whatwg.org/specs/web-apps/current-work/#dom-texttrack-activecues
-    if (m_cues && m_mode != TextTrack::DISABLED)
+    if (m_cues && m_mode != disabledKeyword())
         return m_cues->activeCues();
     return 0;
 }
@@ -299,7 +315,7 @@ bool TextTrack::isRendered()
     if (m_kind != captionsKeyword() && m_kind != subtitlesKeyword())
         return false;
 
-    if (m_mode != SHOWING && !m_showingByDefault)
+    if (m_mode != showingKeyword() && !m_showingByDefault)
         return false;
 
     return true;
index 957bcca..2c799ed 100644 (file)
@@ -79,9 +79,12 @@ public:
     String language() const { return m_language; }
     void setLanguage(const String& language) { m_language = language; }
 
-    enum Mode { DISABLED = 0, HIDDEN = 1, SHOWING = 2 };
-    Mode mode() const;
-    void setMode(unsigned short, ExceptionCode&);
+    static const AtomicString& disabledKeyword();
+    static const AtomicString& hiddenKeyword();
+    static const AtomicString& showingKeyword();
+
+    String mode() const;
+    void setMode(const String&);
 
     bool showingByDefault() const { return m_showingByDefault; }
     void setShowingByDefault(bool showing) { m_showingByDefault = showing; }
@@ -123,7 +126,7 @@ private:
     String m_kind;
     String m_label;
     String m_language;
-    Mode m_mode;
+    String m_mode;
     TextTrackClient* m_client;
     TextTrackType m_trackType;
     ReadinessState m_readinessState;
index 845a80c..9836f02 100644 (file)
@@ -36,11 +36,7 @@ module html {
         readonly attribute DOMString label;
         readonly attribute DOMString language;
 
-        const unsigned short DISABLED = 0;
-        const unsigned short HIDDEN = 1;
-        const unsigned short SHOWING = 2;
-        attribute unsigned short mode
-            setter raises (DOMException);
+        attribute DOMString mode;
 
         readonly attribute TextTrackCueList cues;
         readonly attribute TextTrackCueList activeCues;
index 6e53953..e79cd1d 100644 (file)
@@ -493,7 +493,7 @@ PassRefPtr<DocumentFragment> TextTrackCue::getCueAsHTML()
 bool TextTrackCue::dispatchEvent(PassRefPtr<Event> event)
 {
     // When a TextTrack's mode is disabled: no cues are active, no events fired.
-    if (!track() || track()->mode() == TextTrack::DISABLED)
+    if (!track() || track()->mode() == TextTrack::disabledKeyword())
         return false;
 
     return EventTarget::dispatchEvent(event);
@@ -506,7 +506,7 @@ bool TextTrackCue::dispatchEvent(PassRefPtr<Event> event, ExceptionCode &ec)
 
 bool TextTrackCue::isActive()
 {
-    return m_isActive && track() && track()->mode() != TextTrack::DISABLED;
+    return m_isActive && track() && track()->mode() != TextTrack::disabledKeyword();
 }
 
 void TextTrackCue::setIsActive(bool active)