mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-08 10:36:02 +00:00
LibWeb: Implement VTTCue.line
This commit is contained in:
parent
9080af4085
commit
8204143b08
Notes:
github-actions[bot]
2025-08-13 21:06:59 +00:00
Author: https://github.com/jamierocks
Commit: 8204143b08
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5840
Reviewed-by: https://github.com/gmta ✅
3 changed files with 55 additions and 4 deletions
|
@ -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 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<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 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()
|
||||
{
|
||||
|
|
|
@ -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 };
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue