Skip to content

Truly independent web browser

LibWeb: Drop the conservative style reset of animated SVG boxes

Aliaksandr Kalenik1aa8d5942177
diff --git a/Libraries/LibWeb/Layout/Node.cpp b/Libraries/LibWeb/Layout/Node.cpp
index 93fc5c4b88e..4d0ee2c829f 100644
--- a/Libraries/LibWeb/Layout/Node.cpp
+++ b/Libraries/LibWeb/Layout/Node.cpp
@@ -529,11 +529,7 @@ void NodeWithStyle::set_style_record_identity(CSS::InstalledStyle const& install
? held_before.view()
: document().style_computer().style_engine().style_record_view(held_read(), m_style_record_identity);
}
- // NB: SVG geometry can depend on animation composition. Keep its conservative reset.
- bool svg_animation_may_affect_intrinsic_sizes = is_svg_box()
- && (old_record_view.animation_overlay_identity != 0 || new_record_view.animation_overlay_identity != 0);
bool changes_layout_affecting_style = !old_record_view.present
- || svg_animation_may_affect_intrinsic_sizes
|| !CSS::ComputedValuesFFI::rust_style_payloads_layout_inputs_equal(old_record_view.payloads, new_record_view.payloads, is_svg_box());
release_pinned_style_record();
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/animated-svg-geometry-matches-full-rebuild.txt b/Tests/LibWeb/Text/expected/css/style-engine/animated-svg-geometry-matches-full-rebuild.txt
new file mode 100644
index 00000000000..6f5728b5890
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/style-engine/animated-svg-geometry-matches-full-rebuild.txt
@@ -0,0 +1,9 @@
+rect sample changes geometry: true
+circle sample changes geometry: true
+path sample changes geometry: true
+opacity sample changes geometry: false
+animated SVG layout stays consistent: true
+rect geometry matches fresh layout: true
+circle geometry matches fresh layout: true
+path geometry matches fresh layout: true
+opacity geometry matches fresh layout: true
diff --git a/Tests/LibWeb/Text/input/css/style-engine/animated-svg-geometry-matches-full-rebuild.html b/Tests/LibWeb/Text/input/css/style-engine/animated-svg-geometry-matches-full-rebuild.html
new file mode 100644
index 00000000000..36a8973fe1b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/style-engine/animated-svg-geometry-matches-full-rebuild.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<svg width="200" height="100">
+ <rect id="rect" x="10" y="10" width="10" height="10" stroke="black" stroke-width="2" />
+ <circle id="circle" cx="60" cy="50" r="5" />
+ <path id="path" d="M 100 10 L 110 10 L 110 20 Z" />
+ <rect id="opacity" x="150" y="10" width="10" height="10" />
+</svg>
+<script>
+ test(() => {
+ const animations = [
+ rect.animate({ width: ["10px", "30px"], strokeWidth: ["2px", "6px"] }, { duration: 1000, fill: "both" }),
+ circle.animate({ r: ["5px", "25px"] }, { duration: 1000, fill: "both" }),
+ path.animate({ d: ['path("M 100 10 L 110 10 L 110 20 Z")', 'path("M 100 10 L 150 10 L 150 60 Z")'] }, { duration: 1000, fill: "both" }),
+ opacity.animate({ opacity: [1, 0] }, { duration: 1000, fill: "both" }),
+ ];
+ const shapes = [rect, circle, path, opacity];
+ for (const animation of animations) {
+ animation.pause();
+ animation.currentTime = 0;
+ }
+ internals.updateStyle();
+ const widthsBefore = shapes.map(shape => shape.getBoundingClientRect().width);
+ for (const animation of animations)
+ animation.currentTime = 500;
+ internals.updateStyle();
+ const sampledWidths = shapes.map(shape => shape.getBoundingClientRect().width);
+ for (const [index, shape] of shapes.entries())
+ println(`${shape.id} sample changes geometry: ${sampledWidths[index] !== widthsBefore[index]}`);
+ println(`animated SVG layout stays consistent: ${internals.compareLayoutTreeWithFullRebuild().matches}`);
+ for (const [index, shape] of shapes.entries())
+ println(`${shape.id} geometry matches fresh layout: ${shape.getBoundingClientRect().width === sampledWidths[index]}`);
+ });
+</script>