HTMLAnchorElement.cpp 2.6 KB

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