1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:38:11 +00:00

LibWeb: Move select-all implementation to BrowsingContext

This commit is contained in:
Timothy Flynn 2021-07-14 08:38:10 -04:00 committed by Andreas Kling
parent 58cb37f986
commit fea7e84b26
3 changed files with 38 additions and 30 deletions

View file

@ -54,36 +54,7 @@ InProcessWebView::~InProcessWebView()
void InProcessWebView::select_all()
{
auto* layout_root = this->layout_root();
if (!layout_root)
return;
const Layout::Node* first_layout_node = layout_root;
for (;;) {
auto* next = first_layout_node->next_in_pre_order();
if (!next)
break;
first_layout_node = next;
if (is<Layout::TextNode>(*first_layout_node))
break;
}
const Layout::Node* last_layout_node = first_layout_node;
for (const Layout::Node* layout_node = first_layout_node; layout_node; layout_node = layout_node->next_in_pre_order()) {
if (is<Layout::TextNode>(*layout_node))
last_layout_node = layout_node;
}
VERIFY(first_layout_node);
VERIFY(last_layout_node);
int last_layout_node_index_in_node = 0;
if (is<Layout::TextNode>(*last_layout_node))
last_layout_node_index_in_node = verify_cast<Layout::TextNode>(*last_layout_node).text_for_rendering().length() - 1;
layout_root->set_selection({ { first_layout_node, 0 }, { last_layout_node, last_layout_node_index_in_node } });
page().focused_context().select_all();
update();
}