From 4d42885327cd70c146a8f47da4396348eb98a415 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 13 Apr 2022 19:33:56 +0100 Subject: [PATCH] LibWeb: Return Optional from StyleProperties::box_sizing() This function was written as if it returned `Optional` but actually returned a plain `CSS::BoxSizing`, meaning if the property was not set or was invalid, it would return whichever enum value was first. This wasn't visible because we don't yet pay any attention to the `box-sizing` property. --- Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 2 +- Userland/Libraries/LibWeb/CSS/StyleProperties.h | 2 +- Userland/Libraries/LibWeb/Layout/Node.cpp | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 868d571417..3ce0aee612 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -961,7 +961,7 @@ Vector StyleProperties::text_shadow() const return shadow(PropertyID::TextShadow); } -CSS::BoxSizing StyleProperties::box_sizing() const +Optional StyleProperties::box_sizing() const { auto value = property(CSS::PropertyID::BoxSizing); if (!value.has_value()) diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index a2676e142e..1a55552440 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -74,7 +74,7 @@ public: Optional overflow_x() const; Optional overflow_y() const; Vector box_shadow() const; - CSS::BoxSizing box_sizing() const; + Optional box_sizing() const; Optional pointer_events() const; Variant vertical_align() const; Optional font_variant() const; diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 81ecad005b..3ce80add85 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -363,7 +363,8 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) } computed_values.set_background_color(computed_style.color_or_fallback(CSS::PropertyID::BackgroundColor, *this, CSS::InitialValues::background_color())); - computed_values.set_box_sizing(computed_style.box_sizing()); + if (auto box_sizing = computed_style.box_sizing(); box_sizing.has_value()) + computed_values.set_box_sizing(box_sizing.release_value()); if (auto maybe_font_variant = computed_style.font_variant(); maybe_font_variant.has_value()) computed_values.set_font_variant(maybe_font_variant.release_value());