mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-01 15:18:06 +00:00
LibWeb/CSS: Separate IntegerSV and NumberSV from CSSUnitValue
This inheritance exists for typed-om classes, but StyleValues aren't
typed-om.
Somehow this makes our z-index interpolation slightly more correct. 🎉
This commit is contained in:
parent
51a657ca47
commit
7157d19f56
Notes:
github-actions[bot]
2025-08-08 14:20:36 +00:00
Author: https://github.com/AtkinsSJ
Commit: 7157d19f56
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5775
Reviewed-by: https://github.com/tcl3 ✅
10 changed files with 23 additions and 25 deletions
|
@ -1494,7 +1494,7 @@ Optional<HashMap<FlyString, IntegerOrCalculated>> ComputedProperties::font_featu
|
|||
auto const& feature_tag = tag_value->as_open_type_tagged();
|
||||
|
||||
if (feature_tag.value()->is_integer()) {
|
||||
result.set(feature_tag.tag(), feature_tag.value()->as_integer().value());
|
||||
result.set(feature_tag.tag(), feature_tag.value()->as_integer().integer());
|
||||
} else {
|
||||
VERIFY(feature_tag.value()->is_calculated());
|
||||
result.set(feature_tag.tag(), IntegerOrCalculated { feature_tag.value()->as_calculated() });
|
||||
|
@ -1521,7 +1521,7 @@ Optional<HashMap<FlyString, NumberOrCalculated>> ComputedProperties::font_variat
|
|||
auto const& axis_tag = tag_value->as_open_type_tagged();
|
||||
|
||||
if (axis_tag.value()->is_number()) {
|
||||
result.set(axis_tag.tag(), axis_tag.value()->as_number().value());
|
||||
result.set(axis_tag.tag(), axis_tag.value()->as_number().number());
|
||||
} else {
|
||||
VERIFY(axis_tag.value()->is_calculated());
|
||||
result.set(axis_tag.tag(), NumberOrCalculated { axis_tag.value()->as_calculated() });
|
||||
|
|
|
@ -1151,8 +1151,8 @@ static RefPtr<StyleValue const> interpolate_value_impl(DOM::Element& element, Ca
|
|||
// https://drafts.csswg.org/css-values/#combine-integers
|
||||
// Interpolation of <integer> is defined as Vresult = round((1 - p) × VA + p × VB);
|
||||
// that is, interpolation happens in the real number space as for <number>s, and the result is converted to an <integer> by rounding to the nearest integer.
|
||||
auto interpolated_value = interpolate_raw(from.as_integer().value(), to.as_integer().value(), delta);
|
||||
return IntegerStyleValue::create(round_to<i64>(interpolated_value));
|
||||
auto interpolated_value = interpolate_raw(from.as_integer().integer(), to.as_integer().integer(), delta);
|
||||
return IntegerStyleValue::create(interpolated_value);
|
||||
}
|
||||
case StyleValue::Type::Length: {
|
||||
auto const& from_length = from.as_length().length();
|
||||
|
|
|
@ -2180,7 +2180,7 @@ RefPtr<StyleValue const> Parser::parse_stroke_dasharray_value(TokenStream<Compon
|
|||
|
||||
// A <dasharray> is a list of comma and/or white space separated <number> or <length-percentage> values. A <number> value represents a value in user units.
|
||||
auto value = parse_number_value(tokens);
|
||||
if (value && value->is_number() && value->as_number().value() < 0)
|
||||
if (value && value->is_number() && value->as_number().number() < 0)
|
||||
return {};
|
||||
|
||||
if (value) {
|
||||
|
@ -2836,7 +2836,7 @@ RefPtr<StyleValue const> Parser::parse_font_feature_settings_value(TokenStream<C
|
|||
RefPtr<StyleValue const> value;
|
||||
if (tag_tokens.has_next_token()) {
|
||||
if (auto integer = parse_integer_value(tag_tokens)) {
|
||||
if (integer->is_integer() && integer->as_integer().value() < 0)
|
||||
if (integer->is_integer() && integer->as_integer().integer() < 0)
|
||||
return nullptr;
|
||||
value = integer;
|
||||
} else {
|
||||
|
|
|
@ -365,7 +365,7 @@ Optional<Ratio> Parser::parse_ratio(TokenStream<ComponentValue>& tokens)
|
|||
if (!maybe_calc)
|
||||
return {};
|
||||
if (maybe_calc->is_number())
|
||||
return maybe_calc->as_number().value();
|
||||
return maybe_calc->as_number().number();
|
||||
if (!maybe_calc->is_calculated() || !maybe_calc->as_calculated().resolves_to_number())
|
||||
return {};
|
||||
if (auto resolved_number = maybe_calc->as_calculated().resolve_number_deprecated({}); resolved_number.has_value() && resolved_number.value() >= 0) {
|
||||
|
|
|
@ -130,11 +130,11 @@ String ColorFunctionStyleValue::to_string(SerializationMode mode) const
|
|||
|
||||
bool const is_alpha_required = [&]() {
|
||||
if (alpha->is_number())
|
||||
return alpha->as_number().value() < 1;
|
||||
return alpha->as_number().number() < 1;
|
||||
return true;
|
||||
}();
|
||||
|
||||
if (alpha->is_number() && alpha->as_number().value() < 0)
|
||||
if (alpha->is_number() && alpha->as_number().number() < 0)
|
||||
alpha = NumberStyleValue::create(0);
|
||||
|
||||
if (is_alpha_required) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include "IntegerStyleValue.h"
|
||||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
|
@ -15,7 +16,7 @@ String IntegerStyleValue::to_string(SerializationMode) const
|
|||
|
||||
Vector<Parser::ComponentValue> IntegerStyleValue::tokenize() const
|
||||
{
|
||||
return { Parser::Token::create_number(Number { Number::Type::Integer, value() }) };
|
||||
return { Parser::Token::create_number(Number { Number::Type::Integer, static_cast<double>(m_value) }) };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/CSS/StyleValues/CSSUnitValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class IntegerStyleValue final : public CSSUnitValue {
|
||||
class IntegerStyleValue final : public StyleValue {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<IntegerStyleValue const> create(i64 value)
|
||||
{
|
||||
|
@ -18,8 +18,6 @@ public:
|
|||
}
|
||||
|
||||
i64 integer() const { return m_value; }
|
||||
virtual double value() const override { return m_value; }
|
||||
virtual StringView unit() const override { return "number"sv; }
|
||||
|
||||
virtual String to_string(SerializationMode) const override;
|
||||
virtual Vector<Parser::ComponentValue> tokenize() const override;
|
||||
|
@ -34,7 +32,7 @@ public:
|
|||
|
||||
private:
|
||||
explicit IntegerStyleValue(i64 value)
|
||||
: CSSUnitValue(Type::Integer)
|
||||
: StyleValue(Type::Integer)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "NumberStyleValue.h"
|
||||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
|
|
|
@ -9,11 +9,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/CSS/StyleValues/CSSUnitValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class NumberStyleValue final : public CSSUnitValue {
|
||||
class NumberStyleValue final : public StyleValue {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<NumberStyleValue const> create(double value)
|
||||
{
|
||||
|
@ -21,8 +21,6 @@ public:
|
|||
}
|
||||
|
||||
double number() const { return m_value; }
|
||||
virtual double value() const override { return m_value; }
|
||||
virtual StringView unit() const override { return "number"sv; }
|
||||
|
||||
virtual String to_string(SerializationMode) const override;
|
||||
virtual Vector<Parser::ComponentValue> tokenize() const override;
|
||||
|
@ -37,7 +35,7 @@ public:
|
|||
|
||||
private:
|
||||
explicit NumberStyleValue(double value)
|
||||
: CSSUnitValue(Type::Number)
|
||||
: StyleValue(Type::Number)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@ Harness status: OK
|
|||
|
||||
Found 250 tests
|
||||
|
||||
212 Pass
|
||||
38 Fail
|
||||
215 Pass
|
||||
35 Fail
|
||||
Pass CSS Transitions: property <z-index> from neutral to [5] at (-0.3) should be [-4]
|
||||
Pass CSS Transitions: property <z-index> from neutral to [5] at (0) should be [-2]
|
||||
Pass CSS Transitions: property <z-index> from neutral to [5] at (0.3) should be [0]
|
||||
Pass CSS Transitions: property <z-index> from neutral to [5] at (0.6) should be [2]
|
||||
Pass CSS Transitions: property <z-index> from neutral to [5] at (1) should be [5]
|
||||
Fail CSS Transitions: property <z-index> from neutral to [5] at (1.5) should be [9]
|
||||
Pass CSS Transitions: property <z-index> from neutral to [5] at (1.5) should be [9]
|
||||
Fail CSS Transitions with transition: all: property <z-index> from neutral to [5] at (-0.3) should be [-4]
|
||||
Fail CSS Transitions with transition: all: property <z-index> from neutral to [5] at (0) should be [-2]
|
||||
Fail CSS Transitions with transition: all: property <z-index> from neutral to [5] at (0.3) should be [0]
|
||||
|
@ -21,13 +21,13 @@ Pass CSS Animations: property <z-index> from neutral to [5] at (0) should be [-2
|
|||
Pass CSS Animations: property <z-index> from neutral to [5] at (0.3) should be [0]
|
||||
Pass CSS Animations: property <z-index> from neutral to [5] at (0.6) should be [2]
|
||||
Pass CSS Animations: property <z-index> from neutral to [5] at (1) should be [5]
|
||||
Fail CSS Animations: property <z-index> from neutral to [5] at (1.5) should be [9]
|
||||
Pass CSS Animations: property <z-index> from neutral to [5] at (1.5) should be [9]
|
||||
Pass Web Animations: property <z-index> from neutral to [5] at (-0.3) should be [-4]
|
||||
Pass Web Animations: property <z-index> from neutral to [5] at (0) should be [-2]
|
||||
Pass Web Animations: property <z-index> from neutral to [5] at (0.3) should be [0]
|
||||
Pass Web Animations: property <z-index> from neutral to [5] at (0.6) should be [2]
|
||||
Pass Web Animations: property <z-index> from neutral to [5] at (1) should be [5]
|
||||
Fail Web Animations: property <z-index> from neutral to [5] at (1.5) should be [9]
|
||||
Pass Web Animations: property <z-index> from neutral to [5] at (1.5) should be [9]
|
||||
Pass CSS Transitions with transition-behavior:allow-discrete: property <z-index> from [initial] to [5] at (-0.3) should be [initial]
|
||||
Pass CSS Transitions with transition-behavior:allow-discrete: property <z-index> from [initial] to [5] at (0) should be [initial]
|
||||
Pass CSS Transitions with transition-behavior:allow-discrete: property <z-index> from [initial] to [5] at (0.3) should be [initial]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue