Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Unified Diff: Source/core/html/track/VideoTrackList.cpp

Issue 284513003: Implement AudioTrack, AudioTrackList, VideoTrack, and VideoTrackList (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: complete the transition to WebTrackId Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/track/VideoTrackList.cpp
diff --git a/Source/core/html/track/VideoTrackList.cpp b/Source/core/html/track/VideoTrackList.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..38ad9f33b4e7647e3da93684f4017d0ae50f8ee5
--- /dev/null
+++ b/Source/core/html/track/VideoTrackList.cpp
@@ -0,0 +1,64 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/html/track/VideoTrackList.h"
+
+#include "core/html/HTMLMediaElement.h"
+#include "core/html/track/VideoTrack.h"
+
+namespace WebCore {
+
+PassRefPtr<VideoTrackList> VideoTrackList::create(HTMLMediaElement& mediaElement)
+{
+ return adoptRef(new VideoTrackList(mediaElement));
+}
+
+VideoTrackList::~VideoTrackList()
+{
+}
+
+VideoTrackList::VideoTrackList(HTMLMediaElement& mediaElement)
+ : TrackListBase<VideoTrack>(&mediaElement)
+ , m_selectedIndex(-1)
+{
+ ScriptWrappable::init(this);
+}
+
+const AtomicString& VideoTrackList::interfaceName() const
+{
+ return EventTargetNames::VideoTrackList;
+}
+
+void VideoTrackList::trackSelected(blink::WebTrackId* selectedTrackId)
+{
+ bool scheduleEvent = false;
+ if (m_selectedIndex != -1) {
+ RefPtr<VideoTrack> oldTrack = anonymousIndexedGetter(m_selectedIndex);
+
+ ASSERT(!selectedTrackId || oldTrack->webId() != *selectedTrackId);
+
+ oldTrack->clearSelected();
+ m_selectedIndex = -1;
+ scheduleEvent = true;
+ }
+
+ if (selectedTrackId) {
+ for (unsigned i = 0; i < length(); ++i) {
+ RefPtr<VideoTrack> track = anonymousIndexedGetter(i);
+
+ if (track->webId() != *selectedTrackId)
+ continue;
+
+ m_selectedIndex = i;
+ scheduleEvent = true;
+ break;
+ }
+ }
+
+ if (scheduleEvent)
+ scheduleChangeEvent();
+}
+
+}

Powered by Google App Engine
This is Rietveld 408576698