Title: [104327] trunk
Revision
104327
Author
eric.carl...@apple.com
Date
2012-01-06 13:12:40 -0800 (Fri, 06 Jan 2012)

Log Message

Make TextTrackCue more mutable
https://bugs.webkit.org/show_bug.cgi?id=72555

Reviewed by Anders Carlsson.

Source/WebCore: 

Test: media/track/track-cue-mutable.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::updateActiveTextTrackCues): Do nothing if the "ignore cue updates"
    flag is set
(WebCore::HTMLMediaElement::textTrackAddCues): Block cue updates until all of the new cues have
    been added, then call updateActiveTextTrackCues so update the display if necessary.
(WebCore::HTMLMediaElement::textTrackRemoveCues): Block cue updates until all of the new cues have
    been removed, then call updateActiveTextTrackCues so update the display if necessary.
(WebCore::HTMLMediaElement::textTrackAddCue): Call updateActiveTextTrackCues so update the display if necessary.
(WebCore::HTMLMediaElement::textTrackRemoveCue): Ditto.
* html/HTMLMediaElement.h:
(WebCore::HTMLMediaElement::ignoreTrackDisplayUpdateRequests):
(WebCore::HTMLMediaElement::beginIgnoringTrackDisplayUpdateRequests):
(WebCore::HTMLMediaElement::endIgnoringTrackDisplayUpdateRequests):

* html/TextTrack.cpp:
(WebCore::TextTrack::cueWillChange): New, remove the cue from the media element because its
    position in the interval tree is based on start and end times.
(WebCore::TextTrack::cueDidChange): Add the cue to the media element.
* html/TextTrack.h:

* html/TextTrackCue.cpp:
(WebCore::startKeyword): New, use a static String for the constant.
(WebCore::middleKeyword): Ditto.
(WebCore::endKeyword): Ditto.
(WebCore::horizontalKeyword): Ditto.
(WebCore::verticalKeyword): Ditto.
(WebCore::verticallrKeyword): Ditto.
(WebCore::TextTrackCue::cueWillChange): New, tell the track the cue is about to change.
(WebCore::TextTrackCue::cueDidChange): New, tell the track the cue has changed.
(WebCore::TextTrackCue::setId): New, attribute is mutable.
(WebCore::TextTrackCue::setStartTime): Ditto.
(WebCore::TextTrackCue::setEndTime): Ditto.
(WebCore::TextTrackCue::setPauseOnExit): Ditto.
(WebCore::TextTrackCue::direction): Ditto.
(WebCore::TextTrackCue::setDirection): Ditto.
(WebCore::TextTrackCue::setSnapToLines): Ditto.
(WebCore::TextTrackCue::setLinePosition): Ditto.
(WebCore::TextTrackCue::setTextPosition): Ditto.
(WebCore::TextTrackCue::setSize): Ditto.
(WebCore::TextTrackCue::alignment): Ditto.
(WebCore::TextTrackCue::setAlignment): Ditto.
(WebCore::TextTrackCue::parseSettings): Use the static strings.
* html/TextTrackCue.h:
(WebCore::TextTrackCue::id):
(WebCore::TextTrackCue::startTime):
(WebCore::TextTrackCue::endTime):
(WebCore::TextTrackCue::pauseOnExit):
* html/TextTrackCue.idl:

LayoutTests: 

* media/track/track-cue-mutable-expected.txt: Added.
* media/track/track-cue-mutable.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (104326 => 104327)


--- trunk/LayoutTests/ChangeLog	2012-01-06 20:44:50 UTC (rev 104326)
+++ trunk/LayoutTests/ChangeLog	2012-01-06 21:12:40 UTC (rev 104327)
@@ -1,3 +1,13 @@
+2012-01-06  Eric Carlson  <eric.carl...@apple.com>
+
+        Make TextTrackCue more mutable
+        https://bugs.webkit.org/show_bug.cgi?id=72555
+
+        Reviewed by Anders Carlsson.
+
+        * media/track/track-cue-mutable-expected.txt: Added.
+        * media/track/track-cue-mutable.html: Added.
+
 2012-01-06  Ken Buchanan  <ke...@chromium.org>
 
         ASSERT failure due to combine-text with preceding spaces

Added: trunk/LayoutTests/media/track/track-cue-mutable-expected.txt (0 => 104327)


--- trunk/LayoutTests/media/track/track-cue-mutable-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/track/track-cue-mutable-expected.txt	2012-01-06 21:12:40 UTC (rev 104327)
@@ -0,0 +1,70 @@
+Tests modifying attributes of a TextTrackCue
+
+** Test initial values.
+RUN(textCue = cues.getCueById('1'))
+EXPECTED (textCue.startTime == '0') OK
+EXPECTED (textCue.endTime == '1') OK
+EXPECTED (textCue.pauseOnExit == 'false') OK
+EXPECTED (textCue.direction == 'horizontal') OK
+EXPECTED (textCue.snapToLines == 'true') OK
+EXPECTED (textCue.linePosition == '-1') OK
+EXPECTED (textCue.textPosition == '50') OK
+EXPECTED (textCue.size == '100') OK
+EXPECTED (textCue.alignment == 'middle') OK
+
+** Modify cue values.
+RUN(textCue.startTime = 1.1)
+EXPECTED (textCue.startTime == '1.1') OK
+
+RUN(textCue.endTime = 3.9)
+EXPECTED (textCue.endTime == '3.9') OK
+
+RUN(textCue.pauseOnExit = true)
+EXPECTED (textCue.pauseOnExit == 'true') OK
+
+On setting, the text track cue writing direction must be set to the value ... is a case-sensitive match for the new value, if any. If none of the values match, then the user agent must instead throw a SyntaxError exception.
+http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-direction
+TEST(textCue.direction = 'VERTICAL') THROWS(DOMException.SYNTAX_ERR) OK
+EXPECTED (textCue.direction == 'horizontal') OK
+RUN(textCue.direction = 'vertical')
+EXPECTED (textCue.direction == 'vertical') OK
+
+RUN(textCue.snapToLines = false)
+EXPECTED (textCue.snapToLines == 'false') OK
+
+On setting, if the text track cue snap-to-lines flag is not set, and the new value is negative or greater than 100, then throw an IndexSizeError exception.
+http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-lineposition
+TEST(textCue.linePosition = -2) THROWS(DOMException.INDEX_SIZE_ERR) OK
+TEST(textCue.linePosition = 102) THROWS(DOMException.INDEX_SIZE_ERR) OK
+EXPECTED (textCue.linePosition == '-1') OK
+RUN(textCue.linePosition = 42)
+EXPECTED (textCue.linePosition == '42') OK
+RUN(textCue.snapToLines = true)
+RUN(textCue.linePosition = -2)
+EXPECTED (textCue.linePosition == '-2') OK
+RUN(textCue.linePosition = 102)
+EXPECTED (textCue.linePosition == '102') OK
+
+On setting, if the new value is negative or greater than 100, then throw an IndexSizeError exception. Otherwise, set the text track cue text position to the new value.
+http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-lineposition
+TEST(textCue.textPosition = -200) THROWS(DOMException.INDEX_SIZE_ERR) OK
+TEST(textCue.textPosition = 110) THROWS(DOMException.INDEX_SIZE_ERR) OK
+RUN(textCue.textPosition = 11)
+EXPECTED (textCue.textPosition == '11') OK
+
+On setting, if the new value is negative or greater than 100, then throw an IndexSizeError exception. Otherwise, set the text track cue size to the new value.
+http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-size
+TEST(textCue.size = -200) THROWS(DOMException.INDEX_SIZE_ERR) OK
+TEST(textCue.size = 110) THROWS(DOMException.INDEX_SIZE_ERR) OK
+RUN(textCue.size = 57)
+EXPECTED (textCue.size == '57') OK
+
+On setting, the text track cue alignment must be set to the value ... is a case-sensitive match for the new value, if any. If none of the values match, then the user agent must instead throw a SyntaxError exception.
+http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-alignment
+TEST(textCue.alignment = 'End') THROWS(DOMException.SYNTAX_ERR) OK
+EXPECTED (textCue.alignment == 'middle') OK
+RUN(textCue.alignment = 'end')
+EXPECTED (textCue.alignment == 'end') OK
+
+END OF TEST
+

Added: trunk/LayoutTests/media/track/track-cue-mutable.html (0 => 104327)


--- trunk/LayoutTests/media/track/track-cue-mutable.html	                        (rev 0)
+++ trunk/LayoutTests/media/track/track-cue-mutable.html	2012-01-06 21:12:40 UTC (rev 104327)
@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+        <script src=""
+        <script src=""
+        <script>           
+
+            var cues;
+            
+            function logSpecURL(url, description)
+            {
+                consoleWrite("<br><i>" + description + "</i>");
+                consoleWrite("<a href="" + url + ">" + url + "<" + "/a>");
+            }
+
+            function trackLoaded()
+            {
+                track = document.getElementById('captions');
+                cues = track.track.cues;
+
+                consoleWrite("** Test initial values.");
+                run("textCue = cues.getCueById('1')");
+
+                testExpected("textCue.startTime", 0);
+                testExpected("textCue.endTime", 1.0);
+                testExpected("textCue.pauseOnExit", false);
+                testExpected("textCue.direction", "horizontal");
+                testExpected("textCue.snapToLines", true);
+                testExpected("textCue.linePosition", -1);
+                testExpected("textCue.textPosition", 50);
+                testExpected("textCue.size", 100);
+                testExpected("textCue.alignment", "middle");
+
+                consoleWrite("<br>** Modify cue values.");
+
+                run("textCue.startTime = 1.1");
+                testExpected("textCue.startTime", 1.1);
+
+                consoleWrite("");
+                run("textCue.endTime = 3.9");
+                testExpected("textCue.endTime", 3.9);
+
+                consoleWrite("");
+                run("textCue.pauseOnExit = true");
+                testExpected("textCue.pauseOnExit", true);
+
+                logSpecURL("http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-direction", 
+                           "On setting, the text track cue writing direction must be set to the value ... is a case-sensitive match for the new value, if any. If none of the values match, then the user agent must instead throw a SyntaxError exception.");
+                testException("textCue.direction = 'VERTICAL'", "DOMException.SYNTAX_ERR");
+                testExpected("textCue.direction", "horizontal");
+                run("textCue.direction = 'vertical'");
+                testExpected("textCue.direction", "vertical");
+
+                consoleWrite("");
+                run("textCue.snapToLines = false");
+                testExpected("textCue.snapToLines", false);
+
+                logSpecURL("http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-lineposition",
+                            "On setting, if the text track cue snap-to-lines flag is not set, and the new value is negative or greater than 100, then throw an IndexSizeError exception.");
+                testException("textCue.linePosition = -2", "DOMException.INDEX_SIZE_ERR");
+                testException("textCue.linePosition = 102", "DOMException.INDEX_SIZE_ERR");
+                testExpected("textCue.linePosition", -1);
+                run("textCue.linePosition = 42");
+                testExpected("textCue.linePosition", 42);
+                run("textCue.snapToLines = true");
+                run("textCue.linePosition = -2");
+                testExpected("textCue.linePosition", -2);
+                run("textCue.linePosition = 102");
+                testExpected("textCue.linePosition", 102);
+
+                logSpecURL("http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-lineposition", 
+                           "On setting, if the new value is negative or greater than 100, then throw an IndexSizeError exception. Otherwise, set the text track cue text position to the new value.");
+                testException("textCue.textPosition = -200", "DOMException.INDEX_SIZE_ERR");
+                testException("textCue.textPosition = 110", "DOMException.INDEX_SIZE_ERR");
+                run("textCue.textPosition = 11");
+                testExpected("textCue.textPosition", 11);
+
+                logSpecURL("http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-size",
+                           "On setting, if the new value is negative or greater than 100, then throw an IndexSizeError exception. Otherwise, set the text track cue size to the new value.");
+                testException("textCue.size = -200", "DOMException.INDEX_SIZE_ERR");
+                testException("textCue.size = 110", "DOMException.INDEX_SIZE_ERR");
+                run("textCue.size = 57");
+                testExpected("textCue.size", 57);
+
+                logSpecURL("http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-alignment",
+                           "On setting, the text track cue alignment must be set to the value ... is a case-sensitive match for the new value, if any. If none of the values match, then the user agent must instead throw a SyntaxError exception.");
+                testException("textCue.alignment = 'End'", "DOMException.SYNTAX_ERR");
+                testExpected("textCue.alignment", "middle");
+                run("textCue.alignment = 'end'");
+                testExpected("textCue.alignment", "end");
+
+                consoleWrite("");
+                endTest();
+            }
+
+        </script>
+    </head>
+    <body>
+        <p>Tests modifying attributes of a TextTrackCue</p>
+        <video controls>
+            <track id="captions" src="" kind="captions" _onload_="trackLoaded()" default>
+        </video>
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (104326 => 104327)


--- trunk/Source/WebCore/ChangeLog	2012-01-06 20:44:50 UTC (rev 104326)
+++ trunk/Source/WebCore/ChangeLog	2012-01-06 21:12:40 UTC (rev 104327)
@@ -1,3 +1,61 @@
+2012-01-06  Eric Carlson  <eric.carl...@apple.com>
+
+        Make TextTrackCue more mutable
+        https://bugs.webkit.org/show_bug.cgi?id=72555
+
+        Reviewed by Anders Carlsson.
+
+        Test: media/track/track-cue-mutable.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::updateActiveTextTrackCues): Do nothing if the "ignore cue updates"
+            flag is set
+        (WebCore::HTMLMediaElement::textTrackAddCues): Block cue updates until all of the new cues have
+            been added, then call updateActiveTextTrackCues so update the display if necessary.
+        (WebCore::HTMLMediaElement::textTrackRemoveCues): Block cue updates until all of the new cues have
+            been removed, then call updateActiveTextTrackCues so update the display if necessary.
+        (WebCore::HTMLMediaElement::textTrackAddCue): Call updateActiveTextTrackCues so update the display if necessary.
+        (WebCore::HTMLMediaElement::textTrackRemoveCue): Ditto.
+        * html/HTMLMediaElement.h:
+        (WebCore::HTMLMediaElement::ignoreTrackDisplayUpdateRequests):
+        (WebCore::HTMLMediaElement::beginIgnoringTrackDisplayUpdateRequests):
+        (WebCore::HTMLMediaElement::endIgnoringTrackDisplayUpdateRequests):
+
+        * html/TextTrack.cpp:
+        (WebCore::TextTrack::cueWillChange): New, remove the cue from the media element because its
+            position in the interval tree is based on start and end times.
+        (WebCore::TextTrack::cueDidChange): Add the cue to the media element.
+        * html/TextTrack.h:
+
+        * html/TextTrackCue.cpp:
+        (WebCore::startKeyword): New, use a static String for the constant.
+        (WebCore::middleKeyword): Ditto.
+        (WebCore::endKeyword): Ditto.
+        (WebCore::horizontalKeyword): Ditto.
+        (WebCore::verticalKeyword): Ditto.
+        (WebCore::verticallrKeyword): Ditto.
+        (WebCore::TextTrackCue::cueWillChange): New, tell the track the cue is about to change.
+        (WebCore::TextTrackCue::cueDidChange): New, tell the track the cue has changed.
+        (WebCore::TextTrackCue::setId): New, attribute is mutable.
+        (WebCore::TextTrackCue::setStartTime): Ditto.
+        (WebCore::TextTrackCue::setEndTime): Ditto.
+        (WebCore::TextTrackCue::setPauseOnExit): Ditto.
+        (WebCore::TextTrackCue::direction): Ditto.
+        (WebCore::TextTrackCue::setDirection): Ditto.
+        (WebCore::TextTrackCue::setSnapToLines): Ditto.
+        (WebCore::TextTrackCue::setLinePosition): Ditto.
+        (WebCore::TextTrackCue::setTextPosition): Ditto.
+        (WebCore::TextTrackCue::setSize): Ditto.
+        (WebCore::TextTrackCue::alignment): Ditto.
+        (WebCore::TextTrackCue::setAlignment): Ditto.
+        (WebCore::TextTrackCue::parseSettings): Use the static strings.
+        * html/TextTrackCue.h:
+        (WebCore::TextTrackCue::id):
+        (WebCore::TextTrackCue::startTime):
+        (WebCore::TextTrackCue::endTime):
+        (WebCore::TextTrackCue::pauseOnExit):
+        * html/TextTrackCue.idl:
+
 2012-01-06  Oliver Hunt  <oli...@apple.com>
 
         DFG no longer optimises CanvasPixelArray

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (104326 => 104327)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2012-01-06 20:44:50 UTC (rev 104326)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2012-01-06 21:12:40 UTC (rev 104327)
@@ -948,6 +948,9 @@
 #if ENABLE(VIDEO_TRACK)
 void HTMLMediaElement::updateActiveTextTrackCues(float movieTime)
 {
+    if (ignoreTrackDisplayUpdateRequests())
+        return;
+    
     CueList previouslyActiveCues = m_currentlyActiveCues;
     bool activeSetChanged = false;
 
@@ -1030,24 +1033,32 @@
 
 void HTMLMediaElement::textTrackAddCues(TextTrack*, const TextTrackCueList* cues) 
 {
+    beginIgnoringTrackDisplayUpdateRequests();
     for (size_t i = 0; i < cues->length(); ++i)
         textTrackAddCue(cues->item(i)->track(), cues->item(i));
+    endIgnoringTrackDisplayUpdateRequests();
+    updateActiveTextTrackCues(currentTime());
 }
 
 void HTMLMediaElement::textTrackRemoveCues(TextTrack*, const TextTrackCueList* cues) 
 {
+    beginIgnoringTrackDisplayUpdateRequests();
     for (size_t i = 0; i < cues->length(); ++i)
         textTrackRemoveCue(cues->item(i)->track(), cues->item(i));
+    endIgnoringTrackDisplayUpdateRequests();
+    updateActiveTextTrackCues(currentTime());
 }
 
 void HTMLMediaElement::textTrackAddCue(TextTrack*, PassRefPtr<TextTrackCue> cue)
 {
     m_cueTree.add(m_cueTree.createInterval(cue->startTime(), cue->endTime(), cue.get()));
+    updateActiveTextTrackCues(currentTime());
 }
 
 void HTMLMediaElement::textTrackRemoveCue(TextTrack*, PassRefPtr<TextTrackCue> cue)
 {
     m_cueTree.remove(m_cueTree.createInterval(cue->startTime(), cue->endTime(), cue.get()));
+    updateActiveTextTrackCues(currentTime());
 }
 
 #endif

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (104326 => 104327)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2012-01-06 20:44:50 UTC (rev 104326)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2012-01-06 21:12:40 UTC (rev 104327)
@@ -400,6 +400,10 @@
     bool userIsInterestedInThisLanguage(const String&) const;
     bool userIsInterestedInThisTrack(HTMLTrackElement*) const;
     HTMLTrackElement* showingTrackWithSameKind(HTMLTrackElement*) const;
+
+    bool ignoreTrackDisplayUpdateRequests() const { return m_ignoreTrackDisplayUpdate > 0; }
+    void beginIgnoringTrackDisplayUpdateRequests() { ++m_ignoreTrackDisplayUpdate; }
+    void endIgnoringTrackDisplayUpdateRequests() { ASSERT(m_ignoreTrackDisplayUpdate); --m_ignoreTrackDisplayUpdate; }
 #endif
 
     // These "internal" functions do not check user gesture restrictions.
@@ -566,6 +570,7 @@
     Vector<RefPtr<TextTrack> > m_textTracksWhenResourceSelectionBegan;
     CueIntervalTree m_cueTree;
     CueList m_currentlyActiveCues;
+    int m_ignoreTrackDisplayUpdate;
 #endif
 
 #if ENABLE(WEB_AUDIO)

Modified: trunk/Source/WebCore/html/TextTrack.cpp (104326 => 104327)


--- trunk/Source/WebCore/html/TextTrack.cpp	2012-01-06 20:44:50 UTC (rev 104326)
+++ trunk/Source/WebCore/html/TextTrack.cpp	2012-01-06 21:12:40 UTC (rev 104327)
@@ -251,7 +251,26 @@
     ExceptionCode ec = 0;
     dispatchEvent(Event::create(eventNames().cuechangeEvent, false, false), ec);
 }
+    
+void TextTrack::cueWillChange(TextTrackCue* cue)
+{
+    if (!m_client)
+        return;
 
+    // The cue may need to be repositioned in the media element's interval tree, may need to
+    // be re-rendered, etc, so remove it before the modification...
+    m_client->textTrackRemoveCue(this, cue);
+}
+
+void TextTrack::cueDidChange(TextTrackCue* cue)
+{
+    if (!m_client)
+        return;
+
+    // ... and add it back again.
+    m_client->textTrackAddCue(this, cue);
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/html/TextTrack.h (104326 => 104327)


--- trunk/Source/WebCore/html/TextTrack.h	2012-01-06 20:44:50 UTC (rev 104326)
+++ trunk/Source/WebCore/html/TextTrack.h	2012-01-06 21:12:40 UTC (rev 104327)
@@ -98,6 +98,9 @@
 
     void addCue(PassRefPtr<TextTrackCue>, ExceptionCode&);
     void removeCue(TextTrackCue*, ExceptionCode&);
+
+    void cueWillChange(TextTrackCue*);
+    void cueDidChange(TextTrackCue*);
     
     virtual void fireCueChangeEvent();
     DEFINE_ATTRIBUTE_EVENT_LISTENER(cuechange);

Modified: trunk/Source/WebCore/html/TextTrackCue.cpp (104326 => 104327)


--- trunk/Source/WebCore/html/TextTrackCue.cpp	2012-01-06 20:44:50 UTC (rev 104326)
+++ trunk/Source/WebCore/html/TextTrackCue.cpp	2012-01-06 21:12:40 UTC (rev 104327)
@@ -42,6 +42,41 @@
 
 namespace WebCore {
 
+static const AtomicString& startKeyword()
+{
+    DEFINE_STATIC_LOCAL(const AtomicString, start, ("start"));
+    return start;
+}
+
+static const AtomicString& middleKeyword()
+{
+    DEFINE_STATIC_LOCAL(const AtomicString, middle, ("middle"));
+    return middle;
+}
+
+static const AtomicString& endKeyword()
+{
+    DEFINE_STATIC_LOCAL(const AtomicString, end, ("end"));
+    return end;
+}
+
+static const AtomicString& horizontalKeyword()
+{
+    DEFINE_STATIC_LOCAL(const AtomicString, horizontal, ("horizontal"));
+    return horizontal;
+}
+
+static const AtomicString& verticalKeyword()
+{
+    DEFINE_STATIC_LOCAL(const AtomicString, vertical, ("vertical"));
+    return vertical;
+}
+static const AtomicString& verticallrKeyword()
+{
+    DEFINE_STATIC_LOCAL(const AtomicString, verticallr, ("vertical-lr"));
+    return verticallr;
+}
+    
 TextTrackCue::TextTrackCue(ScriptExecutionContext* context, const String& id, double start, double end, const String& content, const String& settings, bool pauseOnExit)
     : m_id(id)
     , m_startTime(start)
@@ -64,6 +99,18 @@
 {
 }
 
+void TextTrackCue::cueWillChange()
+{
+    if (m_track)
+        m_track->cueWillChange(this);
+}
+
+void TextTrackCue::cueDidChange()
+{
+    if (m_track)
+        m_track->cueDidChange(this);
+}
+
 TextTrack* TextTrackCue::track() const
 {
     return m_track.get();
@@ -74,54 +121,195 @@
     m_track = track;
 }
 
-String TextTrackCue::id() const
+void TextTrackCue::setId(const String& id)
 {
-    return m_id;
+    if (m_id == id)
+        return;
+
+    cueWillChange();
+    m_id = id;
+    cueDidChange();
 }
 
-double TextTrackCue::startTime() const
+void TextTrackCue::setStartTime(double value)
 {
-    return m_startTime;
+    if (m_startTime == value)
+        return;
+    
+    cueWillChange();
+    m_startTime = value;
+    cueDidChange();
 }
-
-double TextTrackCue::endTime() const
+    
+void TextTrackCue::setEndTime(double value)
 {
-    return m_endTime;
+    if (m_endTime == value)
+        return;
+    
+    cueWillChange();
+    m_endTime = value;
+    cueDidChange();
 }
-
-bool TextTrackCue::pauseOnExit() const
+    
+void TextTrackCue::setPauseOnExit(bool value)
 {
-    return m_pauseOnExit;
+    if (m_pauseOnExit == value)
+        return;
+    
+    cueWillChange();
+    m_pauseOnExit = value;
+    cueDidChange();
 }
 
 String TextTrackCue::direction() const
 {
     switch (m_writingDirection) {
     case Horizontal: 
-        return "horizontal";
+        return horizontalKeyword();
     case VerticalGrowingLeft:
-        return "vertical";
+        return verticalKeyword();
     case VerticalGrowingRight:
-        return "vertical-lr";
+        return verticallrKeyword();
     default:
+        ASSERT_NOT_REACHED();
         return "";
     }
 }
 
+void TextTrackCue::setDirection(const String& value, ExceptionCode& ec)
+{
+    // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-direction
+    // On setting, the text track cue writing direction must be set to the value given 
+    // in the first cell of the row in the table above whose second cell is a 
+    // case-sensitive match for the new value, if any. If none of the values match, then
+    // the user agent must instead throw a SyntaxError exception.
+    
+    Direction direction = m_writingDirection;
+    if (value == horizontalKeyword())
+        direction = Horizontal;
+    else if (value == verticalKeyword())
+        direction = VerticalGrowingLeft;
+    else if (value == verticallrKeyword())
+        direction = VerticalGrowingRight;
+    else
+        ec = SYNTAX_ERR;
+    
+    if (direction == m_writingDirection)
+        return;
+
+    cueWillChange();
+    m_writingDirection = direction;
+    cueDidChange();
+}
+
+void TextTrackCue::setSnapToLines(bool value)
+{
+    if (m_snapToLines == value)
+        return;
+    
+    cueWillChange();
+    m_snapToLines = value;
+    cueDidChange();
+}
+
+void TextTrackCue::setLinePosition(int position, ExceptionCode& ec)
+{
+    // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-lineposition
+    // On setting, if the text track cue snap-to-lines flag is not set, and the new
+    // value is negative or greater than 100, then throw an IndexSizeError exception.
+    if (!m_snapToLines && (position < 0 || position > 100)) {
+        ec = INDEX_SIZE_ERR;
+        return;
+    }
+    
+    // Otherwise, set the text track cue line position to the new value.
+    if (m_linePosition == position)
+        return;
+    
+    cueWillChange();
+    m_linePosition = position; 
+    cueDidChange();
+}
+
+void TextTrackCue::setTextPosition(int position, ExceptionCode& ec)
+{
+    // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-lineposition
+    // On setting, if the new value is negative or greater than 100, then throw an IndexSizeError exception.
+    // Otherwise, set the text track cue text position to the new value.
+    if (position < 0 || position > 100) {
+        ec = INDEX_SIZE_ERR;
+        return;
+    }
+    
+    // Otherwise, set the text track cue line position to the new value.
+    if (m_textPosition == position)
+        return;
+    
+    cueWillChange();
+    m_textPosition = position; 
+    cueDidChange();
+}
+
+void TextTrackCue::setSize(int size, ExceptionCode& ec)
+{
+    // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-size
+    // On setting, if the new value is negative or greater than 100, then throw an IndexSizeError
+    // exception. Otherwise, set the text track cue size to the new value.
+    if (size < 0 || size > 100) {
+        ec = INDEX_SIZE_ERR;
+        return;
+    }
+    
+    // Otherwise, set the text track cue line position to the new value.
+    if (m_cueSize == size)
+        return;
+    
+    cueWillChange();
+    m_cueSize = size;
+    cueDidChange();
+}
+
 String TextTrackCue::alignment() const
 {
     switch (m_cueAlignment) {
-    case Start: 
-        return "start";
+    case Start:
+        return startKeyword();
     case Middle:
-        return "middle";
+        return middleKeyword();
     case End:
-        return "end";
+        return endKeyword();
     default:
+        ASSERT_NOT_REACHED();
         return "";
     }
 }
 
+void TextTrackCue::setAlignment(const String& value, ExceptionCode& ec)
+{
+    // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-alignment
+    // On setting, the text track cue alignment must be set to the value given in the 
+    // first cell of the row in the table above whose second cell is a case-sensitive
+    // match for the new value, if any. If none of the values match, then the user
+    // agent must instead throw a SyntaxError exception.
+    
+    Alignment alignment = m_cueAlignment;
+    if (value == startKeyword())
+        alignment = Start;
+    else if (value == middleKeyword())
+        alignment = Middle;
+    else if (value == endKeyword())
+        alignment = End;
+    else
+        ec = SYNTAX_ERR;
+    
+    if (alignment == m_cueAlignment)
+        return;
+
+    cueWillChange();
+    m_cueAlignment = alignment;
+    cueDidChange();
+}
+    
 String TextTrackCue::getCueAsSource()
 {
     return m_content;
@@ -187,9 +375,9 @@
             {
             // 1-3 - Collect the next word and set the writing direction accordingly.
             String writingDirection = WebVTTParser::collectWord(input, &position);
-            if (writingDirection == "vertical")
+            if (writingDirection == verticalKeyword())
                 m_writingDirection = VerticalGrowingLeft;
-            else if (writingDirection == "vertical-lr")
+            else if (writingDirection == verticallrKeyword())
                 m_writingDirection = VerticalGrowingRight;
             }
             break;
@@ -297,11 +485,11 @@
             {
             // 1-4 - Collect the next word and set the cue alignment accordingly.
             String cueAlignment = WebVTTParser::collectWord(input, &position);
-            if (cueAlignment == "start")
+            if (cueAlignment == startKeyword())
                 m_cueAlignment = Start;
-            else if (cueAlignment == "middle")
+            else if (cueAlignment == middleKeyword())
                 m_cueAlignment = Middle;
-            else if (cueAlignment == "end")
+            else if (cueAlignment == endKeyword())
                 m_cueAlignment = End;
             }
             break;

Modified: trunk/Source/WebCore/html/TextTrackCue.h (104326 => 104327)


--- trunk/Source/WebCore/html/TextTrackCue.h	2012-01-06 20:44:50 UTC (rev 104326)
+++ trunk/Source/WebCore/html/TextTrackCue.h	2012-01-06 21:12:40 UTC (rev 104327)
@@ -59,19 +59,38 @@
     TextTrack* track() const;
     void setTrack(PassRefPtr<TextTrack>);
 
-    String id() const;
-    double startTime() const;
-    double endTime() const;
-    bool pauseOnExit() const;
-    
+    String id() const { return m_id; }
+    void setId(const String&);
+
+    double startTime() const { return m_startTime; }
+    void setStartTime(double);
+
+    double endTime() const { return m_endTime; }
+    void setEndTime(double);
+
+    bool pauseOnExit() const { return m_pauseOnExit; }
+    void setPauseOnExit(bool);
+
     String direction() const;
+    void setDirection(const String&, ExceptionCode&);
+
     bool snapToLines() const { return m_snapToLines; }
+    void setSnapToLines(bool);
+
     int linePosition() const { return m_linePosition; }
+    void setLinePosition(int, ExceptionCode&);
+
     int textPosition() const { return m_textPosition; }
+    void setTextPosition(int, ExceptionCode&);
+
     int size() const { return m_cueSize; }
+    void setSize(int, ExceptionCode&);
+
     String alignment() const;
+    void setAlignment(const String&, ExceptionCode&);
 
     String getCueAsSource();
+
     PassRefPtr<DocumentFragment> getCueAsHTML();
     void setCueHTML(PassRefPtr<DocumentFragment>);
 
@@ -96,6 +115,8 @@
     TextTrackCue(ScriptExecutionContext*, const String& id, double start, double end, const String& content, const String& settings, bool pauseOnExit);
 
     void parseSettings(const String&);
+    void cueWillChange();
+    void cueDidChange();
     
     virtual void refEventTarget() { ref(); }
     virtual void derefEventTarget() { deref(); }

Modified: trunk/Source/WebCore/html/TextTrackCue.idl (104326 => 104327)


--- trunk/Source/WebCore/html/TextTrackCue.idl	2012-01-06 20:44:50 UTC (rev 104326)
+++ trunk/Source/WebCore/html/TextTrackCue.idl	2012-01-06 21:12:40 UTC (rev 104327)
@@ -36,18 +36,23 @@
         CustomIsReachable
     ] TextTrackCue {
         readonly attribute TextTrack track;
-        readonly attribute DOMString id;
 
-        readonly attribute double startTime;
-        readonly attribute double endTime;
-        readonly attribute boolean pauseOnExit;
+        attribute DOMString id;
+        attribute double startTime;
+        attribute double endTime;
+        attribute boolean pauseOnExit;
 
-        readonly attribute DOMString direction;
-        readonly attribute boolean snapToLines;
-        readonly attribute long linePosition;
-        readonly attribute long textPosition;
-        readonly attribute long size;
-        readonly attribute DOMString alignment;
+        attribute DOMString direction
+            setter raises (DOMException);
+        attribute boolean snapToLines;
+        attribute long linePosition
+            setter raises (DOMException);
+        attribute long textPosition
+            setter raises (DOMException);
+        attribute long size
+            setter raises (DOMException);
+        attribute DOMString alignment
+            setter raises (DOMException);
 
         DOMString getCueAsSource();
         DocumentFragment getCueAsHTML();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to