Serenity Operating System
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/HTML/HTMLAreaElement.h>
9#include <LibWeb/HTML/Window.h>
10
11namespace Web::HTML {
12
13HTMLAreaElement::HTMLAreaElement(DOM::Document& document, DOM::QualifiedName qualified_name)
14 : HTMLElement(document, move(qualified_name))
15{
16}
17
18HTMLAreaElement::~HTMLAreaElement() = default;
19
20JS::ThrowCompletionOr<void> HTMLAreaElement::initialize(JS::Realm& realm)
21{
22 MUST_OR_THROW_OOM(Base::initialize(realm));
23 set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLAreaElementPrototype>(realm, "HTMLAreaElement"));
24
25 return {};
26}
27
28void HTMLAreaElement::parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value)
29{
30 HTMLElement::parse_attribute(name, value);
31 if (name == HTML::AttributeNames::href) {
32 set_the_url();
33 }
34}
35
36DeprecatedString HTMLAreaElement::hyperlink_element_utils_href() const
37{
38 return attribute(HTML::AttributeNames::href);
39}
40
41void HTMLAreaElement::set_hyperlink_element_utils_href(DeprecatedString href)
42{
43 MUST(set_attribute(HTML::AttributeNames::href, move(href)));
44}
45
46// https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex
47i32 HTMLAreaElement::default_tab_index_value() const
48{
49 // See the base function for the spec comments.
50 return 0;
51}
52
53Optional<ARIA::Role> HTMLAreaElement::default_role() const
54{
55 // https://www.w3.org/TR/html-aria/#el-area-no-href
56 if (!href().is_null())
57 return ARIA::Role::link;
58 // https://www.w3.org/TR/html-aria/#el-area
59 return ARIA::Role::generic;
60}
61
62}