2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2022-11-28 17:58:13 -06:00
|
|
|
#include <LibWeb/DOM/ARIARoleNames.h>
|
2020-07-26 15:08:16 +02:00
|
|
|
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
2022-08-28 13:42:07 +02:00
|
|
|
#include <LibWeb/HTML/Window.h>
|
2019-09-29 11:59:38 +02:00
|
|
|
|
2020-07-28 18:20:36 +02:00
|
|
|
namespace Web::HTML {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2022-02-18 21:00:52 +01:00
|
|
|
HTMLAnchorElement::HTMLAnchorElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-02-07 11:20:15 +01:00
|
|
|
: HTMLElement(document, move(qualified_name))
|
2019-09-29 11:59:38 +02:00
|
|
|
{
|
2022-09-25 16:38:21 -06:00
|
|
|
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLAnchorElement"));
|
2022-08-28 13:42:07 +02:00
|
|
|
|
2022-03-15 14:37:58 +00:00
|
|
|
activation_behavior = [this](auto const& event) {
|
|
|
|
run_activation_behavior(event);
|
|
|
|
};
|
2019-09-29 11:59:38 +02:00
|
|
|
}
|
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
HTMLAnchorElement::~HTMLAnchorElement() = default;
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2023-01-08 19:23:00 -05:00
|
|
|
void HTMLAnchorElement::parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value)
|
2021-10-03 19:39:12 +02:00
|
|
|
{
|
|
|
|
HTMLElement::parse_attribute(name, value);
|
|
|
|
if (name == HTML::AttributeNames::href) {
|
|
|
|
set_the_url();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString HTMLAnchorElement::hyperlink_element_utils_href() const
|
2021-10-03 19:39:12 +02:00
|
|
|
{
|
|
|
|
return attribute(HTML::AttributeNames::href);
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
void HTMLAnchorElement::set_hyperlink_element_utils_href(DeprecatedString href)
|
2021-10-03 19:39:12 +02:00
|
|
|
{
|
2022-10-30 17:50:04 +00:00
|
|
|
MUST(set_attribute(HTML::AttributeNames::href, move(href)));
|
2021-10-03 19:39:12 +02:00
|
|
|
}
|
|
|
|
|
2022-03-15 14:37:58 +00:00
|
|
|
void HTMLAnchorElement::run_activation_behavior(Web::DOM::Event const&)
|
|
|
|
{
|
|
|
|
// The activation behavior of an a element element given an event event is:
|
|
|
|
|
|
|
|
// 1. If element has no href attribute, then return.
|
|
|
|
if (href().is_empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// 2. Let hyperlinkSuffix be null.
|
2022-12-04 18:02:33 +00:00
|
|
|
Optional<DeprecatedString> hyperlink_suffix {};
|
2022-03-15 14:37:58 +00:00
|
|
|
|
|
|
|
// FIXME: 3. If event's target is an img with an ismap attribute
|
|
|
|
// specified, then:
|
|
|
|
// 3.1. Let x and y be 0.
|
|
|
|
//
|
|
|
|
// 3.2. If event's isTrusted attribute is initialized to true, then
|
|
|
|
// set x to the distance in CSS pixels from the left edge of the image
|
|
|
|
// to the location of the click, and set y to the distance in CSS
|
|
|
|
// pixels from the top edge of the image to the location of the click.
|
|
|
|
//
|
|
|
|
// 3.3. If x is negative, set x to 0.
|
|
|
|
//
|
|
|
|
// 3.4. If y is negative, set y to 0.
|
|
|
|
//
|
|
|
|
// 3.5. Set hyperlinkSuffix to the concatenation of U+003F (?), the
|
|
|
|
// value of x expressed as a base-ten integer using ASCII digits,
|
|
|
|
// U+002C (,), and the value of y expressed as a base-ten integer
|
|
|
|
// using ASCII digits.
|
|
|
|
|
|
|
|
// FIXME: 4. If element has a download attribute, or if the user has
|
|
|
|
// expressed a preference to download the hyperlink, then download the
|
|
|
|
// hyperlink created by element given hyperlinkSuffix.
|
|
|
|
|
|
|
|
// 5. Otherwise, follow the hyperlink created by element given
|
|
|
|
// hyperlinkSuffix.
|
|
|
|
follow_the_hyperlink(hyperlink_suffix);
|
|
|
|
}
|
|
|
|
|
2022-11-05 03:58:14 +00:00
|
|
|
// https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex
|
|
|
|
i32 HTMLAnchorElement::default_tab_index_value() const
|
|
|
|
{
|
|
|
|
// See the base function for the spec comments.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-08 19:23:00 -05:00
|
|
|
DeprecatedFlyString HTMLAnchorElement::default_role() const
|
2022-11-28 17:58:13 -06:00
|
|
|
{
|
|
|
|
// https://www.w3.org/TR/html-aria/#el-a-no-href
|
|
|
|
if (!href().is_null())
|
|
|
|
return DOM::ARIARoleNames::link;
|
|
|
|
// https://www.w3.org/TR/html-aria/#el-a
|
|
|
|
return DOM::ARIARoleNames::generic;
|
|
|
|
}
|
|
|
|
|
2020-03-07 10:27:02 +01:00
|
|
|
}
|