Home | History | Annotate | Download | only in track
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "config.h"
      6 #include "core/html/track/VideoTrackList.h"
      7 
      8 #include "core/html/HTMLMediaElement.h"
      9 #include "core/html/track/VideoTrack.h"
     10 
     11 namespace blink {
     12 
     13 PassRefPtrWillBeRawPtr<VideoTrackList> VideoTrackList::create(HTMLMediaElement& mediaElement)
     14 {
     15     return adoptRefWillBeNoop(new VideoTrackList(mediaElement));
     16 }
     17 
     18 VideoTrackList::~VideoTrackList()
     19 {
     20 }
     21 
     22 VideoTrackList::VideoTrackList(HTMLMediaElement& mediaElement)
     23     : TrackListBase<VideoTrack>(&mediaElement)
     24 {
     25 }
     26 
     27 const AtomicString& VideoTrackList::interfaceName() const
     28 {
     29     return EventTargetNames::VideoTrackList;
     30 }
     31 
     32 int VideoTrackList::selectedIndex() const
     33 {
     34     for (unsigned i = 0; i < length(); ++i) {
     35         VideoTrack* track = anonymousIndexedGetter(i);
     36 
     37         if (track->selected())
     38             return i;
     39     }
     40 
     41     return -1;
     42 }
     43 
     44 void VideoTrackList::trackSelected(blink::WebMediaPlayer::TrackId selectedTrackId)
     45 {
     46     // Clear the selected flag on the previously selected track, if any.
     47     for (unsigned i = 0; i < length(); ++i) {
     48         VideoTrack* track = anonymousIndexedGetter(i);
     49 
     50         if (track->trackId() != selectedTrackId)
     51             track->clearSelected();
     52         else
     53             ASSERT(track->selected());
     54     }
     55 
     56     scheduleChangeEvent();
     57 }
     58 
     59 }
     60