diff --git a/Libraries/LibWeb/Animations/KeyframeEffect.cpp b/Libraries/LibWeb/Animations/KeyframeEffect.cpp index c50d827c68c..a841629c162 100644 --- a/Libraries/LibWeb/Animations/KeyframeEffect.cpp +++ b/Libraries/LibWeb/Animations/KeyframeEffect.cpp @@ -946,27 +946,17 @@ void KeyframeEffect::update_computed_properties() return; } - GC::Ptr style = {}; - if (!pseudo_element_type().has_value()) - style = target->computed_properties(); - else - style = target->pseudo_element_computed_properties(pseudo_element_type().value()); - - if (!style) + auto computed_properties = target->computed_properties(pseudo_element_type()); + if (!computed_properties) return; - auto animated_properties_before_update = style->animated_property_values(); - if (!pseudo_element_type().has_value()) { - if (auto computed_properties = target->computed_properties()) - computed_properties->reset_animated_properties({}); - } else if (auto computed_properties = target->pseudo_element_computed_properties(pseudo_element_type().value())) { - computed_properties->reset_animated_properties({}); - } + auto animated_properties_before_update = computed_properties->animated_property_values(); + computed_properties->reset_animated_properties({}); auto& document = target->document(); - document.style_computer().collect_animation_into(*target, pseudo_element_type(), *this, *style, CSS::StyleComputer::AnimationRefresh::Yes); + document.style_computer().collect_animation_into(*target, pseudo_element_type(), *this, *computed_properties, CSS::StyleComputer::AnimationRefresh::Yes); - auto invalidation = compute_required_invalidation(animated_properties_before_update, style->animated_property_values()); + auto invalidation = compute_required_invalidation(animated_properties_before_update, computed_properties->animated_property_values()); if (invalidation.is_none()) return; @@ -982,11 +972,11 @@ void KeyframeEffect::update_computed_properties() if (!pseudo_element_type().has_value()) { if (target->layout_node()) - target->layout_node()->apply_style(*style); + target->layout_node()->apply_style(*computed_properties); } else { auto pseudo_element_node = target->get_pseudo_element_node(pseudo_element_type().value()); if (auto* node_with_style = dynamic_cast(pseudo_element_node.ptr())) { - node_with_style->apply_style(*style); + node_with_style->apply_style(*computed_properties); } } diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp index 52861189765..b49d88c6008 100644 --- a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp @@ -518,19 +518,11 @@ RefPtr CSSStyleProperties::style_value_for_computed_propert }; auto get_computed_value = [&element, pseudo_element](PropertyID property_id) -> auto const& { - if (pseudo_element.has_value()) - return element.pseudo_element_computed_properties(pseudo_element.value())->property(property_id); - return element.computed_properties()->property(property_id); + return element.computed_properties(pseudo_element)->property(property_id); }; if (property_is_logical_alias(property_id)) { - GC::Ptr computed_properties; - - if (pseudo_element.has_value()) - computed_properties = element.pseudo_element_computed_properties(pseudo_element.value()); - else - computed_properties = element.computed_properties(); - + auto computed_properties = element.computed_properties(pseudo_element); return style_value_for_computed_property( layout_node, map_logical_alias_to_physical_property(property_id, LogicalAliasMappingContext { computed_properties->writing_mode(), computed_properties->direction() })); diff --git a/Libraries/LibWeb/DOM/AbstractElement.cpp b/Libraries/LibWeb/DOM/AbstractElement.cpp index d1c2c44b7c4..80e8fb886c5 100644 --- a/Libraries/LibWeb/DOM/AbstractElement.cpp +++ b/Libraries/LibWeb/DOM/AbstractElement.cpp @@ -75,9 +75,7 @@ bool AbstractElement::is_before(AbstractElement const& other) const GC::Ptr AbstractElement::computed_properties() const { - if (m_pseudo_element.has_value()) - return m_element->pseudo_element_computed_properties(*m_pseudo_element); - return m_element->computed_properties(); + return m_element->computed_properties(m_pseudo_element); } HashMap const& AbstractElement::custom_properties() const diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index b3b90c20038..c375df3be16 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -714,7 +714,7 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_style() auto old_display_is_none = m_computed_properties ? m_computed_properties->display().is_none() : true; auto new_display_is_none = new_computed_properties->display().is_none(); - set_computed_properties(move(new_computed_properties)); + set_computed_properties({}, move(new_computed_properties)); if (old_display_is_none != new_display_is_none) { for_each_shadow_including_inclusive_descendant([&](auto& node) { @@ -730,7 +730,7 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_style() auto recompute_pseudo_element_style = [&](CSS::PseudoElement pseudo_element) { style_computer.push_ancestor(*this); - auto pseudo_element_style = pseudo_element_computed_properties(pseudo_element); + auto pseudo_element_style = computed_properties(pseudo_element); auto new_pseudo_element_style = style_computer.compute_pseudo_element_style_if_needed(*this, pseudo_element); // TODO: Can we be smarter about invalidation? @@ -740,7 +740,7 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_style() invalidation = CSS::RequiredInvalidationAfterStyleChange::full(); } - set_pseudo_element_computed_properties(pseudo_element, move(new_pseudo_element_style)); + set_computed_properties(pseudo_element, move(new_pseudo_element_style)); style_computer.pop_ancestor(*this); }; @@ -770,7 +770,7 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_style() if (!pseudo_element.has_value() || !pseudo_element->layout_node()) continue; - auto pseudo_element_style = pseudo_element_computed_properties(pseudo_element_type); + auto pseudo_element_style = computed_properties(pseudo_element_type); if (!pseudo_element_style) continue; @@ -2970,31 +2970,38 @@ void Element::set_cascaded_properties(Optional pseudo_elemen } } -void Element::set_computed_properties(GC::Ptr style) +GC::Ptr Element::computed_properties(Optional pseudo_element_type) { + if (pseudo_element_type.has_value()) { + if (auto pseudo_element = get_pseudo_element(*pseudo_element_type); pseudo_element.has_value()) + return pseudo_element->computed_properties(); + return {}; + } + return m_computed_properties; +} + +GC::Ptr Element::computed_properties(Optional pseudo_element_type) const +{ + if (pseudo_element_type.has_value()) { + if (auto pseudo_element = get_pseudo_element(*pseudo_element_type); pseudo_element.has_value()) + return pseudo_element->computed_properties(); + return {}; + } + return m_computed_properties; +} + +void Element::set_computed_properties(Optional pseudo_element_type, GC::Ptr style) +{ + if (pseudo_element_type.has_value()) { + if (!CSS::Selector::PseudoElementSelector::is_known_pseudo_element_type(*pseudo_element_type)) + return; + ensure_pseudo_element(*pseudo_element_type).set_computed_properties(style); + return; + } m_computed_properties = style; computed_properties_changed(); } -void Element::set_pseudo_element_computed_properties(CSS::PseudoElement pseudo_element, GC::Ptr style) -{ - if (!m_pseudo_element_data && !style) - return; - - if (!CSS::Selector::PseudoElementSelector::is_known_pseudo_element_type(pseudo_element)) - return; - - ensure_pseudo_element(pseudo_element).set_computed_properties(style); -} - -GC::Ptr Element::pseudo_element_computed_properties(CSS::PseudoElement type) -{ - auto pseudo_element = get_pseudo_element(type); - if (pseudo_element.has_value()) - return pseudo_element->computed_properties(); - return {}; -} - Optional Element::get_pseudo_element(CSS::PseudoElement type) const { if (!m_pseudo_element_data) diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h index 4cda69ed442..bbf446f768f 100644 --- a/Libraries/LibWeb/DOM/Element.h +++ b/Libraries/LibWeb/DOM/Element.h @@ -209,17 +209,14 @@ public: GC::Ptr layout_node(); GC::Ptr layout_node() const; - GC::Ptr computed_properties() { return m_computed_properties; } - GC::Ptr computed_properties() const { return m_computed_properties; } - void set_computed_properties(GC::Ptr); + GC::Ptr computed_properties(Optional = {}); + GC::Ptr computed_properties(Optional = {}) const; + void set_computed_properties(Optional, GC::Ptr); GC::Ref resolved_css_values(Optional = {}); [[nodiscard]] GC::Ptr cascaded_properties(Optional) const; void set_cascaded_properties(Optional, GC::Ptr); - void set_pseudo_element_computed_properties(CSS::PseudoElement, GC::Ptr); - GC::Ptr pseudo_element_computed_properties(CSS::PseudoElement); - Optional get_pseudo_element(CSS::PseudoElement) const; GC::Ptr inline_style() { return m_inline_style; } diff --git a/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Libraries/LibWeb/Layout/TreeBuilder.cpp index f1bbe667a77..82041dfc443 100644 --- a/Libraries/LibWeb/Layout/TreeBuilder.cpp +++ b/Libraries/LibWeb/Layout/TreeBuilder.cpp @@ -187,7 +187,7 @@ void TreeBuilder::create_pseudo_element_if_needed(DOM::Element& element, CSS::Ps { auto& document = element.document(); - auto pseudo_element_style = element.pseudo_element_computed_properties(pseudo_element); + auto pseudo_element_style = element.computed_properties(pseudo_element); if (!pseudo_element_style) return; @@ -726,7 +726,7 @@ void TreeBuilder::update_layout_tree_after_children(DOM::Node& dom_node, GC::Ref auto marker_style = style_computer.compute_style(element, CSS::PseudoElement::Marker); auto list_item_marker = document.heap().allocate(document, layout_node->computed_values().list_style_type(), layout_node->computed_values().list_style_position(), element, marker_style); static_cast(*layout_node).set_marker(list_item_marker); - element.set_pseudo_element_computed_properties(CSS::PseudoElement::Marker, marker_style); + element.set_computed_properties(CSS::PseudoElement::Marker, marker_style); element.set_pseudo_element_node({}, CSS::PseudoElement::Marker, list_item_marker); layout_node->prepend_child(*list_item_marker); DOM::AbstractElement marker_reference { element, CSS::PseudoElement::Marker }; diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp index d88d5f6f998..5cadb9dd767 100644 --- a/Services/WebContent/ConnectionFromClient.cpp +++ b/Services/WebContent/ConnectionFromClient.cpp @@ -461,13 +461,7 @@ void ConnectionFromClient::inspect_dom_node(u64 page_id, WebView::DOMNodePropert auto& element = as(*node); node->document().set_inspected_node(node); - GC::Ptr properties; - if (pseudo_element.has_value()) { - if (auto pseudo_element_node = element.get_pseudo_element_node(*pseudo_element)) - properties = element.pseudo_element_computed_properties(*pseudo_element); - } else { - properties = element.computed_properties(); - } + auto properties = element.computed_properties(pseudo_element); if (!properties) { async_did_inspect_dom_node(page_id, { property_type, {} });