Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / html / track / CueTimeline.h
blob8bd32208e1d4e7274b0432194fe3a68905e10e23
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.
5 #ifndef CueTimeline_h
6 #define CueTimeline_h
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"
14 namespace blink {
16 class HTMLMediaElement;
17 class TextTrackCueList;
19 // TODO(Oilpan): This needs to be PODIntervalTree<double, Member<TextTrackCue>>.
20 // However, it is not easy to move PODIntervalTree to the heap (for a C++-template
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
23 // when the owner HTMLMediaElement dies. Thus the raw TextTrackCue* cannot
24 // become stale pointers.
25 typedef PODIntervalTree<double, TextTrackCue*> CueIntervalTree;
26 typedef CueIntervalTree::IntervalType CueInterval;
27 typedef Vector<CueInterval> CueList;
29 // This class manages the timeline and rendering updates of cues associated
30 // with TextTracks. Owned by a HTMLMediaElement.
31 class CueTimeline final : public NoBaseWillBeGarbageCollectedFinalized<CueTimeline> {
32 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(CueTimeline);
33 public:
34 CueTimeline(HTMLMediaElement&);
36 void addCues(TextTrack*, const TextTrackCueList*);
37 void addCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue>);
38 void removeCues(TextTrack*, const TextTrackCueList*);
39 void removeCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue>);
41 void hideCues(TextTrack*, const TextTrackCueList*);
43 void updateActiveCues(double);
45 bool ignoreUpdateRequests() const { return m_ignoreUpdate > 0; }
46 void beginIgnoringUpdateRequests();
47 void endIgnoringUpdateRequests();
49 const CueList& currentlyActiveCues() const { return m_currentlyActiveCues; }
51 DECLARE_TRACE();
53 private:
54 HTMLMediaElement& mediaElement() const { return *m_mediaElement; }
56 void addCueInternal(PassRefPtrWillBeRawPtr<TextTrackCue>);
57 void removeCueInternal(PassRefPtrWillBeRawPtr<TextTrackCue>);
59 RawPtrWillBeMember<HTMLMediaElement> m_mediaElement;
61 CueIntervalTree m_cueTree;
63 CueList m_currentlyActiveCues;
64 double m_lastUpdateTime;
66 int m_ignoreUpdate;
69 class TrackDisplayUpdateScope {
70 STACK_ALLOCATED();
71 public:
72 TrackDisplayUpdateScope(CueTimeline& cueTimeline)
74 m_cueTimeline = &cueTimeline;
75 m_cueTimeline->beginIgnoringUpdateRequests();
77 ~TrackDisplayUpdateScope()
79 ASSERT(m_cueTimeline);
80 m_cueTimeline->endIgnoringUpdateRequests();
83 private:
84 RawPtrWillBeMember<CueTimeline> m_cueTimeline;
87 #ifndef NDEBUG
88 // Template specializations required by PodIntervalTree in debug mode.
89 template <>
90 struct ValueToString<double> {
91 static String string(const double value)
93 return String::number(value);
97 template <>
98 struct ValueToString<TextTrackCue*> {
99 static String string(TextTrackCue* const& cue)
101 return cue->toString();
104 #endif
106 } // namespace blink
108 #endif // CueTimeline_h