mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:27:35 +00:00
LibWeb: Make computed flex-grow and flex-shrink always available
These values are not allowed to be absent (auto/none/etc) so we don't need to use Optional<float> for them. This simplifies some things.
This commit is contained in:
parent
19eda59359
commit
07f15aa550
6 changed files with 32 additions and 40 deletions
|
@ -34,6 +34,8 @@ public:
|
|||
static CSS::Overflow overflow() { return CSS::Overflow::Visible; }
|
||||
static CSS::BoxSizing box_sizing() { return CSS::BoxSizing::ContentBox; }
|
||||
static CSS::PointerEvents pointer_events() { return CSS::PointerEvents::Auto; }
|
||||
static float flex_grow() { return 0.0f; }
|
||||
static float flex_shrink() { return 1.0f; }
|
||||
};
|
||||
|
||||
struct BorderData {
|
||||
|
@ -78,8 +80,8 @@ public:
|
|||
CSS::FlexDirection flex_direction() const { return m_noninherited.flex_direction; }
|
||||
CSS::FlexWrap flex_wrap() const { return m_noninherited.flex_wrap; }
|
||||
FlexBasisData const& flex_basis() const { return m_noninherited.flex_basis; }
|
||||
Optional<float> const& flex_grow_factor() const { return m_noninherited.flex_grow_factor; }
|
||||
Optional<float> const& flex_shrink_factor() const { return m_noninherited.flex_shrink_factor; }
|
||||
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; }
|
||||
CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; }
|
||||
|
@ -174,8 +176,9 @@ protected:
|
|||
CSS::FlexDirection flex_direction { InitialValues::flex_direction() };
|
||||
CSS::FlexWrap flex_wrap { InitialValues::flex_wrap() };
|
||||
CSS::FlexBasisData flex_basis {};
|
||||
Optional<float> flex_grow_factor;
|
||||
Optional<float> flex_shrink_factor;
|
||||
float flex_grow { InitialValues::flex_grow() };
|
||||
float flex_shrink { InitialValues::flex_shrink() };
|
||||
;
|
||||
CSS::AlignItems align_items { InitialValues::align_items() };
|
||||
CSS::JustifyContent justify_content { InitialValues::justify_content() };
|
||||
CSS::Overflow overflow_x { InitialValues::overflow() };
|
||||
|
@ -230,8 +233,8 @@ public:
|
|||
void set_flex_direction(CSS::FlexDirection value) { m_noninherited.flex_direction = value; }
|
||||
void set_flex_wrap(CSS::FlexWrap value) { m_noninherited.flex_wrap = value; }
|
||||
void set_flex_basis(FlexBasisData value) { m_noninherited.flex_basis = value; }
|
||||
void set_flex_grow_factor(Optional<float> value) { m_noninherited.flex_grow_factor = value; }
|
||||
void set_flex_shrink_factor(Optional<float> value) { m_noninherited.flex_shrink_factor = value; }
|
||||
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_justify_content(CSS::JustifyContent value) { m_noninherited.justify_content = value; }
|
||||
|
|
|
@ -497,18 +497,10 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
break;
|
||||
case CSS::PropertyID::FlexGrow: {
|
||||
auto maybe_grow_factor = layout_node.computed_values().flex_grow_factor();
|
||||
if (!maybe_grow_factor.has_value())
|
||||
return {};
|
||||
return NumericStyleValue::create_float(maybe_grow_factor.release_value());
|
||||
}
|
||||
case CSS::PropertyID::FlexShrink: {
|
||||
auto maybe_shrink_factor = layout_node.computed_values().flex_shrink_factor();
|
||||
if (!maybe_shrink_factor.has_value())
|
||||
return {};
|
||||
return NumericStyleValue::create_float(maybe_shrink_factor.release_value());
|
||||
}
|
||||
case CSS::PropertyID::FlexGrow:
|
||||
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())
|
||||
|
|
|
@ -194,25 +194,22 @@ Optional<CSS::FlexBasisData> StyleProperties::flex_basis() const
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<float> StyleProperties::flex_grow_factor() const
|
||||
float StyleProperties::flex_grow() const
|
||||
{
|
||||
auto value = property(CSS::PropertyID::FlexGrow);
|
||||
if (!value.has_value())
|
||||
return {};
|
||||
if (value.value()->has_number())
|
||||
return value.value()->to_number();
|
||||
return {};
|
||||
if (!value.has_value() || !value.value()->has_number())
|
||||
return 0;
|
||||
return value.value()->to_number();
|
||||
}
|
||||
|
||||
Optional<float> StyleProperties::flex_shrink_factor() const
|
||||
float StyleProperties::flex_shrink() const
|
||||
{
|
||||
auto value = property(CSS::PropertyID::FlexShrink);
|
||||
if (!value.has_value())
|
||||
return {};
|
||||
if (value.value()->has_number())
|
||||
return value.value()->to_number();
|
||||
return {};
|
||||
if (!value.has_value() || !value.value()->has_number())
|
||||
return 1;
|
||||
return value.value()->to_number();
|
||||
}
|
||||
|
||||
Optional<CSS::JustifyContent> StyleProperties::justify_content() const
|
||||
{
|
||||
auto value = property(CSS::PropertyID::JustifyContent);
|
||||
|
|
|
@ -56,8 +56,8 @@ public:
|
|||
Optional<CSS::FlexDirection> flex_direction() const;
|
||||
Optional<CSS::FlexWrap> flex_wrap() const;
|
||||
Optional<CSS::FlexBasisData> flex_basis() const;
|
||||
Optional<float> flex_grow_factor() const;
|
||||
Optional<float> flex_shrink_factor() const;
|
||||
float flex_grow() const;
|
||||
float flex_shrink() const;
|
||||
Optional<CSS::AlignItems> align_items() const;
|
||||
Optional<float> opacity() const;
|
||||
Optional<CSS::JustifyContent> justify_content() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue