1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 20:17:41 +00:00

LibWeb: Use the globals from HTML::AttributeNames in style resolution

Using these avoids the FlyString lookups, so we should basically always
prefer them over string literal attribute names.
This commit is contained in:
Andreas Kling 2020-05-30 13:06:26 +02:00
parent 770372ad02
commit 7f22e2a3c4
4 changed files with 9 additions and 3 deletions

View file

@ -391,7 +391,7 @@ NonnullRefPtr<StyleProperties> StyleResolver::resolve_style(const Element& eleme
} }
} }
auto style_attribute = element.attribute("style"); auto style_attribute = element.attribute(HTML::AttributeNames::style);
if (!style_attribute.is_null()) { if (!style_attribute.is_null()) {
if (auto declaration = parse_css_declaration(style_attribute)) { if (auto declaration = parse_css_declaration(style_attribute)) {
for (auto& property : declaration->properties()) { for (auto& property : declaration->properties()) {

View file

@ -33,6 +33,8 @@ namespace AttributeNames {
FlyString id; FlyString id;
FlyString class_; FlyString class_;
FlyString type; FlyString type;
FlyString href;
FlyString style;
void initialize() void initialize()
{ {
@ -42,6 +44,8 @@ void initialize()
id = "id"; id = "id";
class_ = "class"; class_ = "class";
type = "type"; type = "type";
href = "href";
style = "style";
s_initialized = true; s_initialized = true;
} }

View file

@ -37,6 +37,8 @@ void initialize();
extern FlyString id; extern FlyString id;
extern FlyString class_; extern FlyString class_;
extern FlyString type; extern FlyString type;
extern FlyString href;
extern FlyString style;
} }
} }

View file

@ -63,7 +63,7 @@ Node::~Node()
const HTMLAnchorElement* Node::enclosing_link_element() const const HTMLAnchorElement* Node::enclosing_link_element() const
{ {
for (auto* node = this; node; node = node->parent()) { for (auto* node = this; node; node = node->parent()) {
if (is<HTMLAnchorElement>(*node) && to<HTMLAnchorElement>(*node).has_attribute("href")) if (is<HTMLAnchorElement>(*node) && to<HTMLAnchorElement>(*node).has_attribute(HTML::AttributeNames::href))
return to<HTMLAnchorElement>(node); return to<HTMLAnchorElement>(node);
} }
return nullptr; return nullptr;
@ -127,7 +127,7 @@ bool Node::is_link() const
auto* enclosing_link = enclosing_link_element(); auto* enclosing_link = enclosing_link_element();
if (!enclosing_link) if (!enclosing_link)
return false; return false;
return enclosing_link->has_attribute("href"); return enclosing_link->has_attribute(HTML::AttributeNames::href);
} }
void Node::dispatch_event(NonnullRefPtr<Event> event) void Node::dispatch_event(NonnullRefPtr<Event> event)