mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibWeb: Add mode flag to CSSStyleValue::to_string()
This will be used to differentiate between serialization for resolved style (i.e window.getComputedStyle()) and serialization for all other purposes.
This commit is contained in:
parent
c1b29e7cc4
commit
e85c3c97fb
Notes:
github-actions[bot]
2024-12-07 08:32:08 +00:00
Author: https://github.com/awesomekling
Commit: e85c3c97fb
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2820
Reviewed-by: https://github.com/AtkinsSJ ✅
112 changed files with 217 additions and 208 deletions
|
@ -13,7 +13,7 @@
|
|||
namespace Web::CSS {
|
||||
|
||||
// https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#individual-transform-serialization
|
||||
String RotationStyleValue::to_string() const
|
||||
String RotationStyleValue::to_string(SerializationMode mode) const
|
||||
{
|
||||
auto resolve_to_number = [](ValueComparingNonnullRefPtr<CSSStyleValue const> const& value) -> Optional<double> {
|
||||
if (value->is_number())
|
||||
|
@ -30,20 +30,20 @@ String RotationStyleValue::to_string() const
|
|||
|
||||
// If the axis is parallel with the x or y axes, it must serialize as the appropriate keyword.
|
||||
if (x_value > 0.0 && y_value == 0 && z_value == 0)
|
||||
return MUST(String::formatted("x {}", m_properties.angle->to_string()));
|
||||
return MUST(String::formatted("x {}", m_properties.angle->to_string(mode)));
|
||||
|
||||
if (x_value == 0 && y_value > 0.0 && z_value == 0)
|
||||
return MUST(String::formatted("y {}", m_properties.angle->to_string()));
|
||||
return MUST(String::formatted("y {}", m_properties.angle->to_string(mode)));
|
||||
|
||||
// If a rotation about the z axis (that is, in 2D) is specified, the property must serialize as just an <angle>.
|
||||
if (x_value == 0 && y_value == 0 && z_value > 0.0)
|
||||
return m_properties.angle->to_string();
|
||||
return m_properties.angle->to_string(mode);
|
||||
|
||||
// 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.
|
||||
|
||||
// If any other rotation is specified, the property must serialize with an axis specified.
|
||||
return MUST(String::formatted("{} {} {} {}", m_properties.rotation_x->to_string(), m_properties.rotation_y->to_string(), m_properties.rotation_z->to_string(), m_properties.angle->to_string()));
|
||||
return MUST(String::formatted("{} {} {} {}", m_properties.rotation_x->to_string(mode), m_properties.rotation_y->to_string(mode), m_properties.rotation_z->to_string(mode), m_properties.angle->to_string(mode)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue