Update platform text track menu
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Jun 2013 20:37:31 +0000 (20:37 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Jun 2013 20:37:31 +0000 (20:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=117884

Reviewed by Jer Noble.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::setSelectedTextTrack):
* html/track/TextTrack.cpp:
(WebCore::TextTrack::platformTextTrack):
* platform/graphics/PlatformTextTrack.h:
(WebCore::PlatformTextTrack::create):
(WebCore::PlatformTextTrack::uniqueId):
(WebCore::PlatformTextTrack::captionMenuOffItem):
(WebCore::PlatformTextTrack::captionMenuAutomaticItem):
(WebCore::PlatformTextTrack::PlatformTextTrack):

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

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/track/TextTrack.cpp
Source/WebCore/platform/graphics/PlatformTextTrack.h

index 2a685be..aedf603 100644 (file)
@@ -1,3 +1,21 @@
+2013-06-21  Eric Carlson  <eric.carlson@apple.com>
+
+        Update platform text track menu
+        https://bugs.webkit.org/show_bug.cgi?id=117884
+
+        Reviewed by Jer Noble.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::setSelectedTextTrack):
+        * html/track/TextTrack.cpp:
+        (WebCore::TextTrack::platformTextTrack):
+        * platform/graphics/PlatformTextTrack.h:
+        (WebCore::PlatformTextTrack::create): 
+        (WebCore::PlatformTextTrack::uniqueId):
+        (WebCore::PlatformTextTrack::captionMenuOffItem):
+        (WebCore::PlatformTextTrack::captionMenuAutomaticItem):
+        (WebCore::PlatformTextTrack::PlatformTextTrack):
+
 2013-06-21  James Craig  <james@cookiecrook.com>
 
         AX: audio/video playback control timers (elapsed and remaining) should be exposed as ApplicationTimerRole
index 7f7b32e..47a55c0 100644 (file)
@@ -2948,21 +2948,27 @@ void HTMLMediaElement::setSelectedTextTrack(PassRefPtr<PlatformTextTrack> platfo
     TrackDisplayUpdateScope scope(this);
 
     if (!platformTrack) {
-        setSelectedTextTrack(0);
+        setSelectedTextTrack(TextTrack::captionMenuOffItem());
         return;
     }
 
     TextTrack* textTrack;
-    size_t i;
-    for (i = 0; i < m_textTracks->length(); ++i) {
-        textTrack = m_textTracks->item(i);
-        
-        if (textTrack->platformTextTrack() == platformTrack)
-            break;
+    if (platformTrack == PlatformTextTrack::captionMenuOffItem())
+        textTrack = TextTrack::captionMenuOffItem();
+    else if (platformTrack == PlatformTextTrack::captionMenuAutomaticItem())
+        textTrack = TextTrack::captionMenuAutomaticItem();
+    else {
+        size_t i;
+        for (i = 0; i < m_textTracks->length(); ++i) {
+            textTrack = m_textTracks->item(i);
+            
+            if (textTrack->platformTextTrack() == platformTrack)
+                break;
+        }
+        if (i == m_textTracks->length())
+            return;
     }
 
-    if (i == m_textTracks->length())
-        return;
     setSelectedTextTrack(textTrack);
 }
 
index 2410b63..c692ed9 100644 (file)
@@ -527,6 +527,8 @@ bool TextTrack::hasCue(TextTrackCue* cue, TextTrackCue::CueMatchRules match)
 #if USE(PLATFORM_TEXT_TRACK_MENU)
 PassRefPtr<PlatformTextTrack> TextTrack::platformTextTrack()
 {
+    static int uniqueId = 0;
+
     if (m_platformTextTrack)
         return m_platformTextTrack;
 
@@ -552,7 +554,7 @@ PassRefPtr<PlatformTextTrack> TextTrack::platformTextTrack()
     else if (m_trackType == InBand)
         type = PlatformTextTrack::InBand;
 
-    m_platformTextTrack = PlatformTextTrack::create(this, label(), language(), platformKind, type);
+    m_platformTextTrack = PlatformTextTrack::create(this, label(), language(), platformKind, type, ++uniqueId);
 
     return m_platformTextTrack;
 }
index d23799e..c2b8450 100644 (file)
@@ -60,9 +60,9 @@ public:
         Script = 2
     };
 
-    static PassRefPtr<PlatformTextTrack> create(PlatformTextTrackClient* client, const String& label, const String& language, TrackKind kind, TrackType type)
+    static PassRefPtr<PlatformTextTrack> create(PlatformTextTrackClient* client, const String& label, const String& language, TrackKind kind, TrackType type, int uniqueId)
     {
-        return adoptRef(new PlatformTextTrack(client, label, language, kind, type));
+        return adoptRef(new PlatformTextTrack(client, label, language, kind, type, uniqueId));
     }
 
     virtual ~PlatformTextTrack() { }
@@ -72,14 +72,28 @@ public:
     String label() const { return m_label; }
     String language() const { return m_language; }
     PlatformTextTrackClient* client() const { return m_client; }
-    
+    int uniqueId() const { return m_uniqueId; }
+
+    static PlatformTextTrack* captionMenuOffItem()
+    {
+        DEFINE_STATIC_LOCAL(RefPtr<PlatformTextTrack>, off, (PlatformTextTrack::create(0, "off menu item", "", Subtitle, InBand, 0)));
+        return off.get();
+    }
+
+    static PlatformTextTrack* captionMenuAutomaticItem()
+    {
+        DEFINE_STATIC_LOCAL(RefPtr<PlatformTextTrack>, automatic, (PlatformTextTrack::create(0, "automatic menu item", "", Subtitle, InBand, 0)));
+        return automatic.get();
+    }
+
 protected:
-    PlatformTextTrack(PlatformTextTrackClient* client, const String& label, const String& language, TrackKind kind, TrackType type)
+    PlatformTextTrack(PlatformTextTrackClient* client, const String& label, const String& language, TrackKind kind, TrackType type, int uniqueId)
         : m_label(label)
         , m_language(language)
         , m_kind(kind)
         , m_type(type)
         , m_client(client)
+        , m_uniqueId(uniqueId)
     {
     }
 
@@ -88,6 +102,7 @@ protected:
     TrackKind m_kind;
     TrackType m_type;
     PlatformTextTrackClient* m_client;
+    int m_uniqueId;
 };
 
 }