mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:47:35 +00:00
LibWeb: Use Optional instead of undefined-lengths for widths/heights
This commit is contained in:
parent
699b48ccc8
commit
5b2482a939
10 changed files with 126 additions and 92 deletions
|
@ -108,12 +108,12 @@ public:
|
|||
CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; }
|
||||
Vector<BoxShadowData> const& box_shadow() const { return m_noninherited.box_shadow; }
|
||||
CSS::BoxSizing box_sizing() const { return m_noninherited.box_sizing; }
|
||||
CSS::LengthPercentage const& width() const { return m_noninherited.width; }
|
||||
CSS::LengthPercentage const& min_width() const { return m_noninherited.min_width; }
|
||||
CSS::LengthPercentage const& max_width() const { return m_noninherited.max_width; }
|
||||
CSS::LengthPercentage const& height() const { return m_noninherited.height; }
|
||||
CSS::LengthPercentage const& min_height() const { return m_noninherited.min_height; }
|
||||
CSS::LengthPercentage const& max_height() const { return m_noninherited.max_height; }
|
||||
Optional<CSS::LengthPercentage> const& width() const { return m_noninherited.width; }
|
||||
Optional<CSS::LengthPercentage> const& min_width() const { return m_noninherited.min_width; }
|
||||
Optional<CSS::LengthPercentage> const& max_width() const { return m_noninherited.max_width; }
|
||||
Optional<CSS::LengthPercentage> const& height() const { return m_noninherited.height; }
|
||||
Optional<CSS::LengthPercentage> const& min_height() const { return m_noninherited.min_height; }
|
||||
Optional<CSS::LengthPercentage> const& max_height() const { return m_noninherited.max_height; }
|
||||
|
||||
const CSS::LengthBox& offset() const { return m_noninherited.offset; }
|
||||
const CSS::LengthBox& margin() const { return m_noninherited.margin; }
|
||||
|
@ -174,12 +174,12 @@ protected:
|
|||
CSS::TextDecorationLine text_decoration_line { InitialValues::text_decoration_line() };
|
||||
CSS::TextDecorationStyle text_decoration_style { InitialValues::text_decoration_style() };
|
||||
CSS::Position position { InitialValues::position() };
|
||||
CSS::LengthPercentage width { Length::make_auto() };
|
||||
CSS::LengthPercentage min_width { Length::make_auto() };
|
||||
CSS::LengthPercentage max_width { Length::make_auto() };
|
||||
CSS::LengthPercentage height { Length::make_auto() };
|
||||
CSS::LengthPercentage min_height { Length::make_auto() };
|
||||
CSS::LengthPercentage max_height { Length::make_auto() };
|
||||
Optional<CSS::LengthPercentage> width;
|
||||
Optional<CSS::LengthPercentage> min_width;
|
||||
Optional<CSS::LengthPercentage> max_width;
|
||||
Optional<CSS::LengthPercentage> height;
|
||||
Optional<CSS::LengthPercentage> min_height;
|
||||
Optional<CSS::LengthPercentage> max_height;
|
||||
CSS::LengthBox offset;
|
||||
CSS::LengthBox margin;
|
||||
CSS::LengthBox padding;
|
||||
|
|
|
@ -536,25 +536,25 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
|
|||
return StyleValueList::create(move(box_shadow), StyleValueList::Separator::Comma);
|
||||
}
|
||||
case CSS::PropertyID::Width:
|
||||
return style_value_for_length_percentage(layout_node.computed_values().width());
|
||||
return style_value_for_length_percentage(layout_node.computed_values().width().value_or(Length::make_auto()));
|
||||
case CSS::PropertyID::MinWidth:
|
||||
if (layout_node.computed_values().min_width().is_length() && layout_node.computed_values().min_width().length().is_undefined_or_auto())
|
||||
if (!layout_node.computed_values().min_width().has_value())
|
||||
return IdentifierStyleValue::create(CSS::ValueID::Auto);
|
||||
return style_value_for_length_percentage(layout_node.computed_values().min_width());
|
||||
return style_value_for_length_percentage(layout_node.computed_values().min_width().value());
|
||||
case CSS::PropertyID::MaxWidth:
|
||||
if (layout_node.computed_values().max_width().is_length() && layout_node.computed_values().max_width().length().is_undefined())
|
||||
if (!layout_node.computed_values().max_width().has_value())
|
||||
return IdentifierStyleValue::create(CSS::ValueID::None);
|
||||
return style_value_for_length_percentage(layout_node.computed_values().max_width());
|
||||
return style_value_for_length_percentage(layout_node.computed_values().max_width().value());
|
||||
case CSS::PropertyID::Height:
|
||||
return style_value_for_length_percentage(layout_node.computed_values().height());
|
||||
return style_value_for_length_percentage(layout_node.computed_values().height().value_or(Length::make_auto()));
|
||||
case CSS::PropertyID::MinHeight:
|
||||
if (layout_node.computed_values().min_height().is_length() && layout_node.computed_values().min_height().length().is_undefined_or_auto())
|
||||
if (!layout_node.computed_values().min_height().has_value())
|
||||
return IdentifierStyleValue::create(CSS::ValueID::Auto);
|
||||
return style_value_for_length_percentage(layout_node.computed_values().min_height());
|
||||
return style_value_for_length_percentage(layout_node.computed_values().min_height().value());
|
||||
case CSS::PropertyID::MaxHeight:
|
||||
if (layout_node.computed_values().max_height().is_length() && layout_node.computed_values().max_height().length().is_undefined())
|
||||
if (!layout_node.computed_values().max_height().has_value())
|
||||
return IdentifierStyleValue::create(CSS::ValueID::None);
|
||||
return style_value_for_length_percentage(layout_node.computed_values().max_height());
|
||||
return style_value_for_length_percentage(layout_node.computed_values().max_height().value());
|
||||
case CSS::PropertyID::Margin: {
|
||||
auto margin = layout_node.computed_values().margin();
|
||||
auto values = NonnullRefPtrVector<StyleValue> {};
|
||||
|
|
|
@ -64,10 +64,15 @@ Length StyleProperties::length_or_fallback(CSS::PropertyID id, Length const& fal
|
|||
}
|
||||
|
||||
LengthPercentage StyleProperties::length_percentage_or_fallback(CSS::PropertyID id, LengthPercentage const& fallback) const
|
||||
{
|
||||
return length_percentage(id).value_or(fallback);
|
||||
}
|
||||
|
||||
Optional<LengthPercentage> StyleProperties::length_percentage(CSS::PropertyID id) const
|
||||
{
|
||||
auto maybe_value = property(id);
|
||||
if (!maybe_value.has_value())
|
||||
return fallback;
|
||||
return {};
|
||||
auto& value = maybe_value.value();
|
||||
|
||||
if (value->is_calculated())
|
||||
|
@ -79,7 +84,7 @@ LengthPercentage StyleProperties::length_percentage_or_fallback(CSS::PropertyID
|
|||
if (value->has_length())
|
||||
return value->to_length();
|
||||
|
||||
return fallback;
|
||||
return {};
|
||||
}
|
||||
|
||||
LengthBox StyleProperties::length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id, const CSS::Length& default_value) const
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
|
||||
Length length_or_fallback(CSS::PropertyID, Length const& fallback) const;
|
||||
LengthPercentage length_percentage_or_fallback(CSS::PropertyID, LengthPercentage const& fallback) const;
|
||||
Optional<LengthPercentage> length_percentage(CSS::PropertyID) const;
|
||||
LengthBox length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id, const CSS::Length& default_value) const;
|
||||
Color color_or_fallback(CSS::PropertyID, Layout::NodeWithStyle const&, Color fallback) const;
|
||||
Optional<CSS::TextAlign> text_align() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue