mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:57:35 +00:00
LibWeb: Remove StyleValue::has/to_integer()
Only NumericStyleValue holds integers. I'm not sure our current distinction between NumericStyleValue holding an integer or non-integer is useful given it always returns a float. :thonk:
This commit is contained in:
parent
4ecf0b7768
commit
5cbf6eb930
5 changed files with 9 additions and 11 deletions
|
@ -226,10 +226,10 @@ Optional<int> StyleProperties::z_index() const
|
|||
auto value = property(CSS::PropertyID::ZIndex);
|
||||
if (value->has_auto())
|
||||
return {};
|
||||
if (value->has_integer()) {
|
||||
if (value->is_numeric() && value->as_numeric().has_integer()) {
|
||||
// Clamp z-index to the range of a signed 32-bit integer for consistency with other engines.
|
||||
// NOTE: Casting between 32-bit float and 32-bit integer is finicky here, since INT32_MAX is not representable as a 32-bit float!
|
||||
auto integer = value->to_integer();
|
||||
auto integer = value->as_numeric().integer();
|
||||
if (integer >= static_cast<float>(NumericLimits<int>::max()))
|
||||
return NumericLimits<int>::max();
|
||||
if (integer <= static_cast<float>(NumericLimits<int>::min()))
|
||||
|
@ -344,9 +344,9 @@ float StyleProperties::flex_shrink() const
|
|||
int StyleProperties::order() const
|
||||
{
|
||||
auto value = property(CSS::PropertyID::Order);
|
||||
if (!value->has_integer())
|
||||
if (!value->is_numeric() || !value->as_numeric().has_integer())
|
||||
return 0;
|
||||
return value->to_integer();
|
||||
return value->as_numeric().integer();
|
||||
}
|
||||
|
||||
Optional<CSS::ImageRendering> StyleProperties::image_rendering() const
|
||||
|
|
|
@ -395,8 +395,8 @@ int StyleValue::to_font_weight() const
|
|||
return Gfx::FontWeight::Regular;
|
||||
}
|
||||
}
|
||||
if (has_integer()) {
|
||||
return to_integer();
|
||||
if (is_numeric() && as_numeric().has_integer()) {
|
||||
return as_numeric().integer();
|
||||
}
|
||||
if (is_calculated()) {
|
||||
auto maybe_weight = const_cast<CalculatedStyleValue&>(as_calculated()).resolve_integer();
|
||||
|
|
|
@ -294,14 +294,12 @@ public:
|
|||
bool has_auto() const;
|
||||
virtual bool has_color() const { return false; }
|
||||
virtual bool has_length() const { return false; }
|
||||
virtual bool has_integer() const { return false; }
|
||||
|
||||
virtual ErrorOr<ValueComparingNonnullRefPtr<StyleValue const>> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const;
|
||||
|
||||
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const { return {}; }
|
||||
ValueID to_identifier() const;
|
||||
virtual Length to_length() const { VERIFY_NOT_REACHED(); }
|
||||
virtual float to_integer() const { return 0; }
|
||||
virtual ErrorOr<String> to_string() const = 0;
|
||||
|
||||
[[nodiscard]] int to_font_weight() const;
|
||||
|
|
|
@ -35,8 +35,8 @@ public:
|
|||
[](i64 value) { return (float)value; });
|
||||
}
|
||||
|
||||
virtual bool has_integer() const override { return m_value.has<i64>(); }
|
||||
virtual float to_integer() const override { return m_value.get<i64>(); }
|
||||
bool has_integer() const { return m_value.has<i64>(); }
|
||||
float integer() const { return m_value.get<i64>(); }
|
||||
|
||||
virtual ErrorOr<String> to_string() const override;
|
||||
|
||||
|
|
|
@ -295,7 +295,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
|
|||
// That's why it has to be set before everything else.
|
||||
m_font = computed_style.computed_font();
|
||||
computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize)->to_length().to_px(*this).value());
|
||||
computed_values.set_font_weight(computed_style.property(CSS::PropertyID::FontWeight)->to_integer());
|
||||
computed_values.set_font_weight(computed_style.property(CSS::PropertyID::FontWeight)->as_numeric().integer());
|
||||
m_line_height = computed_style.line_height(*this);
|
||||
|
||||
computed_values.set_vertical_align(computed_style.vertical_align());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue