/work/obj-fuzz/dist/include/mozilla/dom/TimeRanges.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
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 | | |
7 | | #ifndef mozilla_dom_TimeRanges_h_ |
8 | | #define mozilla_dom_TimeRanges_h_ |
9 | | |
10 | | #include "nsCOMPtr.h" |
11 | | #include "nsISupports.h" |
12 | | #include "nsTArray.h" |
13 | | #include "nsWrapperCache.h" |
14 | | #include "mozilla/ErrorResult.h" |
15 | | #include "TimeUnits.h" |
16 | | |
17 | | namespace mozilla { |
18 | | |
19 | | namespace dom { |
20 | | class TimeRanges; |
21 | | } // namespace dom |
22 | | |
23 | | namespace dom { |
24 | | |
25 | | // Implements media TimeRanges: |
26 | | // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#timeranges |
27 | | class TimeRanges final : public nsISupports, |
28 | | public nsWrapperCache |
29 | | { |
30 | | public: |
31 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
32 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TimeRanges) |
33 | | |
34 | | TimeRanges(); |
35 | | explicit TimeRanges(nsISupports* aParent); |
36 | | explicit TimeRanges(const media::TimeIntervals& aTimeIntervals); |
37 | | TimeRanges(nsISupports* aParent, const media::TimeIntervals& aTimeIntervals); |
38 | | |
39 | | media::TimeIntervals ToTimeIntervals() const; |
40 | | |
41 | | void Add(double aStart, double aEnd); |
42 | | |
43 | | // Returns the start time of the first range, or -1 if no ranges exist. |
44 | | double GetStartTime(); |
45 | | |
46 | | // Returns the end time of the last range, or -1 if no ranges exist. |
47 | | double GetEndTime(); |
48 | | |
49 | | // See http://www.whatwg.org/html/#normalized-timeranges-object |
50 | | void Normalize(double aTolerance = 0.0); |
51 | | |
52 | | // Mutate this TimeRange to be the union of this and aOtherRanges. |
53 | | void Union(const TimeRanges* aOtherRanges, double aTolerance); |
54 | | |
55 | | // Mutate this TimeRange to be the intersection of this and aOtherRanges. |
56 | | void Intersection(const TimeRanges* aOtherRanges); |
57 | | |
58 | | JSObject* WrapObject(JSContext* aCx, |
59 | | JS::Handle<JSObject*> aGivenProto) override; |
60 | | |
61 | | nsISupports* GetParentObject() const; |
62 | | |
63 | | uint32_t Length() const |
64 | 0 | { |
65 | 0 | return mRanges.Length(); |
66 | 0 | } |
67 | | |
68 | | double Start(uint32_t aIndex, ErrorResult& aRv) const; |
69 | | |
70 | | double End(uint32_t aIndex, ErrorResult& aRv) const; |
71 | | |
72 | | double Start(uint32_t aIndex) const |
73 | | { |
74 | | return mRanges[aIndex].mStart; |
75 | | } |
76 | | |
77 | | double End(uint32_t aIndex) const |
78 | | { |
79 | | return mRanges[aIndex].mEnd; |
80 | | } |
81 | | |
82 | | // Shift all values by aOffset seconds. |
83 | | void Shift(double aOffset); |
84 | | |
85 | | private: |
86 | | ~TimeRanges(); |
87 | | |
88 | | // Comparator which orders TimeRanges by start time. Used by Normalize(). |
89 | | struct TimeRange |
90 | | { |
91 | | TimeRange(double aStart, double aEnd) |
92 | | : mStart(aStart), |
93 | 0 | mEnd(aEnd) {} |
94 | | double mStart; |
95 | | double mEnd; |
96 | | }; |
97 | | |
98 | | struct CompareTimeRanges |
99 | | { |
100 | 0 | bool Equals(const TimeRange& aTr1, const TimeRange& aTr2) const { |
101 | 0 | return aTr1.mStart == aTr2.mStart && aTr1.mEnd == aTr2.mEnd; |
102 | 0 | } |
103 | | |
104 | 0 | bool LessThan(const TimeRange& aTr1, const TimeRange& aTr2) const { |
105 | 0 | return aTr1.mStart < aTr2.mStart; |
106 | 0 | } |
107 | | }; |
108 | | |
109 | | AutoTArray<TimeRange,4> mRanges; |
110 | | |
111 | | nsCOMPtr<nsISupports> mParent; |
112 | | |
113 | | public: |
114 | | typedef nsTArray<TimeRange>::index_type index_type; |
115 | | static const index_type NoIndex = index_type(-1); |
116 | | |
117 | | index_type Find(double aTime, double aTolerance = 0); |
118 | | |
119 | 0 | bool Contains(double aStart, double aEnd) { |
120 | 0 | index_type target = Find(aStart); |
121 | 0 | if (target == NoIndex) { |
122 | 0 | return false; |
123 | 0 | } |
124 | 0 |
|
125 | 0 | return mRanges[target].mEnd >= aEnd; |
126 | 0 | } |
127 | | }; |
128 | | |
129 | | } // namespace dom |
130 | | } // namespace mozilla |
131 | | |
132 | | #endif // mozilla_dom_TimeRanges_h_ |