diff --git a/Libraries/LibWeb/CSS/ComputedProperties.cpp b/Libraries/LibWeb/CSS/ComputedProperties.cpp index e05f476f329..ea0266c2d78 100644 --- a/Libraries/LibWeb/CSS/ComputedProperties.cpp +++ b/Libraries/LibWeb/CSS/ComputedProperties.cpp @@ -595,6 +595,7 @@ float ComputedProperties::flex_shrink() const int ComputedProperties::order() const { auto const& value = property(PropertyID::Order); + // FIXME: Support calc() if (!value.is_integer()) return 0; return value.as_integer().integer(); @@ -1633,12 +1634,7 @@ HashMap ComputedProperties::font_feature_settings() const for (auto const& tag_value : feature_tags) { 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().integer()); - } else { - VERIFY(feature_tag.value()->is_calculated()); - result.set(feature_tag.tag(), feature_tag.value()->as_calculated().resolve_integer({}).value()); - } + result.set(feature_tag.tag(), int_from_style_value(feature_tag.value())); } return result; } @@ -2201,17 +2197,10 @@ Vector ComputedProperties::counter_data(PropertyID property_id) con .is_reversed = counter.is_reversed, .value = {}, }; - if (counter.value) { - if (counter.value->is_integer()) { - data.value = AK::clamp_to(counter.value->as_integer().integer()); - } else if (counter.value->is_calculated()) { - auto maybe_int = counter.value->as_calculated().resolve_integer({}); - if (maybe_int.has_value()) - data.value = AK::clamp_to(*maybe_int); - } else { - dbgln("Unimplemented type for {} integer value: '{}'", string_from_property_id(property_id), counter.value->to_string(SerializationMode::Normal)); - } - } + + if (counter.value) + data.value = AK::clamp_to(int_from_style_value(*counter.value)); + result.append(move(data)); } return result; diff --git a/Libraries/LibWeb/CSS/EasingFunction.cpp b/Libraries/LibWeb/CSS/EasingFunction.cpp index 2e18657c4c7..0e1035fb237 100644 --- a/Libraries/LibWeb/CSS/EasingFunction.cpp +++ b/Libraries/LibWeb/CSS/EasingFunction.cpp @@ -317,16 +317,6 @@ EasingFunction EasingFunction::from_style_value(StyleValue const& style_value) VERIFY_NOT_REACHED(); }; - auto const resolve_integer = [](StyleValue const& style_value) { - if (style_value.is_integer()) - return style_value.as_integer().integer(); - - if (style_value.is_calculated()) - return style_value.as_calculated().resolve_integer({}).value(); - - VERIFY_NOT_REACHED(); - }; - if (style_value.is_easing()) { return style_value.as_easing().function().visit( [&](EasingStyleValue::Linear const& linear) -> EasingFunction { @@ -358,7 +348,7 @@ EasingFunction EasingFunction::from_style_value(StyleValue const& style_value) return CubicBezierEasingFunction { resolved_x1, resolved_y1, resolved_x2, resolved_y2, cubic_bezier.to_string(SerializationMode::Normal) }; }, [&](EasingStyleValue::Steps const& steps) -> EasingFunction { - return StepsEasingFunction { resolve_integer(steps.number_of_intervals), steps.position, steps.to_string(SerializationMode::ResolvedValue) }; + return StepsEasingFunction { int_from_style_value(steps.number_of_intervals), steps.position, steps.to_string(SerializationMode::ResolvedValue) }; }); } diff --git a/Libraries/LibWeb/CSS/ParsedFontFace.cpp b/Libraries/LibWeb/CSS/ParsedFontFace.cpp index b2746301813..61dfdc2fd5e 100644 --- a/Libraries/LibWeb/CSS/ParsedFontFace.cpp +++ b/Libraries/LibWeb/CSS/ParsedFontFace.cpp @@ -157,15 +157,11 @@ ParsedFontFace ParsedFontFace::from_descriptors(CSSFontFaceDescriptors const& de auto const& feature_tags = value->as_value_list().values(); OrderedHashMap settings; settings.ensure_capacity(feature_tags.size()); - for (auto const& feature_tag : feature_tags) { - auto const& setting_value = feature_tag->as_open_type_tagged().value(); - if (setting_value->is_integer()) { - settings.set(feature_tag->as_open_type_tagged().tag(), setting_value->as_integer().integer()); - } else if (setting_value->is_calculated() && setting_value->as_calculated().resolves_to_number()) { - if (auto integer = setting_value->as_calculated().resolve_integer({}); integer.has_value()) { - settings.set(feature_tag->as_open_type_tagged().tag(), *integer); - } - } + for (auto const& feature_tag_style_value : feature_tags) { + auto const& feature_tag = feature_tag_style_value->as_open_type_tagged(); + + // FIXME: We should absolutize feature_tag.value() in case there are relative lengths + settings.set(feature_tag.tag(), int_from_style_value(feature_tag.value())); } font_feature_settings = move(settings); } diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index 57ccb3e73c6..6b53638efd3 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -2804,16 +2804,6 @@ NonnullRefPtr StyleComputer::compute_math_depth(NonnullRefPtr< ? inheritance_parent->computed_properties()->math_style() : InitialValues::math_style(); - auto resolve_integer = [&](StyleValue const& integer_value) { - if (integer_value.is_integer()) - return integer_value.as_integer().integer(); - - if (integer_value.is_calculated()) - return integer_value.as_calculated().resolve_integer({}).value(); - - VERIFY_NOT_REACHED(); - }; - // The computed value of the math-depth value is determined as follows: // - If the specified value of math-depth is auto-add and the inherited value of math-style is compact // then the computed value of math-depth of the element is its inherited value plus one. @@ -2823,12 +2813,12 @@ NonnullRefPtr StyleComputer::compute_math_depth(NonnullRefPtr< // - If the specified value of math-depth is of the form add() then the computed value of // math-depth of the element is its inherited value plus the specified integer. if (absolutized_value->is_add_function()) - return IntegerStyleValue::create(inherited_math_depth + resolve_integer(*absolutized_value->as_add_function().value())); + return IntegerStyleValue::create(inherited_math_depth + int_from_style_value(absolutized_value->as_add_function().value())); // - If the specified value of math-depth is of the form then the computed value of math-depth // of the element is the specified integer. if (absolutized_value->is_integer() || absolutized_value->is_calculated()) - return IntegerStyleValue::create(resolve_integer(*absolutized_value)); + return IntegerStyleValue::create(int_from_style_value(absolutized_value)); // - Otherwise, the computed value of math-depth of the element is the inherited one. return IntegerStyleValue::create(inherited_math_depth); diff --git a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp index c21e815dfbb..dc34813c549 100644 --- a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp @@ -186,6 +186,17 @@ StyleValueVector StyleValue::subdivide_into_iterations(PropertyNameAndID const&) return StyleValueVector { *this }; } +i64 int_from_style_value(NonnullRefPtr const& style_value) +{ + if (style_value->is_integer()) + return style_value->as_integer().integer(); + + if (style_value->is_calculated()) + return style_value->as_calculated().resolve_integer({}).value(); + + VERIFY_NOT_REACHED(); +} + double number_from_style_value(NonnullRefPtr const& style_value, Optional percentage_basis) { if (style_value->is_number()) diff --git a/Libraries/LibWeb/CSS/StyleValues/StyleValue.h b/Libraries/LibWeb/CSS/StyleValues/StyleValue.h index cc62de72d14..6b4d88dd853 100644 --- a/Libraries/LibWeb/CSS/StyleValues/StyleValue.h +++ b/Libraries/LibWeb/CSS/StyleValues/StyleValue.h @@ -204,6 +204,7 @@ struct StyleValueWithDefaultOperators : public StyleValue { } }; +i64 int_from_style_value(NonnullRefPtr const& style_value); double number_from_style_value(NonnullRefPtr const& style_value, Optional percentage_basis); FlyString const& string_from_style_value(NonnullRefPtr const& style_value); diff --git a/Libraries/LibWeb/Layout/Node.cpp b/Libraries/LibWeb/Layout/Node.cpp index 0d13ea83fd8..15751cf7341 100644 --- a/Libraries/LibWeb/Layout/Node.cpp +++ b/Libraries/LibWeb/Layout/Node.cpp @@ -894,6 +894,7 @@ void NodeWithStyle::apply_style(CSS::ComputedProperties const& computed_style) computed_values.set_text_anchor(computed_style.text_anchor()); + // FIXME: Support calc() if (auto const& column_count = computed_style.property(CSS::PropertyID::ColumnCount); column_count.is_integer()) computed_values.set_column_count(CSS::ColumnCount::make_integer(column_count.as_integer().integer()));