mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:18:12 +00:00
LibWeb: Move use pseudo element styles from TreeBuilder to StyleComputer
The styling of elements using the `use_pseudo_element()` was only applied on layout. When an element style was recomputed later that styling was not overruled with the pseudo element selector styles. This moves the styling override from `TreeBuilder.cpp` to `StyleComputer.cpp`. Now the styles are always correctly applied. I also removed the method `property_id_by_index()` because it was not needed anymore. Als some calls to `invalidate_layout()` in the Meter, Progress and Select elements where not needed anymore because the style values are update on the changing of the style attribute. This fixes issue #22278.
This commit is contained in:
parent
7578620f25
commit
a05fd28b7b
11 changed files with 44 additions and 49 deletions
|
@ -313,32 +313,10 @@ ErrorOr<void> TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::
|
|||
|
||||
if (is<DOM::Element>(dom_node)) {
|
||||
auto& element = static_cast<DOM::Element&>(dom_node);
|
||||
|
||||
// Special path for elements that use pseudo element as style selector.
|
||||
if (element.use_pseudo_element().has_value()) {
|
||||
// Get base psuedo element selector style properties
|
||||
auto& parent_element = verify_cast<HTML::HTMLElement>(*element.root().parent_or_shadow_host());
|
||||
style = TRY(style_computer.compute_style(parent_element, *element.use_pseudo_element()));
|
||||
|
||||
// Merge back inline styles
|
||||
auto const* inline_style = element.inline_style();
|
||||
if (inline_style) {
|
||||
auto const& computed_style = element.computed_css_values();
|
||||
for (size_t i = 0; i < inline_style->length(); i++) {
|
||||
auto property_id = inline_style->property_id_by_index(i);
|
||||
if (auto property = computed_style->maybe_null_property(property_id); property)
|
||||
style->set_property(property_id, *property);
|
||||
}
|
||||
}
|
||||
display = style->display();
|
||||
}
|
||||
// Common path: this is a regular DOM element. Style should be present already, thanks to Document::update_style().
|
||||
else {
|
||||
element.clear_pseudo_element_nodes({});
|
||||
VERIFY(!element.needs_style_update());
|
||||
style = element.computed_css_values();
|
||||
display = style->display();
|
||||
}
|
||||
element.clear_pseudo_element_nodes({});
|
||||
VERIFY(!element.needs_style_update());
|
||||
style = element.computed_css_values();
|
||||
display = style->display();
|
||||
if (display.is_none())
|
||||
return {};
|
||||
layout_node = element.create_layout_node(*style);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue