summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2022-03-15 14:37:58 +0000
committerAndreas Kling <kling@serenityos.org>2022-03-26 14:01:17 +0100
commitaaa954f900816deb82d4b545bb6b8e28e7971432 (patch)
treeaaf0abd909f0f00a4be4fce8b11015608fa93297 /Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp
parent034c57f1f9be60c08ad80b864e6c78d1d4e6de40 (diff)
downloadserenity-aaa954f900816deb82d4b545bb6b8e28e7971432.zip
LibWeb: Bring handling of anchor elements closer to spec
This commit moves the regular handling of links to the anchor elements' activation behavior, and implements a few auxiliary algorithms as defined by the HTML specification. Note that certain things such as javascript links, fragments and opening a new tab are still handled directly in EventHandler, but they have been moved to handle_mouseup so that it behaves closer to how it would if it was entirely up-to-spec.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp')
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp
index 665b119027..3b2533fd13 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp
@@ -11,6 +11,9 @@ namespace Web::HTML {
HTMLAnchorElement::HTMLAnchorElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
+ activation_behavior = [this](auto const& event) {
+ run_activation_behavior(event);
+ };
}
HTMLAnchorElement::~HTMLAnchorElement() = default;
@@ -33,4 +36,42 @@ void HTMLAnchorElement::set_hyperlink_element_utils_href(String href)
set_attribute(HTML::AttributeNames::href, move(href));
}
+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.
+ Optional<String> hyperlink_suffix {};
+
+ // 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);
+}
+
}