OLD | NEW |
(Empty) | |
| 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 WebCore { |
| 12 |
| 13 PassRefPtrWillBeRawPtr<VideoTrackList> VideoTrackList::create(HTMLMediaElement*
mediaElement) |
| 14 { |
| 15 RefPtrWillBeRawPtr<VideoTrackList> trackList(adoptRefWillBeRefCountedGarbage
Collected(new VideoTrackList(mediaElement))); |
| 16 trackList->suspendIfNeeded(); |
| 17 return trackList.release(); |
| 18 } |
| 19 |
| 20 VideoTrackList::~VideoTrackList() |
| 21 { |
| 22 } |
| 23 |
| 24 VideoTrackList::VideoTrackList(HTMLMediaElement* mediaElement) |
| 25 : TrackBaseList(mediaElement) |
| 26 , m_selectedIndex(-1) |
| 27 { |
| 28 ScriptWrappable::init(this); |
| 29 } |
| 30 |
| 31 VideoTrack* VideoTrackList::anonymousIndexedGetter(unsigned index) const |
| 32 { |
| 33 return static_cast<VideoTrack*>(getByIndex(index)); |
| 34 } |
| 35 |
| 36 VideoTrack* VideoTrackList::getTrackById(const AtomicString& id) const |
| 37 { |
| 38 return static_cast<VideoTrack*>(getById(id)); |
| 39 } |
| 40 |
| 41 const AtomicString& VideoTrackList::interfaceName() const |
| 42 { |
| 43 return EventTargetNames::VideoTrackList; |
| 44 } |
| 45 |
| 46 void VideoTrackList::trackSelected(const AtomicString& selectedTrackID) |
| 47 { |
| 48 |
| 49 bool scheduleEvent = false; |
| 50 if (m_selectedIndex != -1) { |
| 51 VideoTrack* oldTrack = anonymousIndexedGetter(m_selectedIndex); |
| 52 |
| 53 ASSERT(oldTrack->id() != selectedTrackID); |
| 54 |
| 55 oldTrack->clearSelected(); |
| 56 scheduleEvent = true; |
| 57 } |
| 58 |
| 59 if (selectedTrackID.isEmpty()) { |
| 60 m_selectedIndex = -1; |
| 61 } else { |
| 62 m_selectedIndex = getIndex(selectedTrackID); |
| 63 scheduleEvent = true; |
| 64 } |
| 65 |
| 66 if (scheduleEvent) |
| 67 scheduleChangeEvent(); |
| 68 } |
| 69 |
| 70 } |
OLD | NEW |