mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWeb: Parse the rotate css property
This commit is contained in:
parent
8ac60273a6
commit
488436fb54
Notes:
github-actions[bot]
2024-10-29 14:41:49 +00:00
Author: https://github.com/stelar7
Commit: 488436fb54
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1823
Reviewed-by: https://github.com/AtkinsSJ ✅
17 changed files with 284 additions and 0 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/RectStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/RotationStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ScrollbarGutterStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/StringStyleValue.h>
|
||||
|
@ -521,6 +522,43 @@ Vector<CSS::Transformation> StyleProperties::transformations() const
|
|||
return transformations_for_style_value(property(CSS::PropertyID::Transform));
|
||||
}
|
||||
|
||||
Optional<CSS::Transformation> StyleProperties::rotate(Layout::Node const& layout_node) const
|
||||
{
|
||||
auto value = property(CSS::PropertyID::Rotate);
|
||||
if (!value->is_rotation())
|
||||
return {};
|
||||
auto& rotation = value->as_rotation();
|
||||
|
||||
auto resolve_angle = [&layout_node](CSSStyleValue const& value) -> Optional<Angle> {
|
||||
if (value.is_angle())
|
||||
return value.as_angle().angle();
|
||||
if (value.is_math() && value.as_math().resolves_to_angle())
|
||||
return value.as_math().resolve_angle(layout_node);
|
||||
return {};
|
||||
};
|
||||
|
||||
auto resolve_number = [&](CSSStyleValue const& value) -> Optional<double> {
|
||||
if (value.is_number())
|
||||
return value.as_number().number();
|
||||
if (value.is_math() && value.as_math().resolves_to_number())
|
||||
return value.as_math().resolve_number();
|
||||
return {};
|
||||
};
|
||||
|
||||
auto x = resolve_number(rotation.rotation_x()).value_or(0);
|
||||
auto y = resolve_number(rotation.rotation_y()).value_or(0);
|
||||
auto z = resolve_number(rotation.rotation_z()).value_or(0);
|
||||
auto angle = resolve_angle(rotation.angle()).value_or(Angle::make_degrees(0));
|
||||
|
||||
Vector<TransformValue> values;
|
||||
values.append({ Number(Number::Type::Number, x) });
|
||||
values.append({ Number(Number::Type::Number, y) });
|
||||
values.append({ Number(Number::Type::Number, z) });
|
||||
values.append({ angle });
|
||||
|
||||
return CSS::Transformation(CSS::TransformFunction::Rotate3d, move(values));
|
||||
}
|
||||
|
||||
static Optional<LengthPercentage> length_percentage_for_style_value(CSSStyleValue const& value)
|
||||
{
|
||||
if (value.is_length())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue