Move readyState from TextTrack to HTMLTrackElement
authorannacc@chromium.org <annacc@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Nov 2011 09:25:39 +0000 (09:25 +0000)
committerannacc@chromium.org <annacc@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Nov 2011 09:25:39 +0000 (09:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=72553

Reviewed by Eric Carlson.

Source/WebCore:

* html/HTMLTrackElement.cpp:
(WebCore::HTMLTrackElement::HTMLTrackElement):
    Set initial readyState to NONE.
(WebCore::HTMLTrackElement::didCompleteLoad):
    Set readyState based on load completed status.
(WebCore::HTMLTrackElement::setReadyState):
    This replaces textTrackReadyStateChanged() because only LoadableTextTrack
    needs to notify HTMLTrackElement of readyState changes (i.e.
    textTrackReadyStateChanged() is no longer required of TextTrackClient).
* html/HTMLTrackElement.h:
    ReadyState enum and m_readyState member variable moved from TextTrack.
(WebCore::HTMLTrackElement::readyState):
    New: readyState() getter.
* html/HTMLTrackElement.idl:
    Add readyState attribute and associated constants.

* html/LoadableTextTrack.cpp:
(WebCore::LoadableTextTrack::loadTimerFired): Set readyState on HTMLTrackElement.
(WebCore::LoadableTextTrack::cueLoadingStarted): Ditto.
(WebCore::LoadableTextTrack::cueLoadingCompleted): Move code to set readyState
    to HTMLTrackElement (it can set it based on loading status).

* html/TextTrack.cpp: Remove readyState from TextTrack.
(WebCore::TextTrack::TextTrack): Ditto.
* html/TextTrack.h: Ditto.
* html/TextTrack.idl: Ditto.

LayoutTests:

* media/track/track-add-track-expected.txt:
* media/track/track-add-track.html:
* media/track/track-constants-expected.txt:
* media/track/track-constants.html:
* media/track/track-load-error-readyState-expected.txt:
* media/track/track-load-error-readyState.html:
* media/track/track-load-from-element-readyState-expected.txt:
* media/track/track-load-from-element-readyState.html:
* media/track/track-load-from-src-readyState-expected.txt:
* media/track/track-load-from-src-readyState.html:

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

19 files changed:
LayoutTests/ChangeLog
LayoutTests/media/track/track-add-track-expected.txt
LayoutTests/media/track/track-add-track.html
LayoutTests/media/track/track-constants-expected.txt
LayoutTests/media/track/track-constants.html
LayoutTests/media/track/track-load-error-readyState-expected.txt
LayoutTests/media/track/track-load-error-readyState.html
LayoutTests/media/track/track-load-from-element-readyState-expected.txt
LayoutTests/media/track/track-load-from-element-readyState.html
LayoutTests/media/track/track-load-from-src-readyState-expected.txt
LayoutTests/media/track/track-load-from-src-readyState.html
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLTrackElement.cpp
Source/WebCore/html/HTMLTrackElement.h
Source/WebCore/html/HTMLTrackElement.idl
Source/WebCore/html/LoadableTextTrack.cpp
Source/WebCore/html/TextTrack.cpp
Source/WebCore/html/TextTrack.h
Source/WebCore/html/TextTrack.idl

index 01ef4b2..2292e16 100644 (file)
@@ -1,3 +1,21 @@
+2011-11-23  Anna Cavender  <annacc@chromium.org>
+
+        Move readyState from TextTrack to HTMLTrackElement
+        https://bugs.webkit.org/show_bug.cgi?id=72553
+
+        Reviewed by Eric Carlson.
+
+        * media/track/track-add-track-expected.txt:
+        * media/track/track-add-track.html:
+        * media/track/track-constants-expected.txt:
+        * media/track/track-constants.html:
+        * media/track/track-load-error-readyState-expected.txt:
+        * media/track/track-load-error-readyState.html:
+        * media/track/track-load-from-element-readyState-expected.txt:
+        * media/track/track-load-from-element-readyState.html:
+        * media/track/track-load-from-src-readyState-expected.txt:
+        * media/track/track-load-from-src-readyState.html:
+
 2011-11-23  Nikolas Zimmermann  <nzimmermann@rim.com>
 
         Add flags/precision arguments to String::number(double) to allow fine-grained control over the result string
index 5af427d..cfc5e2d 100644 (file)
@@ -5,7 +5,7 @@ RUN(trackElement = document.createElement('track'))
 RUN(video.appendChild(trackElement))
 RUN(trackElement.src = 'captions-webvtt/tc004-webvtt-file.vtt')
 EXPECTED (video.textTracks.length == '1') OK
-EXPECTED (tracks[0].readyState == '0') OK
+EXPECTED (trackElement.readyState == '0') OK
 EVENT(addtrack)
 EXPECTED (event.target == '[object TextTrackList]') OK
 EXPECTED (event instanceof window.TrackEvent == 'true') OK
@@ -14,12 +14,10 @@ EXPECTED (event.track == '[object TextTrack]') OK
 ** Test a TextTrack created with video.addTrack().
 RUN(tracks.push(video.addTrack('captions', 'Caption Track', 'en')))
 EXPECTED (video.textTracks.length == '2') OK
-EXPECTED (tracks[1].readyState == '0') OK
 EVENT(addtrack)
 EXPECTED (event.target == '[object TextTrackList]') OK
 EXPECTED (event instanceof window.TrackEvent == 'true') OK
 EXPECTED (event.track == '[object TextTrack]') OK
-EXPECTED (tracks[1].readyState == '0') OK
 
 END OF TEST
 
index c760801..177097d 100644 (file)
@@ -21,9 +21,7 @@
                     consoleWrite("<br>** Test a TextTrack created with video.addTrack().");
                     run("tracks.push(video.addTrack('captions', 'Caption Track', 'en'))");
                     testExpected("video.textTracks.length", 2);
-                    testExpected("tracks[1].readyState", TextTrack.NONE);
                 } else {
-                    testExpected("tracks[1].readyState", TextTrack.NONE);
                     consoleWrite("");
                     endTest();
                 }
@@ -44,7 +42,7 @@
 
                 run("trackElement.src = 'captions-webvtt/tc004-webvtt-file.vtt'");
                 testExpected("video.textTracks.length", 1);
-                testExpected("tracks[0].readyState", TextTrack.NONE);
+                testExpected("trackElement.readyState", HTMLTrackElement.NONE);
             }
 
         </script>
index 0153cc2..83ac544 100644 (file)
@@ -1,9 +1,9 @@
 Test TextTrack constants.
 
-EXPECTED (TextTrack.NONE == '0') OK
-EXPECTED (TextTrack.LOADING == '1') OK
-EXPECTED (TextTrack.LOADED == '2') OK
-EXPECTED (TextTrack.ERROR == '3') OK
+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
index f963637..42305cf 100644 (file)
@@ -5,10 +5,10 @@
     <script type="text/javascript">
         function doTest () 
         {
-            testExpected("TextTrack.NONE", 0);
-            testExpected("TextTrack.LOADING", 1);
-            testExpected("TextTrack.LOADED", 2);
-            testExpected("TextTrack.ERROR", 3);
+            testExpected("HTMLTrackElement.NONE", 0);
+            testExpected("HTMLTrackElement.LOADING", 1);
+            testExpected("HTMLTrackElement.LOADED", 2);
+            testExpected("HTMLTrackElement.ERROR", 3);
             consoleWrite("");
 
             testExpected("TextTrack.DISABLED", 0);
index 9e2d00e..102eb7b 100644 (file)
@@ -1,6 +1,6 @@
 Tests the error event on HTMLTrackElement and ERROR readyState on TextTrack.
 
 EVENT(error)
-EXPECTED (track.track.readyState == '3') OK
+EXPECTED (track.readyState == '3') OK
 END OF TEST
 
index f7e6e8e..900e957 100644 (file)
@@ -11,7 +11,7 @@
             {
                 consoleWrite("EVENT(error)");
                 track = document.getElementById('testTrackError'); 
-                testExpected("track.track.readyState", TextTrack.ERROR);
+                testExpected("track.readyState", HTMLTrackElement.ERROR);
                 endTest();
             }
 
index 3a6e71c..4926d13 100644 (file)
@@ -1,6 +1,6 @@
 Tests the load event on HTMLTrackElement and LOADED readyState on TextTrack when src is set on the element.
 
 EVENT(load)
-EXPECTED (track.track.readyState == '2') OK
+EXPECTED (track.readyState == '2') OK
 END OF TEST
 
index bfc657f..ed75635 100644 (file)
@@ -11,7 +11,7 @@
             {
                 consoleWrite("EVENT(load)");
                 track = document.getElementById('testTrackSrc'); 
-                testExpected("track.track.readyState", TextTrack.LOADED);
+                testExpected("track.readyState", HTMLTrackElement.LOADED);
                 endTest();
             }
 
index 4c405af..31dd1f0 100644 (file)
@@ -1,7 +1,7 @@
 Tests the load event on HTMLTrackElement and LOADED readyState on TextTrack when src is set from JavaScript.
 
-EXPECTED (track.track.readyState == '0') OK
+EXPECTED (track.readyState == '0') OK
 EVENT(load)
-EXPECTED (track.track.readyState == '2') OK
+EXPECTED (track.readyState == '2') OK
 END OF TEST
 
index 9c8af31..925f1dc 100644 (file)
             function trackLoaded()
             {
                 consoleWrite("EVENT(load)");
-                testExpected("track.track.readyState", TextTrack.LOADED);
+                testExpected("track.readyState", HTMLTrackElement.LOADED);
                 endTest();
             }
 
             track = document.getElementById('testTrackEmpty');
-            testExpected("track.track.readyState", TextTrack.NONE);
+            testExpected("track.readyState", HTMLTrackElement.NONE);
             track.addEventListener("load", function () { trackLoaded(); }, true);
             track.src = "captions-webvtt/tc004-webvtt-file.vtt";   
 
index e39ca60..4196654 100644 (file)
@@ -1,3 +1,37 @@
+2011-11-23  Anna Cavender  <annacc@chromium.org>
+
+        Move readyState from TextTrack to HTMLTrackElement
+        https://bugs.webkit.org/show_bug.cgi?id=72553
+
+        Reviewed by Eric Carlson.
+
+        * html/HTMLTrackElement.cpp:
+        (WebCore::HTMLTrackElement::HTMLTrackElement):
+            Set initial readyState to NONE.
+        (WebCore::HTMLTrackElement::didCompleteLoad):
+            Set readyState based on load completed status.
+        (WebCore::HTMLTrackElement::setReadyState):
+            This replaces textTrackReadyStateChanged() because only LoadableTextTrack
+            needs to notify HTMLTrackElement of readyState changes (i.e.
+            textTrackReadyStateChanged() is no longer required of TextTrackClient).
+        * html/HTMLTrackElement.h:
+            ReadyState enum and m_readyState member variable moved from TextTrack.
+        (WebCore::HTMLTrackElement::readyState):
+            New: readyState() getter.
+        * html/HTMLTrackElement.idl:
+            Add readyState attribute and associated constants.
+
+        * html/LoadableTextTrack.cpp:
+        (WebCore::LoadableTextTrack::loadTimerFired): Set readyState on HTMLTrackElement.
+        (WebCore::LoadableTextTrack::cueLoadingStarted): Ditto.
+        (WebCore::LoadableTextTrack::cueLoadingCompleted): Move code to set readyState
+            to HTMLTrackElement (it can set it based on loading status).
+
+        * html/TextTrack.cpp: Remove readyState from TextTrack.
+        (WebCore::TextTrack::TextTrack): Ditto.
+        * html/TextTrack.h: Ditto.
+        * html/TextTrack.idl: Ditto.
+
 2011-11-23  Raphael Kubo da Costa  <kubo@profusion.mobi>
 
         [CMake] Move the top-level logic to the top-level directory.
index d9171a3..cdc3a68 100644 (file)
@@ -43,6 +43,7 @@ using namespace HTMLNames;
 
 inline HTMLTrackElement::HTMLTrackElement(const QualifiedName& tagName, Document* document)
     : HTMLElement(tagName, document)
+    , m_readyState(HTMLTrackElement::NONE)
 {
     LOG(Media, "HTMLTrackElement::HTMLTrackElement - %p", this);
     ASSERT(hasTagName(trackTag));
@@ -206,14 +207,17 @@ bool HTMLTrackElement::canLoadUrl(LoadableTextTrack*, const KURL& url)
 
 void HTMLTrackElement::didCompleteLoad(LoadableTextTrack*, bool loadingFailed)
 {
+    loadingFailed ? setReadyState(HTMLTrackElement::ERROR) : setReadyState(HTMLTrackElement::LOADED);
+
     ExceptionCode ec = 0;
     dispatchEvent(Event::create(loadingFailed ? eventNames().errorEvent : eventNames().loadEvent, false, false), ec);
 }
-    
-void HTMLTrackElement::textTrackReadyStateChanged(TextTrack* track)
+
+void HTMLTrackElement::setReadyState(ReadyState state)
 {
+    m_readyState = state;
     if (HTMLMediaElement* parent = mediaElement())
-        return parent->textTrackReadyStateChanged(track);
+        return parent->textTrackReadyStateChanged(m_track.get());
 }
     
 void HTMLTrackElement::textTrackKindChanged(TextTrack* track)
index f68ea9a..764d84d 100644 (file)
@@ -53,12 +53,17 @@ public:
 
     bool isDefault() const;
     void setIsDefault(bool);
+    
+    enum ReadyState { NONE = 0, LOADING = 1, LOADED = 2, ERROR = 3 };
+    ReadyState readyState() const { return m_readyState; }
 
     TextTrack* track();
     
     void scheduleLoad();
     virtual bool canLoadUrl(LoadableTextTrack*, const KURL&);
     virtual void didCompleteLoad(LoadableTextTrack*, bool /* loadingFailed */);
+    
+    void setReadyState(ReadyState);
 
 private:
     HTMLTrackElement(const QualifiedName&, Document*);
@@ -79,7 +84,6 @@ private:
     HTMLMediaElement* mediaElement() const;
 
     // TextTrackClient
-    virtual void textTrackReadyStateChanged(TextTrack*);
     virtual void textTrackModeChanged(TextTrack*);
     virtual void textTrackKindChanged(TextTrack*);
     virtual void textTrackAddCues(TextTrack*, const TextTrackCueList*);
@@ -89,6 +93,7 @@ private:
 
     LoadableTextTrack* ensureTrack();
 
+    HTMLTrackElement::ReadyState m_readyState;
     RefPtr<LoadableTextTrack> m_track;
 };
 
index 0782fe9..5bb7319 100644 (file)
@@ -28,12 +28,18 @@ module html {
         Conditional=VIDEO_TRACK,
         EnabledAtRuntime=webkitVideoTrack
     ] HTMLTrackElement : HTMLElement {
-    attribute [Reflect, URL] DOMString src;
-    attribute DOMString kind;
-    attribute DOMString srclang;
-    attribute DOMString label;
-    attribute [Reflect=default] boolean isDefault;
+        attribute [Reflect, URL] DOMString src;
+        attribute DOMString kind;
+        attribute DOMString srclang;
+        attribute DOMString label;
+        attribute [Reflect=default] boolean isDefault;
 
-    readonly attribute TextTrack track;
+        const unsigned short NONE = 0;
+        const unsigned short LOADING = 1;
+        const unsigned short LOADED = 2;
+        const unsigned short ERROR = 3;
+        readonly attribute unsigned short readyState;
+
+        readonly attribute TextTrack track;
 };
 }
index 87ec56b..61e2aaf 100644 (file)
@@ -64,13 +64,16 @@ void LoadableTextTrack::scheduleLoad(const KURL& url)
 
 void LoadableTextTrack::loadTimerFired(Timer<LoadableTextTrack>*)
 {
-    setReadyState(TextTrack::LOADING);
+    if (!m_trackElement)
+        return;
+
+    m_trackElement->setReadyState(HTMLTrackElement::LOADING);
     
     if (m_loader)
         m_loader->cancelLoad();
 
-    if (!m_trackElement || !m_trackElement->canLoadUrl(this, m_url)) {
-        setReadyState(TextTrack::HTML_ERROR);
+    if (!m_trackElement->canLoadUrl(this, m_url)) {
+        m_trackElement->setReadyState(HTMLTrackElement::ERROR);
         return;
     }
 
@@ -100,17 +103,18 @@ void LoadableTextTrack::cueLoadingStarted(TextTrackLoader* loader)
 {
     ASSERT_UNUSED(loader, m_loader == loader);
     
-    setReadyState(TextTrack::LOADING);
+    if (!m_trackElement)
+        return;
+    m_trackElement->setReadyState(HTMLTrackElement::LOADING);
 }
 
 void LoadableTextTrack::cueLoadingCompleted(TextTrackLoader* loader, bool loadingFailed)
 {
     ASSERT_UNUSED(loader, m_loader == loader);
 
-    loadingFailed ? setReadyState(TextTrack::HTML_ERROR) : setReadyState(TextTrack::LOADED);
-
-    if (m_trackElement)
-        m_trackElement->didCompleteLoad(this, loadingFailed);
+    if (!m_trackElement)
+        return;
+    m_trackElement->didCompleteLoad(this, loadingFailed);
 }
 
 void LoadableTextTrack::fireCueChangeEvent()
index 8d10bd7..f372f54 100644 (file)
@@ -75,7 +75,6 @@ TextTrack::TextTrack(ScriptExecutionContext* context, TextTrackClient* client, c
     : TrackBase(context, TrackBase::TextTrack)
     , m_label(label)
     , m_language(language)
-    , m_readyState(TextTrack::NONE)
     , m_mode(TextTrack::HIDDEN)
     , m_client(client)
     , m_trackType(type)
@@ -119,13 +118,6 @@ void TextTrack::setKind(const String& kind)
         m_client->textTrackKindChanged(this);
 }
 
-void TextTrack::setReadyState(ReadyState state)
-{
-    m_readyState = state;
-    if (m_client)
-        m_client->textTrackReadyStateChanged(this);
-}
-
 void TextTrack::setMode(unsigned short mode, ExceptionCode& ec)
 {
     // 4.8.10.12.5 On setting the mode, if the new value is not either 0, 1, or 2,
index 733660e..e169922 100644 (file)
@@ -43,7 +43,6 @@ class TextTrackCueList;
 class TextTrackClient {
 public:
     virtual ~TextTrackClient() { }
-    virtual void textTrackReadyStateChanged(TextTrack*) = 0;
     virtual void textTrackKindChanged(TextTrack*) = 0;
     virtual void textTrackModeChanged(TextTrack*) = 0;
     virtual void textTrackAddCues(TextTrack*, const TextTrackCueList*) = 0;
@@ -76,9 +75,6 @@ public:
     String language() const { return m_language; }
     void setLanguage(const String& language) { m_language = language; }
 
-    enum ReadyState { NONE = 0, LOADING = 1, LOADED = 2, HTML_ERROR = 3 };
-    ReadyState readyState() const { return m_readyState; }
-
     enum Mode { DISABLED = 0, HIDDEN = 1, SHOWING = 2 };
     Mode mode() const { return m_mode; }
     void setMode(unsigned short, ExceptionCode&);
@@ -107,15 +103,12 @@ public:
 protected:
     TextTrack(ScriptExecutionContext*, TextTrackClient*, const String& kind, const String& label, const String& language, TextTrackType);
 
-    void setReadyState(ReadyState);
-
     RefPtr<TextTrackCueList> m_cues;
 
 private:
     String m_kind;
     String m_label;
     String m_language;
-    TextTrack::ReadyState m_readyState;
     TextTrack::Mode m_mode;
     TextTrackClient* m_client;
     TextTrackType m_trackType;
index aac42d0..c62812e 100644 (file)
@@ -34,13 +34,6 @@ module html {
         readonly attribute DOMString label;
         readonly attribute DOMString language;
 
-        const unsigned short NONE = 0;
-        const unsigned short LOADING = 1;
-        const unsigned short LOADED = 2;
-        // Reflect is used for TextTrack::ERROR because it conflicts with a windows define.
-        const [Reflect=HTML_ERROR] unsigned short ERROR = 3;
-        readonly attribute unsigned short readyState;
-
         const unsigned short DISABLED = 0;
         const unsigned short HIDDEN = 1;
         const unsigned short SHOWING = 2;