HTMLAnchorElement.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/HTML/HTMLAnchorElement.h>
  7. namespace Web::HTML {
  8. HTMLAnchorElement::HTMLAnchorElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  9. : HTMLElement(document, move(qualified_name))
  10. {
  11. activation_behavior = [this](auto const& event) {
  12. run_activation_behavior(event);
  13. };
  14. }
  15. HTMLAnchorElement::~HTMLAnchorElement() = default;
  16. void HTMLAnchorElement::parse_attribute(FlyString const& name, String const& value)
  17. {
  18. HTMLElement::parse_attribute(name, value);
  19. if (name == HTML::AttributeNames::href) {
  20. set_the_url();
  21. }
  22. }
  23. String HTMLAnchorElement::hyperlink_element_utils_href() const
  24. {
  25. return attribute(HTML::AttributeNames::href);
  26. }
  27. void HTMLAnchorElement::set_hyperlink_element_utils_href(String href)
  28. {
  29. set_attribute(HTML::AttributeNames::href, move(href));
  30. }
  31. void HTMLAnchorElement::run_activation_behavior(Web::DOM::Event const&)
  32. {
  33. // The activation behavior of an a element element given an event event is:
  34. // 1. If element has no href attribute, then return.
  35. if (href().is_empty())
  36. return;
  37. // 2. Let hyperlinkSuffix be null.
  38. Optional<String> hyperlink_suffix {};
  39. // FIXME: 3. If event's target is an img with an ismap attribute
  40. // specified, then:
  41. // 3.1. Let x and y be 0.
  42. //
  43. // 3.2. If event's isTrusted attribute is initialized to true, then
  44. // set x to the distance in CSS pixels from the left edge of the image
  45. // to the location of the click, and set y to the distance in CSS
  46. // pixels from the top edge of the image to the location of the click.
  47. //
  48. // 3.3. If x is negative, set x to 0.
  49. //
  50. // 3.4. If y is negative, set y to 0.
  51. //
  52. // 3.5. Set hyperlinkSuffix to the concatenation of U+003F (?), the
  53. // value of x expressed as a base-ten integer using ASCII digits,
  54. // U+002C (,), and the value of y expressed as a base-ten integer
  55. // using ASCII digits.
  56. // FIXME: 4. If element has a download attribute, or if the user has
  57. // expressed a preference to download the hyperlink, then download the
  58. // hyperlink created by element given hyperlinkSuffix.
  59. // 5. Otherwise, follow the hyperlink created by element given
  60. // hyperlinkSuffix.
  61. follow_the_hyperlink(hyperlink_suffix);
  62. }
  63. }