mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 04:39:06 +00:00
LibWeb/CSS: Merge TranslationStyleValue into TransformationStyleValue
As with ScaleStyleValue, the serialization is the only unique part of this class, and we can just move it over.
This commit is contained in:
parent
ac15e626dd
commit
03a4ecce19
Notes:
github-actions[bot]
2025-01-17 09:15:27 +00:00
Author: https://github.com/AtkinsSJ
Commit: 03a4ecce19
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3263
9 changed files with 36 additions and 125 deletions
|
@ -164,7 +164,6 @@ set(SOURCES
|
||||||
CSS/StyleValues/StyleValueList.cpp
|
CSS/StyleValues/StyleValueList.cpp
|
||||||
CSS/StyleValues/TransformationStyleValue.cpp
|
CSS/StyleValues/TransformationStyleValue.cpp
|
||||||
CSS/StyleValues/TransitionStyleValue.cpp
|
CSS/StyleValues/TransitionStyleValue.cpp
|
||||||
CSS/StyleValues/TranslationStyleValue.cpp
|
|
||||||
CSS/StyleValues/UnresolvedStyleValue.cpp
|
CSS/StyleValues/UnresolvedStyleValue.cpp
|
||||||
CSS/Supports.cpp
|
CSS/Supports.cpp
|
||||||
CSS/SyntaxHighlighter/SyntaxHighlighter.cpp
|
CSS/SyntaxHighlighter/SyntaxHighlighter.cpp
|
||||||
|
|
|
@ -57,7 +57,6 @@
|
||||||
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/TransitionStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/TransitionStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/TranslationStyleValue.h>
|
|
||||||
#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
|
||||||
|
|
||||||
|
@ -344,12 +343,6 @@ TransitionStyleValue const& CSSStyleValue::as_transition() const
|
||||||
return static_cast<TransitionStyleValue const&>(*this);
|
return static_cast<TransitionStyleValue const&>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TranslationStyleValue const& CSSStyleValue::as_translation() const
|
|
||||||
{
|
|
||||||
VERIFY(is_translation());
|
|
||||||
return static_cast<TranslationStyleValue const&>(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
UnresolvedStyleValue const& CSSStyleValue::as_unresolved() const
|
UnresolvedStyleValue const& CSSStyleValue::as_unresolved() const
|
||||||
{
|
{
|
||||||
VERIFY(is_unresolved());
|
VERIFY(is_unresolved());
|
||||||
|
|
|
@ -135,7 +135,6 @@ public:
|
||||||
Time,
|
Time,
|
||||||
Transformation,
|
Transformation,
|
||||||
Transition,
|
Transition,
|
||||||
Translation,
|
|
||||||
Unresolved,
|
Unresolved,
|
||||||
URL,
|
URL,
|
||||||
ValueList,
|
ValueList,
|
||||||
|
@ -330,10 +329,6 @@ public:
|
||||||
TransitionStyleValue const& as_transition() const;
|
TransitionStyleValue const& as_transition() const;
|
||||||
TransitionStyleValue& as_transition() { return const_cast<TransitionStyleValue&>(const_cast<CSSStyleValue const&>(*this).as_transition()); }
|
TransitionStyleValue& as_transition() { return const_cast<TransitionStyleValue&>(const_cast<CSSStyleValue const&>(*this).as_transition()); }
|
||||||
|
|
||||||
bool is_translation() const { return type() == Type::Translation; }
|
|
||||||
TranslationStyleValue const& as_translation() const;
|
|
||||||
TranslationStyleValue& as_translation() { return const_cast<TranslationStyleValue&>(const_cast<CSSStyleValue const&>(*this).as_translation()); }
|
|
||||||
|
|
||||||
bool is_unresolved() const { return type() == Type::Unresolved; }
|
bool is_unresolved() const { return type() == Type::Unresolved; }
|
||||||
UnresolvedStyleValue const& as_unresolved() const;
|
UnresolvedStyleValue const& as_unresolved() const;
|
||||||
UnresolvedStyleValue& as_unresolved() { return const_cast<UnresolvedStyleValue&>(const_cast<CSSStyleValue const&>(*this).as_unresolved()); }
|
UnresolvedStyleValue& as_unresolved() { return const_cast<UnresolvedStyleValue&>(const_cast<CSSStyleValue const&>(*this).as_unresolved()); }
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
#include <LibWeb/CSS/StyleValues/StringStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/StringStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
|
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
|
||||||
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/TranslationStyleValue.h>
|
|
||||||
#include <LibWeb/Layout/BlockContainer.h>
|
#include <LibWeb/Layout/BlockContainer.h>
|
||||||
#include <LibWeb/Layout/Node.h>
|
#include <LibWeb/Layout/Node.h>
|
||||||
#include <LibWeb/Platform/FontPlugin.h>
|
#include <LibWeb/Platform/FontPlugin.h>
|
||||||
|
@ -596,18 +595,12 @@ Optional<CSS::Transformation> ComputedProperties::rotate(Layout::Node const& lay
|
||||||
return CSS::Transformation(CSS::TransformFunction::Rotate3d, move(values));
|
return CSS::Transformation(CSS::TransformFunction::Rotate3d, move(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<CSS::Transformation> ComputedProperties::translate() const
|
Optional<Transformation> ComputedProperties::translate() const
|
||||||
{
|
{
|
||||||
auto const& value = property(CSS::PropertyID::Translate);
|
auto const& value = property(PropertyID::Translate);
|
||||||
if (!value.is_translation())
|
if (!value.is_transformation())
|
||||||
return {};
|
return {};
|
||||||
auto const& translation = value.as_translation();
|
return value.as_transformation().to_transformation();
|
||||||
|
|
||||||
Vector<TransformValue> values;
|
|
||||||
values.append(translation.x());
|
|
||||||
values.append(translation.y());
|
|
||||||
|
|
||||||
return CSS::Transformation(CSS::TransformFunction::Translate, move(values));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Transformation> ComputedProperties::scale() const
|
Optional<Transformation> ComputedProperties::scale() const
|
||||||
|
|
|
@ -78,7 +78,6 @@
|
||||||
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/TransitionStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/TransitionStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/TranslationStyleValue.h>
|
|
||||||
#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
|
||||||
#include <LibWeb/Dump.h>
|
#include <LibWeb/Dump.h>
|
||||||
|
@ -7671,21 +7670,21 @@ RefPtr<CSSStyleValue> Parser::parse_translate_value(TokenStream<ComponentValue>&
|
||||||
|
|
||||||
auto transaction = tokens.begin_transaction();
|
auto transaction = tokens.begin_transaction();
|
||||||
|
|
||||||
auto maybe_x = parse_length_percentage(tokens);
|
auto maybe_x = parse_length_percentage_value(tokens);
|
||||||
if (!maybe_x.has_value())
|
if (!maybe_x)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
if (!tokens.has_next_token()) {
|
if (!tokens.has_next_token()) {
|
||||||
transaction.commit();
|
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);
|
auto maybe_y = parse_length_percentage_value(tokens);
|
||||||
if (!maybe_y.has_value())
|
if (!maybe_y)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
transaction.commit();
|
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<CSSStyleValue> Parser::parse_scale_value(TokenStream<ComponentValue>& tokens)
|
RefPtr<CSSStyleValue> Parser::parse_scale_value(TokenStream<ComponentValue>& tokens)
|
||||||
|
|
|
@ -87,6 +87,32 @@ String TransformationStyleValue::to_string(SerializationMode mode) const
|
||||||
}
|
}
|
||||||
return builder.to_string_without_validation();
|
return builder.to_string_without_validation();
|
||||||
}
|
}
|
||||||
|
if (m_properties.property == PropertyID::Translate) {
|
||||||
|
auto resolve_to_string = [mode](CSSStyleValue const& value) -> Optional<String> {
|
||||||
|
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;
|
StringBuilder builder;
|
||||||
builder.append(CSS::to_string(m_properties.transform_function));
|
builder.append(CSS::to_string(m_properties.transform_function));
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <AK/String.h>
|
|
||||||
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
|
||||||
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
|
||||||
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
|
||||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
|
||||||
#include <LibWeb/CSS/StyleValues/TranslationStyleValue.h>
|
|
||||||
|
|
||||||
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<String> {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <LibWeb/CSS/CSSStyleValue.h>
|
|
||||||
#include <LibWeb/CSS/PercentageOr.h>
|
|
||||||
|
|
||||||
namespace Web::CSS {
|
|
||||||
|
|
||||||
class TranslationStyleValue : public StyleValueWithDefaultOperators<TranslationStyleValue> {
|
|
||||||
public:
|
|
||||||
static ValueComparingNonnullRefPtr<TranslationStyleValue> 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;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
|
@ -229,7 +229,6 @@ class TimeStyleValue;
|
||||||
class Transformation;
|
class Transformation;
|
||||||
class TransformationStyleValue;
|
class TransformationStyleValue;
|
||||||
class TransitionStyleValue;
|
class TransitionStyleValue;
|
||||||
class TranslationStyleValue;
|
|
||||||
class UnresolvedStyleValue;
|
class UnresolvedStyleValue;
|
||||||
class URLStyleValue;
|
class URLStyleValue;
|
||||||
class VisualViewport;
|
class VisualViewport;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue