TextTrack.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim:set ts=2 sw=2 et tw=78: */
  3. /* This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #ifndef mozilla_dom_TextTrack_h
  7. #define mozilla_dom_TextTrack_h
  8. #include "mozilla/DOMEventTargetHelper.h"
  9. #include "mozilla/dom/TextTrackBinding.h"
  10. #include "nsCOMPtr.h"
  11. #include "nsCycleCollectionParticipant.h"
  12. #include "nsString.h"
  13. namespace mozilla {
  14. namespace dom {
  15. class TextTrackList;
  16. class TextTrackCue;
  17. class TextTrackCueList;
  18. class HTMLTrackElement;
  19. enum TextTrackSource {
  20. Track,
  21. AddTextTrack,
  22. MediaResourceSpecific
  23. };
  24. // Constants for numeric readyState property values.
  25. enum TextTrackReadyState {
  26. NotLoaded = 0U,
  27. Loading = 1U,
  28. Loaded = 2U,
  29. FailedToLoad = 3U
  30. };
  31. class TextTrack final : public DOMEventTargetHelper
  32. {
  33. public:
  34. NS_DECL_ISUPPORTS_INHERITED
  35. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextTrack, DOMEventTargetHelper)
  36. TextTrack(nsPIDOMWindowInner* aOwnerWindow,
  37. TextTrackKind aKind,
  38. const nsAString& aLabel,
  39. const nsAString& aLanguage,
  40. TextTrackMode aMode,
  41. TextTrackReadyState aReadyState,
  42. TextTrackSource aTextTrackSource);
  43. TextTrack(nsPIDOMWindowInner* aOwnerWindow,
  44. TextTrackList* aTextTrackList,
  45. TextTrackKind aKind,
  46. const nsAString& aLabel,
  47. const nsAString& aLanguage,
  48. TextTrackMode aMode,
  49. TextTrackReadyState aReadyState,
  50. TextTrackSource aTextTrackSource);
  51. void SetDefaultSettings();
  52. JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
  53. TextTrackKind Kind() const
  54. {
  55. return mKind;
  56. }
  57. void GetLabel(nsAString& aLabel) const;
  58. void GetLanguage(nsAString& aLanguage) const;
  59. void GetInBandMetadataTrackDispatchType(nsAString& aType) const
  60. {
  61. aType = mType;
  62. }
  63. void GetId(nsAString& aId) const;
  64. TextTrackMode Mode() const
  65. {
  66. return mMode;
  67. }
  68. void SetMode(TextTrackMode aValue);
  69. TextTrackCueList* GetCues() const
  70. {
  71. if (mMode == TextTrackMode::Disabled) {
  72. return nullptr;
  73. }
  74. return mCueList;
  75. }
  76. TextTrackCueList* GetActiveCues();
  77. void UpdateActiveCueList();
  78. void GetActiveCueArray(nsTArray<RefPtr<TextTrackCue> >& aCues);
  79. TextTrackReadyState ReadyState() const;
  80. void SetReadyState(TextTrackReadyState aState);
  81. void SetReadyState(uint32_t aReadyState);
  82. void AddCue(TextTrackCue& aCue);
  83. void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv);
  84. void SetDirty() { mDirty = true; }
  85. void SetCuesDirty();
  86. TextTrackList* GetTextTrackList();
  87. void SetTextTrackList(TextTrackList* aTextTrackList);
  88. IMPL_EVENT_HANDLER(cuechange)
  89. HTMLTrackElement* GetTrackElement();
  90. void SetTrackElement(HTMLTrackElement* aTrackElement);
  91. TextTrackSource GetTextTrackSource() {
  92. return mTextTrackSource;
  93. }
  94. void SetCuesInactive();
  95. void NotifyCueUpdated(TextTrackCue *aCue);
  96. void DispatchAsyncTrustedEvent(const nsString& aEventName);
  97. private:
  98. ~TextTrack();
  99. RefPtr<TextTrackList> mTextTrackList;
  100. TextTrackKind mKind;
  101. nsString mLabel;
  102. nsString mLanguage;
  103. nsString mType;
  104. TextTrackMode mMode;
  105. RefPtr<TextTrackCueList> mCueList;
  106. RefPtr<TextTrackCueList> mActiveCueList;
  107. RefPtr<HTMLTrackElement> mTrackElement;
  108. uint32_t mCuePos;
  109. TextTrackReadyState mReadyState;
  110. bool mDirty;
  111. // An enum that represents where the track was sourced from.
  112. TextTrackSource mTextTrackSource;
  113. };
  114. } // namespace dom
  115. } // namespace mozilla
  116. #endif // mozilla_dom_TextTrack_h