OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #ifndef CueTimeline_h |
| 6 #define CueTimeline_h |
| 7 |
| 8 #include "core/html/track/TextTrackCue.h" |
| 9 #include "core/html/track/vtt/VTTCue.h" |
| 10 #include "platform/PODIntervalTree.h" |
| 11 #include "platform/heap/Handle.h" |
| 12 #include "wtf/Vector.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 class HTMLMediaElement; |
| 17 class TextTrackCueList; |
| 18 |
| 19 typedef PODIntervalTree<double, TextTrackCue*> CueIntervalTree; |
| 20 typedef CueIntervalTree::IntervalType CueInterval; |
| 21 typedef Vector<CueInterval> CueList; |
| 22 |
| 23 // This class manages the timeline and rendering updates of cues associated |
| 24 // with TextTracks. Owned by a HTMLMediaElement. |
| 25 class CueTimeline : public NoBaseWillBeGarbageCollectedFinalized<CueTimeline> { |
| 26 public: |
| 27 CueTimeline(HTMLMediaElement&); |
| 28 |
| 29 void addCues(TextTrack*, const TextTrackCueList*); |
| 30 void addCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue>); |
| 31 void removeCues(TextTrack*, const TextTrackCueList*); |
| 32 void removeCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue>); |
| 33 |
| 34 void updateActiveCues(double); |
| 35 |
| 36 bool ignoreUpdateRequests() const { return m_ignoreUpdate > 0; } |
| 37 void beginIgnoringUpdateRequests(); |
| 38 void endIgnoringUpdateRequests(); |
| 39 |
| 40 CueList currentlyActiveCues() const { return m_currentlyActiveCues; } |
| 41 |
| 42 DECLARE_TRACE(); |
| 43 |
| 44 private: |
| 45 HTMLMediaElement& mediaElement() const { return *m_mediaElement; } |
| 46 |
| 47 RawPtrWillBeMember<HTMLMediaElement> m_mediaElement; |
| 48 |
| 49 CueIntervalTree m_cueTree; |
| 50 |
| 51 CueList m_currentlyActiveCues; |
| 52 double m_lastUpdateTime; |
| 53 |
| 54 int m_ignoreUpdate; |
| 55 }; |
| 56 |
| 57 class TrackDisplayUpdateScope { |
| 58 STACK_ALLOCATED(); |
| 59 public: |
| 60 TrackDisplayUpdateScope(CueTimeline& cueTimeline) |
| 61 { |
| 62 m_cueTimeline = &cueTimeline; |
| 63 m_cueTimeline->beginIgnoringUpdateRequests(); |
| 64 } |
| 65 ~TrackDisplayUpdateScope() |
| 66 { |
| 67 ASSERT(m_cueTimeline); |
| 68 m_cueTimeline->endIgnoringUpdateRequests(); |
| 69 } |
| 70 |
| 71 private: |
| 72 RawPtrWillBeMember<CueTimeline> m_cueTimeline; |
| 73 }; |
| 74 |
| 75 #ifndef NDEBUG |
| 76 // Template specializations required by PodIntervalTree in debug mode. |
| 77 template <> |
| 78 struct ValueToString<double> { |
| 79 static String string(const double value) |
| 80 { |
| 81 return String::number(value); |
| 82 } |
| 83 }; |
| 84 |
| 85 template <> |
| 86 struct ValueToString<TextTrackCue*> { |
| 87 static String string(TextTrackCue* const& cue) |
| 88 { |
| 89 return cue->toString(); |
| 90 } |
| 91 }; |
| 92 #endif |
| 93 |
| 94 } // namespace blink |
| 95 |
| 96 #endif // CueTimeline_h |
OLD | NEW |