Skip to content

Truly independent web browser

LibWeb: Note a table's wrapper for every visual context change

Aliaksandr Kalenik4745aa803ea6
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 34b9320cc6d..fc74ee8efa8 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -10996,11 +10996,18 @@ void Document::schedule_accumulated_visual_context_update(Layout::Node const& la
{
if (!Painting::has_committed_box(layout_node))
return;
- auto slot = Painting::committed_row_slot(layout_node);
- Layout::RustFFI::render_state_note_visual_context_style_change(
- layout_node_arena().host(),
- slot,
- scope == AccumulatedVisualContextUpdateScope::Structure);
+ auto note_style_change = [&](Layout::Node const& box) {
+ Layout::RustFFI::render_state_note_visual_context_style_change(
+ layout_node_arena().host(),
+ Painting::committed_row_slot(box),
+ scope == AccumulatedVisualContextUpdateScope::Structure);
+ };
+ note_style_change(layout_node);
+ // A table box's wrapper carries table properties of its own, such as its clip and what makes its stacking context,
+ // so the visual contexts they make move with the table's.
+ if (auto const* wrapper = layout_node.parent(); wrapper && wrapper->is_table_wrapper()
+ && Painting::display(layout_node).is_table_inside() && Painting::has_committed_box(*wrapper))
+ note_style_change(*wrapper);
set_needs_accumulated_visual_contexts_update(true);
}
diff --git a/Libraries/LibWeb/Painting/BoxViews.cpp b/Libraries/LibWeb/Painting/BoxViews.cpp
index 9b5b34781e3..f6a2e6d4eac 100644
--- a/Libraries/LibWeb/Painting/BoxViews.cpp
+++ b/Libraries/LibWeb/Painting/BoxViews.cpp
@@ -811,14 +811,8 @@ void repaint_after_style_change(Layout::Node const& node, CSS::RequiredInvalidat
set_needs_repaint(node, invalidation.invalidates_hit_test_display_list() ? InvalidateDisplayList::PaintCommandsAndHitTestList : InvalidateDisplayList::PaintCommands);
if (invalidation.repaint_propagated_text_decorations)
invalidate_propagated_text_decoration_caches(node);
- if (invalidation.needs_stacking_context_tree_rebuild()) {
- auto& document = const_cast<DOM::Document&>(node.document());
- document.schedule_accumulated_visual_context_update(node, DOM::Document::AccumulatedVisualContextUpdateScope::Structure);
- auto const* table_wrapper_carrying_the_moved_table_properties
- = display(node).is_table_inside() && node.parent() && node.parent()->is_table_wrapper() ? node.parent() : nullptr;
- if (table_wrapper_carrying_the_moved_table_properties)
- document.schedule_accumulated_visual_context_update(*table_wrapper_carrying_the_moved_table_properties, DOM::Document::AccumulatedVisualContextUpdateScope::Structure);
- }
+ if (invalidation.needs_stacking_context_tree_rebuild())
+ const_cast<DOM::Document&>(node.document()).schedule_accumulated_visual_context_update(node, DOM::Document::AccumulatedVisualContextUpdateScope::Structure);
}
Layout::RustFFI::FfiRectToViewportTransform identity_rect_to_viewport_transform()
diff --git a/Tests/LibWeb/Text/expected/css/clip-change-on-positioned-table.txt b/Tests/LibWeb/Text/expected/css/clip-change-on-positioned-table.txt
new file mode 100644
index 00000000000..5ebc62eb4cf
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/clip-change-on-positioned-table.txt
@@ -0,0 +1,2 @@
+before: HTML
+after: cell
diff --git a/Tests/LibWeb/Text/input/css/clip-change-on-positioned-table.html b/Tests/LibWeb/Text/input/css/clip-change-on-positioned-table.html
new file mode 100644
index 00000000000..9d9d321320b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/clip-change-on-positioned-table.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ body { margin: 0; }
+</style>
+<table id="table" style="position: absolute; top: 0; left: 0; border-spacing: 0; clip: rect(0, 50px, 50px, 0);">
+ <tr><td id="cell" style="padding: 0; width: 100px; height: 100px; background: green;"></td></tr>
+</table>
+<script>
+ // The wrapper of a positioned table carries its clip, so a change of the clip clips the table anew.
+ test(() => {
+ const hit = () => {
+ const element = document.elementFromPoint(75, 75);
+ return element.id || element.nodeName;
+ };
+ println(`before: ${hit()}`);
+ table.style.clip = "rect(0, 100px, 100px, 0)";
+ println(`after: ${hit()}`);
+ });
+</script>