#include "config.h"
#include "TimeRanges.h"
#include "ExceptionCode.h"
#include "ExceptionCodePlaceholder.h"
namespace WebCore {
PassRefPtr<TimeRanges> TimeRanges::create()
{
return adoptRef(new TimeRanges);
}
PassRefPtr<TimeRanges> TimeRanges::create(double start, double end)
{
return adoptRef(new TimeRanges(start, end));
}
PassRefPtr<TimeRanges> TimeRanges::create(const PlatformTimeRanges& other)
{
return adoptRef(new TimeRanges(other));
}
TimeRanges::TimeRanges()
{
}
TimeRanges::TimeRanges(double start, double end)
: m_ranges(PlatformTimeRanges(MediaTime::createWithDouble(start), MediaTime::createWithDouble(end)))
{
}
TimeRanges::TimeRanges(const PlatformTimeRanges& other)
: m_ranges(other)
{
}
double TimeRanges::start(unsigned index, ExceptionCode& ec) const
{
bool valid;
MediaTime result = m_ranges.start(index, valid);
if (!valid) {
ec = INDEX_SIZE_ERR;
return 0;
}
return result.toDouble();
}
double TimeRanges::end(unsigned index, ExceptionCode& ec) const
{
bool valid;
MediaTime result = m_ranges.end(index, valid);
if (!valid) {
ec = INDEX_SIZE_ERR;
return 0;
}
return result.toDouble();
}
void TimeRanges::invert()
{
m_ranges.invert();
}
PassRefPtr<TimeRanges> TimeRanges::copy() const
{
return TimeRanges::create(m_ranges);
}
void TimeRanges::intersectWith(const TimeRanges& other)
{
m_ranges.intersectWith(other.ranges());
}
void TimeRanges::unionWith(const TimeRanges& other)
{
m_ranges.unionWith(other.ranges());
}
unsigned TimeRanges::length() const
{
return m_ranges.length();
}
void TimeRanges::add(double start, double end)
{
m_ranges.add(MediaTime::createWithDouble(start), MediaTime::createWithDouble(end));
}
bool TimeRanges::contain(double time) const
{
return m_ranges.contain(MediaTime::createWithDouble(time));
}
size_t TimeRanges::find(double time) const
{
return m_ranges.find(MediaTime::createWithDouble(time));
}
double TimeRanges::nearest(double time) const
{
return m_ranges.nearest(MediaTime::createWithDouble(time)).toDouble();
}
double TimeRanges::totalDuration() const
{
return m_ranges.totalDuration().toDouble();
}
}