⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 101185 in webkit


Ignore:
Timestamp:
Nov 25, 2011, 8:28:39 PM (15 years ago)
Author:
eric.carlson@apple.com
Message:

Implement addCue and removeCue in TextTrack
https://bugs.webkit.org/show_bug.cgi?id=72554

Reviewed by Darin Adler.

Source/WebCore:

Test: media/track/track-add-remove-cue.html

  • html/HTMLTrackElement.cpp:

(WebCore::HTMLTrackElement::ensureTrack): Go ahead and allocate a Track even if the feature

is disabled, it just won't load anything.

(WebCore::HTMLTrackElement::scheduleLoad): Early return if the featue is disabled.
(WebCore::HTMLTrackElement::canLoadUrl): Ditto.

  • html/LoadableTextTrack.cpp:

(WebCore::LoadableTextTrack::newCuesAvailable): Add new cues one at a time because

cues->add(Vector<TextTrackCue*>&) is gone.

  • html/TextTrack.cpp:

(WebCore::TextTrack::addCue): Implement.
(WebCore::TextTrack::removeCue): Ditto.

  • html/TextTrack.h:

(WebCore::TextTrackCue::TextTrackCue): Initialize every member variable.
(WebCore::TextTrackCue::track): m_track is now a RefPtr.
(WebCore::TextTrackCue::setTrack): Ditto.

  • html/TextTrackCue.h:
  • html/TextTrackCueList.cpp:

(WebCore::TextTrackCueList::add): Don't ignore out of order cues, the spec text is not

a conformance requirement. Return bool to indicate success or failure.

(WebCore::TextTrackCueList::remove): Return bool to indicate success or failure.

  • html/TextTrackCueList.h:
  • loader/TextTrackLoader.cpp:

(WebCore::TextTrackLoader::notifyFinished): Don't change m_state once it is set to Failed.

LayoutTests:

  • media/track/track-add-remove-cue-expected.txt: Added.
  • media/track/track-add-remove-cue.html: Added.
  • media/track/track-webvtt-tc012-out-of-order-expected.txt: Removed.
  • media/track/track-webvtt-tc012-out-of-order.html: Removed.
Location:
trunk
Files:
2 added
2 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r101183 r101185  
     12011-11-25  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Implement addCue and removeCue in TextTrack
     4        https://bugs.webkit.org/show_bug.cgi?id=72554
     5
     6        Reviewed by Darin Adler.
     7
     8        * media/track/track-add-remove-cue-expected.txt: Added.
     9        * media/track/track-add-remove-cue.html: Added.
     10        * media/track/track-webvtt-tc012-out-of-order-expected.txt: Removed.
     11        * media/track/track-webvtt-tc012-out-of-order.html: Removed.
     12
    1132011-11-25  Kentaro Hara  <haraken@chromium.org>
    214
  • trunk/Source/WebCore/ChangeLog

    r101184 r101185  
     12011-11-25  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Implement addCue and removeCue in TextTrack
     4        https://bugs.webkit.org/show_bug.cgi?id=72554
     5
     6        Reviewed by Darin Adler.
     7
     8        Test: media/track/track-add-remove-cue.html
     9
     10        * html/HTMLTrackElement.cpp:
     11        (WebCore::HTMLTrackElement::ensureTrack): Go ahead and allocate a Track even if the feature
     12            is disabled, it just won't load anything.
     13        (WebCore::HTMLTrackElement::scheduleLoad): Early return if the featue is disabled.
     14        (WebCore::HTMLTrackElement::canLoadUrl): Ditto.
     15
     16        * html/LoadableTextTrack.cpp:
     17        (WebCore::LoadableTextTrack::newCuesAvailable): Add new cues one at a time because
     18            cues->add(Vector<TextTrackCue*>&) is gone.
     19
     20        * html/TextTrack.cpp:
     21        (WebCore::TextTrack::addCue): Implement.
     22        (WebCore::TextTrack::removeCue): Ditto.
     23        * html/TextTrack.h:
     24
     25        (WebCore::TextTrackCue::TextTrackCue): Initialize every member variable.
     26        (WebCore::TextTrackCue::track): m_track is now a RefPtr.
     27        (WebCore::TextTrackCue::setTrack): Ditto.
     28        * html/TextTrackCue.h:
     29
     30        * html/TextTrackCueList.cpp:
     31        (WebCore::TextTrackCueList::add): Don't ignore out of order cues, the spec text is not
     32            a conformance requirement. Return bool to indicate success or failure.
     33        (WebCore::TextTrackCueList::remove): Return bool to indicate success or failure.
     34        * html/TextTrackCueList.h:
     35
     36        * loader/TextTrackLoader.cpp:
     37        (WebCore::TextTrackLoader::notifyFinished): Don't change m_state once it is set to Failed.
     38
    1392011-11-25  Kentaro Hara  <haraken@chromium.org>
    240
  • trunk/Source/WebCore/html/HTMLTrackElement.cpp

    r101088 r101185  
    159159LoadableTextTrack* HTMLTrackElement::ensureTrack()
    160160{
    161     if (!RuntimeEnabledFeatures::webkitVideoTrackEnabled())
    162         return 0;
    163 
    164161    if (!m_track) {
    165162        // The kind attribute is an enumerated attribute, limited only to know values. It defaults to 'subtitles' if missing or invalid.
     
    184181void HTMLTrackElement::scheduleLoad()
    185182{
     183    if (!RuntimeEnabledFeatures::webkitVideoTrackEnabled())
     184        return;
     185
    186186    if (!mediaElement())
    187187        return;
     
    195195bool HTMLTrackElement::canLoadUrl(LoadableTextTrack*, const KURL& url)
    196196{
     197    if (!RuntimeEnabledFeatures::webkitVideoTrackEnabled())
     198        return false;
     199
    197200    HTMLMediaElement* parent = mediaElement();
    198201    if (!parent)
  • trunk/Source/WebCore/html/LoadableTextTrack.cpp

    r101088 r101185  
    8686    m_loader->getNewCues(newCues);
    8787
    88     for (size_t i = 0; i < newCues.size(); ++i)
    89         newCues[i]->setTrack(this);
    90 
    9188    if (!m_cues)
    9289        m_cues = TextTrackCueList::create();   
    93     m_cues->add(newCues);
     90
     91    for (size_t i = 0; i < newCues.size(); ++i) {
     92        newCues[i]->setTrack(this);
     93        m_cues->add(newCues[i]);
     94    }
    9495
    9596    if (client())
  • trunk/Source/WebCore/html/TextTrack.cpp

    r101088 r101185  
    167167}
    168168
    169 void TextTrack::addCue(PassRefPtr<TextTrackCue>, ExceptionCode&)
    170 {
    171     // FIXME(62890): Implement.
     169void TextTrack::addCue(PassRefPtr<TextTrackCue> prpCue, ExceptionCode& ec)
     170{
     171    if (!prpCue)
     172        return;
     173
     174    RefPtr<TextTrackCue> cue = prpCue;
     175
     176    // 4.8.10.12.4 Text track API
     177
     178    // The addCue(cue) method of TextTrack objects, when invoked, must run the following steps:
     179
     180    // 1. If the given cue is already associated with a text track other than
     181    // the method's TextTrack object's text track, then throw an InvalidStateError
     182    // exception and abort these steps.
     183    TextTrack* cueTrack = cue->track();
     184    if (cueTrack && cueTrack != this) {
     185        ec = INVALID_STATE_ERR;
     186        return;
     187    }
     188
     189    // 2. Associate cue with the method's TextTrack object's text track, if it is
     190    // not currently associated with a text track.
     191    cue->setTrack(this);
     192
     193    // 3. If the given cue is already listed in the method's TextTrack object's text
     194    // track's text track list of cues, then throw an InvalidStateError exception.
     195    // 4. Add cue to the method's TextTrack object's text track's text track list of cues.
     196    if (!m_cues->add(cue)) {
     197        ec = INVALID_STATE_ERR;
     198        return;
     199    }
    172200   
    173 }
    174 
    175 void TextTrack::removeCue(PassRefPtr<TextTrackCue>, ExceptionCode&)
    176 {
    177     // FIXME(62890): Implement.
    178 }
    179 
    180 void TextTrack::newCuesLoaded()
    181 {
    182     // FIXME(62890): Implement.
    183 }
    184 
    185 void TextTrack::fetchNewestCues(Vector<TextTrackCue*>&)
    186 {
    187     // FIXME(62890): Implement.
     201    if (m_client)
     202        m_client->textTrackAddCue(this, cue.get());
     203}
     204
     205void TextTrack::removeCue(TextTrackCue* cue, ExceptionCode& ec)
     206{
     207    if (!cue)
     208        return;
     209
     210    // 4.8.10.12.4 Text track API
     211
     212    // The removeCue(cue) method of TextTrack objects, when invoked, must run the following steps:
     213
     214    // 1. If the given cue is not associated with the method's TextTrack
     215    // object's text track, then throw an InvalidStateError exception.
     216    if (cue->track() != this) {
     217        ec = INVALID_STATE_ERR;
     218        return;
     219    }
     220   
     221    // 2. If the given cue is not currently listed in the method's TextTrack
     222    // object's text track's text track list of cues, then throw a NotFoundError exception.
     223    // 3. Remove cue from the method's TextTrack object's text track's text track list of cues.
     224    if (!m_cues->remove(cue)) {
     225        ec = INVALID_STATE_ERR;
     226        return;
     227    }
     228
     229    cue->setTrack(0);
     230    if (m_client)
     231        m_client->textTrackRemoveCue(this, cue);
    188232}
    189233
  • trunk/Source/WebCore/html/TextTrack.h

    r101088 r101185  
    9494
    9595    void addCue(PassRefPtr<TextTrackCue>, ExceptionCode&);
    96     void removeCue(PassRefPtr<TextTrackCue>, ExceptionCode&);
    97    
    98     void newCuesLoaded();
    99     void fetchNewestCues(Vector<TextTrackCue*>&);
     96    void removeCue(TextTrackCue*, ExceptionCode&);
    10097   
    10198    virtual void fireCueChangeEvent();
  • trunk/Source/WebCore/html/TextTrackCue.cpp

    r100064 r101185  
    4848    , m_endTime(end)
    4949    , m_content(content)
    50     , m_pauseOnExit(pauseOnExit)
    5150    , m_writingDirection(Horizontal)
    52     , m_snapToLines(true)
    5351    , m_linePosition(-1)
    5452    , m_textPosition(50)
    5553    , m_cueSize(100)
    5654    , m_cueAlignment(Middle)
     55    , m_scriptExecutionContext(context)
    5756    , m_isActive(false)
    58     , m_scriptExecutionContext(context)
     57    , m_pauseOnExit(pauseOnExit)
     58    , m_snapToLines(true)
    5959{
    6060    parseSettings(settings);
     
    6767TextTrack* TextTrackCue::track() const
    6868{
    69     return m_track;
    70 }
    71 
    72 void TextTrackCue::setTrack(TextTrack* track)
     69    return m_track.get();
     70}
     71
     72void TextTrackCue::setTrack(PassRefPtr<TextTrack>track)
    7373{
    7474    m_track = track;
  • trunk/Source/WebCore/html/TextTrackCue.h

    r100064 r101185  
    5858
    5959    TextTrack* track() const;
    60     void setTrack(TextTrack*);
     60    void setTrack(PassRefPtr<TextTrack>);
    6161
    6262    String id() const;
     
    101101    virtual void derefEventTarget() { deref(); }
    102102   
    103     TextTrack* m_track;
    104    
    105103    String m_id;
    106104    double m_startTime;
    107105    double m_endTime;
    108106    String m_content;
    109     bool m_pauseOnExit;
    110107    Direction m_writingDirection;
    111     bool m_snapToLines;
    112108    int m_linePosition;
    113109    int m_textPosition;
     
    115111    Alignment m_cueAlignment;
    116112    RefPtr<DocumentFragment> m_documentFragment;
     113    RefPtr<TextTrack> m_track;
     114
     115    EventTargetData m_eventTargetData;
     116    ScriptExecutionContext* m_scriptExecutionContext;
    117117
    118118    bool m_isActive;
    119    
    120     EventTargetData m_eventTargetData;
    121     ScriptExecutionContext* m_scriptExecutionContext;
     119    bool m_pauseOnExit;
     120    bool m_snapToLines;
    122121};
    123122
  • trunk/Source/WebCore/html/TextTrackCueList.cpp

    r100085 r101185  
    7171}
    7272
    73 void TextTrackCueList::add(const Vector<RefPtr<TextTrackCue> >& newCues)
     73bool TextTrackCueList::add(PassRefPtr<TextTrackCue> cue)
    7474{
    75     for (size_t i = 0; i < newCues.size(); ++i)
    76         add(newCues[i]);
     75    return add(cue, 0, m_list.size());
    7776}
    7877
    79 void TextTrackCueList::add(PassRefPtr<TextTrackCue> cue)
    80 {
    81     // WebVTT cue timings
    82     // 1. The time represented by this WebVTT timestamp must be greater than or equal
    83     // to the start time offsets of all previous cues in the file.
    84     // http://www.whatwg.org/specs/web-apps/current-work/#webvtt-cue-timings
    85     // Note: because this requirement is specific to WebVTT, we may want to check first
    86     // whether the cues in this list came from a WebVTT file.
    87     if (!m_list.isEmpty() && cue->startTime() < m_list.last()->startTime())
    88         return;
    89     add(cue, 0, m_list.size());
    90 }
    91 
    92 void TextTrackCueList::add(PassRefPtr<TextTrackCue> cue, size_t start, size_t end)
     78bool TextTrackCueList::add(PassRefPtr<TextTrackCue> prpCue, size_t start, size_t end)
    9379{
    9480    ASSERT(start <= m_list.size());
     
    9783    // Maintain text track cue order:
    9884    // http://www.whatwg.org/specs/web-apps/current-work/#text-track-cue-order
    99     RefPtr<TextTrackCue> newCue = cue;
     85    RefPtr<TextTrackCue> cue = prpCue;
    10086    if (start == end) {
    101        m_list.insert(start, newCue);
    102        return;
     87        if (!m_list.isEmpty() && (m_list[start - 1].get() == cue.get()))
     88            return false;
     89
     90       m_list.insert(start, cue);
     91       return true;
    10392    }
    10493
    10594    size_t index = (start + end) / 2;
    106     if (newCue->startTime() < m_list[index]->startTime() || (newCue->startTime() == m_list[index]->startTime() && newCue->endTime() > m_list[index]->endTime()))
    107         add(newCue.release(), start, index);
    108     else
    109         add(newCue.release(), index + 1, end);
     95    if (cue->startTime() < m_list[index]->startTime() || (cue->startTime() == m_list[index]->startTime() && cue->endTime() > m_list[index]->endTime()))
     96        return add(cue.release(), start, index);
     97
     98    return add(cue.release(), index + 1, end);
    11099}
    111100
    112 void TextTrackCueList::remove(TextTrackCue* cue)
     101bool TextTrackCueList::remove(TextTrackCue* cue)
    113102{
    114103    size_t index = m_list.find(cue);
    115104    if (index == notFound)
    116         return;
     105        return false;
     106
    117107    cue->setIsActive(false);
    118108    m_list.remove(index);
     109    return true;
    119110}
    120111
  • trunk/Source/WebCore/html/TextTrackCueList.h

    r100064 r101185  
    5050    TextTrackCueList* activeCues();
    5151
    52     void add(PassRefPtr<TextTrackCue>);
    53     void add(const Vector<RefPtr<TextTrackCue> >&);
    54     void remove(TextTrackCue*);
     52    bool add(PassRefPtr<TextTrackCue>);
     53    bool remove(TextTrackCue*);
    5554    bool contains(TextTrackCue*) const;
    5655
    5756private:
    5857    TextTrackCueList();
    59     void add(PassRefPtr<TextTrackCue>, size_t, size_t);
     58    bool add(PassRefPtr<TextTrackCue>, size_t, size_t);
    6059    void clear();
    6160   
  • trunk/Source/WebCore/loader/TextTrackLoader.cpp

    r99984 r101185  
    146146    processNewCueData(resource);
    147147
    148     m_state = resource->errorOccurred() ? Failed : Finished;
     148    if (m_state != Failed)
     149        m_state = resource->errorOccurred() ? Failed : Finished;
    149150
    150151    if (!m_cueLoadTimer.isActive())
Note: See TracChangeset for help on using the changeset viewer.