Files
ladybird/Libraries/LibWeb/HTML/TimeRanges.cpp
Shannon Booth fd44da6829 LibWeb/Bindings: Emit one bindings header and cpp per IDL
Previously, the LibWeb bindings generator would output multiple per
interface files like Prototype/Constructor/Namespace/GlobalMixin
depending on the contents of that IDL file.

This complicates the build system as it means that it does not know
what files will be generated without knowledge of the contents of that
IDL file.

Instead, for each IDL file only generate a single Bindings/<IDLFile>.h
and Bindings/<IDLFile>.cpp.
2026-04-21 07:36:13 +02:00

71 lines
2.4 KiB
C++

/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/TimeRanges.h>
#include <LibWeb/HTML/TimeRanges.h>
namespace Web::HTML {
GC_DEFINE_ALLOCATOR(TimeRanges);
TimeRanges::TimeRanges(JS::Realm& realm)
: Base(realm)
{
}
void TimeRanges::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(TimeRanges);
Base::initialize(realm);
}
// https://html.spec.whatwg.org/multipage/media.html#dom-timeranges-length
size_t TimeRanges::length() const
{
return m_ranges.size();
}
// https://html.spec.whatwg.org/multipage/media.html#dom-timeranges-start
WebIDL::ExceptionOr<double> TimeRanges::start(u32 index) const
{
// 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"_utf16);
// 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
WebIDL::ExceptionOr<double> TimeRanges::end(u32 index) const
{
// 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"_utf16);
// 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;
}
}