Files
ladybird/Libraries/LibWeb/HTML/HTMLStyleElement.cpp
Shannon Booth fd44da6829 LibWeb/Bindings: Emit one bindings header and cpp per IDL
Previously, the LibWeb bindings generator would output multiple per
interface files like Prototype/Constructor/Namespace/GlobalMixin
depending on the contents of that IDL file.

This complicates the build system as it means that it does not know
what files will be generated without knowledge of the contents of that
IDL file.

Instead, for each IDL file only generate a single Bindings/<IDLFile>.h
and Bindings/<IDLFile>.cpp.
2026-04-21 07:36:13 +02:00

118 lines
3.6 KiB
C++

/*
* Copyright (c) 2018-2021, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2021, the SerenityOS developers.
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/HTMLStyleElement.h>
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLStyleElement.h>
namespace Web::HTML {
GC_DEFINE_ALLOCATOR(HTMLStyleElement);
HTMLStyleElement::HTMLStyleElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
}
HTMLStyleElement::~HTMLStyleElement() = default;
void HTMLStyleElement::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLStyleElement);
Base::initialize(realm);
}
void HTMLStyleElement::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visit_style_element_edges(visitor);
}
void HTMLStyleElement::children_changed(ChildrenChangedMetadata const& metadata)
{
Base::children_changed(metadata);
update_a_style_block();
}
void HTMLStyleElement::inserted()
{
Base::inserted();
update_a_style_block();
}
void HTMLStyleElement::removed_from(Node* old_parent, Node& old_root)
{
Base::removed_from(old_parent, old_root);
update_a_style_block();
}
void HTMLStyleElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)
{
Base::attribute_changed(name, old_value, value, namespace_);
if (name == HTML::AttributeNames::media) {
if (auto* sheet = this->sheet())
sheet->set_media(value.value_or({}));
} else if (name == HTML::AttributeNames::type) {
update_a_style_block();
}
}
// https://html.spec.whatwg.org/multipage/semantics.html#dom-style-disabled
bool HTMLStyleElement::disabled()
{
// 1. If this does not have an associated CSS style sheet, return false.
if (!sheet())
return false;
// 2. If this's associated CSS style sheet's disabled flag is set, return true.
if (sheet()->disabled())
return true;
// 3. Return false.
return false;
}
// https://html.spec.whatwg.org/multipage/semantics.html#dom-style-disabled
void HTMLStyleElement::set_disabled(bool disabled)
{
// 1. If this does not have an associated CSS style sheet, return.
if (!sheet())
return;
// 2. If the given value is true, set this's associated CSS style sheet's disabled flag.
// Otherwise, unset this's associated CSS style sheet's disabled flag.
sheet()->set_disabled(disabled);
}
// https://html.spec.whatwg.org/multipage/semantics.html#contributes-a-script-blocking-style-sheet
bool HTMLStyleElement::contributes_a_script_blocking_style_sheet() const
{
// An element el in the context of a Document of an HTML parser or XML parser
// contributes a script-blocking style sheet if all of the following are true:
// FIXME: el was created by that Document's parser.
// el is either a style element or a link element that was an external resource link that contributes to the styling processing model when the el was created by the parser.
// NOTE: This is a style element, so all good!
// FIXME: el's media attribute's value matches the environment.
// FIXME: el's style sheet was enabled when the element was created by the parser.
// FIXME: The last time the event loop reached step 1, el's root was that Document.
// FIXME: The user agent hasn't given up on loading that particular style sheet yet.
// A user agent may give up on loading a style sheet at any time.
return false;
}
}