mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 17:58:11 +00:00
LibWeb: Port Element::local_name and TagNames from Deprecated String
Which pretty much needs to be done together due to the amount of places where they are compared together. This also involves porting over StackOfOpenElements over to FlyString from DeprecatedFly string to prevent a gazillion calls to `.to_deprecated_fly_string` calls in HTMLParser.
This commit is contained in:
parent
bbfe0d3a82
commit
9303e9e76f
30 changed files with 163 additions and 158 deletions
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
static Vector<DeprecatedFlyString> s_base_list { "applet", "caption", "html", "table", "td", "th", "marquee", "object", "template" };
|
||||
static Vector<FlyString> s_base_list { "applet"_fly_string, "caption"_fly_string, "html"_fly_string, "table"_fly_string, "td"_fly_string, "th"_fly_string, "marquee"_fly_string, "object"_fly_string, "template"_fly_string };
|
||||
|
||||
StackOfOpenElements::~StackOfOpenElements() = default;
|
||||
|
||||
|
@ -20,7 +20,7 @@ void StackOfOpenElements::visit_edges(JS::Cell::Visitor& visitor)
|
|||
visitor.visit(element);
|
||||
}
|
||||
|
||||
bool StackOfOpenElements::has_in_scope_impl(DeprecatedFlyString const& tag_name, Vector<DeprecatedFlyString> const& list) const
|
||||
bool StackOfOpenElements::has_in_scope_impl(FlyString const& tag_name, Vector<FlyString> const& list) const
|
||||
{
|
||||
for (auto const& element : m_elements.in_reverse()) {
|
||||
if (element->local_name() == tag_name)
|
||||
|
@ -31,12 +31,12 @@ bool StackOfOpenElements::has_in_scope_impl(DeprecatedFlyString const& tag_name,
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
bool StackOfOpenElements::has_in_scope(DeprecatedFlyString const& tag_name) const
|
||||
bool StackOfOpenElements::has_in_scope(FlyString const& tag_name) const
|
||||
{
|
||||
return has_in_scope_impl(tag_name, s_base_list);
|
||||
}
|
||||
|
||||
bool StackOfOpenElements::has_in_scope_impl(const DOM::Element& target_node, Vector<DeprecatedFlyString> const& list) const
|
||||
bool StackOfOpenElements::has_in_scope_impl(const DOM::Element& target_node, Vector<FlyString> const& list) const
|
||||
{
|
||||
for (auto& element : m_elements.in_reverse()) {
|
||||
if (element.ptr() == &target_node)
|
||||
|
@ -52,23 +52,23 @@ bool StackOfOpenElements::has_in_scope(const DOM::Element& target_node) const
|
|||
return has_in_scope_impl(target_node, s_base_list);
|
||||
}
|
||||
|
||||
bool StackOfOpenElements::has_in_button_scope(DeprecatedFlyString const& tag_name) const
|
||||
bool StackOfOpenElements::has_in_button_scope(FlyString const& tag_name) const
|
||||
{
|
||||
auto list = s_base_list;
|
||||
list.append("button");
|
||||
list.append("button"_fly_string);
|
||||
return has_in_scope_impl(tag_name, list);
|
||||
}
|
||||
|
||||
bool StackOfOpenElements::has_in_table_scope(DeprecatedFlyString const& tag_name) const
|
||||
bool StackOfOpenElements::has_in_table_scope(FlyString const& tag_name) const
|
||||
{
|
||||
return has_in_scope_impl(tag_name, { "html", "table", "template" });
|
||||
return has_in_scope_impl(tag_name, { "html"_fly_string, "table"_fly_string, "template"_fly_string });
|
||||
}
|
||||
|
||||
bool StackOfOpenElements::has_in_list_item_scope(DeprecatedFlyString const& tag_name) const
|
||||
bool StackOfOpenElements::has_in_list_item_scope(FlyString const& tag_name) const
|
||||
{
|
||||
auto list = s_base_list;
|
||||
list.append("ol");
|
||||
list.append("ul");
|
||||
list.append("ol"_fly_string);
|
||||
list.append("ul"_fly_string);
|
||||
return has_in_scope_impl(tag_name, list);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ bool StackOfOpenElements::has_in_list_item_scope(DeprecatedFlyString const& tag_
|
|||
// - optgroup in the HTML namespace
|
||||
// - option in the HTML namespace
|
||||
// NOTE: In this case it's "all element types _except_"
|
||||
bool StackOfOpenElements::has_in_select_scope(DeprecatedFlyString const& tag_name) const
|
||||
bool StackOfOpenElements::has_in_select_scope(FlyString const& tag_name) const
|
||||
{
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#has-an-element-in-the-specific-scope
|
||||
// 1. Initialize node to be the current node (the bottommost node of the stack).
|
||||
|
@ -106,7 +106,7 @@ bool StackOfOpenElements::contains(const DOM::Element& element) const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool StackOfOpenElements::contains(DeprecatedFlyString const& tag_name) const
|
||||
bool StackOfOpenElements::contains(FlyString const& tag_name) const
|
||||
{
|
||||
for (auto& element_on_stack : m_elements) {
|
||||
if (element_on_stack->local_name() == tag_name)
|
||||
|
@ -115,7 +115,7 @@ bool StackOfOpenElements::contains(DeprecatedFlyString const& tag_name) const
|
|||
return false;
|
||||
}
|
||||
|
||||
void StackOfOpenElements::pop_until_an_element_with_tag_name_has_been_popped(DeprecatedFlyString const& tag_name)
|
||||
void StackOfOpenElements::pop_until_an_element_with_tag_name_has_been_popped(FlyString const& tag_name)
|
||||
{
|
||||
while (m_elements.last()->local_name() != tag_name)
|
||||
(void)pop();
|
||||
|
@ -134,7 +134,7 @@ JS::GCPtr<DOM::Element> StackOfOpenElements::topmost_special_node_below(DOM::Ele
|
|||
return found_element.ptr();
|
||||
}
|
||||
|
||||
StackOfOpenElements::LastElementResult StackOfOpenElements::last_element_with_tag_name(DeprecatedFlyString const& tag_name)
|
||||
StackOfOpenElements::LastElementResult StackOfOpenElements::last_element_with_tag_name(FlyString const& tag_name)
|
||||
{
|
||||
for (ssize_t i = m_elements.size() - 1; i >= 0; --i) {
|
||||
auto& element = m_elements[i];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue