summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp8
-rw-r--r--Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp25
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleComputer.cpp7
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.cpp5
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.h23
5 files changed, 28 insertions, 40 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 21e05cb054..ba322bdc9f 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -3828,7 +3828,7 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_number_value(TokenStream<ComponentValu
auto peek_token = tokens.peek_token();
if (peek_token.is(Token::Type::Number)) {
(void)tokens.next_token();
- return NumberStyleValue::create_float(peek_token.token().number().value());
+ return NumberStyleValue::create(peek_token.token().number().value());
}
return nullptr;
@@ -5511,16 +5511,16 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_flex_value(Vector<ComponentValue> cons
// https://github.com/w3c/csswg-drafts/issues/5742
// (flex-basis takes `<length>`, not `<number>`, so the 0 is a Length.)
auto flex_basis = TRY(LengthStyleValue::create(Length::make_px(0)));
- auto one = TRY(NumberStyleValue::create_integer(1));
+ auto one = TRY(NumberStyleValue::create(1));
return FlexStyleValue::create(*value, one, flex_basis);
}
case PropertyID::FlexBasis: {
- auto one = TRY(NumberStyleValue::create_integer(1));
+ auto one = TRY(NumberStyleValue::create(1));
return FlexStyleValue::create(one, one, *value);
}
case PropertyID::Flex: {
if (value->is_identifier() && value->to_identifier() == ValueID::None) {
- auto zero = TRY(NumberStyleValue::create_integer(0));
+ auto zero = TRY(NumberStyleValue::create(0));
return FlexStyleValue::create(zero, zero, TRY(IdentifierStyleValue::create(ValueID::Auto)));
}
break;
diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
index 96d1d956b1..f576125969 100644
--- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
+++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
@@ -28,6 +28,7 @@
#include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
#include <LibWeb/CSS/StyleValues/IdentifierStyleValue.h>
#include <LibWeb/CSS/StyleValues/InitialStyleValue.h>
+#include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
@@ -534,9 +535,9 @@ ErrorOr<RefPtr<StyleValue const>> ResolvedCSSStyleDeclaration::style_value_for_p
case PropertyID::FlexDirection:
return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().flex_direction()));
case PropertyID::FlexGrow:
- return NumberStyleValue::create_float(layout_node.computed_values().flex_grow());
+ return NumberStyleValue::create(layout_node.computed_values().flex_grow());
case PropertyID::FlexShrink:
- return NumberStyleValue::create_float(layout_node.computed_values().flex_shrink());
+ return NumberStyleValue::create(layout_node.computed_values().flex_shrink());
case PropertyID::FlexWrap:
return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().flex_wrap()));
case PropertyID::Float:
@@ -554,7 +555,7 @@ ErrorOr<RefPtr<StyleValue const>> ResolvedCSSStyleDeclaration::style_value_for_p
VERIFY_NOT_REACHED();
}
case PropertyID::FontWeight:
- return NumberStyleValue::create_integer(layout_node.computed_values().font_weight());
+ return NumberStyleValue::create(layout_node.computed_values().font_weight());
case PropertyID::GridArea: {
auto maybe_grid_row_start = property(PropertyID::GridRowStart);
auto maybe_grid_column_start = property(PropertyID::GridColumnStart);
@@ -682,9 +683,9 @@ ErrorOr<RefPtr<StyleValue const>> ResolvedCSSStyleDeclaration::style_value_for_p
case PropertyID::MinWidth:
return style_value_for_size(layout_node.computed_values().min_width());
case PropertyID::Opacity:
- return NumberStyleValue::create_float(layout_node.computed_values().opacity());
+ return NumberStyleValue::create(layout_node.computed_values().opacity());
case PropertyID::Order:
- return NumberStyleValue::create_integer(layout_node.computed_values().order());
+ return IntegerStyleValue::create(layout_node.computed_values().order());
case PropertyID::OverflowX:
return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().overflow_x()));
case PropertyID::OverflowY:
@@ -753,12 +754,12 @@ ErrorOr<RefPtr<StyleValue const>> ResolvedCSSStyleDeclaration::style_value_for_p
StyleValueVector parameters;
TRY(parameters.try_ensure_capacity(6));
- parameters.unchecked_append(TRY(NumberStyleValue::create_float(affine_matrix.a())));
- parameters.unchecked_append(TRY(NumberStyleValue::create_float(affine_matrix.b())));
- parameters.unchecked_append(TRY(NumberStyleValue::create_float(affine_matrix.c())));
- parameters.unchecked_append(TRY(NumberStyleValue::create_float(affine_matrix.d())));
- parameters.unchecked_append(TRY(NumberStyleValue::create_float(affine_matrix.e())));
- parameters.unchecked_append(TRY(NumberStyleValue::create_float(affine_matrix.f())));
+ parameters.unchecked_append(TRY(NumberStyleValue::create(affine_matrix.a())));
+ parameters.unchecked_append(TRY(NumberStyleValue::create(affine_matrix.b())));
+ parameters.unchecked_append(TRY(NumberStyleValue::create(affine_matrix.c())));
+ parameters.unchecked_append(TRY(NumberStyleValue::create(affine_matrix.d())));
+ parameters.unchecked_append(TRY(NumberStyleValue::create(affine_matrix.e())));
+ parameters.unchecked_append(TRY(NumberStyleValue::create(affine_matrix.f())));
NonnullRefPtr<StyleValue> matrix_function = TRY(TransformationStyleValue::create(TransformFunction::Matrix, move(parameters)));
// Elsewhere we always store the transform property's value as a StyleValueList of TransformationStyleValues,
@@ -779,7 +780,7 @@ ErrorOr<RefPtr<StyleValue const>> ResolvedCSSStyleDeclaration::style_value_for_p
auto maybe_z_index = layout_node.computed_values().z_index();
if (!maybe_z_index.has_value())
return nullptr;
- return NumberStyleValue::create_integer(maybe_z_index.release_value());
+ return IntegerStyleValue::create(maybe_z_index.release_value());
}
case PropertyID::Invalid:
return IdentifierStyleValue::create(ValueID::Invalid);
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
index f0b1d9f0ff..db01248be3 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -45,6 +45,7 @@
#include <LibWeb/CSS/StyleValues/GridTrackSizeListShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
#include <LibWeb/CSS/StyleValues/IdentifierStyleValue.h>
+#include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
#include <LibWeb/CSS/StyleValues/ListStyleStyleValue.h>
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
@@ -1081,13 +1082,15 @@ static ErrorOr<NonnullRefPtr<StyleValue>> interpolate_property(StyleValue const&
return ColorStyleValue::create(color);
}
+ case StyleValue::Type::Integer:
+ return IntegerStyleValue::create(interpolate_raw(from.as_integer().integer(), to.as_integer().integer()));
case StyleValue::Type::Length: {
auto& from_length = from.as_length().length();
auto& to_length = to.as_length().length();
return LengthStyleValue::create(Length(interpolate_raw(from_length.raw_value(), to_length.raw_value()), from_length.type()));
}
case StyleValue::Type::Number:
- return NumberStyleValue::create_float(interpolate_raw(from.as_number().number(), to.as_number().number()));
+ return NumberStyleValue::create(interpolate_raw(from.as_number().number(), to.as_number().number()));
case StyleValue::Type::Percentage:
return PercentageStyleValue::create(Percentage(interpolate_raw(from.as_percentage().percentage().value(), to.as_percentage().percentage().value())));
case StyleValue::Type::Position: {
@@ -1929,7 +1932,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
FontCache::the().set(font_selector, *found_font);
style.set_property(CSS::PropertyID::FontSize, LengthStyleValue::create(CSS::Length::make_px(font_size_in_px)).release_value_but_fixme_should_propagate_errors(), nullptr);
- style.set_property(CSS::PropertyID::FontWeight, NumberStyleValue::create_integer(weight).release_value_but_fixme_should_propagate_errors(), nullptr);
+ style.set_property(CSS::PropertyID::FontWeight, NumberStyleValue::create(weight).release_value_but_fixme_should_propagate_errors(), nullptr);
style.set_computed_font(found_font.release_nonnull());
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.cpp
index 6e155d25e7..748e1f965e 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.cpp
@@ -13,10 +13,7 @@ namespace Web::CSS {
ErrorOr<String> NumberStyleValue::to_string() const
{
- return m_value.visit(
- [](auto value) {
- return String::formatted("{}", value);
- });
+ return String::number(m_value);
}
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.h
index 04a0f4fdce..08464947fb 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.h
@@ -15,38 +15,25 @@ namespace Web::CSS {
class NumberStyleValue : public StyleValueWithDefaultOperators<NumberStyleValue> {
public:
- static ErrorOr<ValueComparingNonnullRefPtr<NumberStyleValue>> create_float(float value)
+ static ErrorOr<ValueComparingNonnullRefPtr<NumberStyleValue>> create(float value)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) NumberStyleValue(value));
}
- static ErrorOr<ValueComparingNonnullRefPtr<NumberStyleValue>> create_integer(i64 value)
- {
- return adopt_nonnull_ref_or_enomem(new (nothrow) NumberStyleValue(value));
- }
-
- float number() const
- {
- return m_value.visit(
- [](float value) { return value; },
- [](i64 value) { return (float)value; });
- }
-
- bool has_integer() const { return m_value.has<i64>(); }
- float integer() const { return m_value.get<i64>(); }
+ float number() const { return m_value; }
virtual ErrorOr<String> to_string() const override;
bool properties_equal(NumberStyleValue const& other) const { return m_value == other.m_value; }
private:
- explicit NumberStyleValue(Variant<float, i64> value)
+ explicit NumberStyleValue(float value)
: StyleValueWithDefaultOperators(Type::Number)
- , m_value(move(value))
+ , m_value(value)
{
}
- Variant<float, i64> m_value { (i64)0 };
+ float m_value { 0 };
};
}