Truly independent web browser
LibWeb: Build no computed values for a view of no style
Andreas Kling71b6856afb63
diff --git a/Libraries/LibWeb/CSS/ComputedValues.cpp b/Libraries/LibWeb/CSS/ComputedValues.cppindex e80bafc7a2c..93699a97caa 100644--- a/Libraries/LibWeb/CSS/ComputedValues.cpp+++ b/Libraries/LibWeb/CSS/ComputedValues.cpp@@ -283,40 +283,40 @@ ComputedStyleRecordView::ComputedStyleRecordView(StyleEngineFFI::FfiStyleRecordVVERIFY(view.base_payloads);auto payloads = ReadonlySpan<void const*> { view.payloads, view.payload_count };auto base_payloads = ReadonlySpan<void const*> { view.base_payloads, view.payload_count };- m_values.borrow_style_record_payloads(payloads);+ m_values.emplace(ComputedValues::BorrowedStyleRecord::Yes);+ m_values->borrow_style_record_payloads(payloads);if (view.animation_overlay_identity != 0) {m_base_values.emplace(ComputedValues::BorrowedStyleRecord::Yes);m_base_values->borrow_style_record_payloads(base_payloads);- m_values.m_borrowed_base_values = &*m_base_values;+ m_values->m_borrowed_base_values = &*m_base_values;}- m_values.m_pseudo_element_styles = view.pseudo_element_styles;+ m_values->m_pseudo_element_styles = view.pseudo_element_styles;auto dependency_flags = static_cast<StyleRecordDependencyFlag>(view.dependency_flags);- m_values.m_depends_on_viewport_metrics = has_flag(dependency_flags, StyleRecordDependencyFlag::DependsOnViewportMetrics);- m_values.m_font_metrics_depend_on_viewport_metrics = has_flag(dependency_flags, StyleRecordDependencyFlag::FontMetricsDependOnViewportMetrics);- m_values.m_in_display_none_subtree = has_flag(dependency_flags, StyleRecordDependencyFlag::InDisplayNoneSubtree);- m_values.m_highlight_colors_authored = has_flag(dependency_flags, StyleRecordDependencyFlag::HighlightColorsAuthored);- m_values.m_highlight_color_is_current_color = has_flag(dependency_flags, StyleRecordDependencyFlag::HighlightColorIsCurrentColor);- m_values.m_computed_longhand_table = view.longhand_table;- if (m_values.m_computed_longhand_table)- m_values.refresh_computed_longhand_table_views();+ m_values->m_depends_on_viewport_metrics = has_flag(dependency_flags, StyleRecordDependencyFlag::DependsOnViewportMetrics);+ m_values->m_font_metrics_depend_on_viewport_metrics = has_flag(dependency_flags, StyleRecordDependencyFlag::FontMetricsDependOnViewportMetrics);+ m_values->m_in_display_none_subtree = has_flag(dependency_flags, StyleRecordDependencyFlag::InDisplayNoneSubtree);+ m_values->m_highlight_colors_authored = has_flag(dependency_flags, StyleRecordDependencyFlag::HighlightColorsAuthored);+ m_values->m_highlight_color_is_current_color = has_flag(dependency_flags, StyleRecordDependencyFlag::HighlightColorIsCurrentColor);+ m_values->m_computed_longhand_table = view.longhand_table;+ if (m_values->m_computed_longhand_table)+ m_values->refresh_computed_longhand_table_views();if (view.animated_overlay)- m_values.m_animated_properties = adopt_ref(*new AnimatedProperties(static_cast<ComputedValuesFFI::AnimatedOverlay const*>(view.animated_overlay)));+ m_values->m_animated_properties = adopt_ref(*new AnimatedProperties(static_cast<ComputedValuesFFI::AnimatedOverlay const*>(view.animated_overlay)));if (view.animation_overlay_identity != 0) {- m_base_values->m_property_important = m_values.m_property_important;- m_base_values->m_property_inherited = m_values.m_property_inherited;- m_base_values->m_pseudo_element_styles = m_values.m_pseudo_element_styles;- m_base_values->m_depends_on_viewport_metrics = m_values.m_depends_on_viewport_metrics;- m_base_values->m_font_metrics_depend_on_viewport_metrics = m_values.m_font_metrics_depend_on_viewport_metrics;- m_base_values->m_in_display_none_subtree = m_values.m_in_display_none_subtree;- m_base_values->m_highlight_colors_authored = m_values.m_highlight_colors_authored;- m_base_values->m_highlight_color_is_current_color = m_values.m_highlight_color_is_current_color;- m_base_values->m_inheritance_dependent_specified_values = m_values.m_inheritance_dependent_specified_values;- m_base_values->m_computed_longhand_table = m_values.m_computed_longhand_table;+ m_base_values->m_property_important = m_values->m_property_important;+ m_base_values->m_property_inherited = m_values->m_property_inherited;+ m_base_values->m_pseudo_element_styles = m_values->m_pseudo_element_styles;+ m_base_values->m_depends_on_viewport_metrics = m_values->m_depends_on_viewport_metrics;+ m_base_values->m_font_metrics_depend_on_viewport_metrics = m_values->m_font_metrics_depend_on_viewport_metrics;+ m_base_values->m_in_display_none_subtree = m_values->m_in_display_none_subtree;+ m_base_values->m_highlight_colors_authored = m_values->m_highlight_colors_authored;+ m_base_values->m_highlight_color_is_current_color = m_values->m_highlight_color_is_current_color;+ m_base_values->m_inheritance_dependent_specified_values = m_values->m_inheritance_dependent_specified_values;+ m_base_values->m_computed_longhand_table = m_values->m_computed_longhand_table;if (m_base_values->m_computed_longhand_table)m_base_values->refresh_computed_longhand_table_views();}- m_present = true;}ComputedStyleRecordView::~ComputedStyleRecordView()diff --git a/Libraries/LibWeb/CSS/ComputedValues.h b/Libraries/LibWeb/CSS/ComputedValues.hindex 592336865ea..5310a98cdcc 100644--- a/Libraries/LibWeb/CSS/ComputedValues.h+++ b/Libraries/LibWeb/CSS/ComputedValues.h@@ -1262,26 +1262,22 @@ public:ComputedStyleRecordView(StyleEngineFFI::FfiStyleRecordView const&, StyleComputer const&, StyleRecordID, bool owns_style_record_pin);~ComputedStyleRecordView();- explicit operator bool() const { return m_present; }+ explicit operator bool() const { return m_values.has_value(); }ComputedValues const* operator->() const{- if (!m_present)+ if (!m_values.has_value())return nullptr;- return &m_values;- }- ComputedValues const& operator*() const- {- VERIFY(m_present);- return m_values;+ return &*m_values;}+ ComputedValues const& operator*() const { return m_values.value(); }private:Optional<ComputedValues> m_base_values;- ComputedValues m_values { ComputedValues::BorrowedStyleRecord::Yes };+ // NB: Only a present view builds its values, so a view of no record costs nothing to make.+ Optional<ComputedValues> m_values;GC::Ptr<StyleComputer const> m_style_computer;StyleRecordID m_style_record_identity;bool m_owns_style_record_pin { false };- bool m_present { false };};class ComputedValues::Mutator final {