Coverage Report

Created: 2026-02-16 07:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/WebVTT/VTTRegion.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include <LibWeb/Bindings/Intrinsics.h>
8
#include <LibWeb/HTML/Window.h>
9
#include <LibWeb/WebVTT/VTTRegion.h>
10
11
namespace Web::WebVTT {
12
13
JS_DEFINE_ALLOCATOR(VTTRegion);
14
15
// https://w3c.github.io/webvtt/#dom-vttregion-vttregion
16
WebIDL::ExceptionOr<JS::NonnullGCPtr<VTTRegion>> VTTRegion::construct_impl(JS::Realm& realm)
17
0
{
18
    // 1. Create a new WebVTT region. Let region be that WebVTT region.
19
0
    auto region = realm.heap().allocate<VTTRegion>(realm, realm);
20
21
    // 2. Let region’s WebVTT region identifier be the empty string.
22
0
    region->m_identifier = ""_string;
23
24
    // 3. Let region’s WebVTT region width be 100.
25
0
    region->m_width = 100;
26
27
    // 4. Let region’s WebVTT region lines be 3.
28
0
    region->m_lines = 3;
29
30
    // 5. Let region’s text track region regionAnchorX be 0.
31
0
    region->m_anchor_x = 0;
32
33
    // 6. Let region’s text track region regionAnchorY be 100.
34
0
    region->m_anchor_y = 100;
35
36
    // 7. Let region’s text track region viewportAnchorX be 0.
37
0
    region->m_viewport_anchor_x = 0;
38
39
    // 8. Let region’s text track region viewportAnchorY be 100.
40
0
    region->m_viewport_anchor_y = 100;
41
42
    // 9. Let region’s WebVTT region scroll be the empty string.
43
0
    region->m_scroll_setting = Bindings::ScrollSetting::Empty;
44
45
    // 10. Return the VTTRegion object representing region.
46
0
    return region;
47
0
}
48
49
VTTRegion::VTTRegion(JS::Realm& realm)
50
0
    : PlatformObject(realm)
51
0
{
52
0
}
53
54
void VTTRegion::initialize(JS::Realm& realm)
55
0
{
56
0
    Base::initialize(realm);
57
0
    WEB_SET_PROTOTYPE_FOR_INTERFACE(VTTRegion);
58
0
}
59
60
// https://w3c.github.io/webvtt/#dom-vttregion-width
61
WebIDL::ExceptionOr<void> VTTRegion::set_width(double width)
62
0
{
63
    // On setting, if the new value is negative or greater than 100, then an IndexSizeError exception must be thrown.
64
0
    if (width < 0 || width > 100)
65
0
        return WebIDL::IndexSizeError::create(realm(), "Value is negative or greater than 100"_string);
66
67
    // Otherwise, the WebVTT region width must be set to the new value.
68
0
    m_width = width;
69
0
    return {};
70
0
}
71
72
// https://w3c.github.io/webvtt/#dom-vttregion-regionanchorx
73
WebIDL::ExceptionOr<void> VTTRegion::set_region_anchor_x(double region_anchor_x)
74
0
{
75
    // On setting, if the new value is negative or greater than 100, then an IndexSizeError exception must be thrown.
76
0
    if (region_anchor_x < 0 || region_anchor_x > 100)
77
0
        return WebIDL::IndexSizeError::create(realm(), "Value is negative or greater than 100"_string);
78
79
    // Otherwise, the WebVTT region anchor X distance must be set to the new value.
80
0
    m_anchor_x = region_anchor_x;
81
0
    return {};
82
0
}
83
84
// https://w3c.github.io/webvtt/#dom-vttregion-regionanchory
85
WebIDL::ExceptionOr<void> VTTRegion::set_region_anchor_y(double region_anchor_y)
86
0
{
87
    // On setting, if the new value is negative or greater than 100, then an IndexSizeError exception must be thrown.
88
0
    if (region_anchor_y < 0 || region_anchor_y > 100)
89
0
        return WebIDL::IndexSizeError::create(realm(), "Value is negative or greater than 100"_string);
90
91
    // Otherwise, the WebVTT region anchor Y distance must be set to the new value.
92
0
    m_anchor_y = region_anchor_y;
93
0
    return {};
94
0
}
95
96
// https://w3c.github.io/webvtt/#dom-vttregion-viewportanchorx
97
WebIDL::ExceptionOr<void> VTTRegion::set_viewport_anchor_x(double viewport_anchor_x)
98
0
{
99
    // On setting, if the new value is negative or greater than 100, then an IndexSizeError exception must be thrown.
100
0
    if (viewport_anchor_x < 0 || viewport_anchor_x > 100)
101
0
        return WebIDL::IndexSizeError::create(realm(), "Value is negative or greater than 100"_string);
102
103
    // Otherwise, the WebVTT region viewport anchor X distance must be set to the new value.
104
0
    m_viewport_anchor_x = viewport_anchor_x;
105
0
    return {};
106
0
}
107
108
// https://w3c.github.io/webvtt/#dom-vttregion-viewportanchory
109
WebIDL::ExceptionOr<void> VTTRegion::set_viewport_anchor_y(double viewport_anchor_y)
110
0
{
111
    // On setting, if the new value is negative or greater than 100, then an IndexSizeError exception must be thrown.
112
0
    if (viewport_anchor_y < 0 || viewport_anchor_y > 100)
113
0
        return WebIDL::IndexSizeError::create(realm(), "Value is negative or greater than 100"_string);
114
115
    // Otherwise, the WebVTT region viewport anchor Y distance must be set to the new value.
116
0
    m_viewport_anchor_y = viewport_anchor_y;
117
0
    return {};
118
0
}
119
120
}