/src/serenity/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2020, the SerenityOS developers. |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/ARIA/Roles.h> |
8 | | #include <LibWeb/Bindings/HTMLAreaElementPrototype.h> |
9 | | #include <LibWeb/DOM/DOMTokenList.h> |
10 | | #include <LibWeb/HTML/HTMLAreaElement.h> |
11 | | #include <LibWeb/HTML/Window.h> |
12 | | |
13 | | namespace Web::HTML { |
14 | | |
15 | | JS_DEFINE_ALLOCATOR(HTMLAreaElement); |
16 | | |
17 | | HTMLAreaElement::HTMLAreaElement(DOM::Document& document, DOM::QualifiedName qualified_name) |
18 | 0 | : HTMLElement(document, move(qualified_name)) |
19 | 0 | { |
20 | 0 | } |
21 | | |
22 | 0 | HTMLAreaElement::~HTMLAreaElement() = default; |
23 | | |
24 | | void HTMLAreaElement::initialize(JS::Realm& realm) |
25 | 0 | { |
26 | 0 | Base::initialize(realm); |
27 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLAreaElement); |
28 | 0 | } |
29 | | |
30 | | void HTMLAreaElement::visit_edges(Cell::Visitor& visitor) |
31 | 0 | { |
32 | 0 | Base::visit_edges(visitor); |
33 | 0 | visitor.visit(m_rel_list); |
34 | 0 | } |
35 | | |
36 | | void HTMLAreaElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) |
37 | 0 | { |
38 | 0 | HTMLElement::attribute_changed(name, old_value, value); |
39 | 0 | if (name == HTML::AttributeNames::href) { |
40 | 0 | set_the_url(); |
41 | 0 | } else if (name == HTML::AttributeNames::rel) { |
42 | 0 | if (m_rel_list) |
43 | 0 | m_rel_list->associated_attribute_changed(value.value_or(String {})); |
44 | 0 | } |
45 | 0 | } |
46 | | |
47 | | // https://html.spec.whatwg.org/multipage/image-maps.html#dom-area-rellist |
48 | | JS::NonnullGCPtr<DOM::DOMTokenList> HTMLAreaElement::rel_list() |
49 | 0 | { |
50 | | // The IDL attribute relList must reflect the rel content attribute. |
51 | 0 | if (!m_rel_list) |
52 | 0 | m_rel_list = DOM::DOMTokenList::create(*this, HTML::AttributeNames::rel); |
53 | 0 | return *m_rel_list; |
54 | 0 | } |
55 | | |
56 | | Optional<String> HTMLAreaElement::hyperlink_element_utils_href() const |
57 | 0 | { |
58 | 0 | return attribute(HTML::AttributeNames::href); |
59 | 0 | } |
60 | | |
61 | | WebIDL::ExceptionOr<void> HTMLAreaElement::set_hyperlink_element_utils_href(String href) |
62 | 0 | { |
63 | 0 | return set_attribute(HTML::AttributeNames::href, move(href)); |
64 | 0 | } |
65 | | |
66 | | Optional<String> HTMLAreaElement::hyperlink_element_utils_referrerpolicy() const |
67 | 0 | { |
68 | 0 | return attribute(HTML::AttributeNames::referrerpolicy); |
69 | 0 | } |
70 | | |
71 | | // https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex |
72 | | i32 HTMLAreaElement::default_tab_index_value() const |
73 | 0 | { |
74 | | // See the base function for the spec comments. |
75 | 0 | return 0; |
76 | 0 | } |
77 | | |
78 | | Optional<ARIA::Role> HTMLAreaElement::default_role() const |
79 | 0 | { |
80 | | // https://www.w3.org/TR/html-aria/#el-area-no-href |
81 | 0 | if (!href().is_empty()) |
82 | 0 | return ARIA::Role::link; |
83 | | // https://www.w3.org/TR/html-aria/#el-area |
84 | 0 | return ARIA::Role::generic; |
85 | 0 | } |
86 | | |
87 | | } |