mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibWeb: Exclude inert elements from find in page queries
This commit is contained in:
committed by
Sam Atkins
parent
d410fa8381
commit
2e27ffab6c
@@ -68,19 +68,22 @@ void Viewport::update_text_blocks()
|
|||||||
return TraversalDecision::Continue;
|
return TraversalDecision::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (layout_node.is_text_node()) {
|
if (auto* text_node = as_if<Layout::TextNode>(layout_node)) {
|
||||||
auto const& text_node = as<Layout::TextNode>(layout_node);
|
// https://html.spec.whatwg.org/multipage/interaction.html#inert-subtrees
|
||||||
auto& dom_node = const_cast<DOM::Text&>(text_node.dom_node());
|
// When a node is inert:
|
||||||
|
// - The user agent should ignore the node for the purposes of find-in-page.
|
||||||
|
if (auto& dom_node = const_cast<DOM::Text&>(text_node->dom_node()); !dom_node.is_inert()) {
|
||||||
if (text_positions.is_empty()) {
|
if (text_positions.is_empty()) {
|
||||||
text_positions.empend(dom_node);
|
text_positions.empend(dom_node);
|
||||||
} else {
|
} else {
|
||||||
text_positions.empend(dom_node, current_start_position);
|
text_positions.empend(dom_node, current_start_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto const& current_node_text = text_node.text_for_rendering();
|
auto const& current_node_text = text_node->text_for_rendering();
|
||||||
current_start_position += current_node_text.bytes_as_string_view().length();
|
current_start_position += current_node_text.bytes_as_string_view().length();
|
||||||
builder.append(move(current_node_text));
|
builder.append(move(current_node_text));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return TraversalDecision::Continue;
|
return TraversalDecision::Continue;
|
||||||
});
|
});
|
||||||
|
|||||||
2
Tests/LibWeb/Text/expected/HTML/Window-find-inert.txt
Normal file
2
Tests/LibWeb/Text/expected/HTML/Window-find-inert.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
window.find("inert") initial result: true
|
||||||
|
window.find("inert") second call: false
|
||||||
12
Tests/LibWeb/Text/input/HTML/Window-find-inert.html
Normal file
12
Tests/LibWeb/Text/input/HTML/Window-find-inert.html
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<div>not inert</div>
|
||||||
|
<div inert>inert</div>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
let initialResult = window.find("inert");
|
||||||
|
let secondCallResult = window.find("inert");
|
||||||
|
println(`window.find("inert") initial result: ${initialResult}`);
|
||||||
|
println(`window.find("inert") second call: ${secondCallResult}`);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user