diff options
author | Andreas Kling <kling@serenityos.org> | 2023-01-11 19:48:17 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-01-12 19:55:10 +0100 |
commit | 1c4328902d3d2ca9b519ded17a7acb9cb105969e (patch) | |
tree | 9ac93de772e918205e9032c381bf8fabb1d8bb9d /Userland/Libraries/LibWeb/HTML | |
parent | bf69f4370e07ccd84c9673de9c5c18e7ba3ecb63 (diff) | |
download | serenity-1c4328902d3d2ca9b519ded17a7acb9cb105969e.zip |
LibWeb: Implement BrowsingContext::select_all() in terms of Selection
We do what other browsers do and create a selection anchored at the
document's body element.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp | 47 |
1 files changed, 8 insertions, 39 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index d25709cf2c..5ef739105f 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -508,47 +508,16 @@ DeprecatedString BrowsingContext::selected_text() const void BrowsingContext::select_all() { - if (!active_document()) + auto* document = active_document(); + if (!document) return; - auto* layout_root = active_document()->layout_node(); - if (!layout_root) + auto* body = document->body(); + if (!body) return; - - Layout::Node const* 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; - } - - Layout::Node const* last_layout_node = first_layout_node; - - for (Layout::Node const* 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)) { - auto const& text_for_rendering = verify_cast<Layout::TextNode>(*last_layout_node).text_for_rendering(); - if (!text_for_rendering.is_empty()) - last_layout_node_index_in_node = text_for_rendering.length() - 1; - } - - auto start = Layout::LayoutPosition { - JS::make_handle(const_cast<Layout::Node*>(first_layout_node)), 0 - }; - auto end = Layout::LayoutPosition { - JS::make_handle(const_cast<Layout::Node*>(last_layout_node)), last_layout_node_index_in_node - }; - layout_root->set_selection({ move(start), move(end) }); + auto selection = document->get_selection(); + if (!selection) + return; + (void)selection->select_all_children(*document->body()); } void BrowsingContext::register_viewport_client(ViewportClient& client) |