2010-08-05 11:40:35 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
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
|
|
|
|
2010-08-25 12:43:00 +04:00
|
|
|
#include "nsIDOMTimeRanges.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"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2010-08-05 11:40:35 +04:00
|
|
|
|
2013-03-02 23:14:44 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-25 06:09:15 +04:00
|
|
|
class TimeRanges;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2013-03-02 23:14:44 +04:00
|
|
|
class TimeRanges MOZ_FINAL : public nsIDOMTimeRanges
|
2012-05-01 04:29:24 +04:00
|
|
|
{
|
2010-08-05 11:40:35 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2010-08-25 12:43:00 +04:00
|
|
|
NS_DECL_NSIDOMTIMERANGES
|
2010-08-05 11:40:35 +04:00
|
|
|
|
2013-03-02 23:14:44 +04:00
|
|
|
TimeRanges();
|
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
|
2014-12-11 00:52:57 +03:00
|
|
|
void Normalize(double aError = 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.
|
2014-12-11 00:52:57 +03:00
|
|
|
void Union(const TimeRanges* aOtherRanges, double aError);
|
2014-08-11 08:32:21 +04:00
|
|
|
|
|
|
|
// Mutate this TimeRange to be the intersection of this and aOtherRanges.
|
|
|
|
void Intersection(const TimeRanges* aOtherRanges);
|
|
|
|
|
2014-04-09 02:27:18 +04:00
|
|
|
JSObject* WrapObject(JSContext* aCx);
|
2013-03-02 23:16:43 +04:00
|
|
|
|
|
|
|
uint32_t Length() const
|
|
|
|
{
|
|
|
|
return mRanges.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual double Start(uint32_t aIndex, ErrorResult& aRv);
|
|
|
|
|
|
|
|
virtual double End(uint32_t aIndex, ErrorResult& aRv);
|
|
|
|
|
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)
|
2010-08-05 11:40:35 +04:00
|
|
|
: mStart(aStart),
|
|
|
|
mEnd(aEnd) {}
|
2011-01-17 06:03:00 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-08-05 11:40:35 +04:00
|
|
|
nsAutoTArray<TimeRange,4> mRanges;
|
2014-08-11 06:05:09 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef nsTArray<TimeRange>::index_type index_type;
|
|
|
|
static const index_type NoIndex = index_type(-1);
|
|
|
|
|
|
|
|
index_type Find(double aTime);
|
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_
|