2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <andreas@ladybird.org>
|
2021-02-21 13:44:17 -03:00
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
2024-06-22 07:12:44 -03:00
|
|
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2026-04-18 05:54:06 -03:00
|
|
|
#include <LibWeb/Bindings/HTMLStyleElement.h>
|
2020-07-28 14:20:11 -03:00
|
|
|
#include <LibWeb/HTML/HTMLStyleElement.h>
|
2019-09-29 12:43:30 -03:00
|
|
|
|
2020-07-28 13:20:36 -03:00
|
|
|
namespace Web::HTML {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DEFINE_ALLOCATOR(HTMLStyleElement);
|
2023-11-19 15:47:52 -03:00
|
|
|
|
2022-02-18 17:00:52 -03:00
|
|
|
HTMLStyleElement::HTMLStyleElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-02-07 07:20:15 -03:00
|
|
|
: HTMLElement(document, move(qualified_name))
|
2019-09-29 12:43:30 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 16:21:51 -03:00
|
|
|
HTMLStyleElement::~HTMLStyleElement() = default;
|
2019-09-29 12:43:30 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
void HTMLStyleElement::initialize(JS::Realm& realm)
|
2023-01-10 08:28:20 -03:00
|
|
|
{
|
2024-03-16 09:13:08 -03:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLStyleElement);
|
2025-04-20 11:22:57 -03:00
|
|
|
Base::initialize(realm);
|
2023-01-10 08:28:20 -03:00
|
|
|
}
|
|
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
void HTMLStyleElement::visit_edges(Cell::Visitor& visitor)
|
|
|
|
|
{
|
|
|
|
|
Base::visit_edges(visitor);
|
2026-02-05 13:06:29 -03:00
|
|
|
visit_style_element_edges(visitor);
|
2022-08-28 08:42:07 -03:00
|
|
|
}
|
|
|
|
|
|
2026-03-18 09:36:27 -03:00
|
|
|
void HTMLStyleElement::children_changed(ChildrenChangedMetadata const& metadata)
|
2019-09-29 12:43:30 -03:00
|
|
|
{
|
2025-01-26 09:16:33 -03:00
|
|
|
Base::children_changed(metadata);
|
2026-06-03 10:55:54 -03:00
|
|
|
update_a_style_block_for_dynamic_change();
|
2019-09-29 12:43:30 -03:00
|
|
|
}
|
|
|
|
|
|
2022-02-25 18:05:42 -03:00
|
|
|
void HTMLStyleElement::inserted()
|
|
|
|
|
{
|
2023-06-08 12:07:12 -03:00
|
|
|
Base::inserted();
|
2026-06-03 10:55:54 -03:00
|
|
|
update_a_style_block_for_dynamic_change();
|
2022-02-25 18:05:42 -03:00
|
|
|
}
|
|
|
|
|
|
2026-04-16 16:04:54 -03:00
|
|
|
void HTMLStyleElement::removed_from(IsSubtreeRoot is_subtree_root, Node* old_ancestor, Node& old_root)
|
2019-09-29 12:43:30 -03:00
|
|
|
{
|
2026-04-16 16:04:54 -03:00
|
|
|
Base::removed_from(is_subtree_root, old_ancestor, old_root);
|
2026-06-03 10:55:54 -03:00
|
|
|
update_a_style_block_for_dynamic_change();
|
2022-08-07 08:14:54 -03:00
|
|
|
}
|
|
|
|
|
|
2025-03-22 08:33:59 -03:00
|
|
|
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_);
|
2026-06-03 10:55:54 -03:00
|
|
|
style_element_attribute_changed(name, value);
|
2025-03-22 08:33:59 -03:00
|
|
|
}
|
|
|
|
|
|
2024-06-22 07:12:44 -03:00
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-20 06:31:57 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/semantics.html#contributes-a-script-blocking-style-sheet
|
|
|
|
|
bool HTMLStyleElement::contributes_a_script_blocking_style_sheet() const
|
|
|
|
|
{
|
2026-06-03 10:55:54 -03:00
|
|
|
return style_element_contributes_a_script_blocking_style_sheet();
|
2025-04-20 06:31:57 -03:00
|
|
|
}
|
|
|
|
|
|
2020-03-07 06:27:02 -03:00
|
|
|
}
|