LibWeb/HTML: Stub TextTrack IDL interface

This commit is contained in:
Jamie Mansfield 2024-06-09 10:32:20 +01:00 committed by Andreas Kling
parent a9669639ce
commit 67e3ac8916
Notes: sideshowbarker 2024-07-17 08:45:34 +09:00
12 changed files with 217 additions and 1 deletions

View file

@ -1,12 +1,15 @@
/*
* Copyright (c) 2020, the SerenityOS developers.
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/HTMLTrackElementPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLTrackElement.h>
#include <LibWeb/HTML/TextTrack.h>
namespace Web::HTML {
@ -15,6 +18,7 @@ JS_DEFINE_ALLOCATOR(HTMLTrackElement);
HTMLTrackElement::HTMLTrackElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
m_track = TextTrack::create(document.realm());
}
HTMLTrackElement::~HTMLTrackElement() = default;
@ -25,4 +29,19 @@ void HTMLTrackElement::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLTrackElement);
}
void HTMLTrackElement::attribute_changed(FlyString const& name, Optional<String> const& value)
{
HTMLElement::attribute_changed(name, value);
// https://html.spec.whatwg.org/multipage/media.html#sourcing-out-of-band-text-tracks
// As the kind, label, and srclang attributes are set, changed, or removed, the text track must update accordingly, as per the definitions above.
if (name.equals_ignoring_ascii_case("kind"sv)) {
m_track->set_kind(text_track_kind_from_string(value.value_or({})));
} else if (name.equals_ignoring_ascii_case("label"sv)) {
m_track->set_label(value.value_or({}));
} else if (name.equals_ignoring_ascii_case("srclang"sv)) {
m_track->set_language(value.value_or({}));
}
}
}