2010-08-05 00:40:35 -07: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 04:12:37 -07: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 00:40:35 -07:00
|
|
|
|
2013-03-02 11:14:44 -08:00
|
|
|
#ifndef mozilla_dom_TimeRanges_h_
|
|
|
|
#define mozilla_dom_TimeRanges_h_
|
2011-05-16 16:14:40 -07:00
|
|
|
|
2010-08-25 01:43:00 -07:00
|
|
|
#include "nsIDOMTimeRanges.h"
|
2010-08-05 00:40:35 -07:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsTArray.h"
|
2013-03-02 11:16:43 -08:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2010-08-05 00:40:35 -07:00
|
|
|
|
2013-03-02 11:14:44 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-24 19:09:15 -07:00
|
|
|
class TimeRanges;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2010-08-05 00:40:35 -07:00
|
|
|
// Implements media TimeRanges:
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#timeranges
|
2013-03-02 11:14:44 -08:00
|
|
|
class TimeRanges MOZ_FINAL : public nsIDOMTimeRanges
|
2012-04-30 17:29:24 -07:00
|
|
|
{
|
2010-08-05 00:40:35 -07:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2010-08-25 01:43:00 -07:00
|
|
|
NS_DECL_NSIDOMTIMERANGES
|
2010-08-05 00:40:35 -07:00
|
|
|
|
2013-03-02 11:14:44 -08:00
|
|
|
TimeRanges();
|
2011-03-23 15:28:57 -07:00
|
|
|
|
2011-01-16 19:03:00 -08:00
|
|
|
void Add(double aStart, double aEnd);
|
2010-08-05 00:40:35 -07:00
|
|
|
|
2014-04-14 04:23:00 -07: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-28 18:34:27 -08:00
|
|
|
|
2012-04-30 17:29:24 -07:00
|
|
|
// See http://www.whatwg.org/html/#normalized-timeranges-object
|
|
|
|
void Normalize();
|
|
|
|
|
2014-08-10 21:32:21 -07:00
|
|
|
// Mutate this TimeRange to be the union of this and aOtherRanges.
|
|
|
|
void Union(const TimeRanges* aOtherRanges);
|
|
|
|
|
|
|
|
// Mutate this TimeRange to be the intersection of this and aOtherRanges.
|
|
|
|
void Intersection(const TimeRanges* aOtherRanges);
|
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
JSObject* WrapObject(JSContext* aCx);
|
2013-03-02 11:16:43 -08: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 00:40:35 -07:00
|
|
|
private:
|
2014-07-12 18:26:21 -07:00
|
|
|
~TimeRanges();
|
2010-08-05 00:40:35 -07:00
|
|
|
|
2012-04-30 17:29:24 -07:00
|
|
|
// Comparator which orders TimeRanges by start time. Used by Normalize().
|
|
|
|
struct TimeRange
|
|
|
|
{
|
2011-01-16 19:03:00 -08:00
|
|
|
TimeRange(double aStart, double aEnd)
|
2010-08-05 00:40:35 -07:00
|
|
|
: mStart(aStart),
|
|
|
|
mEnd(aEnd) {}
|
2011-01-16 19:03:00 -08:00
|
|
|
double mStart;
|
|
|
|
double mEnd;
|
2010-08-05 00:40:35 -07:00
|
|
|
};
|
|
|
|
|
2012-04-30 17:29:24 -07: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 00:40:35 -07:00
|
|
|
nsAutoTArray<TimeRange,4> mRanges;
|
2014-08-10 19:05:09 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef nsTArray<TimeRange>::index_type index_type;
|
|
|
|
static const index_type NoIndex = index_type(-1);
|
|
|
|
|
|
|
|
index_type Find(double aTime);
|
2010-08-05 00:40:35 -07:00
|
|
|
};
|
2011-05-16 16:14:40 -07:00
|
|
|
|
2013-03-02 11:14:44 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_TimeRanges_h_
|