summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
diff options
context:
space:
mode:
authorTobias Christiansen <tobyase@serenityos.org>2021-09-18 17:20:00 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-18 21:53:37 +0200
commit9ebfafafbe275910f161b6c2bc401994031a2d31 (patch)
tree31641dad700f1ea4cb6ce1f63fefd085c10195d7 /Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
parent74b88a8156a0ab10fc9523c3f5871e1185f10728 (diff)
downloadserenity-9ebfafafbe275910f161b6c2bc401994031a2d31.zip
LibWeb: Add transform property to the system
This patch adds parsing support as well as all the needed stuctures all over LibWeb to pass Transformations around.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/StyleProperties.cpp')
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleProperties.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
index e51111fd85..6fc9bc461b 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
@@ -424,6 +424,44 @@ Optional<CSS::JustifyContent> StyleProperties::justify_content() const
}
}
+Vector<CSS::Transformation> StyleProperties::transformations() const
+{
+ auto value = property(CSS::PropertyID::Transform);
+ if (!value.has_value())
+ return {};
+
+ if (value.value()->is_identifier() && value.value()->to_identifier() == CSS::ValueID::None)
+ return {};
+
+ if (!value.value()->is_value_list())
+ return {};
+
+ auto& list = static_cast<const StyleValueList&>(*value.value());
+
+ Vector<CSS::Transformation> transformations;
+
+ for (auto& it : list.values()) {
+ if (!it.is_transformation())
+ return {};
+ auto& transformation_style_value = static_cast<TransformationStyleValue const&>(it);
+ CSS::Transformation transformation;
+ transformation.function = transformation_style_value.transform_function();
+ Vector<Variant<CSS::Length, float>> values;
+ for (auto& transformation_value : transformation_style_value.values()) {
+ if (transformation_value.is_length()) {
+ values.append({ transformation_value.to_length() });
+ } else if (transformation_value.is_numeric()) {
+ values.append({ static_cast<NumericStyleValue const&>(transformation_value).value() });
+ } else {
+ dbgln("FIXME: Unsupported value in transform!");
+ }
+ }
+ transformation.values = move(values);
+ transformations.append(move(transformation));
+ }
+ return transformations;
+}
+
Optional<CSS::AlignItems> StyleProperties::align_items() const
{
auto value = property(CSS::PropertyID::AlignItems);