mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Support shorthands when setting style attribute
Better support for CSS shorthands when setting the style attribute. This improves some tests in WPT /css/css-align/default-alignment/*shorthand. When setting the style attribute in JS via element.style = '..' or the setAttribute method, shorthand properties were not expanded to longhand properties.
This commit is contained in:
parent
99c66f49fb
commit
2199fde5a9
Notes:
github-actions[bot]
2024-10-31 12:23:58 +00:00
Author: https://github.com/sazarkin 🔰
Commit: 2199fde5a9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1894
Reviewed-by: https://github.com/AtkinsSJ ✅
5 changed files with 130 additions and 1 deletions
|
@ -39,6 +39,7 @@
|
|||
#include <LibWeb/CSS/PropertyName.h>
|
||||
#include <LibWeb/CSS/Selector.h>
|
||||
#include <LibWeb/CSS/Sizing.h>
|
||||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
|
||||
|
@ -1187,9 +1188,28 @@ template Vector<Vector<ComponentValue>> Parser::parse_a_comma_separated_list_of_
|
|||
|
||||
ElementInlineCSSStyleDeclaration* Parser::parse_as_style_attribute(DOM::Element& element)
|
||||
{
|
||||
auto expand_shorthands = [&](Vector<StyleProperty>& properties) -> Vector<StyleProperty> {
|
||||
Vector<StyleProperty> expanded_properties;
|
||||
for (auto& property : properties) {
|
||||
if (property_is_shorthand(property.property_id)) {
|
||||
StyleComputer::for_each_property_expanding_shorthands(property.property_id, *property.value, StyleComputer::AllowUnresolved::Yes, [&](PropertyID longhand_property_id, CSSStyleValue const& longhand_value) {
|
||||
expanded_properties.append(CSS::StyleProperty {
|
||||
.important = property.important,
|
||||
.property_id = longhand_property_id,
|
||||
.value = longhand_value,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
expanded_properties.append(property);
|
||||
}
|
||||
}
|
||||
return expanded_properties;
|
||||
};
|
||||
|
||||
auto declarations_and_at_rules = parse_a_blocks_contents(m_token_stream);
|
||||
auto [properties, custom_properties] = extract_properties(declarations_and_at_rules);
|
||||
return ElementInlineCSSStyleDeclaration::create(element, move(properties), move(custom_properties));
|
||||
auto expanded_properties = expand_shorthands(properties);
|
||||
return ElementInlineCSSStyleDeclaration::create(element, move(expanded_properties), move(custom_properties));
|
||||
}
|
||||
|
||||
Optional<URL::URL> Parser::parse_url_function(TokenStream<ComponentValue>& tokens)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue