mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-10 01:59:31 +00:00
LibWeb: Stop constructing temporary ElementInlineCSSStyleDeclarations
Previously, parse_css_style_attribute() would parse the string, extract the properties, add them to a newly-created ElementInlineCSSStyleDeclarations, and then user code would take the properties back out of it again and throw it away. Instead, just return the list of properties, and the caller can create an EICSD if it needs one.
This commit is contained in:
parent
f0d198ca3f
commit
50455c2f5e
Notes:
github-actions[bot]
2025-03-19 13:54:35 +00:00
Author: https://github.com/AtkinsSJ
Commit: 50455c2f5e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3983
5 changed files with 19 additions and 22 deletions
|
@ -668,8 +668,8 @@ void ElementInlineCSSStyleDeclaration::set_declarations_from_text(StringView css
|
|||
}
|
||||
|
||||
empty_the_declarations();
|
||||
auto style = parse_css_style_attribute(CSS::Parser::ParsingParams(element->element().document()), css_text, element->element());
|
||||
set_the_declarations(style->properties(), style->custom_properties());
|
||||
auto style = parse_css_style_attribute(Parser::ParsingParams(element->element().document()), css_text);
|
||||
set_the_declarations(style.properties, style.custom_properties);
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
|
||||
|
|
|
@ -30,11 +30,11 @@ CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingParams const& conte
|
|||
return style_sheet;
|
||||
}
|
||||
|
||||
CSS::ElementInlineCSSStyleDeclaration* parse_css_style_attribute(CSS::Parser::ParsingParams const& context, StringView css, DOM::Element& element)
|
||||
CSS::Parser::Parser::PropertiesAndCustomProperties parse_css_style_attribute(CSS::Parser::ParsingParams const& context, StringView css)
|
||||
{
|
||||
if (css.is_empty())
|
||||
return CSS::ElementInlineCSSStyleDeclaration::create(element, {}, {});
|
||||
return CSS::Parser::Parser::create(context, css).parse_as_style_attribute(element);
|
||||
return {};
|
||||
return CSS::Parser::Parser::create(context, css).parse_as_style_attribute();
|
||||
}
|
||||
|
||||
RefPtr<CSS::CSSStyleValue> parse_css_value(CSS::Parser::ParsingParams const& context, StringView string, CSS::PropertyID property_id)
|
||||
|
|
|
@ -1317,7 +1317,7 @@ Vector<Vector<ComponentValue>> Parser::parse_a_comma_separated_list_of_component
|
|||
return groups;
|
||||
}
|
||||
|
||||
ElementInlineCSSStyleDeclaration* Parser::parse_as_style_attribute(DOM::Element& element)
|
||||
Parser::PropertiesAndCustomProperties Parser::parse_as_style_attribute()
|
||||
{
|
||||
auto expand_shorthands = [&](Vector<StyleProperty>& properties) -> Vector<StyleProperty> {
|
||||
Vector<StyleProperty> expanded_properties;
|
||||
|
@ -1341,9 +1341,9 @@ ElementInlineCSSStyleDeclaration* Parser::parse_as_style_attribute(DOM::Element&
|
|||
auto declarations_and_at_rules = parse_a_blocks_contents(m_token_stream);
|
||||
m_rule_context.take_last();
|
||||
|
||||
auto [properties, custom_properties] = extract_properties(declarations_and_at_rules);
|
||||
auto expanded_properties = expand_shorthands(properties);
|
||||
return ElementInlineCSSStyleDeclaration::create(element, move(expanded_properties), move(custom_properties));
|
||||
auto properties = extract_properties(declarations_and_at_rules);
|
||||
properties.properties = expand_shorthands(properties.properties);
|
||||
return properties;
|
||||
}
|
||||
|
||||
bool Parser::is_valid_in_the_current_context(Declaration const&) const
|
||||
|
|
|
@ -88,7 +88,12 @@ public:
|
|||
static Parser create(ParsingParams const&, StringView input, StringView encoding = "utf-8"sv);
|
||||
|
||||
CSSStyleSheet* parse_as_css_stylesheet(Optional<URL::URL> location);
|
||||
ElementInlineCSSStyleDeclaration* parse_as_style_attribute(DOM::Element&);
|
||||
|
||||
struct PropertiesAndCustomProperties {
|
||||
Vector<StyleProperty> properties;
|
||||
HashMap<FlyString, StyleProperty> custom_properties;
|
||||
};
|
||||
PropertiesAndCustomProperties parse_as_style_attribute();
|
||||
CSSRule* parse_as_css_rule();
|
||||
Optional<StyleProperty> parse_as_supports_condition();
|
||||
|
||||
|
@ -452,11 +457,6 @@ private:
|
|||
|
||||
static bool has_ignored_vendor_prefix(StringView);
|
||||
|
||||
struct PropertiesAndCustomProperties {
|
||||
Vector<StyleProperty> properties;
|
||||
HashMap<FlyString, StyleProperty> custom_properties;
|
||||
};
|
||||
|
||||
PropertiesAndCustomProperties extract_properties(Vector<RuleOrListOfDeclarations> const&);
|
||||
void extract_property(Declaration const&, Parser::PropertiesAndCustomProperties&);
|
||||
|
||||
|
@ -510,7 +510,7 @@ private:
|
|||
namespace Web {
|
||||
|
||||
CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingParams const&, StringView, Optional<URL::URL> location = {});
|
||||
CSS::ElementInlineCSSStyleDeclaration* parse_css_style_attribute(CSS::Parser::ParsingParams const&, StringView, DOM::Element&);
|
||||
CSS::Parser::Parser::PropertiesAndCustomProperties parse_css_style_attribute(CSS::Parser::ParsingParams const&, StringView);
|
||||
RefPtr<CSS::CSSStyleValue> parse_css_value(CSS::Parser::ParsingParams const&, StringView, CSS::PropertyID property_id = CSS::PropertyID::Invalid);
|
||||
Optional<CSS::SelectorList> parse_selector(CSS::Parser::ParsingParams const&, StringView);
|
||||
Optional<CSS::SelectorList> parse_selector_for_nested_style_rule(CSS::Parser::ParsingParams const&, StringView);
|
||||
|
|
|
@ -3523,12 +3523,9 @@ void Element::attribute_changed(FlyString const& local_name, Optional<String> co
|
|||
// https://drafts.csswg.org/cssom/#ref-for-cssstyledeclaration-updating-flag
|
||||
if (m_inline_style && m_inline_style->is_updating())
|
||||
return;
|
||||
if (!m_inline_style) {
|
||||
m_inline_style = parse_css_style_attribute(CSS::Parser::ParsingParams(document()), *value, *this);
|
||||
} else {
|
||||
// NOTE: ElementInlineCSSStyleDeclaration::set_css_text should never throw an exception.
|
||||
m_inline_style->set_declarations_from_text(*value);
|
||||
}
|
||||
if (!m_inline_style)
|
||||
m_inline_style = CSS::ElementInlineCSSStyleDeclaration::create(*this, {}, {});
|
||||
m_inline_style->set_declarations_from_text(*value);
|
||||
set_needs_style_update(true);
|
||||
}
|
||||
} else if (local_name == HTML::AttributeNames::dir) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue