2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-08-05 11:40:35 +04:00
|
|
|
|
2013-03-02 23:14:44 +04:00
|
|
|
#ifndef mozilla_dom_TimeRanges_h_
|
|
|
|
#define mozilla_dom_TimeRanges_h_
|
2011-05-17 03:14:40 +04:00
|
|
|
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2010-08-05 11:40:35 +04:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsTArray.h"
|
2013-03-02 23:16:43 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2017-08-21 06:08:25 +03:00
|
|
|
#include "TimeUnits.h"
|
2010-08-05 11:40:35 +04:00
|
|
|
|
2013-03-02 23:14:44 +04:00
|
|
|
namespace mozilla {
|
2020-11-23 19:12:02 +03:00
|
|
|
class ErrorResult;
|
2013-03-02 23:14:44 +04:00
|
|
|
|
2017-08-21 06:08:25 +03:00
|
|
|
namespace dom {
|
2014-06-25 06:09:15 +04:00
|
|
|
class TimeRanges;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2014-06-25 06:09:15 +04:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2010-08-05 11:40:35 +04:00
|
|
|
// Implements media TimeRanges:
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#timeranges
|
2018-02-16 21:34:28 +03:00
|
|
|
class TimeRanges final : public nsISupports, public nsWrapperCache {
|
2010-08-05 11:40:35 +04:00
|
|
|
public:
|
2015-10-19 09:10:47 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2022-09-07 14:22:51 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(TimeRanges)
|
2010-08-05 11:40:35 +04:00
|
|
|
|
2013-03-02 23:14:44 +04:00
|
|
|
TimeRanges();
|
2015-10-19 09:10:47 +03:00
|
|
|
explicit TimeRanges(nsISupports* aParent);
|
2017-08-21 06:08:25 +03:00
|
|
|
explicit TimeRanges(const media::TimeIntervals& aTimeIntervals);
|
2023-05-24 16:18:43 +03:00
|
|
|
explicit TimeRanges(const media::TimeRanges& aTimeRanges);
|
2017-08-21 06:08:25 +03:00
|
|
|
TimeRanges(nsISupports* aParent, const media::TimeIntervals& aTimeIntervals);
|
2023-05-24 16:18:43 +03:00
|
|
|
TimeRanges(nsISupports* aParent, const media::TimeRanges& aTimeRanges);
|
2017-08-21 06:08:25 +03:00
|
|
|
|
|
|
|
media::TimeIntervals ToTimeIntervals() const;
|
2011-03-24 01:28:57 +03:00
|
|
|
|
2011-01-17 06:03:00 +03:00
|
|
|
void Add(double aStart, double aEnd);
|
2010-08-05 11:40:35 +04:00
|
|
|
|
2014-04-14 15:23:00 +04:00
|
|
|
// Returns the start time of the first range, or -1 if no ranges exist.
|
|
|
|
double GetStartTime();
|
|
|
|
|
|
|
|
// Returns the end time of the last range, or -1 if no ranges exist.
|
|
|
|
double GetEndTime();
|
2013-01-29 06:34:27 +04:00
|
|
|
|
2012-05-01 04:29:24 +04:00
|
|
|
// See http://www.whatwg.org/html/#normalized-timeranges-object
|
2015-01-31 04:45:49 +03:00
|
|
|
void Normalize(double aTolerance = 0.0);
|
2012-05-01 04:29:24 +04:00
|
|
|
|
2014-08-11 08:32:21 +04:00
|
|
|
// Mutate this TimeRange to be the union of this and aOtherRanges.
|
2015-01-31 04:45:49 +03:00
|
|
|
void Union(const TimeRanges* aOtherRanges, double aTolerance);
|
2014-08-11 08:32:21 +04:00
|
|
|
|
|
|
|
// Mutate this TimeRange to be the intersection of this and aOtherRanges.
|
|
|
|
void Intersection(const TimeRanges* aOtherRanges);
|
|
|
|
|
2017-08-21 06:08:25 +03:00
|
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2015-10-19 09:10:47 +03:00
|
|
|
|
|
|
|
nsISupports* GetParentObject() const;
|
2013-03-02 23:16:43 +04:00
|
|
|
|
|
|
|
uint32_t Length() const { return mRanges.Length(); }
|
|
|
|
|
2017-08-21 06:08:25 +03:00
|
|
|
double Start(uint32_t aIndex, ErrorResult& aRv) const;
|
2013-03-02 23:16:43 +04:00
|
|
|
|
2017-08-21 06:08:25 +03:00
|
|
|
double End(uint32_t aIndex, ErrorResult& aRv) const;
|
2013-03-02 23:16:43 +04:00
|
|
|
|
2018-02-16 21:36:40 +03:00
|
|
|
double Start(uint32_t aIndex) const { return mRanges[aIndex].mStart; }
|
|
|
|
|
|
|
|
double End(uint32_t aIndex) const { return mRanges[aIndex].mEnd; }
|
|
|
|
|
2015-02-09 15:28:59 +03:00
|
|
|
// Shift all values by aOffset seconds.
|
|
|
|
void Shift(double aOffset);
|
|
|
|
|
2010-08-05 11:40:35 +04:00
|
|
|
private:
|
2014-07-13 05:26:21 +04:00
|
|
|
~TimeRanges();
|
2010-08-05 11:40:35 +04:00
|
|
|
|
2012-05-01 04:29:24 +04:00
|
|
|
// Comparator which orders TimeRanges by start time. Used by Normalize().
|
|
|
|
struct TimeRange {
|
2011-01-17 06:03:00 +03:00
|
|
|
TimeRange(double aStart, double aEnd) : mStart(aStart), mEnd(aEnd) {}
|
|
|
|
double mStart;
|
|
|
|
double mEnd;
|
2010-08-05 11:40:35 +04:00
|
|
|
};
|
|
|
|
|
2012-05-01 04:29:24 +04:00
|
|
|
struct CompareTimeRanges {
|
|
|
|
bool Equals(const TimeRange& aTr1, const TimeRange& aTr2) const {
|
|
|
|
return aTr1.mStart == aTr2.mStart && aTr1.mEnd == aTr2.mEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LessThan(const TimeRange& aTr1, const TimeRange& aTr2) const {
|
|
|
|
return aTr1.mStart < aTr2.mStart;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<TimeRange, 4> mRanges;
|
2014-08-11 06:05:09 +04:00
|
|
|
|
2015-10-19 09:10:47 +03:00
|
|
|
nsCOMPtr<nsISupports> mParent;
|
|
|
|
|
2014-08-11 06:05:09 +04:00
|
|
|
public:
|
|
|
|
typedef nsTArray<TimeRange>::index_type index_type;
|
|
|
|
static const index_type NoIndex = index_type(-1);
|
|
|
|
|
2015-01-31 04:45:49 +03:00
|
|
|
index_type Find(double aTime, double aTolerance = 0);
|
2014-11-12 07:50:21 +03:00
|
|
|
|
|
|
|
bool Contains(double aStart, double aEnd) {
|
|
|
|
index_type target = Find(aStart);
|
|
|
|
if (target == NoIndex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mRanges[target].mEnd >= aEnd;
|
|
|
|
}
|
2010-08-05 11:40:35 +04:00
|
|
|
};
|
2011-05-17 03:14:40 +04:00
|
|
|
|
2013-03-02 23:14:44 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_TimeRanges_h_
|