summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorTobias Christiansen <tobi@tobyase.de>2021-07-23 21:22:31 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-24 22:16:48 +0200
commitf1bdaafcf6554ade403552da9e7ec3f832248d52 (patch)
treeeea7f1650860a3914178e7da8effa313bdbafffb /Userland/Libraries/LibWeb
parent36e6f559c5098918b83f421fb3228971fc2a227a (diff)
downloadserenity-f1bdaafcf6554ade403552da9e7ec3f832248d52.zip
LibWeb: Make box-shadow known throughout the CSS subsystem
This patch spreads box-shadows around: - The Values important to box-shadows are stored in a BoxShadowData struct - StyleProperties knows how to construct such a struct from a BoxShadowStyleValue and a Node knows how to ask for it - CalculatedValues contain BoxShadowData and expose them
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/CSS/ComputedValues.h10
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleProperties.cpp14
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleProperties.h1
-rw-r--r--Userland/Libraries/LibWeb/Layout/Node.cpp2
4 files changed, 27 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h
index a7da6dd395..24321e83b1 100644
--- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h
+++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h
@@ -45,6 +45,13 @@ struct FlexBasisData {
CSS::Length length {};
};
+struct BoxShadowData {
+ CSS::Length offset_x {};
+ CSS::Length offset_y {};
+ CSS::Length blur_radius {};
+ Color color {};
+};
+
class ComputedValues {
public:
CSS::Float float_() const { return m_noninherited.float_; }
@@ -64,6 +71,7 @@ public:
Optional<float> flex_shrink_factor() const { return m_noninherited.flex_shrink_factor; }
Optional<float> opacity() const { return m_noninherited.opacity; }
CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; }
+ Optional<BoxShadowData> box_shadow() const { return m_noninherited.box_shadow; }
const CSS::Length& width() const { return m_noninherited.width; }
const CSS::Length& min_width() const { return m_noninherited.min_width; }
const CSS::Length& max_width() const { return m_noninherited.max_width; }
@@ -148,6 +156,7 @@ protected:
CSS::Overflow overflow_x { InitialValues::overflow() };
CSS::Overflow overflow_y { InitialValues::overflow() };
Optional<float> opacity;
+ Optional<BoxShadowData> box_shadow {};
} m_noninherited;
};
@@ -197,6 +206,7 @@ public:
void set_flex_shrink_factor(Optional<float> value) { m_noninherited.flex_shrink_factor = value; }
void set_opacity(Optional<float> value) { m_noninherited.opacity = value; }
void set_justify_content(CSS::JustifyContent value) { m_noninherited.justify_content = value; }
+ void set_box_shadow(Optional<BoxShadowData> value) { m_noninherited.box_shadow = move(value); }
};
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
index 0adb41aad6..84ea18d5d7 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
@@ -764,4 +764,18 @@ Optional<CSS::Repeat> StyleProperties::background_repeat_y() const
return {};
}
}
+
+Optional<CSS::BoxShadowData> StyleProperties::box_shadow() const
+{
+ auto value_or_error = property(CSS::PropertyID::BoxShadow);
+ if (!value_or_error.has_value())
+ return {};
+
+ auto value = value_or_error.value();
+ if (!value->is_box_shadow())
+ return {};
+
+ auto box = verify_cast<CSS::BoxShadowStyleValue>(value.ptr());
+ return { { box->offset_x(), box->offset_y(), box->blur_radius(), box->color() } };
+}
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h
index df289849dd..40da2b77dc 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h
@@ -62,6 +62,7 @@ public:
Optional<CSS::Overflow> overflow_y() const;
Optional<CSS::Repeat> background_repeat_x() const;
Optional<CSS::Repeat> background_repeat_y() const;
+ Optional<CSS::BoxShadowData> box_shadow() const;
const Gfx::Font& font() const
{
diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp
index a9d40b2f72..b6069936ae 100644
--- a/Userland/Libraries/LibWeb/Layout/Node.cpp
+++ b/Userland/Libraries/LibWeb/Layout/Node.cpp
@@ -350,6 +350,8 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
computed_values.set_margin(specified_style.length_box(CSS::PropertyID::MarginLeft, CSS::PropertyID::MarginTop, CSS::PropertyID::MarginRight, CSS::PropertyID::MarginBottom, CSS::Length::make_px(0)));
computed_values.set_padding(specified_style.length_box(CSS::PropertyID::PaddingLeft, CSS::PropertyID::PaddingTop, CSS::PropertyID::PaddingRight, CSS::PropertyID::PaddingBottom, CSS::Length::make_px(0)));
+ computed_values.set_box_shadow(specified_style.box_shadow());
+
auto do_border_style = [&](CSS::BorderData& border, CSS::PropertyID width_property, CSS::PropertyID color_property, CSS::PropertyID style_property) {
border.color = specified_style.color_or_fallback(color_property, document(), Color::Transparent);
border.line_style = specified_style.line_style(style_property).value_or(CSS::LineStyle::None);