HTMLAnchorElement.cpp 2.5 KB

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