Skip to content

Commit d410fa8

Browse files
tcl3AtkinsSJ
authored andcommitted
LibWeb: Ensure inert elements are not selectable
1 parent cb405c7 commit d410fa8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Libraries/LibWeb/Painting/ViewportPaintable.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,35 +298,38 @@ void ViewportPaintable::recompute_selection_states(DOM::Range& range)
298298
}
299299

300300
// 2. If it's a text node, mark it as StartAndEnd and return.
301-
if (is<DOM::Text>(*start_container)) {
301+
if (is<DOM::Text>(*start_container) && !range.start().node->is_inert()) {
302302
if (auto* paintable = start_container->paintable())
303303
paintable->set_selection_state(SelectionState::StartAndEnd);
304304
return;
305305
}
306306
}
307307

308308
// 3. Mark the selection start node as Start (if text) or Full (if anything else).
309-
if (auto* paintable = start_container->paintable()) {
309+
if (auto* paintable = start_container->paintable(); paintable && !range.start().node->is_inert()) {
310310
if (is<DOM::Text>(*start_container))
311311
paintable->set_selection_state(SelectionState::Start);
312312
else
313313
paintable->set_selection_state(SelectionState::Full);
314314
}
315315

316316
// 4. Mark the selection end node as End (if text) or Full (if anything else).
317-
if (auto* paintable = end_container->paintable()) {
317+
if (auto* paintable = end_container->paintable(); paintable && !range.end().node->is_inert()) {
318318
if (is<DOM::Text>(*end_container) || end_container->is_ancestor_of(start_container)) {
319319
paintable->set_selection_state(SelectionState::End);
320320
} else {
321321
paintable->for_each_in_inclusive_subtree([&](auto& layout_node) {
322-
layout_node.set_selection_state(SelectionState::Full);
322+
if (!layout_node.dom_node() || !layout_node.dom_node()->is_inert())
323+
layout_node.set_selection_state(SelectionState::Full);
323324
return TraversalDecision::Continue;
324325
});
325326
}
326327
}
327328

328329
// 5. Mark the nodes between start node and end node (in tree order) as Full.
329330
for (auto* node = start_container->next_in_pre_order(); node && (node->is_before(end_container) || node->is_descendant_of(end_container)); node = node->next_in_pre_order()) {
331+
if (node->is_inert())
332+
continue;
330333
if (auto* paintable = node->paintable())
331334
paintable->set_selection_state(SelectionState::Full);
332335
}

0 commit comments

Comments
 (0)