| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CueTimeline_h | 5 #ifndef CueTimeline_h |
| 6 #define CueTimeline_h | 6 #define CueTimeline_h |
| 7 | 7 |
| 8 #include "core/html/track/TextTrackCue.h" | 8 #include "core/html/track/TextTrackCue.h" |
| 9 #include "core/html/track/vtt/VTTCue.h" | 9 #include "core/html/track/vtt/VTTCue.h" |
| 10 #include "platform/PODIntervalTree.h" | 10 #include "platform/PODIntervalTree.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // reason) so we leave it as a raw pointer at the moment. This is safe | 21 // reason) so we leave it as a raw pointer at the moment. This is safe |
| 22 // because CueTimeline and TextTrackCue are guaranteed to die at the same time | 22 // because CueTimeline and TextTrackCue are guaranteed to die at the same time |
| 23 // when the owner HTMLMediaElement dies. Thus the raw TextTrackCue* cannot | 23 // when the owner HTMLMediaElement dies. Thus the raw TextTrackCue* cannot |
| 24 // become stale pointers. | 24 // become stale pointers. |
| 25 typedef PODIntervalTree<double, TextTrackCue*> CueIntervalTree; | 25 typedef PODIntervalTree<double, TextTrackCue*> CueIntervalTree; |
| 26 typedef CueIntervalTree::IntervalType CueInterval; | 26 typedef CueIntervalTree::IntervalType CueInterval; |
| 27 typedef Vector<CueInterval> CueList; | 27 typedef Vector<CueInterval> CueList; |
| 28 | 28 |
| 29 // This class manages the timeline and rendering updates of cues associated | 29 // This class manages the timeline and rendering updates of cues associated |
| 30 // with TextTracks. Owned by a HTMLMediaElement. | 30 // with TextTracks. Owned by a HTMLMediaElement. |
| 31 class CueTimeline final : public NoBaseWillBeGarbageCollectedFinalized<CueTimeli
ne> { | 31 class CueTimeline final : public GarbageCollectedFinalized<CueTimeline> { |
| 32 USING_FAST_MALLOC_WILL_BE_REMOVED(CueTimeline); | |
| 33 public: | 32 public: |
| 34 CueTimeline(HTMLMediaElement&); | 33 CueTimeline(HTMLMediaElement&); |
| 35 | 34 |
| 36 void addCues(TextTrack*, const TextTrackCueList*); | 35 void addCues(TextTrack*, const TextTrackCueList*); |
| 37 void addCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue>); | 36 void addCue(TextTrack*, RawPtr<TextTrackCue>); |
| 38 void removeCues(TextTrack*, const TextTrackCueList*); | 37 void removeCues(TextTrack*, const TextTrackCueList*); |
| 39 void removeCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue>); | 38 void removeCue(TextTrack*, RawPtr<TextTrackCue>); |
| 40 | 39 |
| 41 void hideCues(TextTrack*, const TextTrackCueList*); | 40 void hideCues(TextTrack*, const TextTrackCueList*); |
| 42 | 41 |
| 43 void updateActiveCues(double); | 42 void updateActiveCues(double); |
| 44 | 43 |
| 45 bool ignoreUpdateRequests() const { return m_ignoreUpdate > 0; } | 44 bool ignoreUpdateRequests() const { return m_ignoreUpdate > 0; } |
| 46 void beginIgnoringUpdateRequests(); | 45 void beginIgnoringUpdateRequests(); |
| 47 void endIgnoringUpdateRequests(); | 46 void endIgnoringUpdateRequests(); |
| 48 | 47 |
| 49 const CueList& currentlyActiveCues() const { return m_currentlyActiveCues; } | 48 const CueList& currentlyActiveCues() const { return m_currentlyActiveCues; } |
| 50 | 49 |
| 51 DECLARE_TRACE(); | 50 DECLARE_TRACE(); |
| 52 | 51 |
| 53 private: | 52 private: |
| 54 HTMLMediaElement& mediaElement() const { return *m_mediaElement; } | 53 HTMLMediaElement& mediaElement() const { return *m_mediaElement; } |
| 55 | 54 |
| 56 void addCueInternal(PassRefPtrWillBeRawPtr<TextTrackCue>); | 55 void addCueInternal(RawPtr<TextTrackCue>); |
| 57 void removeCueInternal(PassRefPtrWillBeRawPtr<TextTrackCue>); | 56 void removeCueInternal(RawPtr<TextTrackCue>); |
| 58 | 57 |
| 59 RawPtrWillBeMember<HTMLMediaElement> m_mediaElement; | 58 Member<HTMLMediaElement> m_mediaElement; |
| 60 | 59 |
| 61 CueIntervalTree m_cueTree; | 60 CueIntervalTree m_cueTree; |
| 62 | 61 |
| 63 CueList m_currentlyActiveCues; | 62 CueList m_currentlyActiveCues; |
| 64 double m_lastUpdateTime; | 63 double m_lastUpdateTime; |
| 65 | 64 |
| 66 int m_ignoreUpdate; | 65 int m_ignoreUpdate; |
| 67 }; | 66 }; |
| 68 | 67 |
| 69 class TrackDisplayUpdateScope { | 68 class TrackDisplayUpdateScope { |
| 70 STACK_ALLOCATED(); | 69 STACK_ALLOCATED(); |
| 71 public: | 70 public: |
| 72 TrackDisplayUpdateScope(CueTimeline& cueTimeline) | 71 TrackDisplayUpdateScope(CueTimeline& cueTimeline) |
| 73 { | 72 { |
| 74 m_cueTimeline = &cueTimeline; | 73 m_cueTimeline = &cueTimeline; |
| 75 m_cueTimeline->beginIgnoringUpdateRequests(); | 74 m_cueTimeline->beginIgnoringUpdateRequests(); |
| 76 } | 75 } |
| 77 ~TrackDisplayUpdateScope() | 76 ~TrackDisplayUpdateScope() |
| 78 { | 77 { |
| 79 ASSERT(m_cueTimeline); | 78 ASSERT(m_cueTimeline); |
| 80 m_cueTimeline->endIgnoringUpdateRequests(); | 79 m_cueTimeline->endIgnoringUpdateRequests(); |
| 81 } | 80 } |
| 82 | 81 |
| 83 private: | 82 private: |
| 84 RawPtrWillBeMember<CueTimeline> m_cueTimeline; | 83 Member<CueTimeline> m_cueTimeline; |
| 85 }; | 84 }; |
| 86 | 85 |
| 87 #ifndef NDEBUG | 86 #ifndef NDEBUG |
| 88 // Template specializations required by PodIntervalTree in debug mode. | 87 // Template specializations required by PodIntervalTree in debug mode. |
| 89 template <> | 88 template <> |
| 90 struct ValueToString<double> { | 89 struct ValueToString<double> { |
| 91 static String toString(const double value) | 90 static String toString(const double value) |
| 92 { | 91 { |
| 93 return String::number(value); | 92 return String::number(value); |
| 94 } | 93 } |
| 95 }; | 94 }; |
| 96 | 95 |
| 97 template <> | 96 template <> |
| 98 struct ValueToString<TextTrackCue*> { | 97 struct ValueToString<TextTrackCue*> { |
| 99 static String toString(TextTrackCue* const& cue) | 98 static String toString(TextTrackCue* const& cue) |
| 100 { | 99 { |
| 101 return cue->toString(); | 100 return cue->toString(); |
| 102 } | 101 } |
| 103 }; | 102 }; |
| 104 #endif | 103 #endif |
| 105 | 104 |
| 106 } // namespace blink | 105 } // namespace blink |
| 107 | 106 |
| 108 #endif // CueTimeline_h | 107 #endif // CueTimeline_h |
| OLD | NEW |