mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-04 08:36:12 +00:00
LibWeb: Remove reference counting for CSS::StyleProperties
`AK::CopyOnWrite` already does reference counting, so there is no need to do it again.
This commit is contained in:
parent
e636f3976d
commit
07cd7d479f
Notes:
github-actions[bot]
2024-10-27 12:27:19 +00:00
Author: https://github.com/yyny
Commit: 07cd7d479f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1980
125 changed files with 207 additions and 216 deletions
|
@ -385,16 +385,16 @@ Vector<String> Element::get_attribute_names() const
|
|||
return names;
|
||||
}
|
||||
|
||||
JS::GCPtr<Layout::Node> Element::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
|
||||
JS::GCPtr<Layout::Node> Element::create_layout_node(CSS::StyleProperties style)
|
||||
{
|
||||
if (local_name() == "noscript" && document().is_scripting_enabled())
|
||||
return nullptr;
|
||||
|
||||
auto display = style->display();
|
||||
auto display = style.display();
|
||||
return create_layout_node_for_display_type(document(), display, move(style), this);
|
||||
}
|
||||
|
||||
JS::GCPtr<Layout::NodeWithStyle> Element::create_layout_node_for_display_type(DOM::Document& document, CSS::Display const& display, NonnullRefPtr<CSS::StyleProperties> style, Element* element)
|
||||
JS::GCPtr<Layout::NodeWithStyle> Element::create_layout_node_for_display_type(DOM::Document& document, CSS::Display const& display, CSS::StyleProperties style, Element* element)
|
||||
{
|
||||
if (display.is_table_inside() || display.is_table_row_group() || display.is_table_header_group() || display.is_table_footer_group() || display.is_table_row())
|
||||
return document.heap().allocate_without_realm<Layout::Box>(document, element, move(style));
|
||||
|
@ -540,14 +540,14 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_style()
|
|||
// Tables must not inherit -libweb-* values for text-align.
|
||||
// FIXME: Find the spec for this.
|
||||
if (is<HTML::HTMLTableElement>(*this)) {
|
||||
auto text_align = new_computed_css_values->text_align();
|
||||
auto text_align = new_computed_css_values.text_align();
|
||||
if (text_align.has_value() && (text_align.value() == CSS::TextAlign::LibwebLeft || text_align.value() == CSS::TextAlign::LibwebCenter || text_align.value() == CSS::TextAlign::LibwebRight))
|
||||
new_computed_css_values->set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Start));
|
||||
new_computed_css_values.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Start));
|
||||
}
|
||||
|
||||
CSS::RequiredInvalidationAfterStyleChange invalidation;
|
||||
if (m_computed_css_values)
|
||||
invalidation = compute_required_invalidation(*m_computed_css_values, *new_computed_css_values);
|
||||
if (m_computed_css_values.has_value())
|
||||
invalidation = compute_required_invalidation(*m_computed_css_values, new_computed_css_values);
|
||||
else
|
||||
invalidation = CSS::RequiredInvalidationAfterStyleChange::full();
|
||||
|
||||
|
@ -562,9 +562,9 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_style()
|
|||
auto new_pseudo_element_style = style_computer.compute_pseudo_element_style_if_needed(*this, pseudo_element);
|
||||
|
||||
// TODO: Can we be smarter about invalidation?
|
||||
if (pseudo_element_style && new_pseudo_element_style) {
|
||||
if (pseudo_element_style.has_value() && new_pseudo_element_style.has_value()) {
|
||||
invalidation |= compute_required_invalidation(*pseudo_element_style, *new_pseudo_element_style);
|
||||
} else if (pseudo_element_style || new_pseudo_element_style) {
|
||||
} else if (pseudo_element_style.has_value() || new_pseudo_element_style.has_value()) {
|
||||
invalidation = CSS::RequiredInvalidationAfterStyleChange::full();
|
||||
}
|
||||
|
||||
|
@ -595,7 +595,7 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_style()
|
|||
continue;
|
||||
|
||||
auto pseudo_element_style = pseudo_element_computed_css_values(pseudo_element_type);
|
||||
if (!pseudo_element_style)
|
||||
if (!pseudo_element_style.has_value())
|
||||
continue;
|
||||
|
||||
if (auto* node_with_style = dynamic_cast<Layout::NodeWithStyle*>(pseudo_element->layout_node.ptr())) {
|
||||
|
@ -609,17 +609,17 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_style()
|
|||
return invalidation;
|
||||
}
|
||||
|
||||
NonnullRefPtr<CSS::StyleProperties> Element::resolved_css_values(Optional<CSS::Selector::PseudoElement::Type> type)
|
||||
CSS::StyleProperties Element::resolved_css_values(Optional<CSS::Selector::PseudoElement::Type> type)
|
||||
{
|
||||
auto element_computed_style = CSS::ResolvedCSSStyleDeclaration::create(*this, type);
|
||||
auto properties = CSS::StyleProperties::create();
|
||||
CSS::StyleProperties properties = {};
|
||||
|
||||
for (auto i = to_underlying(CSS::first_property_id); i <= to_underlying(CSS::last_property_id); ++i) {
|
||||
auto property_id = (CSS::PropertyID)i;
|
||||
auto maybe_value = element_computed_style->property(property_id);
|
||||
if (!maybe_value.has_value())
|
||||
continue;
|
||||
properties->set_property(property_id, maybe_value.release_value().value);
|
||||
properties.set_property(property_id, maybe_value.release_value().value);
|
||||
}
|
||||
|
||||
return properties;
|
||||
|
@ -627,7 +627,7 @@ NonnullRefPtr<CSS::StyleProperties> Element::resolved_css_values(Optional<CSS::S
|
|||
|
||||
void Element::reset_animated_css_properties()
|
||||
{
|
||||
if (!m_computed_css_values)
|
||||
if (!m_computed_css_values.has_value())
|
||||
return;
|
||||
m_computed_css_values->reset_animated_properties();
|
||||
}
|
||||
|
@ -2273,25 +2273,25 @@ size_t Element::attribute_list_size() const
|
|||
return m_attributes->length();
|
||||
}
|
||||
|
||||
void Element::set_computed_css_values(RefPtr<CSS::StyleProperties> style)
|
||||
void Element::set_computed_css_values(Optional<CSS::StyleProperties> style)
|
||||
{
|
||||
m_computed_css_values = move(style);
|
||||
computed_css_values_changed();
|
||||
}
|
||||
|
||||
void Element::set_pseudo_element_computed_css_values(CSS::Selector::PseudoElement::Type pseudo_element, RefPtr<CSS::StyleProperties> style)
|
||||
void Element::set_pseudo_element_computed_css_values(CSS::Selector::PseudoElement::Type pseudo_element, Optional<CSS::StyleProperties> style)
|
||||
{
|
||||
if (!m_pseudo_element_data && !style)
|
||||
if (!m_pseudo_element_data && !style.has_value())
|
||||
return;
|
||||
ensure_pseudo_element(pseudo_element).computed_css_values = move(style);
|
||||
}
|
||||
|
||||
RefPtr<CSS::StyleProperties> Element::pseudo_element_computed_css_values(CSS::Selector::PseudoElement::Type type)
|
||||
Optional<CSS::StyleProperties&> Element::pseudo_element_computed_css_values(CSS::Selector::PseudoElement::Type type)
|
||||
{
|
||||
auto pseudo_element = get_pseudo_element(type);
|
||||
if (pseudo_element.has_value())
|
||||
return pseudo_element->computed_css_values;
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<Element::PseudoElement&> Element::get_pseudo_element(CSS::Selector::PseudoElement::Type type) const
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Optional.h>
|
||||
#include <LibWeb/ARIA/ARIAMixin.h>
|
||||
#include <LibWeb/Animations/Animatable.h>
|
||||
#include <LibWeb/Bindings/ElementPrototype.h>
|
||||
|
@ -14,6 +15,7 @@
|
|||
#include <LibWeb/CSS/CountersSet.h>
|
||||
#include <LibWeb/CSS/Selector.h>
|
||||
#include <LibWeb/CSS/StyleInvalidation.h>
|
||||
#include <LibWeb/CSS/StyleProperties.h>
|
||||
#include <LibWeb/CSS/StyleProperty.h>
|
||||
#include <LibWeb/DOM/ChildNode.h>
|
||||
#include <LibWeb/DOM/NonDocumentTypeChildNode.h>
|
||||
|
@ -183,13 +185,13 @@ public:
|
|||
JS::GCPtr<Layout::NodeWithStyle> layout_node();
|
||||
JS::GCPtr<Layout::NodeWithStyle const> layout_node() const;
|
||||
|
||||
CSS::StyleProperties* computed_css_values() { return m_computed_css_values.ptr(); }
|
||||
CSS::StyleProperties const* computed_css_values() const { return m_computed_css_values.ptr(); }
|
||||
void set_computed_css_values(RefPtr<CSS::StyleProperties>);
|
||||
NonnullRefPtr<CSS::StyleProperties> resolved_css_values(Optional<CSS::Selector::PseudoElement::Type> = {});
|
||||
Optional<CSS::StyleProperties>& computed_css_values() { return m_computed_css_values; }
|
||||
Optional<CSS::StyleProperties> const& computed_css_values() const { return m_computed_css_values; }
|
||||
void set_computed_css_values(Optional<CSS::StyleProperties>);
|
||||
CSS::StyleProperties resolved_css_values(Optional<CSS::Selector::PseudoElement::Type> = {});
|
||||
|
||||
void set_pseudo_element_computed_css_values(CSS::Selector::PseudoElement::Type, RefPtr<CSS::StyleProperties>);
|
||||
RefPtr<CSS::StyleProperties> pseudo_element_computed_css_values(CSS::Selector::PseudoElement::Type);
|
||||
void set_pseudo_element_computed_css_values(CSS::Selector::PseudoElement::Type, Optional<CSS::StyleProperties>);
|
||||
Optional<CSS::StyleProperties&> pseudo_element_computed_css_values(CSS::Selector::PseudoElement::Type);
|
||||
|
||||
void reset_animated_css_properties();
|
||||
|
||||
|
@ -235,13 +237,13 @@ public:
|
|||
JS::NonnullGCPtr<Geometry::DOMRect> get_bounding_client_rect() const;
|
||||
JS::NonnullGCPtr<Geometry::DOMRectList> get_client_rects() const;
|
||||
|
||||
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>);
|
||||
virtual JS::GCPtr<Layout::Node> create_layout_node(CSS::StyleProperties);
|
||||
virtual void adjust_computed_style(CSS::StyleProperties&) { }
|
||||
|
||||
virtual void did_receive_focus() { }
|
||||
virtual void did_lose_focus() { }
|
||||
|
||||
static JS::GCPtr<Layout::NodeWithStyle> create_layout_node_for_display_type(DOM::Document&, CSS::Display const&, NonnullRefPtr<CSS::StyleProperties>, Element*);
|
||||
static JS::GCPtr<Layout::NodeWithStyle> create_layout_node_for_display_type(DOM::Document&, CSS::Display const&, CSS::StyleProperties, Element*);
|
||||
|
||||
void set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector::PseudoElement::Type, JS::GCPtr<Layout::NodeWithStyle>);
|
||||
JS::GCPtr<Layout::NodeWithStyle> get_pseudo_element_node(CSS::Selector::PseudoElement::Type) const;
|
||||
|
@ -456,12 +458,12 @@ private:
|
|||
JS::GCPtr<DOMTokenList> m_class_list;
|
||||
JS::GCPtr<ShadowRoot> m_shadow_root;
|
||||
|
||||
RefPtr<CSS::StyleProperties> m_computed_css_values;
|
||||
Optional<CSS::StyleProperties> m_computed_css_values;
|
||||
HashMap<FlyString, CSS::StyleProperty> m_custom_properties;
|
||||
|
||||
struct PseudoElement {
|
||||
JS::GCPtr<Layout::NodeWithStyle> layout_node;
|
||||
RefPtr<CSS::StyleProperties> computed_css_values;
|
||||
Optional<CSS::StyleProperties> computed_css_values;
|
||||
HashMap<FlyString, CSS::StyleProperty> custom_properties;
|
||||
};
|
||||
// TODO: CSS::Selector::PseudoElement::Type includes a lot of pseudo-elements that exist in shadow trees,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue