mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 06:48:49 +00:00
LibWeb: Implement TimeRanges and HTMLMediaElement.seekable()
This commit is contained in:
parent
3952ff4786
commit
aa243000f3
Notes:
github-actions[bot]
2025-02-18 17:46:30 +00:00
Author: https://github.com/Psychpsyo
Commit: aa243000f3
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3563
Reviewed-by: https://github.com/ADKaster ✅
5 changed files with 103 additions and 18 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue