mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 10:12:25 -05:00
LibWeb: Implement HTMLBaseElement.href
This commit is contained in:
parent
1f820f8840
commit
0a989d1bfd
Notes:
sideshowbarker
2024-07-17 10:04:33 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/0a989d1bfd Pull-request: https://github.com/SerenityOS/serenity/pull/14333 Reviewed-by: https://github.com/linusg
3 changed files with 34 additions and 0 deletions
|
@ -63,4 +63,34 @@ void HTMLBaseElement::set_the_frozen_base_url()
|
||||||
m_frozen_base_url = move(url_record);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@ public:
|
||||||
HTMLBaseElement(DOM::Document&, DOM::QualifiedName);
|
HTMLBaseElement(DOM::Document&, DOM::QualifiedName);
|
||||||
virtual ~HTMLBaseElement() override;
|
virtual ~HTMLBaseElement() override;
|
||||||
|
|
||||||
|
String href() const;
|
||||||
|
void set_href(String const& href);
|
||||||
|
|
||||||
AK::URL const& frozen_base_url() const { return m_frozen_base_url; }
|
AK::URL const& frozen_base_url() const { return m_frozen_base_url; }
|
||||||
|
|
||||||
virtual void inserted() override;
|
virtual void inserted() override;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
interface HTMLBaseElement : HTMLElement {
|
interface HTMLBaseElement : HTMLElement {
|
||||||
|
|
||||||
|
[CEReactions] attribute USVString href;
|
||||||
[Reflect] attribute DOMString target;
|
[Reflect] attribute DOMString target;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue