mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-28 05:07:35 +00:00
LibWeb: Support individual scale
CSS property
This commit is contained in:
parent
66a821e731
commit
9a7c9286c4
Notes:
github-actions[bot]
2024-11-22 19:07:43 +00:00
Author: https://github.com/awesomekling
Commit: 9a7c9286c4
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2506
Reviewed-by: https://github.com/shannonbooth
21 changed files with 234 additions and 55 deletions
37
Libraries/LibWeb/CSS/StyleValues/ScaleStyleValue.cpp
Normal file
37
Libraries/LibWeb/CSS/StyleValues/ScaleStyleValue.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibWeb/CSS/StyleValues/ScaleStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
// https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#individual-transform-serialization
|
||||
String ScaleStyleValue::to_string() const
|
||||
{
|
||||
auto resolve_to_string = [](NumberPercentage const& value) -> String {
|
||||
if (value.is_number()) {
|
||||
return MUST(String::formatted("{}", value.number().value()));
|
||||
}
|
||||
if (value.is_percentage()) {
|
||||
return MUST(String::formatted("{}", value.percentage().value() / 100.0));
|
||||
}
|
||||
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);
|
||||
if (x_value != y_value) {
|
||||
builder.append(" "sv);
|
||||
builder.append(y_value);
|
||||
}
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
}
|
49
Libraries/LibWeb/CSS/StyleValues/ScaleStyleValue.h
Normal file
49
Libraries/LibWeb/CSS/StyleValues/ScaleStyleValue.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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 ScaleStyleValue : public StyleValueWithDefaultOperators<ScaleStyleValue> {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<ScaleStyleValue> create(NumberPercentage x, NumberPercentage y)
|
||||
{
|
||||
return adopt_ref(*new (nothrow) ScaleStyleValue(move(x), move(y)));
|
||||
}
|
||||
|
||||
virtual ~ScaleStyleValue() override = default;
|
||||
|
||||
NumberPercentage const& x() const { return m_properties.x; }
|
||||
NumberPercentage const& y() const { return m_properties.y; }
|
||||
|
||||
virtual String to_string() const override;
|
||||
|
||||
bool properties_equal(ScaleStyleValue const& other) const { return m_properties == other.m_properties; }
|
||||
|
||||
private:
|
||||
explicit ScaleStyleValue(
|
||||
NumberPercentage x,
|
||||
NumberPercentage y)
|
||||
: StyleValueWithDefaultOperators(Type::Scale)
|
||||
, m_properties {
|
||||
.x = move(x),
|
||||
.y = move(y),
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
struct Properties {
|
||||
NumberPercentage x;
|
||||
NumberPercentage y;
|
||||
bool operator==(Properties const&) const = default;
|
||||
} m_properties;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue