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
|
|
|
|
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
|
2015-03-21 19:28:04 +03:00
|
|
|
class TimeRanges 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
|
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);
|
|
|
|
|
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 17:13:32 +03:00
|
|
|
bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
|
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);
|
|
|
|
|
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)
|
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);
|
|
|
|
|
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_
|