/src/serenity/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> |
3 | | * Copyright (c) 2021, the SerenityOS developers. |
4 | | * Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org> |
5 | | * |
6 | | * SPDX-License-Identifier: BSD-2-Clause |
7 | | */ |
8 | | |
9 | | #include <LibWeb/Bindings/HTMLStyleElementPrototype.h> |
10 | | #include <LibWeb/HTML/HTMLStyleElement.h> |
11 | | |
12 | | namespace Web::HTML { |
13 | | |
14 | | JS_DEFINE_ALLOCATOR(HTMLStyleElement); |
15 | | |
16 | | HTMLStyleElement::HTMLStyleElement(DOM::Document& document, DOM::QualifiedName qualified_name) |
17 | 0 | : HTMLElement(document, move(qualified_name)) |
18 | 0 | { |
19 | 0 | } |
20 | | |
21 | 0 | HTMLStyleElement::~HTMLStyleElement() = default; |
22 | | |
23 | | void HTMLStyleElement::initialize(JS::Realm& realm) |
24 | 0 | { |
25 | 0 | Base::initialize(realm); |
26 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLStyleElement); |
27 | 0 | } |
28 | | |
29 | | void HTMLStyleElement::visit_edges(Cell::Visitor& visitor) |
30 | 0 | { |
31 | 0 | Base::visit_edges(visitor); |
32 | 0 | m_style_element_utils.visit_edges(visitor); |
33 | 0 | } |
34 | | |
35 | | void HTMLStyleElement::children_changed() |
36 | 0 | { |
37 | 0 | m_style_element_utils.update_a_style_block(*this); |
38 | 0 | Base::children_changed(); |
39 | 0 | } |
40 | | |
41 | | void HTMLStyleElement::inserted() |
42 | 0 | { |
43 | 0 | m_style_element_utils.update_a_style_block(*this); |
44 | 0 | Base::inserted(); |
45 | 0 | } |
46 | | |
47 | | void HTMLStyleElement::removed_from(Node* old_parent) |
48 | 0 | { |
49 | 0 | m_style_element_utils.update_a_style_block(*this); |
50 | 0 | Base::removed_from(old_parent); |
51 | 0 | } |
52 | | |
53 | | // https://html.spec.whatwg.org/multipage/semantics.html#dom-style-disabled |
54 | | bool HTMLStyleElement::disabled() |
55 | 0 | { |
56 | | // 1. If this does not have an associated CSS style sheet, return false. |
57 | 0 | if (!sheet()) |
58 | 0 | return false; |
59 | | |
60 | | // 2. If this's associated CSS style sheet's disabled flag is set, return true. |
61 | 0 | if (sheet()->disabled()) |
62 | 0 | return true; |
63 | | |
64 | | // 3. Return false. |
65 | 0 | return false; |
66 | 0 | } |
67 | | |
68 | | // https://html.spec.whatwg.org/multipage/semantics.html#dom-style-disabled |
69 | | void HTMLStyleElement::set_disabled(bool disabled) |
70 | 0 | { |
71 | | // 1. If this does not have an associated CSS style sheet, return. |
72 | 0 | if (!sheet()) |
73 | 0 | return; |
74 | | |
75 | | // 2. If the given value is true, set this's associated CSS style sheet's disabled flag. |
76 | | // Otherwise, unset this's associated CSS style sheet's disabled flag. |
77 | 0 | sheet()->set_disabled(disabled); |
78 | 0 | } |
79 | | |
80 | | // https://www.w3.org/TR/cssom/#dom-linkstyle-sheet |
81 | | CSS::CSSStyleSheet* HTMLStyleElement::sheet() |
82 | 0 | { |
83 | | // The sheet attribute must return the associated CSS style sheet for the node or null if there is no associated CSS style sheet. |
84 | 0 | return m_style_element_utils.sheet(); |
85 | 0 | } |
86 | | |
87 | | // https://www.w3.org/TR/cssom/#dom-linkstyle-sheet |
88 | | CSS::CSSStyleSheet const* HTMLStyleElement::sheet() const |
89 | 0 | { |
90 | | // The sheet attribute must return the associated CSS style sheet for the node or null if there is no associated CSS style sheet. |
91 | 0 | return m_style_element_utils.sheet(); |
92 | 0 | } |
93 | | |
94 | | } |