2015-05-03 19:32:37 +00: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 11:12:37 +00: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 07:40:35 +00:00
|
|
|
|
2013-03-02 19:14:44 +00:00
|
|
|
#ifndef mozilla_dom_TimeRanges_h_
|
|
|
|
#define mozilla_dom_TimeRanges_h_
|
2011-05-16 23:14:40 +00:00
|
|
|
|
2010-08-25 08:43:00 +00:00
|
|
|
#include "nsIDOMTimeRanges.h"
|
2010-08-05 07:40:35 +00:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsTArray.h"
|
2013-03-02 19:16:43 +00:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2010-08-05 07:40:35 +00:00
|
|
|
|
2013-03-02 19:14:44 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-25 02:09:15 +00:00
|
|
|
class TimeRanges;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2010-08-05 07:40:35 +00:00
|
|
|
// Implements media TimeRanges:
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#timeranges
|
2015-03-21 16:28:04 +00:00
|
|
|
class TimeRanges final : public nsIDOMTimeRanges
|
2012-05-01 00:29:24 +00:00
|
|
|
{
|
2010-08-05 07:40:35 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2010-08-25 08:43:00 +00:00
|
|
|
NS_DECL_NSIDOMTIMERANGES
|
2010-08-05 07:40:35 +00:00
|
|
|
|
2013-03-02 19:14:44 +00:00
|
|
|
TimeRanges();
|
2011-03-23 22:28:57 +00:00
|
|
|
|
2011-01-17 03:03:00 +00:00
|
|
|
void Add(double aStart, double aEnd);
|
2010-08-05 07:40:35 +00:00
|
|
|
|
2014-04-14 11:23:00 +00: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 02:34:27 +00:00
|
|
|
|
2012-05-01 00:29:24 +00:00
|
|
|
// See http://www.whatwg.org/html/#normalized-timeranges-object
|
2015-01-31 01:45:49 +00:00
|
|
|
void Normalize(double aTolerance = 0.0);
|
2012-05-01 00:29:24 +00:00
|
|
|
|
2014-08-11 04:32:21 +00:00
|
|
|
// Mutate this TimeRange to be the union of this and aOtherRanges.
|
2015-01-31 01:45:49 +00:00
|
|
|
void Union(const TimeRanges* aOtherRanges, double aTolerance);
|
2014-08-11 04:32:21 +00:00
|
|
|
|
|
|
|
// Mutate this TimeRange to be the intersection of this and aOtherRanges.
|
|
|
|
void Intersection(const TimeRanges* aOtherRanges);
|
|
|
|
|
Bug 1117172 part 2. Change the non-wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, Codegen.py, and
StructuredClone.cpp. The rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/WrapObject\((JSContext *\* *(?:aCx|cx)),(\s*)(JS::MutableHandle<JSObject\*> aReflector)/WrapObject(\1,\2JS::Handle<JSObject*> aGivenProto,\2\3/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx)), this, aReflector/\1, this, aGivenProto, aReflector/'
2015-03-19 14:13:32 +00:00
|
|
|
bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
|
2013-03-02 19:16:43 +00:00
|
|
|
|
|
|
|
uint32_t Length() const
|
|
|
|
{
|
|
|
|
return mRanges.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual double Start(uint32_t aIndex, ErrorResult& aRv);
|
|
|
|
|
|
|
|
virtual double End(uint32_t aIndex, ErrorResult& aRv);
|
|
|
|
|
2015-02-09 12:28:59 +00:00
|
|
|
// Shift all values by aOffset seconds.
|
|
|
|
void Shift(double aOffset);
|
|
|
|
|
2010-08-05 07:40:35 +00:00
|
|
|
private:
|
2014-07-13 01:26:21 +00:00
|
|
|
~TimeRanges();
|
2010-08-05 07:40:35 +00:00
|
|
|
|
2012-05-01 00:29:24 +00:00
|
|
|
// Comparator which orders TimeRanges by start time. Used by Normalize().
|
|
|
|
struct TimeRange
|
|
|
|
{
|
2011-01-17 03:03:00 +00:00
|
|
|
TimeRange(double aStart, double aEnd)
|
2010-08-05 07:40:35 +00:00
|
|
|
: mStart(aStart),
|
|
|
|
mEnd(aEnd) {}
|
2011-01-17 03:03:00 +00:00
|
|
|
double mStart;
|
|
|
|
double mEnd;
|
2010-08-05 07:40:35 +00:00
|
|
|
};
|
|
|
|
|
2012-05-01 00:29:24 +00: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 07:40:35 +00:00
|
|
|
nsAutoTArray<TimeRange,4> mRanges;
|
2014-08-11 02:05:09 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef nsTArray<TimeRange>::index_type index_type;
|
|
|
|
static const index_type NoIndex = index_type(-1);
|
|
|
|
|
2015-01-31 01:45:49 +00:00
|
|
|
index_type Find(double aTime, double aTolerance = 0);
|
2014-11-12 04:50:21 +00: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 07:40:35 +00:00
|
|
|
};
|
2011-05-16 23:14:40 +00:00
|
|
|
|
2013-03-02 19:14:44 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_TimeRanges_h_
|