LibWeb: Implement VTTCue.position

This commit is contained in:
Jamie Mansfield 2025-08-13 13:51:00 +01:00 committed by Jelle Raaijmakers
commit 73a05f9163
Notes: github-actions[bot] 2025-08-13 21:06:54 +00:00
3 changed files with 30 additions and 2 deletions

View file

@ -53,7 +53,8 @@ WebIDL::ExceptionOr<GC::Ref<VTTCue>> VTTCue::construct_impl(JS::Realm& realm, do
// 11. Let cues WebVTT cue line alignment be start alignment.
cue->m_line_alignment = Bindings::LineAlignSetting::Start;
// FIXME: 12. Let cues WebVTT cue position be auto.
// 12. Let cues WebVTT cue position be auto.
cue->m_position = Bindings::AutoKeyword::Auto;
// 13. Let cues WebVTT cue position alignment be auto.
cue->m_position_alignment = Bindings::PositionAlignSetting::Auto;
@ -156,6 +157,26 @@ double VTTCue::computed_line()
return n;
}
// https://w3c.github.io/webvtt/#cue-computed-position
double VTTCue::computed_position()
{
// 1. If the position is numeric between 0 and 100, then return the value of the position and abort these steps.
// (Otherwise, the position is the special value auto.)
if (m_position.has<double>() && m_position.get<double>() >= 0 && m_position.get<double>() <= 100)
return m_position.get<double>();
// 2. If the cue text alignment is left, return 0 and abort these steps.
if (m_text_alignment == Bindings::AlignSetting::Left)
return 0;
// 3. If the cue text alignment is right, return 100 and abort these steps.
if (m_text_alignment == Bindings::AlignSetting::Right)
return 100;
// 4. Otherwise, return 50 and abort these steps.
return 50;
}
// https://w3c.github.io/webvtt/#cue-computed-position-alignment
Bindings::PositionAlignSetting VTTCue::computed_position_alignment()
{

View file

@ -50,6 +50,9 @@ public:
Bindings::LineAlignSetting line_align() const { return m_line_alignment; }
void set_line_align(Bindings::LineAlignSetting line_align) { m_line_alignment = line_align; }
LineAndPositionSetting position() const { return m_position; }
void set_position(LineAndPositionSetting position) { m_position = position; }
Bindings::PositionAlignSetting position_align() const { return m_position_alignment; }
void set_position_align(Bindings::PositionAlignSetting position_align) { m_position_alignment = position_align; }
@ -64,6 +67,7 @@ public:
protected:
double computed_line();
double computed_position();
Bindings::PositionAlignSetting computed_position_alignment();
private:
@ -87,6 +91,9 @@ private:
// https://w3c.github.io/webvtt/#webvtt-cue-line-alignment
Bindings::LineAlignSetting m_line_alignment { Bindings::LineAlignSetting::Start };
// https://w3c.github.io/webvtt/#webvtt-cue-position
LineAndPositionSetting m_position { Bindings::AutoKeyword::Auto };
// https://w3c.github.io/webvtt/#webvtt-cue-position-alignment
Bindings::PositionAlignSetting m_position_alignment { Bindings::PositionAlignSetting::Auto };

View file

@ -17,7 +17,7 @@ interface VTTCue : TextTrackCue {
attribute boolean snapToLines;
attribute LineAndPositionSetting line;
attribute LineAlignSetting lineAlign;
[FIXME] attribute LineAndPositionSetting position;
attribute LineAndPositionSetting position;
attribute PositionAlignSetting positionAlign;
attribute double size;
attribute AlignSetting align;