From 0a989d1bfd6627ec453a9a0863508261adcd4884 Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Sun, 19 Jun 2022 15:45:09 +0100 Subject: [PATCH] LibWeb: Implement HTMLBaseElement.href --- .../Libraries/LibWeb/HTML/HTMLBaseElement.cpp | 30 +++++++++++++++++++ .../Libraries/LibWeb/HTML/HTMLBaseElement.h | 3 ++ .../Libraries/LibWeb/HTML/HTMLBaseElement.idl | 1 + 3 files changed, 34 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp index b5008f41e6..afb6d0e292 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp @@ -63,4 +63,34 @@ void HTMLBaseElement::set_the_frozen_base_url() m_frozen_base_url = move(url_record); } +// https://html.spec.whatwg.org/multipage/semantics.html#dom-base-href +String HTMLBaseElement::href() const +{ + // 1. Let document be element's node document. + auto& document = this->document(); + + // 2. Let url be the value of the href attribute of this element, if it has one, and the empty string otherwise. + auto url = String::empty(); + if (has_attribute(AttributeNames::href)) + url = attribute(AttributeNames::href); + + // 3. Let urlRecord be the result of parsing url with document's fallback base URL, and document's character encoding. (Thus, the base element isn't affected by other base elements or itself.) + // FIXME: Pass in document's character encoding. + auto url_record = document.fallback_base_url().complete_url(url); + + // 4. If urlRecord is failure, return url. + if (!url_record.is_valid()) + return url; + + // 5. Return the serialization of urlRecord. + return url_record.to_string(); +} + +// https://html.spec.whatwg.org/multipage/semantics.html#dom-base-href +void HTMLBaseElement::set_href(String const& href) +{ + // The href IDL attribute, on setting, must set the href content attribute to the given new value. + set_attribute(AttributeNames::href, href); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.h b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.h index 40d7bd3525..13afb78cfc 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.h @@ -17,6 +17,9 @@ public: HTMLBaseElement(DOM::Document&, DOM::QualifiedName); virtual ~HTMLBaseElement() override; + String href() const; + void set_href(String const& href); + AK::URL const& frozen_base_url() const { return m_frozen_base_url; } virtual void inserted() override; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.idl index 6e227d64b9..43c4bc80d9 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.idl @@ -2,6 +2,7 @@ interface HTMLBaseElement : HTMLElement { + [CEReactions] attribute USVString href; [Reflect] attribute DOMString target; };