diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index 13ff88b1195..a6e30bedb7a 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -164,7 +164,6 @@ set(SOURCES CSS/StyleValues/StyleValueList.cpp CSS/StyleValues/TransformationStyleValue.cpp CSS/StyleValues/TransitionStyleValue.cpp - CSS/StyleValues/TranslationStyleValue.cpp CSS/StyleValues/UnresolvedStyleValue.cpp CSS/Supports.cpp CSS/SyntaxHighlighter/SyntaxHighlighter.cpp diff --git a/Libraries/LibWeb/CSS/CSSStyleValue.cpp b/Libraries/LibWeb/CSS/CSSStyleValue.cpp index 5e3e651911b..df16704267b 100644 --- a/Libraries/LibWeb/CSS/CSSStyleValue.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleValue.cpp @@ -57,7 +57,6 @@ #include #include #include -#include #include #include @@ -344,12 +343,6 @@ TransitionStyleValue const& CSSStyleValue::as_transition() const return static_cast(*this); } -TranslationStyleValue const& CSSStyleValue::as_translation() const -{ - VERIFY(is_translation()); - return static_cast(*this); -} - UnresolvedStyleValue const& CSSStyleValue::as_unresolved() const { VERIFY(is_unresolved()); diff --git a/Libraries/LibWeb/CSS/CSSStyleValue.h b/Libraries/LibWeb/CSS/CSSStyleValue.h index dcc3cd94b72..9dc4d23e29f 100644 --- a/Libraries/LibWeb/CSS/CSSStyleValue.h +++ b/Libraries/LibWeb/CSS/CSSStyleValue.h @@ -135,7 +135,6 @@ public: Time, Transformation, Transition, - Translation, Unresolved, URL, ValueList, @@ -330,10 +329,6 @@ public: TransitionStyleValue const& as_transition() const; TransitionStyleValue& as_transition() { return const_cast(const_cast(*this).as_transition()); } - bool is_translation() const { return type() == Type::Translation; } - TranslationStyleValue const& as_translation() const; - TranslationStyleValue& as_translation() { return const_cast(const_cast(*this).as_translation()); } - bool is_unresolved() const { return type() == Type::Unresolved; } UnresolvedStyleValue const& as_unresolved() const; UnresolvedStyleValue& as_unresolved() { return const_cast(const_cast(*this).as_unresolved()); } diff --git a/Libraries/LibWeb/CSS/ComputedProperties.cpp b/Libraries/LibWeb/CSS/ComputedProperties.cpp index e6a9026d489..43423f99c69 100644 --- a/Libraries/LibWeb/CSS/ComputedProperties.cpp +++ b/Libraries/LibWeb/CSS/ComputedProperties.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -596,18 +595,12 @@ Optional ComputedProperties::rotate(Layout::Node const& lay return CSS::Transformation(CSS::TransformFunction::Rotate3d, move(values)); } -Optional ComputedProperties::translate() const +Optional ComputedProperties::translate() const { - auto const& value = property(CSS::PropertyID::Translate); - if (!value.is_translation()) + auto const& value = property(PropertyID::Translate); + if (!value.is_transformation()) return {}; - auto const& translation = value.as_translation(); - - Vector values; - values.append(translation.x()); - values.append(translation.y()); - - return CSS::Transformation(CSS::TransformFunction::Translate, move(values)); + return value.as_transformation().to_transformation(); } Optional ComputedProperties::scale() const diff --git a/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Libraries/LibWeb/CSS/Parser/Parser.cpp index fe4d687328a..adcbf68fa50 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -78,7 +78,6 @@ #include #include #include -#include #include #include #include @@ -7671,21 +7670,21 @@ RefPtr Parser::parse_translate_value(TokenStream& auto transaction = tokens.begin_transaction(); - auto maybe_x = parse_length_percentage(tokens); - if (!maybe_x.has_value()) + auto maybe_x = parse_length_percentage_value(tokens); + if (!maybe_x) return nullptr; if (!tokens.has_next_token()) { transaction.commit(); - return TranslationStyleValue::create(maybe_x.release_value(), LengthPercentage(Length::make_px(0))); + return TransformationStyleValue::create(PropertyID::Translate, TransformFunction::Translate, { maybe_x.release_nonnull(), LengthStyleValue::create(Length::make_px(0)) }); } - auto maybe_y = parse_length_percentage(tokens); - if (!maybe_y.has_value()) + auto maybe_y = parse_length_percentage_value(tokens); + if (!maybe_y) return nullptr; transaction.commit(); - return TranslationStyleValue::create(maybe_x.release_value(), maybe_y.release_value()); + return TransformationStyleValue::create(PropertyID::Translate, TransformFunction::Translate, { maybe_x.release_nonnull(), maybe_y.release_nonnull() }); } RefPtr Parser::parse_scale_value(TokenStream& tokens) diff --git a/Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.cpp index 4ba6f52cf0e..c38b06d7fd8 100644 --- a/Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.cpp @@ -87,6 +87,32 @@ String TransformationStyleValue::to_string(SerializationMode mode) const } return builder.to_string_without_validation(); } + if (m_properties.property == PropertyID::Translate) { + auto resolve_to_string = [mode](CSSStyleValue const& value) -> Optional { + if (value.is_length()) { + if (value.as_length().length().raw_value() == 0) + return {}; + } + if (value.is_percentage()) { + if (value.as_percentage().percentage().value() == 0) + return {}; + } + return value.to_string(mode); + }; + + auto x_value = resolve_to_string(m_properties.values[0]); + auto y_value = resolve_to_string(m_properties.values[1]); + // FIXME: 3D translation + + StringBuilder builder; + builder.append(x_value.value_or("0px"_string)); + if (y_value.has_value()) { + builder.append(" "sv); + builder.append(y_value.value()); + } + + return builder.to_string_without_validation(); + } StringBuilder builder; builder.append(CSS::to_string(m_properties.transform_function)); diff --git a/Libraries/LibWeb/CSS/StyleValues/TranslationStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/TranslationStyleValue.cpp deleted file mode 100644 index c738560f993..00000000000 --- a/Libraries/LibWeb/CSS/StyleValues/TranslationStyleValue.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2024, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include -#include -#include -#include - -namespace Web::CSS { - -// https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#individual-transform-serialization -String TranslationStyleValue::to_string(SerializationMode) const -{ - auto resolve_to_string = [](LengthPercentage const& value) -> Optional { - if (value.is_length()) { - if (value.length().raw_value() == 0) - return {}; - } - if (value.is_percentage()) { - if (value.percentage().value() == 0) - return {}; - } - return value.to_string(); - }; - - auto x_value = resolve_to_string(m_properties.x); - auto y_value = resolve_to_string(m_properties.y); - - StringBuilder builder; - builder.append(x_value.value_or("0px"_string)); - if (y_value.has_value()) { - builder.append(" "sv); - builder.append(y_value.value()); - } - - return builder.to_string_without_validation(); -} - -} diff --git a/Libraries/LibWeb/CSS/StyleValues/TranslationStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/TranslationStyleValue.h deleted file mode 100644 index 109000837b8..00000000000 --- a/Libraries/LibWeb/CSS/StyleValues/TranslationStyleValue.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2024, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include - -namespace Web::CSS { - -class TranslationStyleValue : public StyleValueWithDefaultOperators { -public: - static ValueComparingNonnullRefPtr create(LengthPercentage x, LengthPercentage y) - { - return adopt_ref(*new (nothrow) TranslationStyleValue(move(x), move(y))); - } - - virtual ~TranslationStyleValue() override = default; - - LengthPercentage const& x() const { return m_properties.x; } - LengthPercentage const& y() const { return m_properties.y; } - - virtual String to_string(SerializationMode) const override; - - bool properties_equal(TranslationStyleValue const& other) const { return m_properties == other.m_properties; } - -private: - explicit TranslationStyleValue( - LengthPercentage x, - LengthPercentage y) - : StyleValueWithDefaultOperators(Type::Translation) - , m_properties { - .x = move(x), - .y = move(y), - } - { - } - - struct Properties { - LengthPercentage x; - LengthPercentage y; - bool operator==(Properties const&) const = default; - } m_properties; -}; - -} diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index 6e70e645bae..23c874235dc 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -229,7 +229,6 @@ class TimeStyleValue; class Transformation; class TransformationStyleValue; class TransitionStyleValue; -class TranslationStyleValue; class UnresolvedStyleValue; class URLStyleValue; class VisualViewport;