LibWeb: Implement TimeRanges and HTMLMediaElement.seekable()

This commit is contained in:
Psychpsyo 2025-02-14 11:22:12 +01:00 committed by Andrew Kaster
parent 3952ff4786
commit aa243000f3
Notes: github-actions[bot] 2025-02-18 17:46:30 +00:00
5 changed files with 103 additions and 18 deletions

View file

@ -27,24 +27,44 @@ void TimeRanges::initialize(JS::Realm& realm)
// https://html.spec.whatwg.org/multipage/media.html#dom-timeranges-length
size_t TimeRanges::length() const
{
// FIXME: The length IDL attribute must return the number of ranges represented by the object.
return 0;
return m_ranges.size();
}
// https://html.spec.whatwg.org/multipage/media.html#dom-timeranges-start
double TimeRanges::start(u32) const
WebIDL::ExceptionOr<double> TimeRanges::start(u32 index) const
{
// FIXME: The start(index) method must return the position of the start of the indexth range represented by the object,
// in seconds measured from the start of the timeline that the object covers.
return 0.0;
// These methods must throw "IndexSizeError" DOMExceptions if called with an index argument greater than or equal to the number of ranges represented by the object.
if (index >= m_ranges.size())
return WebIDL::IndexSizeError::create(realm(), "Index argument is greater than or equal to the number of ranges represented by this TimeRanges object"_string);
// The start(index) method must return the position of the start of the indexth range represented by the object,
// in seconds measured from the start of the timeline that the object covers.
return m_ranges[index].start;
}
// https://html.spec.whatwg.org/multipage/media.html#dom-timeranges-end
double TimeRanges::end(u32) const
WebIDL::ExceptionOr<double> TimeRanges::end(u32 index) const
{
// FIXME: The end(index) method must return the position of the end of the indexth range represented by the object,
// in seconds measured from the start of the timeline that the object covers.
return 0.0;
// These methods must throw "IndexSizeError" DOMExceptions if called with an index argument greater than or equal to the number of ranges represented by the object.
if (index >= m_ranges.size())
return WebIDL::IndexSizeError::create(realm(), "Index argument is greater than or equal to the number of ranges represented by this TimeRanges object"_string);
// The end(index) method must return the position of the end of the indexth range represented by the object,
// in seconds measured from the start of the timeline that the object covers.
return m_ranges[index].end;
}
void TimeRanges::add_range(double start, double end)
{
m_ranges.append({ start, end });
}
bool TimeRanges::in_range(double point)
{
for (auto range : m_ranges) {
if (point >= range.start && point <= range.end)
return true;
}
return false;
}
}