TextTrack Extension for WebVTT Regions
authorvcarbune@chromium.org <vcarbune@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Mar 2013 23:30:55 +0000 (23:30 +0000)
committervcarbune@chromium.org <vcarbune@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Mar 2013 23:30:55 +0000 (23:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=109820

Reviewed by Eric Carlson.

Source/WebCore:

Implemented the TextTrackRegionList and extended TextTrack with
methods required for proper interaction with TextTrackRegion objects.

Test: media/track/regions-webvtt/text-track-region-list.html

* WebCore.gypi: Added files for proper building of TextTrackRegionList.
* html/track/TextTrack.cpp:
(WebCore::TextTrack::TextTrack):
(WebCore):
(WebCore::TextTrack::ensureTextTrackRegionList): Method for creating a
TextTrackRegionList associated with the current track, if it does exist
already.
(WebCore::TextTrack::regions): Getter for the regions object.
(WebCore::TextTrack::addRegion): Method for adding a region.
(WebCore::TextTrack::removeRegion): Method for removing a region.
* html/track/TextTrack.h:
(WebCore):
(TextTrack):
* html/track/TextTrack.idl: Added methods specific for region handling.
* html/track/TextTrackRegion.cpp:
(WebCore::TextTrackRegion::TextTrackRegion): Initialized the track member variable.
(WebCore::TextTrackRegion::setTrack): Added internal setter for the track attribute.
(WebCore):
(WebCore::TextTrackRegion::updateParametersFromRegion): Method to copy the parameters
from a different region object.
* html/track/TextTrackRegion.h: Added track member variable and copy method.
(WebCore::TextTrackRegion::track): Getter retrieves now the member variable.
(TextTrackRegion):
* html/track/TextTrackRegionList.cpp: Implemented methods required by the IDL.
(WebCore):
(WebCore::TextTrackRegionList::TextTrackRegionList):
(WebCore::TextTrackRegionList::length):
(WebCore::TextTrackRegionList::item):
(WebCore::TextTrackRegionList::getRegionById):
(WebCore::TextTrackRegionList::add):
(WebCore::TextTrackRegionList::remove):
(WebCore::TextTrackRegionList::clear):
* html/track/TextTrackRegionList.h:
(WebCore):
(TextTrackRegionList):
(WebCore::TextTrackRegionList::create):
(WebCore::TextTrackRegionList::~TextTrackRegionList):
* html/track/TextTrackRegionList.idl: IDL defined by the specification.

LayoutTests:

* media/track/regions-webvtt/text-track-region-list-expected.txt: Added.
* media/track/regions-webvtt/text-track-region-list.html: Added.

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

13 files changed:
LayoutTests/ChangeLog
LayoutTests/media/track/regions-webvtt/text-track-region-list-expected.txt [new file with mode: 0644]
LayoutTests/media/track/regions-webvtt/text-track-region-list.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/html/track/TextTrack.cpp
Source/WebCore/html/track/TextTrack.h
Source/WebCore/html/track/TextTrack.idl
Source/WebCore/html/track/TextTrackRegion.cpp
Source/WebCore/html/track/TextTrackRegion.h
Source/WebCore/html/track/TextTrackRegionList.cpp [new file with mode: 0644]
Source/WebCore/html/track/TextTrackRegionList.h [new file with mode: 0644]
Source/WebCore/html/track/TextTrackRegionList.idl [new file with mode: 0644]

index b8a917e..d7c3099 100644 (file)
@@ -1,3 +1,13 @@
+2013-03-25  Victor Carbune  <vcarbune@chromium.org>
+
+        TextTrack Extension for WebVTT Regions
+        https://bugs.webkit.org/show_bug.cgi?id=109820
+
+        Reviewed by Eric Carlson.
+
+        * media/track/regions-webvtt/text-track-region-list-expected.txt: Added.
+        * media/track/regions-webvtt/text-track-region-list.html: Added.
+
 2013-03-25  Brandon Jones  <bajones@google.com>
 
         WEBGL_compressed_texture_pvrtc needs implementation
diff --git a/LayoutTests/media/track/regions-webvtt/text-track-region-list-expected.txt b/LayoutTests/media/track/regions-webvtt/text-track-region-list-expected.txt
new file mode 100644 (file)
index 0000000..013c744
--- /dev/null
@@ -0,0 +1,41 @@
+Tests TextTrackRegionList functionality: length, operator[], and getRegionById()
+
+
+** Implicit mode disabled and the regions attribute is null **
+EXPECTED (testTrack.track.mode == 'disabled') OK
+EXPECTED (testTrack.track.regions == 'null') OK
+
+** The regions attribute should be an empty TextTrackRegionList **
+EXPECTED (regions != null == 'true') OK
+EXPECTED (regions.length == '0') OK
+
+** The default value of the track attribute of the region is null**
+EXPECTED (region.track == 'null') OK
+
+** The addRegion() method properly updates the TextTrackRegionList object **
+EXPECTED (regions.length == '1') OK
+EXPECTED (regions[0] == region == 'true') OK
+EXPECTED (regions[0].track == testTrack.track == 'true') OK
+
+** The track attribute should correctly reflect the track to which the region was added to**
+EXPECTED (region.track == testTrack.track == 'true') OK
+
+** Adding a region with an existing id should update the existing region **
+EXPECTED (regions[0].viewportAnchorX == '59') OK
+EXPECTED (regions[0].viewportAnchorY == '68') OK
+EXPECTED (regions[0].regionAnchorX == '20') OK
+EXPECTED (regions[0].regionAnchorY == '30') OK
+EXPECTED (regions[0].height == '5') OK
+EXPECTED (regions[0].width == '87') OK
+EXPECTED (regions[0].scroll == 'up') OK
+EXPECTED (regions[0] != updatedRegion == 'true') OK
+
+** Add the region back and check if removeRegion() removes it properly **
+EXPECTED (regions.length == '1') OK
+EXPECTED (regions.length == '0') OK
+
+** In case the region is not found, NotFoundError should be thrown **
+Error: NotFoundError: DOM Exception 8
+
+END OF TEST
+
diff --git a/LayoutTests/media/track/regions-webvtt/text-track-region-list.html b/LayoutTests/media/track/regions-webvtt/text-track-region-list.html
new file mode 100644 (file)
index 0000000..976e066
--- /dev/null
@@ -0,0 +1,98 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+        <script src=../../media-file.js></script>
+        <script src=../../video-test.js></script>
+        <script>
+        var testTrack;
+        var region;
+        var regions;
+        var updatedRegion;
+
+        function startTest()
+        {
+            testTrack = document.getElementsByTagName('track')[0];
+
+            consoleWrite("<br>** Implicit mode disabled and the regions attribute is null **");
+            testExpected("testTrack.track.mode", "disabled");
+            testExpected("testTrack.track.regions", null);
+
+            testTrack.track.mode = "hidden";
+            regions = testTrack.track.regions;
+
+            consoleWrite("<br>** The regions attribute should be an empty TextTrackRegionList **");
+            testExpected("regions != null", true);
+            testExpected("regions.length", 0);
+
+            region = new TextTrackRegion();
+            region.id = "TestId";
+
+            consoleWrite("<br>** The default value of the track attribute of the region is null**");
+            testExpected("region.track", null);
+
+            testTrack.track.addRegion(region);
+
+            consoleWrite("<br>** The addRegion() method properly updates the TextTrackRegionList object **");
+            testExpected("regions.length", 1);
+            testExpected("regions[0] == region", true);
+            testExpected("regions[0].track == testTrack.track", true);
+
+            consoleWrite("<br>** The track attribute should correctly reflect the track to which the region was added to**");
+            testExpected("region.track == testTrack.track", true);
+
+            updatedRegion = new TextTrackRegion();
+            updatedRegion.id = region.id;
+            updatedRegion.viewportAnchorX = 59;
+            updatedRegion.viewportAnchorY = 68;
+            updatedRegion.regionAnchorX = 20;
+            updatedRegion.regionAnchorY = 30;
+            updatedRegion.height = 5;
+            updatedRegion.width = 87;
+            updatedRegion.scroll = "up";
+
+            consoleWrite("<br>** Adding a region with an existing id should update the existing region **");
+            testTrack.track.addRegion(updatedRegion);
+            testExpected("regions[0].viewportAnchorX", updatedRegion.viewportAnchorX);
+            testExpected("regions[0].viewportAnchorY", updatedRegion.viewportAnchorY);
+            testExpected("regions[0].regionAnchorX", updatedRegion.regionAnchorX);
+            testExpected("regions[0].regionAnchorY", updatedRegion.regionAnchorY);
+            testExpected("regions[0].height", updatedRegion.height);
+            testExpected("regions[0].width", updatedRegion.width);
+            testExpected("regions[0].scroll", updatedRegion.scroll);
+
+            testExpected("regions[0] != updatedRegion", true);
+
+            consoleWrite("<br>** Add the region back and check if removeRegion() removes it properly **");
+            testTrack.track.addRegion(region);
+            testExpected("regions.length", 1);
+            testTrack.track.removeRegion(region);
+            testExpected("regions.length", 0);
+
+            consoleWrite("<br>** In case the region is not found, NotFoundError should be thrown **");
+            try {
+              testTrack.track.removeRegion(region);
+            } catch(e) {
+              consoleWrite(e);
+            }
+
+            // FIXME(109818): Update test for multiple initial regions (after parsing is supported).
+
+            consoleWrite("");
+            endTest();
+        }
+
+        function startTestWithDelay()
+        {
+            setTimeout(startTest, 100);
+        }
+        </script>
+    </head>
+    <body onload="startTestWithDelay()">
+        <p>Tests TextTrackRegionList functionality: length, operator[], and getRegionById()</p>
+        <video>
+            <track id="testTrack" src="captions-webvtt/captions-fast.vtt">
+        </video>
+    </body>
+</html>
index 5a79b0b..bd52b7c 100644 (file)
@@ -1,3 +1,54 @@
+2013-03-25  Victor Carbune  <vcarbune@chromium.org>
+
+        TextTrack Extension for WebVTT Regions
+        https://bugs.webkit.org/show_bug.cgi?id=109820
+
+        Reviewed by Eric Carlson.
+
+        Implemented the TextTrackRegionList and extended TextTrack with
+        methods required for proper interaction with TextTrackRegion objects.
+
+        Test: media/track/regions-webvtt/text-track-region-list.html
+
+        * WebCore.gypi: Added files for proper building of TextTrackRegionList.
+        * html/track/TextTrack.cpp:
+        (WebCore::TextTrack::TextTrack):
+        (WebCore):
+        (WebCore::TextTrack::ensureTextTrackRegionList): Method for creating a
+        TextTrackRegionList associated with the current track, if it does exist
+        already.
+        (WebCore::TextTrack::regions): Getter for the regions object.
+        (WebCore::TextTrack::addRegion): Method for adding a region.
+        (WebCore::TextTrack::removeRegion): Method for removing a region.
+        * html/track/TextTrack.h:
+        (WebCore):
+        (TextTrack):
+        * html/track/TextTrack.idl: Added methods specific for region handling.
+        * html/track/TextTrackRegion.cpp:
+        (WebCore::TextTrackRegion::TextTrackRegion): Initialized the track member variable.
+        (WebCore::TextTrackRegion::setTrack): Added internal setter for the track attribute.
+        (WebCore):
+        (WebCore::TextTrackRegion::updateParametersFromRegion): Method to copy the parameters
+        from a different region object.
+        * html/track/TextTrackRegion.h: Added track member variable and copy method.
+        (WebCore::TextTrackRegion::track): Getter retrieves now the member variable.
+        (TextTrackRegion):
+        * html/track/TextTrackRegionList.cpp: Implemented methods required by the IDL.
+        (WebCore):
+        (WebCore::TextTrackRegionList::TextTrackRegionList):
+        (WebCore::TextTrackRegionList::length):
+        (WebCore::TextTrackRegionList::item):
+        (WebCore::TextTrackRegionList::getRegionById):
+        (WebCore::TextTrackRegionList::add):
+        (WebCore::TextTrackRegionList::remove):
+        (WebCore::TextTrackRegionList::clear):
+        * html/track/TextTrackRegionList.h:
+        (WebCore):
+        (TextTrackRegionList):
+        (WebCore::TextTrackRegionList::create):
+        (WebCore::TextTrackRegionList::~TextTrackRegionList):
+        * html/track/TextTrackRegionList.idl: IDL defined by the specification.
+
 2013-03-25  Dean Jackson  <dino@apple.com>
 
         Cleanup plugin snapshotting autostart decision making
index 0dd5985..6e525ff 100644 (file)
             'html/track/TextTrackList.idl',
             'html/track/TrackEvent.idl',
             'html/track/TextTrackRegion.idl',
+            'html/track/TextTrackRegionList.idl',
             'inspector/InjectedScriptHost.idl',
             'inspector/InspectorFrontendHost.idl',
             'inspector/JavaScriptCallFrame.idl',
             'html/track/TextTrackList.cpp',
             'html/track/TextTrackRegion.cpp',
             'html/track/TextTrackRegion.h',
+            'html/track/TextTrackRegionList.cpp',
+            'html/track/TextTrackRegionList.h',
             'html/track/TrackBase.cpp',
             'html/track/TrackEvent.cpp',
             'html/track/WebVTTElement.cpp',
index bb5698c..3437fa7 100644 (file)
@@ -40,6 +40,7 @@
 #include "HTMLMediaElement.h"
 #include "TextTrackCueList.h"
 #include "TextTrackList.h"
+#include "TextTrackRegionList.h"
 #include "TrackBase.h"
 
 namespace WebCore {
@@ -97,6 +98,9 @@ const AtomicString& TextTrack::showingKeyword()
 TextTrack::TextTrack(ScriptExecutionContext* context, TextTrackClient* client, const AtomicString& kind, const AtomicString& label, const AtomicString& language, TextTrackType type)
     : TrackBase(context, TrackBase::TextTrack)
     , m_cues(0)
+#if ENABLE(WEBVTT_REGIONS)
+    , m_regions(0)
+#endif
     , m_mediaElement(0)
     , m_label(label)
     , m_language(language)
@@ -119,6 +123,10 @@ TextTrack::~TextTrack()
 
         for (size_t i = 0; i < m_cues->length(); ++i)
             m_cues->item(i)->setTrack(0);
+#if ENABLE(WEBVTT_REGIONS)
+        for (size_t i = 0; i < m_regions->length(); ++i)
+            m_regions->item(i)->setTrack(0);
+#endif
     }
     clearClient();
 }
@@ -272,6 +280,80 @@ void TextTrack::removeCue(TextTrackCue* cue, ExceptionCode& ec)
         m_client->textTrackRemoveCue(this, cue);
 }
 
+#if ENABLE(VIDEO_TRACK) && ENABLE(WEBVTT_REGIONS)
+TextTrackRegionList* TextTrack::ensureTextTrackRegionList()
+{
+    if (!m_regions)
+        m_regions = TextTrackRegionList::create();
+
+    return m_regions.get();
+}
+
+TextTrackRegionList* TextTrack::regions()
+{
+    // If the text track mode of the text track that the TextTrack object
+    // represents is not the text track disabled mode, then the regions
+    // attribute must return a live TextTrackRegionList object that represents
+    // the text track list of regions of the text track. Otherwise, it must
+    // return null. When an object is returned, the same object must be returned
+    // each time.
+    if (m_mode != disabledKeyword())
+        return ensureTextTrackRegionList();
+
+    return 0;
+}
+
+void TextTrack::addRegion(PassRefPtr<TextTrackRegion> prpRegion)
+{
+    if (!prpRegion)
+        return;
+
+    RefPtr<TextTrackRegion> region = prpRegion;
+    TextTrackRegionList* regionList = ensureTextTrackRegionList();
+
+    // 1. If the given region is in a text track list of regions, then remove
+    // region from that text track list of regions.
+    TextTrack* regionTrack = region->track();
+    if (regionTrack && regionTrack != this)
+        regionTrack->removeRegion(region.get(), ASSERT_NO_EXCEPTION);
+
+    // 2. If the method's TextTrack object's text track list of regions contains
+    // a region with the same identifier as region replace the values of that
+    // region's width, height, anchor point, viewport anchor point and scroll
+    // attributes with those of region.
+    TextTrackRegion* existingRegion = regionList->getRegionById(region->id());
+    if (existingRegion) {
+        existingRegion->updateParametersFromRegion(region.get());
+        return;
+    }
+
+    // Otherwise: add region to the method's TextTrack object's text track
+    // list of regions.
+    region->setTrack(this);
+    regionList->add(region);
+}
+
+void TextTrack::removeRegion(TextTrackRegion* region, ExceptionCode &ec)
+{
+    if (!region)
+        return;
+
+    // 1. If the given region is not currently listed in the method's TextTrack
+    // object's text track list of regions, then throw a NotFoundError exception.
+    if (region->track() != this) {
+        ec = NOT_FOUND_ERR;
+        return;
+    }
+
+    if (!m_regions || !m_regions->remove(region)) {
+        ec = INVALID_STATE_ERR;
+        return;
+    }
+
+    region->setTrack(0);
+}
+#endif
+
 void TextTrack::cueWillChange(TextTrackCue* cue)
 {
     if (!m_client)
index 92904e0..c1c1119 100644 (file)
@@ -45,6 +45,10 @@ class HTMLMediaElement;
 class TextTrack;
 class TextTrackCue;
 class TextTrackCueList;
+#if ENABLE(WEBVTT_REGIONS)
+class TextTrackRegion;
+class TextTrackRegionList;
+#endif
 
 class TextTrackClient {
 public:
@@ -109,6 +113,12 @@ public:
     void removeCue(TextTrackCue*, ExceptionCode&);
     bool hasCue(TextTrackCue*);
 
+#if ENABLE(VIDEO_TRACK) && ENABLE(WEBVTT_REGIONS)
+    TextTrackRegionList* regions();
+    void addRegion(PassRefPtr<TextTrackRegion>);
+    void removeRegion(TextTrackRegion*, ExceptionCode&);
+#endif
+
     void cueWillChange(TextTrackCue*);
     void cueDidChange(TextTrackCue*);
 
@@ -147,7 +157,10 @@ protected:
     RefPtr<TextTrackCueList> m_cues;
 
 private:
-    TextTrackCueList* ensureTextTrackCueList();
+#if ENABLE(VIDEO_TRACK) && ENABLE(WEBVTT_REGIONS)
+    TextTrackRegionList* ensureTextTrackRegionList();
+    RefPtr<TextTrackRegionList> m_regions;
+#endif
 
 #if USE(PLATFORM_TEXT_TRACK_MENU)
     virtual TextTrack* publicTrack() OVERRIDE { return this; }
@@ -155,6 +168,8 @@ private:
     RefPtr<PlatformTextTrack> m_platformTextTrack;
 #endif
 
+    TextTrackCueList* ensureTextTrackCueList();
+
     HTMLMediaElement* m_mediaElement;
     AtomicString m_kind;
     AtomicString m_label;
index 75da6b3..da355e2 100644 (file)
     void removeCue(in TextTrackCue cue)
         raises (DOMException);
 
+#if defined(ENABLE_WEBVTT_REGIONS) && ENABLE_WEBVTT_REGIONS
+    readonly attribute TextTrackRegionList regions;
+    void addRegion(in TextTrackRegion region);
+    void removeRegion(in TextTrackRegion region)
+        raises (DOMException);
+#endif
+
     // EventTarget interface
     void addEventListener(in DOMString type, 
                           in EventListener listener, 
index 6658898..6dbc8c7 100644 (file)
@@ -5,7 +5,7 @@
  * modification, are permitted provided that the following conditions are
  * met:
  *
- *     * Redistributions of source ec must retain the above copyright
+ *     * Redistributions of source code must retain the above copyright
  * notice, this list of conditions and the following disclaimer.
  *     * Redistributions in binary form must reproduce the above
  * copyright notice, this list of conditions and the following disclaimer
@@ -34,6 +34,8 @@
 
 #include "TextTrackRegion.h"
 
+#include "ExceptionCodePlaceholder.h"
+
 namespace WebCore {
 
 // The region occupies by default 100% of the width of the video viewport.
@@ -56,6 +58,7 @@ TextTrackRegion::TextTrackRegion()
     , m_regionAnchor(FloatPoint(defaultAnchorPointX, defaultAnchorPointY))
     , m_viewportAnchor(FloatPoint(defaultAnchorPointX, defaultAnchorPointY))
     , m_scroll(defaultScroll)
+    , m_track(0)
 {
 }
 
@@ -63,6 +66,11 @@ TextTrackRegion::~TextTrackRegion()
 {
 }
 
+void TextTrackRegion::setTrack(TextTrack* track)
+{
+    m_track = track;
+}
+
 void TextTrackRegion::setId(const String& id)
 {
     m_id = id;
@@ -175,6 +183,17 @@ void TextTrackRegion::setScroll(const AtomicString& value, ExceptionCode& ec)
     m_scroll = value == upScrollValueKeyword;
 }
 
+void TextTrackRegion::updateParametersFromRegion(TextTrackRegion* region)
+{
+    m_heightInLines = region->height();
+    m_width = region->width();
+
+    m_regionAnchor = FloatPoint(region->regionAnchorX(), region->regionAnchorY());
+    m_viewportAnchor = FloatPoint(region->viewportAnchorX(), region->viewportAnchorY());
+
+    setScroll(region->scroll(), ASSERT_NO_EXCEPTION);
+}
+
 void TextTrackRegion::setRegionSettings(const String& input)
 {
     // FIXME(109818): Parse region header metadata.
index 9eb3cb5..3f3d43e 100644 (file)
@@ -49,7 +49,8 @@ public:
 
     virtual ~TextTrackRegion();
 
-    TextTrack* track() const { return 0; }
+    TextTrack* track() const { return m_track; }
+    void setTrack(TextTrack*);
 
     const String& id() const { return m_id; }
     void setId(const String&);
@@ -75,6 +76,8 @@ public:
     const AtomicString scroll() const;
     void setScroll(const AtomicString&, ExceptionCode&);
 
+    void updateParametersFromRegion(TextTrackRegion*);
+
     const String& regionSettings() const { return m_settings; }
     void setRegionSettings(const String&);
 
@@ -101,6 +104,12 @@ private:
     FloatPoint m_viewportAnchor;
 
     bool m_scroll;
+
+    // The member variable track can be a raw pointer as it will never
+    // reference a destroyed TextTrack, as this member variable
+    // is cleared in the TextTrack destructor and it is generally
+    // set/reset within the addRegion and removeRegion methods.
+    TextTrack* m_track;
 };
 
 } // namespace WebCore
diff --git a/Source/WebCore/html/track/TextTrackRegionList.cpp b/Source/WebCore/html/track/TextTrackRegionList.cpp
new file mode 100644 (file)
index 0000000..63c62da
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2013 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(VIDEO_TRACK) && ENABLE(WEBVTT_REGIONS)
+
+#include "TextTrackRegionList.h"
+
+namespace WebCore {
+
+TextTrackRegionList::TextTrackRegionList()
+{
+}
+
+unsigned long TextTrackRegionList::length() const
+{
+    return m_list.size();
+}
+
+TextTrackRegion* TextTrackRegionList::item(unsigned index) const
+{
+    if (index < m_list.size())
+        return m_list[index].get();
+
+    return 0;
+}
+
+TextTrackRegion* TextTrackRegionList::getRegionById(const String& id) const
+{
+    for (size_t i = 0; i < m_list.size(); ++i) {
+        if (m_list[i]->id() == id)
+            return m_list[i].get();
+    }
+    return 0;
+}
+
+void TextTrackRegionList::add(PassRefPtr<TextTrackRegion> region)
+{
+    m_list.append(region);
+}
+
+bool TextTrackRegionList::remove(TextTrackRegion* region)
+{
+    size_t index = m_list.find(region);
+    if (index == notFound)
+        return false;
+
+    m_list.remove(index);
+    return true;
+}
+
+void TextTrackRegionList::clear()
+{
+    m_list.clear();
+}
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/html/track/TextTrackRegionList.h b/Source/WebCore/html/track/TextTrackRegionList.h
new file mode 100644 (file)
index 0000000..070e3e5
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2013 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TextTrackRegionList_h
+#define TextTrackRegionList_h
+
+#if ENABLE(VIDEO_TRACK) && ENABLE(WEBVTT_REGIONS)
+
+#include "TextTrackRegion.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class TextTrackRegionList : public RefCounted<TextTrackRegionList> {
+public:
+    static PassRefPtr<TextTrackRegionList> create()
+    {
+        return adoptRef(new TextTrackRegionList());
+    }
+
+    ~TextTrackRegionList() { }
+
+    unsigned long length() const;
+
+    TextTrackRegion* item(unsigned index) const;
+    TextTrackRegion* getRegionById(const String&) const;
+
+    void add(PassRefPtr<TextTrackRegion>);
+    bool remove(TextTrackRegion*);
+
+private:
+    TextTrackRegionList();
+    void clear();
+
+    Vector<RefPtr<TextTrackRegion> > m_list;
+};
+
+} // namespace WebCore
+
+#endif
+#endif
diff --git a/Source/WebCore/html/track/TextTrackRegionList.idl b/Source/WebCore/html/track/TextTrackRegionList.idl
new file mode 100644 (file)
index 0000000..3dca629
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2013 Google Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+[
+    Conditional=VIDEO_TRACK & WEBVTT_REGIONS,
+    V8EnabledAtRuntime=webkitVideoTrack,
+    IndexedGetter,
+    ImplementationLacksVTable
+] interface TextTrackRegionList {
+    readonly attribute unsigned long length;
+    TextTrackRegion item(in unsigned long index);
+    TextTrackRegion getRegionById(in DOMString id);
+};
+