diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-07-14 08:38:10 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-14 17:16:39 +0200 |
commit | fea7e84b266c743acdee9b198c69598e4db6de48 (patch) | |
tree | 29788d6f9f9aaa8b927e87a9e96a1b8e3e16778b /Userland/Libraries | |
parent | 58cb37f986dbabd2973d5b975a1166a6f240647e (diff) | |
download | serenity-fea7e84b266c743acdee9b198c69598e4db6de48.zip |
LibWeb: Move select-all implementation to BrowsingContext
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/InProcessWebView.cpp | 31 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Page/BrowsingContext.cpp | 36 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Page/BrowsingContext.h | 1 |
3 files changed, 38 insertions, 30 deletions
diff --git a/Userland/Libraries/LibWeb/InProcessWebView.cpp b/Userland/Libraries/LibWeb/InProcessWebView.cpp index 0379e50dfb..8e0f8fd8ce 100644 --- a/Userland/Libraries/LibWeb/InProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/InProcessWebView.cpp @@ -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(); } diff --git a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp index 17b5f47876..70d9beeb4b 100644 --- a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp @@ -275,6 +275,42 @@ String BrowsingContext::selected_text() const return builder.to_string(); } +void BrowsingContext::select_all() +{ + if (!m_document) + return; + auto* layout_root = m_document->layout_node(); + 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 } }); +} + void BrowsingContext::register_viewport_client(ViewportClient& client) { auto result = m_viewport_clients.set(&client); diff --git a/Userland/Libraries/LibWeb/Page/BrowsingContext.h b/Userland/Libraries/LibWeb/Page/BrowsingContext.h index df89a12c6d..77229647a2 100644 --- a/Userland/Libraries/LibWeb/Page/BrowsingContext.h +++ b/Userland/Libraries/LibWeb/Page/BrowsingContext.h @@ -80,6 +80,7 @@ public: bool cursor_blink_state() const { return m_cursor_blink_state; } String selected_text() const; + void select_all(); void did_edit(Badge<EditEventHandler>); |