diff --git a/Libraries/LibWeb/WebVTT/VTTCue.cpp b/Libraries/LibWeb/WebVTT/VTTCue.cpp index c6699d3c591..c012626ab74 100644 --- a/Libraries/LibWeb/WebVTT/VTTCue.cpp +++ b/Libraries/LibWeb/WebVTT/VTTCue.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Jamie Mansfield + * Copyright (c) 2024-2025, Jamie Mansfield * * SPDX-License-Identifier: BSD-2-Clause */ @@ -47,7 +47,8 @@ WebIDL::ExceptionOr> VTTCue::construct_impl(JS::Realm& realm, do // 9. Let cue’s WebVTT cue snap-to-lines flag be true. cue->m_snap_to_lines = true; - // FIXME: 10. Let cue’s WebVTT cue line be auto. + // 10. Let cue’s WebVTT cue line be auto. + cue->m_line = Bindings::AutoKeyword::Auto; // 11. Let cue’s 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() && !m_snap_to_lines && (m_line.get() < 0 || m_line.get() > 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()) + return m_line.get(); + + // 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 element’s 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() { diff --git a/Libraries/LibWeb/WebVTT/VTTCue.h b/Libraries/LibWeb/WebVTT/VTTCue.h index e5a0e2360ee..276a0734ca0 100644 --- a/Libraries/LibWeb/WebVTT/VTTCue.h +++ b/Libraries/LibWeb/WebVTT/VTTCue.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Jamie Mansfield + * Copyright (c) 2024-2025, Jamie Mansfield * * SPDX-License-Identifier: BSD-2-Clause */ @@ -30,6 +30,8 @@ public: VerticalGrowingRight, }; + using LineAndPositionSetting = Variant; + static WebIDL::ExceptionOr> 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 }; diff --git a/Libraries/LibWeb/WebVTT/VTTCue.idl b/Libraries/LibWeb/WebVTT/VTTCue.idl index 30f7e46e30a..31f5a39e8a5 100644 --- a/Libraries/LibWeb/WebVTT/VTTCue.idl +++ b/Libraries/LibWeb/WebVTT/VTTCue.idl @@ -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;