/src/serenity/Userland/Libraries/LibWeb/HTML/HTMLSummaryElement.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2023, the SerenityOS developers. |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/Bindings/Intrinsics.h> |
8 | | #include <LibWeb/HTML/HTMLDetailsElement.h> |
9 | | #include <LibWeb/HTML/HTMLSummaryElement.h> |
10 | | |
11 | | namespace Web::HTML { |
12 | | |
13 | | JS_DEFINE_ALLOCATOR(HTMLSummaryElement); |
14 | | |
15 | | HTMLSummaryElement::HTMLSummaryElement(DOM::Document& document, DOM::QualifiedName qualified_name) |
16 | 0 | : HTMLElement(document, move(qualified_name)) |
17 | 0 | { |
18 | 0 | } |
19 | | |
20 | | bool HTMLSummaryElement::has_activation_behavior() const |
21 | 0 | { |
22 | 0 | return true; |
23 | 0 | } |
24 | | |
25 | | void HTMLSummaryElement::activation_behavior(DOM::Event const&) |
26 | 0 | { |
27 | | // The activation behavior of summary elements is to run the following steps: |
28 | | |
29 | | // 1. If this summary element is not the summary for its parent details, then return. |
30 | 0 | if (!is_summary_for_its_parent_details()) |
31 | 0 | return; |
32 | | |
33 | | // 2. Let parent be this summary element's parent. |
34 | 0 | auto* parent = this->parent_element(); |
35 | | |
36 | | // 3. If the open attribute is present on parent, then remove it. Otherwise, set parent's open attribute to the empty string. |
37 | 0 | if (parent->has_attribute(HTML::AttributeNames::open)) |
38 | 0 | parent->remove_attribute(HTML::AttributeNames::open); |
39 | 0 | else |
40 | 0 | parent->set_attribute(HTML::AttributeNames::open, String {}).release_value_but_fixme_should_propagate_errors(); |
41 | 0 | } |
42 | | |
43 | | // https://html.spec.whatwg.org/multipage/interactive-elements.html#summary-for-its-parent-details |
44 | | bool HTMLSummaryElement::is_summary_for_its_parent_details() |
45 | 0 | { |
46 | | // A summary element is a summary for its parent details if the following algorithm returns true: |
47 | | |
48 | | // 1. If this summary element has no parent, then return false. |
49 | 0 | if (!parent_element()) |
50 | 0 | return false; |
51 | | |
52 | | // 2. Let parent be this summary element's parent. |
53 | 0 | auto* parent = this->parent_element(); |
54 | | |
55 | | // 3. If parent is not a details element, then return false. |
56 | 0 | if (!is<HTMLDetailsElement>(*parent)) |
57 | 0 | return false; |
58 | | |
59 | | // 4. If parent's first summary element child is not this summary element, then return false. |
60 | 0 | if (parent->first_child_of_type<HTMLSummaryElement>() != this) |
61 | 0 | return false; |
62 | | |
63 | | // 5. Return true. |
64 | 0 | return true; |
65 | 0 | } |
66 | | |
67 | 0 | HTMLSummaryElement::~HTMLSummaryElement() = default; |
68 | | |
69 | | void HTMLSummaryElement::initialize(JS::Realm& realm) |
70 | 0 | { |
71 | 0 | Base::initialize(realm); |
72 | 0 | } |
73 | | |
74 | | } |