LibWeb: Implement VTTCue.line

This commit is contained in:
Jamie Mansfield 2025-08-12 22:01:37 +01:00 committed by Jelle Raaijmakers
commit 8204143b08
Notes: github-actions[bot] 2025-08-13 21:06:59 +00:00
3 changed files with 55 additions and 4 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (c) 2024-2025, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -47,7 +47,8 @@ WebIDL::ExceptionOr<GC::Ref<VTTCue>> VTTCue::construct_impl(JS::Realm& realm, do
// 9. Let cues WebVTT cue snap-to-lines flag be true.
cue->m_snap_to_lines = true;
// FIXME: 10. Let cues WebVTT cue line be auto.
// 10. Let cues WebVTT cue line be auto.
cue->m_line = Bindings::AutoKeyword::Auto;
// 11. Let cues WebVTT cue line alignment be start alignment.
cue->m_line_alignment = Bindings::LineAlignSetting::Start;
@ -114,6 +115,47 @@ void VTTCue::set_vertical(Bindings::DirectionSetting vertical)
}
}
// https://w3c.github.io/webvtt/#cue-computed-line
double VTTCue::computed_line()
{
// 1. If the line is numeric, the WebVTT cue snap-to-lines flag of the WebVTT cue is false, and the line is negative
// or greater than 100, then return 100 and abort these steps.
if (m_line.has<double>() && !m_snap_to_lines && (m_line.get<double>() < 0 || m_line.get<double>() > 100))
return 100;
// 2. If the line is numeric, return the value of the WebVTT cue line and abort these steps. (Either the WebVTT cue
// snap-to-lines flag is true, so any value, not just those in the range 0..100, is valid, or the value is in the
// range 0..100 and is thus valid regardless of the value of that flag.)
if (m_line.has<double>())
return m_line.get<double>();
// 3. If the WebVTT cue snap-to-lines flag of the WebVTT cue is false, return the value 100 and abort these steps.
// (The line is the special value auto.)
if (!m_snap_to_lines)
return 100;
// FIXME: 4. Let cue be the WebVTT cue.
// FIXME: 5. If cue is not in a list of cues of a text track, or if that text track is not in the list of text tracks of
// a media element, return 1 and abort these steps.
// FIXME: 6. Let track be the text track whose list of cues the cue is in.
// FIXME: 7. Let n be the number of text tracks whose text track mode is showing and that are in the media elements list
// of text tracks before track.
auto n = 0;
// 8. Increment n by one.
n++;
// 9. Negate n.
n = -n;
// 10. Return n.
dbgln("FIXME: Stubbed VTTCue.computed_line()");
return n;
}
// https://w3c.github.io/webvtt/#cue-computed-position-alignment
Bindings::PositionAlignSetting VTTCue::computed_position_alignment()
{

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (c) 2024-2025, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -30,6 +30,8 @@ public:
VerticalGrowingRight,
};
using LineAndPositionSetting = Variant<double, Bindings::AutoKeyword>;
static WebIDL::ExceptionOr<GC::Ref<VTTCue>> construct_impl(JS::Realm&, double start_time, double end_time, String const& text);
virtual ~VTTCue() override = default;
@ -42,6 +44,9 @@ public:
bool snap_to_lines() const { return m_snap_to_lines; }
void set_snap_to_lines(bool snap_to_lines) { m_snap_to_lines = snap_to_lines; }
LineAndPositionSetting line() const { return m_line; }
void set_line(LineAndPositionSetting line) { m_line = line; }
Bindings::LineAlignSetting line_align() const { return m_line_alignment; }
void set_line_align(Bindings::LineAlignSetting line_align) { m_line_alignment = line_align; }
@ -58,6 +63,7 @@ public:
void set_text(String const& text) { m_text = text; }
protected:
double computed_line();
Bindings::PositionAlignSetting computed_position_alignment();
private:
@ -75,6 +81,9 @@ private:
// https://w3c.github.io/webvtt/#webvtt-cue-snap-to-lines-flag
bool m_snap_to_lines { true };
// https://w3c.github.io/webvtt/#webvtt-cue-line
LineAndPositionSetting m_line { Bindings::AutoKeyword::Auto };
// https://w3c.github.io/webvtt/#webvtt-cue-line-alignment
Bindings::LineAlignSetting m_line_alignment { Bindings::LineAlignSetting::Start };

View file

@ -15,7 +15,7 @@ interface VTTCue : TextTrackCue {
attribute VTTRegion? region;
attribute DirectionSetting vertical;
attribute boolean snapToLines;
[FIXME] attribute LineAndPositionSetting line;
attribute LineAndPositionSetting line;
attribute LineAlignSetting lineAlign;
[FIXME] attribute LineAndPositionSetting position;
attribute PositionAlignSetting positionAlign;