summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorLuke <luke.wilde@live.co.uk>2021-05-04 22:25:43 +0100
committerLinus Groh <mail@linusgroh.de>2021-05-04 23:24:03 +0100
commit19731fc14cb04da7f795b901a722d95e8d33ea43 (patch)
treec9fa1719c94633fd677fbe68790dd429aa90cba5 /Userland/Libraries/LibWeb
parent7c6c7ca54274653cfda4639afae7390dc90a0b23 (diff)
downloadserenity-19731fc14cb04da7f795b901a722d95e8d33ea43.zip
LibWeb: Use HTML-uppercased qualified name for the Element node name
For regular elements, this is just the qualified name. However, for HTML elements in HTML documents, it is the qualified name uppercased. This is used by jQuery to determine the document is an HTML document. Not having this made jQuery assume the document was XML, causing weird behaviour. To do this, an internal string of qualified name is created. This is to prevent constantly regenerating it. This is allowed by the spec. This is the same for the HTML-uppercased qualified name.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Element.cpp11
-rw-r--r--Userland/Libraries/LibWeb/DOM/Element.h7
-rw-r--r--Userland/Libraries/LibWeb/QualifiedName.h17
3 files changed, 34 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp
index 37cff6ec5f..dae0af495b 100644
--- a/Userland/Libraries/LibWeb/DOM/Element.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Element.cpp
@@ -34,6 +34,7 @@ Element::Element(Document& document, QualifiedName qualified_name)
: ParentNode(document, NodeType::ELEMENT_NODE)
, m_qualified_name(move(qualified_name))
{
+ make_html_uppercased_qualified_name();
}
Element::~Element()
@@ -359,4 +360,14 @@ NonnullRefPtr<CSS::CSSStyleDeclaration> Element::style_for_bindings()
return *m_inline_style;
}
+// https://dom.spec.whatwg.org/#element-html-uppercased-qualified-name
+void Element::make_html_uppercased_qualified_name()
+{
+ // This is allowed by the spec: "User agents could optimize qualified name and HTML-uppercased qualified name by storing them in internal slots."
+ if (namespace_() == Namespace::HTML /* FIXME: and its node document is an HTML document */)
+ m_html_uppercased_qualified_name = qualified_name().to_uppercase();
+ else
+ m_html_uppercased_qualified_name = qualified_name();
+}
+
}
diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h
index 189363a99f..bcf693e6d7 100644
--- a/Userland/Libraries/LibWeb/DOM/Element.h
+++ b/Userland/Libraries/LibWeb/DOM/Element.h
@@ -29,7 +29,9 @@ public:
Element(Document&, QualifiedName);
virtual ~Element() override;
- virtual FlyString node_name() const final { return m_qualified_name.local_name(); }
+ const String& qualified_name() const { return m_qualified_name.as_string(); }
+ String html_uppercased_qualified_name() const { return m_html_uppercased_qualified_name; }
+ virtual FlyString node_name() const final { return html_uppercased_qualified_name(); }
const FlyString& local_name() const { return m_qualified_name.local_name(); }
// NOTE: This is for the JS bindings
@@ -96,7 +98,10 @@ private:
Attribute* find_attribute(const FlyString& name);
const Attribute* find_attribute(const FlyString& name) const;
+ void make_html_uppercased_qualified_name();
+
QualifiedName m_qualified_name;
+ String m_html_uppercased_qualified_name;
Vector<Attribute> m_attributes;
RefPtr<CSS::CSSStyleDeclaration> m_inline_style;
diff --git a/Userland/Libraries/LibWeb/QualifiedName.h b/Userland/Libraries/LibWeb/QualifiedName.h
index c956bc804c..c7c429d2d3 100644
--- a/Userland/Libraries/LibWeb/QualifiedName.h
+++ b/Userland/Libraries/LibWeb/QualifiedName.h
@@ -17,16 +17,33 @@ public:
, m_prefix(prefix)
, m_namespace(namespace_)
{
+ make_internal_string();
}
const FlyString& local_name() const { return m_local_name; }
const FlyString& prefix() const { return m_prefix; }
const FlyString& namespace_() const { return m_namespace; }
+ const String& as_string() const { return m_as_string; }
+
private:
FlyString m_local_name;
FlyString m_prefix;
FlyString m_namespace;
+ String m_as_string;
+
+ // https://dom.spec.whatwg.org/#concept-attribute-qualified-name
+ // https://dom.spec.whatwg.org/#concept-element-qualified-name
+ void make_internal_string()
+ {
+ // This is possible to do according to the spec: "User agents could have this as an internal slot as an optimization."
+ if (m_prefix.is_null()) {
+ m_as_string = m_local_name;
+ return;
+ }
+
+ m_as_string = String::formatted("{}:{}", m_prefix, m_local_name);
+ }
};
}