-
-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibWeb: Parse the rotate css property
- Loading branch information
Showing
10 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Userland/Libraries/LibWeb/CSS/StyleValues/RotationStyleValue.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2024, Steffen T. Larssen <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#include "RotationStyleValue.h" | ||
#include <AK/String.h> | ||
|
||
namespace Web::CSS { | ||
|
||
RotationStyleValue::RotationStyleValue(Angle angle, float x, float y, float z) | ||
: CSSUnitValue(Type::Rotation) | ||
, m_angle(move(angle)) | ||
, m_rotation_vector(x, y, z) | ||
{ | ||
} | ||
|
||
RotationStyleValue::~RotationStyleValue() = default; | ||
|
||
// https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#individual-transform-serialization | ||
String RotationStyleValue::to_string() const | ||
{ | ||
// If a rotation about the z axis (that is, in 2D) is specified, the property must serialize as just an <angle>. | ||
if (m_rotation_vector.x() == 0 && m_rotation_vector.y() == 0 && m_rotation_vector.z() == 1) | ||
return m_angle.to_string(); | ||
|
||
// If any other rotation is specified, the property must serialize with an axis specified. | ||
// If the axis is parallel with the x or y axes, it must serialize as the appropriate keyword. | ||
if (m_rotation_vector.x() == 1 && m_rotation_vector.y() == 0 && m_rotation_vector.z() == 0) | ||
return MUST(String::formatted("x {}", m_angle.to_string())); | ||
|
||
if (m_rotation_vector.x() == 0 && m_rotation_vector.y() == 1 && m_rotation_vector.z() == 0) | ||
return MUST(String::formatted("y {}", m_angle.to_string())); | ||
|
||
if (m_rotation_vector.x() != 0 || m_rotation_vector.y() != 0 || m_rotation_vector.z() != 0) | ||
return MUST(String::formatted("{} {} {} {}", m_rotation_vector.x(), m_rotation_vector.y(), m_rotation_vector.z(), m_angle.to_string())); | ||
|
||
// It must serialize as the keyword none if and only if none was originally specified. | ||
// NOTE: This is handled by returning a keyword from the parser. | ||
VERIFY_NOT_REACHED(); | ||
} | ||
|
||
bool RotationStyleValue::equals(CSSStyleValue const& other) const | ||
{ | ||
if (type() != other.type()) | ||
return false; | ||
auto const& other_angle = other.as_rotation(); | ||
return m_angle == other_angle.m_angle; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
Userland/Libraries/LibWeb/CSS/StyleValues/RotationStyleValue.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2024, Steffen T. Larssen <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <LibGfx/Vector3.h> | ||
#include <LibWeb/CSS/Angle.h> | ||
#include <LibWeb/CSS/StyleValues/CSSUnitValue.h> | ||
|
||
namespace Web::CSS { | ||
|
||
class RotationStyleValue : public CSSUnitValue { | ||
public: | ||
static ValueComparingNonnullRefPtr<RotationStyleValue> create(Angle angle, float x, float y, float z) | ||
{ | ||
return adopt_ref(*new (nothrow) RotationStyleValue(move(angle), x, y, z)); | ||
} | ||
virtual ~RotationStyleValue() override; | ||
|
||
Angle const& angle() const { return m_angle; } | ||
FloatVector3 const& rotation_vector() const { return m_rotation_vector; } | ||
|
||
// FIXME: Return the correct things here... | ||
virtual double value() const override { return m_angle.raw_value(); } | ||
virtual StringView unit() const override { return m_angle.unit_name(); } | ||
|
||
virtual String to_string() const override; | ||
|
||
bool equals(CSSStyleValue const& other) const override; | ||
|
||
private: | ||
explicit RotationStyleValue(Angle angle, float x, float y, float z); | ||
|
||
Angle m_angle; | ||
FloatVector3 m_rotation_vector; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters