mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:17:45 +00:00
LibWeb: Remove StyleValue::has/to_number()
Only NumericStyleValue holds numbers. Renamed `to_number()` to `number()` because it's just a getter now.
This commit is contained in:
parent
5f755d721e
commit
4ecf0b7768
4 changed files with 14 additions and 15 deletions
|
@ -15,6 +15,7 @@
|
||||||
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
|
||||||
|
#include <LibWeb/CSS/StyleValues/NumericStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/RectStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/RectStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
|
||||||
|
@ -170,7 +171,7 @@ CSSPixels StyleProperties::line_height(CSSPixelRect const& viewport_rect, Length
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line_height->is_numeric())
|
if (line_height->is_numeric())
|
||||||
return Length(line_height->to_number(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics);
|
return Length(line_height->as_numeric().number(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics);
|
||||||
|
|
||||||
if (line_height->is_percentage()) {
|
if (line_height->is_percentage()) {
|
||||||
// Percentages are relative to 1em. https://www.w3.org/TR/css-inline-3/#valdef-line-height-percentage
|
// Percentages are relative to 1em. https://www.w3.org/TR/css-inline-3/#valdef-line-height-percentage
|
||||||
|
@ -200,7 +201,7 @@ CSSPixels StyleProperties::line_height(Layout::Node const& layout_node) const
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line_height->is_numeric())
|
if (line_height->is_numeric())
|
||||||
return Length(line_height->to_number(), Length::Type::Em).to_px(layout_node);
|
return Length(line_height->as_numeric().number(), Length::Type::Em).to_px(layout_node);
|
||||||
|
|
||||||
if (line_height->is_percentage()) {
|
if (line_height->is_percentage()) {
|
||||||
// Percentages are relative to 1em. https://www.w3.org/TR/css-inline-3/#valdef-line-height-percentage
|
// Percentages are relative to 1em. https://www.w3.org/TR/css-inline-3/#valdef-line-height-percentage
|
||||||
|
@ -242,8 +243,8 @@ static float resolve_opacity_value(CSS::StyleValue const& value)
|
||||||
{
|
{
|
||||||
float unclamped_opacity = 1.0f;
|
float unclamped_opacity = 1.0f;
|
||||||
|
|
||||||
if (value.has_number()) {
|
if (value.is_numeric()) {
|
||||||
unclamped_opacity = value.to_number();
|
unclamped_opacity = value.as_numeric().number();
|
||||||
} else if (value.is_calculated()) {
|
} else if (value.is_calculated()) {
|
||||||
auto& calculated = value.as_calculated();
|
auto& calculated = value.as_calculated();
|
||||||
if (calculated.resolved_type() == CalculatedStyleValue::ResolvedType::Percentage) {
|
if (calculated.resolved_type() == CalculatedStyleValue::ResolvedType::Percentage) {
|
||||||
|
@ -327,17 +328,17 @@ Optional<CSS::FlexBasisData> StyleProperties::flex_basis() const
|
||||||
float StyleProperties::flex_grow() const
|
float StyleProperties::flex_grow() const
|
||||||
{
|
{
|
||||||
auto value = property(CSS::PropertyID::FlexGrow);
|
auto value = property(CSS::PropertyID::FlexGrow);
|
||||||
if (!value->has_number())
|
if (!value->is_numeric())
|
||||||
return 0;
|
return 0;
|
||||||
return value->to_number();
|
return value->as_numeric().number();
|
||||||
}
|
}
|
||||||
|
|
||||||
float StyleProperties::flex_shrink() const
|
float StyleProperties::flex_shrink() const
|
||||||
{
|
{
|
||||||
auto value = property(CSS::PropertyID::FlexShrink);
|
auto value = property(CSS::PropertyID::FlexShrink);
|
||||||
if (!value->has_number())
|
if (!value->is_numeric())
|
||||||
return 1;
|
return 1;
|
||||||
return value->to_number();
|
return value->as_numeric().number();
|
||||||
}
|
}
|
||||||
|
|
||||||
int StyleProperties::order() const
|
int StyleProperties::order() const
|
||||||
|
@ -395,7 +396,7 @@ Vector<CSS::Transformation> StyleProperties::transformations() const
|
||||||
} else if (transformation_value->is_percentage()) {
|
} else if (transformation_value->is_percentage()) {
|
||||||
values.append({ transformation_value->as_percentage().percentage() });
|
values.append({ transformation_value->as_percentage().percentage() });
|
||||||
} else if (transformation_value->is_numeric()) {
|
} else if (transformation_value->is_numeric()) {
|
||||||
values.append({ transformation_value->to_number() });
|
values.append({ transformation_value->as_numeric().number() });
|
||||||
} else if (transformation_value->is_angle()) {
|
} else if (transformation_value->is_angle()) {
|
||||||
values.append({ transformation_value->as_angle().angle() });
|
values.append({ transformation_value->as_angle().angle() });
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -294,7 +294,6 @@ public:
|
||||||
bool has_auto() const;
|
bool has_auto() const;
|
||||||
virtual bool has_color() const { return false; }
|
virtual bool has_color() const { return false; }
|
||||||
virtual bool has_length() const { return false; }
|
virtual bool has_length() const { return false; }
|
||||||
virtual bool has_number() const { return false; }
|
|
||||||
virtual bool has_integer() 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 ErrorOr<ValueComparingNonnullRefPtr<StyleValue const>> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const;
|
||||||
|
@ -302,7 +301,6 @@ public:
|
||||||
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const { return {}; }
|
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const { return {}; }
|
||||||
ValueID to_identifier() const;
|
ValueID to_identifier() const;
|
||||||
virtual Length to_length() const { VERIFY_NOT_REACHED(); }
|
virtual Length to_length() const { VERIFY_NOT_REACHED(); }
|
||||||
virtual float to_number() const { return 0; }
|
|
||||||
virtual float to_integer() const { return 0; }
|
virtual float to_integer() const { return 0; }
|
||||||
virtual ErrorOr<String> to_string() const = 0;
|
virtual ErrorOr<String> to_string() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,10 @@ public:
|
||||||
return adopt_nonnull_ref_or_enomem(new (nothrow) NumericStyleValue(value));
|
return adopt_nonnull_ref_or_enomem(new (nothrow) NumericStyleValue(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool has_length() const override { return to_number() == 0; }
|
virtual bool has_length() const override { return number() == 0; }
|
||||||
virtual Length to_length() const override { return Length::make_px(0); }
|
virtual Length to_length() const override { return Length::make_px(0); }
|
||||||
|
|
||||||
virtual bool has_number() const override { return true; }
|
float number() const
|
||||||
virtual float to_number() const override
|
|
||||||
{
|
{
|
||||||
return m_value.visit(
|
return m_value.visit(
|
||||||
[](float value) { return value; },
|
[](float value) { return value; },
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||||
|
#include <LibWeb/CSS/StyleValues/NumericStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
|
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
|
||||||
#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
|
||||||
|
@ -676,7 +677,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
|
||||||
// FIXME: Converting to pixels isn't really correct - values should be in "user units"
|
// FIXME: Converting to pixels isn't really correct - values should be in "user units"
|
||||||
// https://svgwg.org/svg2-draft/coords.html#TermUserUnits
|
// https://svgwg.org/svg2-draft/coords.html#TermUserUnits
|
||||||
if (stroke_width->is_numeric())
|
if (stroke_width->is_numeric())
|
||||||
computed_values.set_stroke_width(CSS::Length::make_px(stroke_width->to_number()));
|
computed_values.set_stroke_width(CSS::Length::make_px(stroke_width->as_numeric().number()));
|
||||||
else if (stroke_width->is_length())
|
else if (stroke_width->is_length())
|
||||||
computed_values.set_stroke_width(stroke_width->to_length());
|
computed_values.set_stroke_width(stroke_width->to_length());
|
||||||
else if (stroke_width->is_percentage())
|
else if (stroke_width->is_percentage())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue