1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:27:35 +00:00

LibWeb: Make computed opacity always available

No need to store opacity as Optional<float> as there's always a value
(and the default initial value is 1.)
This commit is contained in:
Andreas Kling 2021-10-19 15:27:40 +02:00
parent 07f15aa550
commit ff45eb7fb1
6 changed files with 14 additions and 20 deletions

View file

@ -36,6 +36,7 @@ public:
static CSS::PointerEvents pointer_events() { return CSS::PointerEvents::Auto; }
static float flex_grow() { return 0.0f; }
static float flex_shrink() { return 1.0f; }
static float opacity() { return 1.0f; }
};
struct BorderData {
@ -83,7 +84,7 @@ public:
float flex_grow() const { return m_noninherited.flex_grow; }
float flex_shrink() const { return m_noninherited.flex_shrink; }
CSS::AlignItems align_items() const { return m_noninherited.align_items; }
Optional<float> const& opacity() const { return m_noninherited.opacity; }
float opacity() const { return m_noninherited.opacity; }
CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; }
Optional<BoxShadowData> const& box_shadow() const { return m_noninherited.box_shadow; }
CSS::BoxSizing box_sizing() const { return m_noninherited.box_sizing; }
@ -183,7 +184,7 @@ protected:
CSS::JustifyContent justify_content { InitialValues::justify_content() };
CSS::Overflow overflow_x { InitialValues::overflow() };
CSS::Overflow overflow_y { InitialValues::overflow() };
Optional<float> opacity;
float opacity { InitialValues::opacity() };
Optional<BoxShadowData> box_shadow {};
Vector<CSS::Transformation> transformations {};
CSS::BoxSizing box_sizing { InitialValues::box_sizing() };
@ -236,7 +237,7 @@ public:
void set_flex_grow(float value) { m_noninherited.flex_grow = value; }
void set_flex_shrink(float value) { m_noninherited.flex_shrink = value; }
void set_align_items(CSS::AlignItems value) { m_noninherited.align_items = value; }
void set_opacity(Optional<float> value) { m_noninherited.opacity = value; }
void set_opacity(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); }
void set_transformations(Vector<CSS::Transformation> value) { m_noninherited.transformations = move(value); }

View file

@ -501,12 +501,8 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
return NumericStyleValue::create_float(layout_node.computed_values().flex_grow());
case CSS::PropertyID::FlexShrink:
return NumericStyleValue::create_float(layout_node.computed_values().flex_shrink());
case CSS::PropertyID::Opacity: {
auto maybe_opacity = layout_node.computed_values().opacity();
if (!maybe_opacity.has_value())
return {};
return NumericStyleValue::create_float(maybe_opacity.release_value());
}
case CSS::PropertyID::Opacity:
return NumericStyleValue::create_float(layout_node.computed_values().opacity());
case CSS::PropertyID::JustifyContent:
return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().justify_content()));
case CSS::PropertyID::BoxShadow: {

View file

@ -121,11 +121,11 @@ Optional<int> StyleProperties::z_index() const
return {};
}
Optional<float> StyleProperties::opacity() const
float StyleProperties::opacity() const
{
auto maybe_value = property(CSS::PropertyID::Opacity);
if (!maybe_value.has_value())
return {};
return 1.0f;
auto& value = maybe_value.value();
if (value->has_number())
@ -137,7 +137,7 @@ Optional<float> StyleProperties::opacity() const
return clamp(length.raw_value() / 100.0f, 0.0f, 1.0f);
}
return {};
return 1.0f;
}
Optional<CSS::FlexDirection> StyleProperties::flex_direction() const

View file

@ -59,7 +59,7 @@ public:
float flex_grow() const;
float flex_shrink() const;
Optional<CSS::AlignItems> align_items() const;
Optional<float> opacity() const;
float opacity() const;
Optional<CSS::JustifyContent> justify_content() const;
Optional<CSS::Overflow> overflow_x() const;
Optional<CSS::Overflow> overflow_y() const;