From b01e810a89d04ea27b844e813257d2d9356264e2 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 31 May 2024 16:01:34 -0400 Subject: [PATCH] LibWeb+LibWebView+WebContent: Support case-insensitive find-in-page This allows searching for text with case-insensitivity. As this is probably what most users expect, the default behavior is changes to perform case-insensitive lookups. Chromes may add UI to change the behavior as they see fit. --- Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp | 2 +- Userland/Libraries/LibWeb/DOM/Document.cpp | 6 ++++-- Userland/Libraries/LibWeb/DOM/Document.h | 2 +- Userland/Libraries/LibWeb/Page/Page.cpp | 4 ++-- Userland/Libraries/LibWeb/Page/Page.h | 2 +- Userland/Libraries/LibWebView/ViewImplementation.cpp | 4 ++-- Userland/Libraries/LibWebView/ViewImplementation.h | 2 +- Userland/Services/WebContent/ConnectionFromClient.cpp | 4 ++-- Userland/Services/WebContent/ConnectionFromClient.h | 2 +- Userland/Services/WebContent/WebContentServer.ipc | 2 +- 10 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp index 4299a505e80..ba0e5d28767 100644 --- a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp @@ -70,7 +70,7 @@ static bool is_primitive_type(ByteString const& type) static bool is_simple_type(ByteString const& type) { // Small types that it makes sense just to pass by value. - return type.is_one_of("Gfx::Color", "Web::DevicePixels", "Gfx::IntPoint", "Gfx::FloatPoint", "Web::DevicePixelPoint", "Gfx::IntSize", "Gfx::FloatSize", "Web::DevicePixelSize", "Core::File::OpenMode", "Web::Cookie::Source", "Web::HTML::AllowMultipleFiles", "Web::HTML::AudioPlayState", "Web::HTML::HistoryHandlingBehavior"); + return type.is_one_of("AK::CaseSensitivity", "Gfx::Color", "Web::DevicePixels", "Gfx::IntPoint", "Gfx::FloatPoint", "Web::DevicePixelPoint", "Gfx::IntSize", "Gfx::FloatSize", "Web::DevicePixelSize", "Core::File::OpenMode", "Web::Cookie::Source", "Web::HTML::AllowMultipleFiles", "Web::HTML::AudioPlayState", "Web::HTML::HistoryHandlingBehavior"); } static bool is_primitive_or_simple_type(ByteString const& type) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 5706f2b513e..de28809beae 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -5068,7 +5068,7 @@ void Document::set_needs_to_refresh_scroll_state(bool b) paintable->set_needs_to_refresh_scroll_state(b); } -Vector> Document::find_matching_text(String const& query) +Vector> Document::find_matching_text(String const& query, CaseSensitivity case_sensitivity) { if (!document_element() || !document_element()->layout_node()) return {}; @@ -5078,7 +5078,9 @@ Vector> Document::find_matching_text(String const& query) auto const& text = text_node.text_for_rendering(); size_t offset = 0; while (true) { - auto match_index = text.find_byte_offset(query, offset); + auto match_index = case_sensitivity == CaseSensitivity::CaseInsensitive + ? text.find_byte_offset_ignoring_case(query, offset) + : text.find_byte_offset(query, offset); if (!match_index.has_value()) break; diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index ef588725f93..6108a6cbf94 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -667,7 +667,7 @@ public: // Does document represent an embedded svg img [[nodiscard]] bool is_decoded_svg() const; - Vector> find_matching_text(String const&); + Vector> find_matching_text(String const&, CaseSensitivity); protected: virtual void initialize(JS::Realm&) override; diff --git a/Userland/Libraries/LibWeb/Page/Page.cpp b/Userland/Libraries/LibWeb/Page/Page.cpp index 7b8eaf1fa8c..b93f725952c 100644 --- a/Userland/Libraries/LibWeb/Page/Page.cpp +++ b/Userland/Libraries/LibWeb/Page/Page.cpp @@ -539,7 +539,7 @@ void Page::clear_selection() } } -void Page::find_in_page(String const& query) +void Page::find_in_page(String const& query, CaseSensitivity case_sensitivity) { m_find_in_page_match_index = 0; @@ -555,7 +555,7 @@ void Page::find_in_page(String const& query) if (&document->page() != this) continue; - auto matches = document->find_matching_text(query); + auto matches = document->find_matching_text(query, case_sensitivity); all_matches.extend(move(matches)); } diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index 2911089cd6a..1a836db63d9 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -180,7 +180,7 @@ public: void clear_selection(); - void find_in_page(String const& query); + void find_in_page(String const& query, CaseSensitivity); void find_in_page_next_match(); void find_in_page_previous_match(); diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp index 1fc13499ce2..8477f895e16 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.cpp +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -180,9 +180,9 @@ void ViewImplementation::paste(String const& text) client().async_paste(page_id(), text); } -void ViewImplementation::find_in_page(String const& query) +void ViewImplementation::find_in_page(String const& query, CaseSensitivity case_sensitivity) { - client().async_find_in_page(page_id(), query); + client().async_find_in_page(page_id(), query, case_sensitivity); } void ViewImplementation::find_in_page_next_match() diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index dcc242e7870..c79d939368d 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -66,7 +66,7 @@ public: ByteString selected_text(); Optional selected_text_with_whitespace_collapsed(); void select_all(); - void find_in_page(String const& query); + void find_in_page(String const& query, CaseSensitivity = CaseSensitivity::CaseInsensitive); void find_in_page_next_match(); void find_in_page_previous_match(); void paste(String const&); diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index 3fe422f0399..84b68499b9f 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -827,13 +827,13 @@ void ConnectionFromClient::select_all(u64 page_id) page->page().focused_navigable().select_all(); } -void ConnectionFromClient::find_in_page(u64 page_id, String const& query) +void ConnectionFromClient::find_in_page(u64 page_id, String const& query, CaseSensitivity case_sensitivity) { auto page = this->page(page_id); if (!page.has_value()) return; - page->page().find_in_page(query); + page->page().find_in_page(query, case_sensitivity); } void ConnectionFromClient::find_in_page_next_match(u64 page_id) diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h index e487facd25f..60175ee5a41 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.h +++ b/Userland/Services/WebContent/ConnectionFromClient.h @@ -130,7 +130,7 @@ private: virtual Messages::WebContentServer::GetSelectedTextResponse get_selected_text(u64 page_id) override; virtual void select_all(u64 page_id) override; - virtual void find_in_page(u64 page_id, String const& query) override; + virtual void find_in_page(u64 page_id, String const& query, CaseSensitivity) override; virtual void find_in_page_next_match(u64 page_id) override; virtual void find_in_page_previous_match(u64 page_id) override; diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index b58f06ef7bd..4c293c6bab3 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -69,7 +69,7 @@ endpoint WebContentServer select_all(u64 page_id) =| paste(u64 page_id, String text) =| - find_in_page(u64 page_id, String query) =| + find_in_page(u64 page_id, String query, AK::CaseSensitivity case_sensitivity) =| find_in_page_next_match(u64 page_id) =| find_in_page_previous_match(u64 page_id) =|