/src/serenity/Userland/Libraries/LibWeb/HTML/HTMLOrSVGElement.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/HTML/Focus.h> |
8 | | #include <LibWeb/HTML/HTMLElement.h> |
9 | | #include <LibWeb/HTML/HTMLOrSVGElement.h> |
10 | | #include <LibWeb/MathML/MathMLElement.h> |
11 | | #include <LibWeb/SVG/SVGElement.h> |
12 | | |
13 | | namespace Web::HTML { |
14 | | |
15 | | // https://html.spec.whatwg.org/multipage/dom.html#dom-dataset-dev |
16 | | template<typename ElementBase> |
17 | | JS::NonnullGCPtr<DOMStringMap> HTMLOrSVGElement<ElementBase>::dataset() |
18 | 0 | { |
19 | 0 | if (!m_dataset) |
20 | 0 | m_dataset = DOMStringMap::create(*static_cast<ElementBase*>(this)); |
21 | 0 | return *m_dataset; |
22 | 0 | } Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::HTML::HTMLElement>::dataset() Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::MathML::MathMLElement>::dataset() Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::SVG::SVGElement>::dataset() |
23 | | |
24 | | // https://html.spec.whatwg.org/multipage/interaction.html#dom-focus |
25 | | template<typename ElementBase> |
26 | | void HTMLOrSVGElement<ElementBase>::focus() |
27 | 0 | { |
28 | | // FIXME: below are the focus(options) steps, also implement focus() |
29 | | |
30 | | // 1. If the element is marked as locked for focus, then return. |
31 | 0 | if (m_locked_for_focus) |
32 | 0 | return; |
33 | | |
34 | | // 2. Mark the element as locked for focus. |
35 | 0 | m_locked_for_focus = true; |
36 | | |
37 | | // 3. Run the focusing steps for the element. |
38 | 0 | run_focusing_steps(static_cast<ElementBase*>(this)); |
39 | | |
40 | | // FIXME: 4. If the value of the preventScroll dictionary member of options is false, |
41 | | // then scroll the element into view with scroll behavior "auto", |
42 | | // block flow direction position set to an implementation-defined value, |
43 | | // and inline base direction position set to an implementation-defined value. |
44 | | |
45 | | // 5. Unmark the element as locked for focus. |
46 | 0 | m_locked_for_focus = false; |
47 | 0 | } Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::HTML::HTMLElement>::focus() Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::MathML::MathMLElement>::focus() Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::SVG::SVGElement>::focus() |
48 | | |
49 | | // https://html.spec.whatwg.org/multipage/interaction.html#dom-blur |
50 | | template<typename ElementBase> |
51 | | void HTMLOrSVGElement<ElementBase>::blur() |
52 | 0 | { |
53 | | // The blur() method, when invoked, should run the unfocusing steps for the element on which the method was called. |
54 | 0 | run_unfocusing_steps(static_cast<ElementBase*>(this)); |
55 | | |
56 | | // User agents may selectively or uniformly ignore calls to this method for usability reasons. |
57 | 0 | } Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::HTML::HTMLElement>::blur() Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::MathML::MathMLElement>::blur() Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::SVG::SVGElement>::blur() |
58 | | |
59 | | // https://html.spec.whatwg.org/#dom-noncedelement-nonce |
60 | | template<typename ElementBase> |
61 | | void HTMLOrSVGElement<ElementBase>::attribute_change_steps(FlyString const& local_name, Optional<String> const&, Optional<String> const& value, Optional<FlyString> const& namespace_) |
62 | 0 | { |
63 | | // 1. If element does not include HTMLOrSVGElement, then return. |
64 | | // 2. If localName is not nonce or namespace is not null, then return. |
65 | 0 | if (local_name != HTML::AttributeNames::nonce || namespace_.has_value()) |
66 | 0 | return; |
67 | | |
68 | | // 3. If value is null, then set element's [[CryptographicNonce]] to the empty string. |
69 | 0 | if (!value.has_value()) { |
70 | 0 | m_cryptographic_nonce = {}; |
71 | 0 | } |
72 | | |
73 | | // 4. Otherwise, set element's [[CryptographicNonce]] to value. |
74 | 0 | else { |
75 | 0 | m_cryptographic_nonce = value.value(); |
76 | 0 | } |
77 | 0 | } Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::HTML::HTMLElement>::attribute_change_steps(AK::FlyString const&, AK::Optional<AK::String> const&, AK::Optional<AK::String> const&, AK::Optional<AK::FlyString> const&) Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::MathML::MathMLElement>::attribute_change_steps(AK::FlyString const&, AK::Optional<AK::String> const&, AK::Optional<AK::String> const&, AK::Optional<AK::FlyString> const&) Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::SVG::SVGElement>::attribute_change_steps(AK::FlyString const&, AK::Optional<AK::String> const&, AK::Optional<AK::String> const&, AK::Optional<AK::FlyString> const&) |
78 | | |
79 | | // https://html.spec.whatwg.org/#dom-noncedelement-nonce |
80 | | template<typename ElementBase> |
81 | | WebIDL::ExceptionOr<void> HTMLOrSVGElement<ElementBase>::cloned(DOM::Node& copy, bool) |
82 | 0 | { |
83 | | // The cloning steps for elements that include HTMLOrSVGElement must set the |
84 | | // [[CryptographicNonce]] slot on the copy to the value of the slot on the element being cloned. |
85 | 0 | static_cast<ElementBase&>(copy).m_cryptographic_nonce = m_cryptographic_nonce; |
86 | 0 | return {}; |
87 | 0 | } Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::HTML::HTMLElement>::cloned(Web::DOM::Node&, bool) Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::MathML::MathMLElement>::cloned(Web::DOM::Node&, bool) Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::SVG::SVGElement>::cloned(Web::DOM::Node&, bool) |
88 | | |
89 | | // https://html.spec.whatwg.org/#dom-noncedelement-nonce |
90 | | template<typename ElementBase> |
91 | | void HTMLOrSVGElement<ElementBase>::inserted() |
92 | 0 | { |
93 | | // Whenever an element including HTMLOrSVGElement becomes browsing-context connected, the user |
94 | | // agent must execute the following steps on the element: |
95 | 0 | DOM::Element& element = *static_cast<ElementBase*>(this); |
96 | | |
97 | | // FIXME: 1. Let CSP list be element's shadow-including root's policy container's CSP list. |
98 | 0 | [[maybe_unused]] auto policy_container = element.shadow_including_root().document().policy_container(); |
99 | | |
100 | | // FIXME: 2. If CSP list contains a header-delivered Content Security Policy, and element has a |
101 | | // nonce content attribute attr whose value is not the empty string, then: |
102 | 0 | if (true && element.has_attribute(HTML::AttributeNames::nonce)) { |
103 | | // 2.1. Let nonce be element's [[CryptographicNonce]]. |
104 | 0 | auto nonce = m_cryptographic_nonce; |
105 | | |
106 | | // 2.2. Set an attribute value for element using "nonce" and the empty string. |
107 | 0 | element.set_attribute_value(HTML::AttributeNames::nonce, {}); |
108 | | |
109 | | // 2.3. Set element's [[CryptographicNonce]] to nonce. |
110 | 0 | m_cryptographic_nonce = nonce; |
111 | 0 | } |
112 | 0 | } Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::HTML::HTMLElement>::inserted() Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::MathML::MathMLElement>::inserted() Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::SVG::SVGElement>::inserted() |
113 | | |
114 | | template<typename ElementBase> |
115 | | void HTMLOrSVGElement<ElementBase>::visit_edges(JS::Cell::Visitor& visitor) |
116 | 0 | { |
117 | 0 | visitor.visit(m_dataset); |
118 | 0 | } Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::HTML::HTMLElement>::visit_edges(JS::Cell::Visitor&) Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::MathML::MathMLElement>::visit_edges(JS::Cell::Visitor&) Unexecuted instantiation: Web::HTML::HTMLOrSVGElement<Web::SVG::SVGElement>::visit_edges(JS::Cell::Visitor&) |
119 | | |
120 | | template class HTMLOrSVGElement<HTMLElement>; |
121 | | template class HTMLOrSVGElement<MathML::MathMLElement>; |
122 | | template class HTMLOrSVGElement<SVG::SVGElement>; |
123 | | |
124 | | } |