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.
This commit is contained in:
Timothy Flynn 2024-05-31 16:01:34 -04:00 committed by Andreas Kling
parent fe3fde2411
commit b01e810a89
Notes: sideshowbarker 2024-07-17 06:45:52 +09:00
10 changed files with 16 additions and 14 deletions

View file

@ -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)

View file

@ -5068,7 +5068,7 @@ void Document::set_needs_to_refresh_scroll_state(bool b)
paintable->set_needs_to_refresh_scroll_state(b);
}
Vector<JS::Handle<DOM::Range>> Document::find_matching_text(String const& query)
Vector<JS::Handle<DOM::Range>> Document::find_matching_text(String const& query, CaseSensitivity case_sensitivity)
{
if (!document_element() || !document_element()->layout_node())
return {};
@ -5078,7 +5078,9 @@ Vector<JS::Handle<DOM::Range>> 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;

View file

@ -667,7 +667,7 @@ public:
// Does document represent an embedded svg img
[[nodiscard]] bool is_decoded_svg() const;
Vector<JS::Handle<DOM::Range>> find_matching_text(String const&);
Vector<JS::Handle<DOM::Range>> find_matching_text(String const&, CaseSensitivity);
protected:
virtual void initialize(JS::Realm&) override;

View file

@ -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));
}

View file

@ -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();

View file

@ -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()

View file

@ -66,7 +66,7 @@ public:
ByteString selected_text();
Optional<String> 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&);

View file

@ -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)

View file

@ -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;

View file

@ -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) =|