mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
LibWeb+WebContent: Provide feedback on find in page requests
This change allows the results of a find in page query to be reported back to the user interface. Currently, the number of results found and the current match index are reported.
This commit is contained in:
parent
6957b87ac2
commit
d33c4c751f
Notes:
sideshowbarker
2024-07-16 22:18:54 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/d33c4c751f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/121 Reviewed-by: https://github.com/trflynn89 ✅
@ -548,14 +548,14 @@ void Page::clear_selection()
|
||||
}
|
||||
}
|
||||
|
||||
void Page::find_in_page(String const& query, CaseSensitivity case_sensitivity)
|
||||
Page::FindInPageResult Page::find_in_page(String const& query, CaseSensitivity case_sensitivity)
|
||||
{
|
||||
m_find_in_page_match_index = 0;
|
||||
|
||||
if (query.is_empty()) {
|
||||
m_find_in_page_matches = {};
|
||||
update_find_in_page_selection();
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
|
||||
auto documents = HTML::main_thread_event_loop().documents_in_this_event_loop();
|
||||
@ -573,12 +573,17 @@ void Page::find_in_page(String const& query, CaseSensitivity case_sensitivity)
|
||||
m_find_in_page_matches.append(*match);
|
||||
|
||||
update_find_in_page_selection();
|
||||
|
||||
return Page::FindInPageResult {
|
||||
.current_match_index = m_find_in_page_match_index,
|
||||
.total_match_count = m_find_in_page_matches.size(),
|
||||
};
|
||||
}
|
||||
|
||||
void Page::find_in_page_next_match()
|
||||
Page::FindInPageResult Page::find_in_page_next_match()
|
||||
{
|
||||
if (m_find_in_page_matches.is_empty())
|
||||
return;
|
||||
return {};
|
||||
|
||||
if (m_find_in_page_match_index == m_find_in_page_matches.size() - 1) {
|
||||
m_find_in_page_match_index = 0;
|
||||
@ -587,12 +592,17 @@ void Page::find_in_page_next_match()
|
||||
}
|
||||
|
||||
update_find_in_page_selection();
|
||||
|
||||
return Page::FindInPageResult {
|
||||
.current_match_index = m_find_in_page_match_index,
|
||||
.total_match_count = m_find_in_page_matches.size(),
|
||||
};
|
||||
}
|
||||
|
||||
void Page::find_in_page_previous_match()
|
||||
Page::FindInPageResult Page::find_in_page_previous_match()
|
||||
{
|
||||
if (m_find_in_page_matches.is_empty())
|
||||
return;
|
||||
return {};
|
||||
|
||||
if (m_find_in_page_match_index == 0) {
|
||||
m_find_in_page_match_index = m_find_in_page_matches.size() - 1;
|
||||
@ -601,6 +611,11 @@ void Page::find_in_page_previous_match()
|
||||
}
|
||||
|
||||
update_find_in_page_selection();
|
||||
|
||||
return Page::FindInPageResult {
|
||||
.current_match_index = m_find_in_page_match_index,
|
||||
.total_match_count = m_find_in_page_matches.size(),
|
||||
};
|
||||
}
|
||||
|
||||
void Page::update_find_in_page_selection()
|
||||
|
@ -181,9 +181,13 @@ public:
|
||||
|
||||
void clear_selection();
|
||||
|
||||
void find_in_page(String const& query, CaseSensitivity);
|
||||
void find_in_page_next_match();
|
||||
void find_in_page_previous_match();
|
||||
struct FindInPageResult {
|
||||
size_t current_match_index { 0 };
|
||||
Optional<size_t> total_match_count {};
|
||||
};
|
||||
FindInPageResult find_in_page(String const& query, CaseSensitivity);
|
||||
FindInPageResult find_in_page_next_match();
|
||||
FindInPageResult find_in_page_previous_match();
|
||||
|
||||
private:
|
||||
explicit Page(JS::NonnullGCPtr<PageClient>);
|
||||
|
@ -189,6 +189,7 @@ public:
|
||||
Function<void(Gfx::IntPoint content_position, i32 minimum_width, Vector<Web::HTML::SelectItem> items)> on_request_select_dropdown;
|
||||
Function<void(Web::KeyEvent const&)> on_finish_handling_key_event;
|
||||
Function<void()> on_text_test_finish;
|
||||
Function<void(size_t current_match_index, Optional<size_t> const& total_match_count)> on_find_in_page;
|
||||
Function<void(Gfx::Color)> on_theme_color_change;
|
||||
Function<void(String const&, String const&, String const&)> on_insert_clipboard_entry;
|
||||
Function<void(Web::HTML::AudioPlayState)> on_audio_play_state_changed;
|
||||
|
@ -78,6 +78,14 @@ void WebContentClient::did_finish_text_test(u64 page_id)
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::did_find_in_page(u64 page_id, size_t current_match_index, Optional<size_t> const& total_match_count)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_find_in_page)
|
||||
view->on_find_in_page(current_match_index, total_match_count);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::did_request_navigate_back(u64 page_id)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
|
@ -95,6 +95,7 @@ private:
|
||||
virtual void did_request_select_dropdown(u64 page_id, Gfx::IntPoint content_position, i32 minimum_width, Vector<Web::HTML::SelectItem> const& items) override;
|
||||
virtual void did_finish_handling_input_event(u64 page_id, bool event_was_accepted) override;
|
||||
virtual void did_finish_text_test(u64 page_id) override;
|
||||
virtual void did_find_in_page(u64 page_id, size_t current_match_index, Optional<size_t> const& total_match_count) override;
|
||||
virtual void did_change_theme_color(u64 page_id, Gfx::Color color) override;
|
||||
virtual void did_insert_clipboard_entry(u64 page_id, String const& data, String const& presentation_style, String const& mime_type) override;
|
||||
virtual void did_change_audio_play_state(u64 page_id, Web::HTML::AudioPlayState) override;
|
||||
|
@ -826,7 +826,8 @@ void ConnectionFromClient::find_in_page(u64 page_id, String const& query, CaseSe
|
||||
if (!page.has_value())
|
||||
return;
|
||||
|
||||
page->page().find_in_page(query, case_sensitivity);
|
||||
auto result = page->page().find_in_page(query, case_sensitivity);
|
||||
async_did_find_in_page(page_id, result.current_match_index, result.total_match_count);
|
||||
}
|
||||
|
||||
void ConnectionFromClient::find_in_page_next_match(u64 page_id)
|
||||
@ -835,7 +836,8 @@ void ConnectionFromClient::find_in_page_next_match(u64 page_id)
|
||||
if (!page.has_value())
|
||||
return;
|
||||
|
||||
page->page().find_in_page_next_match();
|
||||
auto result = page->page().find_in_page_next_match();
|
||||
async_did_find_in_page(page_id, result.current_match_index, result.total_match_count);
|
||||
}
|
||||
|
||||
void ConnectionFromClient::find_in_page_previous_match(u64 page_id)
|
||||
@ -844,7 +846,8 @@ void ConnectionFromClient::find_in_page_previous_match(u64 page_id)
|
||||
if (!page.has_value())
|
||||
return;
|
||||
|
||||
page->page().find_in_page_previous_match();
|
||||
auto result = page->page().find_in_page_previous_match();
|
||||
async_did_find_in_page(page_id, result.current_match_index, result.total_match_count);
|
||||
}
|
||||
|
||||
void ConnectionFromClient::paste(u64 page_id, String const& text)
|
||||
|
@ -88,6 +88,8 @@ endpoint WebContentClient
|
||||
|
||||
did_finish_text_test(u64 page_id) =|
|
||||
|
||||
did_find_in_page(u64 page_id, size_t current_match_index, Optional<size_t> total_match_count) =|
|
||||
|
||||
request_worker_agent(u64 page_id) => (IPC::File socket) // FIXME: Add required attributes to select a SharedWorker Agent
|
||||
|
||||
inspector_did_load(u64 page_id) =|
|
||||
|
Loading…
Reference in New Issue
Block a user