author Manuel Rego Casasnovas <>
Thu, 13 Sep 2018 02:59:55 +0000
changeset 492332 16fb60d25c1d5c2375477f97495615b145356189
parent 466378 a0710c21795a24888a15da8edc39699f0598c53d
child 503006 d1e2bb18d628e3b5cd6ed47e4a9adf55a8cdcfd1
permissions -rw-r--r--
Bug 1490634 [wpt PR 8579] - [css-grid-1] Add tests for percentage tracks inside shrinkwrapped width/height., a=testonly Automatic update from web-platform-testsMerge pull request #8579 from fantasai/indefinite-percentage-tracks [css-grid-1] Add tests for percentage tracks inside shrinkwrapped width/height. -- wpt-commits: 584149f5256d7f8243f715dad07f8529a9ea30ee wpt-pr: 8579

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 et tw=78: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

#ifndef mozilla_dom_MediaTrackList_h
#define mozilla_dom_MediaTrackList_h

#include "mozilla/DOMEventTargetHelper.h"

namespace mozilla {
class DOMMediaStream;

namespace dom {

class HTMLMediaElement;
class MediaTrack;
class AudioTrackList;
class VideoTrackList;
class AudioTrack;
class VideoTrack;
class VideoStreamTrack;

 * Base class of AudioTrackList and VideoTrackList. The AudioTrackList and
 * VideoTrackList objects represent a dynamic list of zero or more audio and
 * video tracks respectively.
 * When a media element is to forget its media-resource-specific tracks, its
 * audio track list and video track list will be emptied.
class MediaTrackList : public DOMEventTargetHelper
  MediaTrackList(nsPIDOMWindowInner* aOwnerWindow, HTMLMediaElement* aMediaElement);


  using DOMEventTargetHelper::DispatchTrustedEvent;

  // The return value is non-null, assert an error if aIndex is out of bound
  // for array mTracks.
  MediaTrack* operator[](uint32_t aIndex);

  // The track must be from the same Window as this MediaTrackList.
  void AddTrack(MediaTrack* aTrack);

  // In remove track case, the VideoTrackList::mSelectedIndex should be updated
  // due to mTracks changed. No need to take care this in add track case.
  virtual void RemoveTrack(const RefPtr<MediaTrack>& aTrack);

  void RemoveTracks();

  static already_AddRefed<AudioTrack>
  CreateAudioTrack(nsIGlobalObject* aOwnerGlobal,
                   const nsAString& aId,
                   const nsAString& aKind,
                   const nsAString& aLabel,
                   const nsAString& aLanguage,
                   bool aEnabled);

  // For the case of src of HTMLMediaElement is non-MediaStream, leave the
  // aVideoTrack as default(nullptr).
  static already_AddRefed<VideoTrack>
  CreateVideoTrack(nsIGlobalObject* aOwnerGlobal,
                   const nsAString& aId,
                   const nsAString& aKind,
                   const nsAString& aLabel,
                   const nsAString& aLanguage,
                   VideoStreamTrack* aVideoTrack = nullptr);

  virtual void EmptyTracks();

  void CreateAndDispatchChangeEvent();

  // WebIDL
  MediaTrack* IndexedGetter(uint32_t aIndex, bool& aFound);

  MediaTrack* GetTrackById(const nsAString& aId);

  bool IsEmpty() const
    return mTracks.IsEmpty();

  uint32_t Length() const
    return mTracks.Length();


  friend class AudioTrack;
  friend class VideoTrack;

  virtual ~MediaTrackList();

  void CreateAndDispatchTrackEventRunner(MediaTrack* aTrack,
                                         const nsAString& aEventName);

  virtual AudioTrackList* AsAudioTrackList() { return nullptr; }

  virtual VideoTrackList* AsVideoTrackList() { return nullptr; }

  HTMLMediaElement* GetMediaElement() { return mMediaElement; }

  nsTArray<RefPtr<MediaTrack>> mTracks;
  RefPtr<HTMLMediaElement> mMediaElement;

} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_MediaTrackList_h