mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:07:35 +00:00
LibWeb: Use FlyString for element attribute names
Attribute names occur again and again.
This commit is contained in:
parent
26bc3d4ea0
commit
7f83f77377
6 changed files with 19 additions and 18 deletions
|
@ -49,7 +49,7 @@ Element::~Element()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Attribute* Element::find_attribute(const String& name)
|
Attribute* Element::find_attribute(const FlyString& name)
|
||||||
{
|
{
|
||||||
for (auto& attribute : m_attributes) {
|
for (auto& attribute : m_attributes) {
|
||||||
if (attribute.name() == name)
|
if (attribute.name() == name)
|
||||||
|
@ -58,7 +58,7 @@ Attribute* Element::find_attribute(const String& name)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Attribute* Element::find_attribute(const String& name) const
|
const Attribute* Element::find_attribute(const FlyString& name) const
|
||||||
{
|
{
|
||||||
for (auto& attribute : m_attributes) {
|
for (auto& attribute : m_attributes) {
|
||||||
if (attribute.name() == name)
|
if (attribute.name() == name)
|
||||||
|
@ -67,14 +67,14 @@ const Attribute* Element::find_attribute(const String& name) const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
String Element::attribute(const String& name) const
|
String Element::attribute(const FlyString& name) const
|
||||||
{
|
{
|
||||||
if (auto* attribute = find_attribute(name))
|
if (auto* attribute = find_attribute(name))
|
||||||
return attribute->value();
|
return attribute->value();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Element::set_attribute(const String& name, const String& value)
|
void Element::set_attribute(const FlyString& name, const String& value)
|
||||||
{
|
{
|
||||||
if (auto* attribute = find_attribute(name))
|
if (auto* attribute = find_attribute(name))
|
||||||
attribute->set_value(value);
|
attribute->set_value(value);
|
||||||
|
@ -131,7 +131,7 @@ RefPtr<LayoutNode> Element::create_layout_node(const StyleProperties* parent_sty
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Element::parse_attribute(const String&, const String&)
|
void Element::parse_attribute(const FlyString&, const String&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/FlyString.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibWeb/DOM/ParentNode.h>
|
#include <LibWeb/DOM/ParentNode.h>
|
||||||
#include <LibWeb/Layout/LayoutNode.h>
|
#include <LibWeb/Layout/LayoutNode.h>
|
||||||
|
@ -36,19 +37,19 @@ class LayoutNodeWithStyle;
|
||||||
|
|
||||||
class Attribute {
|
class Attribute {
|
||||||
public:
|
public:
|
||||||
Attribute(const String& name, const String& value)
|
Attribute(const FlyString& name, const String& value)
|
||||||
: m_name(name)
|
: m_name(name)
|
||||||
, m_value(value)
|
, m_value(value)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const String& name() const { return m_name; }
|
const FlyString& name() const { return m_name; }
|
||||||
const String& value() const { return m_value; }
|
const String& value() const { return m_value; }
|
||||||
|
|
||||||
void set_value(const String& value) { m_value = value; }
|
void set_value(const String& value) { m_value = value; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String m_name;
|
FlyString m_name;
|
||||||
String m_value;
|
String m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -59,9 +60,9 @@ public:
|
||||||
|
|
||||||
virtual String tag_name() const final { return m_tag_name; }
|
virtual String tag_name() const final { return m_tag_name; }
|
||||||
|
|
||||||
bool has_attribute(const String& name) const { return !attribute(name).is_null(); }
|
bool has_attribute(const FlyString& name) const { return !attribute(name).is_null(); }
|
||||||
String attribute(const String& name) const;
|
String attribute(const FlyString& name) const;
|
||||||
void set_attribute(const String& name, const String& value);
|
void set_attribute(const FlyString& name, const String& value);
|
||||||
|
|
||||||
void set_attributes(Vector<Attribute>&&);
|
void set_attributes(Vector<Attribute>&&);
|
||||||
|
|
||||||
|
@ -75,7 +76,7 @@ public:
|
||||||
bool has_class(const StringView&) const;
|
bool has_class(const StringView&) const;
|
||||||
|
|
||||||
virtual void apply_presentational_hints(StyleProperties&) const {}
|
virtual void apply_presentational_hints(StyleProperties&) const {}
|
||||||
virtual void parse_attribute(const String& name, const String& value);
|
virtual void parse_attribute(const FlyString& name, const String& value);
|
||||||
|
|
||||||
void recompute_style();
|
void recompute_style();
|
||||||
|
|
||||||
|
@ -90,8 +91,8 @@ public:
|
||||||
private:
|
private:
|
||||||
RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
|
RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
|
||||||
|
|
||||||
Attribute* find_attribute(const String& name);
|
Attribute* find_attribute(const FlyString& name);
|
||||||
const Attribute* find_attribute(const String& name) const;
|
const Attribute* find_attribute(const FlyString& name) const;
|
||||||
|
|
||||||
String m_tag_name;
|
String m_tag_name;
|
||||||
Vector<Attribute> m_attributes;
|
Vector<Attribute> m_attributes;
|
||||||
|
|
|
@ -58,7 +58,7 @@ void HTMLBodyElement::apply_presentational_hints(StyleProperties& style) const
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLBodyElement::parse_attribute(const String& name, const String& value)
|
void HTMLBodyElement::parse_attribute(const FlyString& name, const String& value)
|
||||||
{
|
{
|
||||||
if (name.equals_ignoring_case("link")) {
|
if (name.equals_ignoring_case("link")) {
|
||||||
auto color = Color::from_string(value);
|
auto color = Color::from_string(value);
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
HTMLBodyElement(Document&, const String& tag_name);
|
HTMLBodyElement(Document&, const String& tag_name);
|
||||||
virtual ~HTMLBodyElement() override;
|
virtual ~HTMLBodyElement() override;
|
||||||
|
|
||||||
virtual void parse_attribute(const String&, const String&) override;
|
virtual void parse_attribute(const FlyString&, const String&) override;
|
||||||
virtual void apply_presentational_hints(StyleProperties&) const override;
|
virtual void apply_presentational_hints(StyleProperties&) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -43,7 +43,7 @@ HTMLImageElement::~HTMLImageElement()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLImageElement::parse_attribute(const String& name, const String& value)
|
void HTMLImageElement::parse_attribute(const FlyString& name, const String& value)
|
||||||
{
|
{
|
||||||
if (name.equals_ignoring_case("src"))
|
if (name.equals_ignoring_case("src"))
|
||||||
load_image(value);
|
load_image(value);
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
HTMLImageElement(Document&, const String& tag_name);
|
HTMLImageElement(Document&, const String& tag_name);
|
||||||
virtual ~HTMLImageElement() override;
|
virtual ~HTMLImageElement() override;
|
||||||
|
|
||||||
virtual void parse_attribute(const String& name, const String& value) override;
|
virtual void parse_attribute(const FlyString& name, const String& value) override;
|
||||||
|
|
||||||
String alt() const { return attribute("alt"); }
|
String alt() const { return attribute("alt"); }
|
||||||
String src() const { return attribute("src"); }
|
String src() const { return attribute("src"); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue