summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
diff options
context:
space:
mode:
authorTobias Christiansen <tobyase@serenityos.org>2021-09-18 18:42:27 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-18 21:53:37 +0200
commit6e1f6bd6842d391cf44dc2558e36748c0f22c4b1 (patch)
tree23af38ecec7d2c95ce795f3c635fd74c0c62509b /Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
parent9ebfafafbe275910f161b6c2bc401994031a2d31 (diff)
downloadserenity-6e1f6bd6842d391cf44dc2558e36748c0f22c4b1.zip
LibWeb: Add transform: translateY() support
This is very naive.
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp')
-rw-r--r--Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
index 17dee023af..a4fadbf6bf 100644
--- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
@@ -61,6 +61,42 @@ void BlockFormattingContext::run(Box& box, LayoutMode layout_mode)
return IterationDecision::Continue;
});
}
+
+ apply_transformations_to_children(box);
+}
+
+void BlockFormattingContext::apply_transformations_to_children(Box& box)
+{
+ box.for_each_child_of_type<Box>([&](auto& child_box) {
+ float transform_y_offset = 0.0f;
+ if (!child_box.computed_values().transformations().is_empty()) {
+ // FIXME: All transformations can be interpreted as successive 3D-matrix operations on the box, we don't do that yet.
+ // https://drafts.csswg.org/css-transforms/#serialization-of-the-computed-value
+ for (auto transformation : child_box.computed_values().transformations()) {
+ switch (transformation.function) {
+ case CSS::TransformFunction::TranslateY:
+ if (transformation.values.size() != 1)
+ continue;
+ transformation.values.first().visit(
+ [&](CSS::Length& value) {
+ transform_y_offset += value.resolved_or_zero(child_box, child_box.width()).to_px(child_box);
+ },
+ [&](float value) {
+ transform_y_offset += value;
+ },
+ [&](auto&) {
+ dbgln("FIXME: Implement unsupported transformation function value type!");
+ });
+ break;
+ default:
+ dbgln("FIXME: Implement missing transform function!");
+ }
+ }
+ }
+
+ auto untransformed_offset = child_box.effective_offset();
+ child_box.set_offset(untransformed_offset.x(), untransformed_offset.y() + transform_y_offset);
+ });
}
void BlockFormattingContext::compute_width(Box& box)