Skip to content

Truly independent web browser

LibWebView+UI/Qt: Change the omnibox popup once per change to the text

Andreas Kling3ef5dacd1e3e
diff --git a/Libraries/LibWebView/Omnibox.cpp b/Libraries/LibWebView/Omnibox.cpp
index 9e63b5e6a45..0fde1e05ead 100644
--- a/Libraries/LibWebView/Omnibox.cpp
+++ b/Libraries/LibWebView/Omnibox.cpp
@@ -156,8 +156,8 @@ Optional<URL::URL> url_for_omnibox_destination(StringView text, OmniboxDestinati
Omnibox::Omnibox(NonnullOwnPtr<OmniboxSuggestionProvider> provider)
: m_provider(move(provider))
{
- m_provider->on_suggestions = [this](auto query_id, auto suggestions) {
- received_suggestions(query_id, move(suggestions));
+ m_provider->on_suggestions = [this](auto query_id, auto suggestions, auto kind) {
+ received_suggestions(query_id, move(suggestions), kind);
};
}
@@ -246,6 +246,9 @@ void Omnibox::text_edited(String text, bool cursor_at_end)
// NB: Return now goes to the text as typed, so its row leads and is highlighted.
if (m_popup_visible && m_popup_query_id.has_value() && m_popup_query == m_query) {
move_typed_text_row_to_front(m_suggestions);
+ // NB: The popup still shows the rows in their old order, and takes the new one with the final rows for
+ // the text, or when the user steps through the rows.
+ m_popup_shows_current_suggestions = false;
m_selection = index_of_typed_text_suggestion(m_query, m_suggestions).map([](auto index) {
return Selection { index, Selection::Origin::Automatic };
});
@@ -331,7 +334,7 @@ void Omnibox::set_suspended(bool suspended)
// NB: The rows that arrived while suspended are shown now, as one more delivery.
if (was_suspended && !suspended) {
if (auto held_delivery = exchange(m_delivery_held_while_suspended, {}); held_delivery.has_value())
- received_suggestions(held_delivery->query_id, move(held_delivery->suggestions));
+ received_suggestions(held_delivery->query_id, move(held_delivery->suggestions), held_delivery->kind);
}
}
@@ -353,12 +356,12 @@ bool Omnibox::selection_is_explicit() const
return m_selection.has_value() && m_selection->origin == Selection::Origin::ExplicitChoice;
}
-void Omnibox::received_suggestions(AutocompleteQueryID query_id, Vector<AutocompleteSuggestion> suggestions)
+void Omnibox::received_suggestions(AutocompleteQueryID query_id, Vector<AutocompleteSuggestion> suggestions, AutocompleteResultKind kind)
{
if (!m_is_editing || m_active_query_id != query_id)
return;
if (m_is_suspended) {
- m_delivery_held_while_suspended = HeldDelivery { query_id, move(suggestions) };
+ m_delivery_held_while_suspended = HeldDelivery { query_id, move(suggestions), kind };
return;
}
@@ -380,6 +383,7 @@ void Omnibox::received_suggestions(AutocompleteQueryID query_id, Vector<Autocomp
m_popup_query_id = query_id;
m_popup_query = m_query;
m_suggestions = move(suggestions);
+ m_popup_shows_current_suggestions = false;
// NB: The selection indexes the old rows, and the chrome may read it while a completion is shown below.
m_selection = {};
@@ -411,6 +415,10 @@ void Omnibox::received_suggestions(AutocompleteQueryID query_id, Vector<Autocomp
if (on_suggestions_change)
on_suggestions_change();
}
+
+ // NB: The popup keeps the rows it shows until the final ones arrive, rather than showing each delivery on the way.
+ if (kind == AutocompleteResultKind::Final)
+ present_popup();
}
// When Return goes to the text as typed, because the user rejected a completion or because the top row may not be
@@ -544,7 +552,7 @@ void Omnibox::return_pressed()
if (auto index = suggestion_index_for_return(); index.has_value()) {
auto was_explicit = selection_is_explicit() && m_selection->index == *index;
- commit_suggestion(*index, true, was_explicit);
+ commit_suggestion(m_suggestions[*index], true, was_explicit);
return;
}
@@ -603,7 +611,7 @@ Optional<AutocompleteSuggestion const&> Omnibox::suggestion_for_return() const
// The chrome dismissed the popup without a key press (for example a click elsewhere in the window).
void Omnibox::popup_dismissed()
{
- if (!m_is_editing || !m_popup_visible)
+ if (!m_is_editing || (!m_popup_visible && !m_popup.is_visible))
return;
restore_query_display();
@@ -612,7 +620,7 @@ void Omnibox::popup_dismissed()
Omnibox::EscapeAction Omnibox::escape_pressed()
{
- if (!m_is_editing || !m_popup_visible)
+ if (!m_is_editing || (!m_popup_visible && !m_popup.is_visible))
return EscapeAction::EndEditing;
if (m_provenance == TextProvenance::InlineCompleted && !selection_is_explicit())
@@ -652,21 +660,28 @@ bool Omnibox::select_adjacent_suggestion(StepDirection direction)
auto count = m_suggestions.size();
auto step = direction == StepDirection::Next ? 1 : count - 1;
auto index = direction == StepDirection::Next ? 0 : count - 1;
- if (!m_popup_visible)
+ if (!m_popup_visible) {
show_popup();
- else if (m_selection.has_value())
- index = (m_selection->index + step) % count;
+ } else {
+ if (m_selection.has_value())
+ index = (m_selection->index + step) % count;
+ // NB: The user steps through the suggestions as they are now, so the popup shows them without waiting for the
+ // final ones.
+ if (!m_popup_shows_current_suggestions || !m_popup.is_visible)
+ present_popup();
+ }
highlight_suggestion(index, Selection::Origin::ExplicitChoice);
return true;
}
-void Omnibox::suggestion_clicked(size_t suggestion_index)
+void Omnibox::suggestion_clicked(size_t popup_row_index)
{
- if (!m_is_editing || suggestion_index >= m_suggestions.size())
+ if (!m_is_editing || popup_row_index >= m_popup.suggestions.size())
return;
- commit_suggestion(suggestion_index, true, true);
+ // NB: The click goes to the row the popup shows, even if newer suggestions have arrived that it does not show yet.
+ commit_suggestion(m_popup.suggestions[popup_row_index], true, true);
}
void Omnibox::highlight_suggestion(size_t suggestion_index, Selection::Origin origin)
@@ -695,9 +710,8 @@ void Omnibox::display_suggestion(size_t suggestion_index)
apply_preview(suggestion_text);
}
-void Omnibox::commit_suggestion(size_t suggestion_index, bool should_record_engagement, bool was_explicit)
+void Omnibox::commit_suggestion(AutocompleteSuggestion suggestion, bool should_record_engagement, bool was_explicit)
{
- auto suggestion = m_suggestions[suggestion_index];
auto destination_kind = suggestion.source == AutocompleteSuggestionSource::Search
? OmniboxDestinationKind::Search
: OmniboxDestinationKind::URL;
@@ -833,24 +847,46 @@ void Omnibox::show_popup()
m_popup_visible = true;
if (on_suggestions_change)
on_suggestions_change();
+ present_popup();
}
// Hides the popup; the rows are kept so the arrow keys can bring it back.
void Omnibox::close_popup()
{
- if (!m_popup_visible)
- return;
+ if (m_popup_visible) {
+ m_popup_visible = false;
+ m_selection = {};
+ if (on_suggestions_change)
+ on_suggestions_change();
+ }
- m_popup_visible = false;
- m_selection = {};
- if (on_suggestions_change)
- on_suggestions_change();
+ // NB: The popup may still show older rows while the suggestions it waits for are none at all.
+ if (m_popup.is_visible) {
+ m_popup.is_visible = false;
+ m_popup.selected_suggestion = {};
+ if (on_popup_change)
+ on_popup_change();
+ }
+}
+
+// Has the popup show the suggestions as they are now.
+void Omnibox::present_popup()
+{
+ m_popup.is_visible = m_popup_visible;
+ m_popup.suggestions = m_suggestions;
+ m_popup.selected_suggestion = selected_suggestion();
+ m_popup_shows_current_suggestions = true;
+ if (on_popup_change)
+ on_popup_change();
}
void Omnibox::set_selection(Optional<Selection> selection)
{
bool index_changed = selection.map([](auto const& s) { return s.index; }) != selected_suggestion();
m_selection = move(selection);
+ // NB: A row of older suggestions has another index, and the popup takes the selection along with the final ones.
+ if (m_popup_shows_current_suggestions)
+ m_popup.selected_suggestion = selected_suggestion();
if (index_changed && on_selection_change)
on_selection_change();
}
diff --git a/Libraries/LibWebView/Omnibox.h b/Libraries/LibWebView/Omnibox.h
index db9f4270b56..7a4e5a558e5 100644
--- a/Libraries/LibWebView/Omnibox.h
+++ b/Libraries/LibWebView/Omnibox.h
@@ -25,7 +25,9 @@ class WEBVIEW_API OmniboxSuggestionProvider {
public:
virtual ~OmniboxSuggestionProvider() = default;
- Function<void(AutocompleteQueryID, Vector<AutocompleteSuggestion>)> on_suggestions;
+ // The rows for a query end with a final delivery. Any before it are intermediate, such as the local rows while the
+ // remote ones load.
+ Function<void(AutocompleteQueryID, Vector<AutocompleteSuggestion>, AutocompleteResultKind)> on_suggestions;
virtual void query(AutocompleteQueryID, String, size_t max_suggestions) = 0;
virtual void cancel() = 0;
@@ -54,6 +56,10 @@ public:
// When results lag behind fast typing, Enter otherwise commits the current input through the browser's
// normal URL-or-search resolution. It never waits for a provider response that may arrive after the
// user's intent has changed.
+//
+// The popup shows a copy of the rows, which changes only to the final rows for the text. The model itself takes in
+// every delivery, so the text is completed and Return goes to the best row as soon as the first rows arrive, while the
+// popup changes once for each change to the text, rather than once for each delivery.
class WEBVIEW_API Omnibox {
AK_MAKE_NONCOPYABLE(Omnibox);
AK_MAKE_NONMOVABLE(Omnibox);
@@ -90,7 +96,8 @@ public:
void popup_dismissed();
bool select_next_suggestion();
bool select_previous_suggestion();
- void suggestion_clicked(size_t suggestion_index);
+ // The index is that of a row in the popup.
+ void suggestion_clicked(size_t popup_row_index);
void navigate_directly_to_query(String text);
static String text_for_paste_and_go_action(String const& clipboard_text, bool has_search_engine_enabled);
@@ -107,6 +114,14 @@ public:
return m_selection.map([](auto const& selection) { return selection.index; });
}
+ // What the popup shows, which lags behind the suggestions above until the final ones for the text arrive.
+ struct Popup {
+ bool is_visible { false };
+ Vector<AutocompleteSuggestion> suggestions;
+ Optional<size_t> selected_suggestion;
+ };
+ Popup const& popup() const { return m_popup; }
+
// Whether the selected suggestion was chosen by the user, rather than selected automatically.
bool selection_is_explicit() const;
// Whether the text on display is inline completed to a suggestion.
@@ -132,7 +147,11 @@ public:
// Callbacks to the chrome:
Function<void(Display const&)> on_display_change;
+ // The suggestions changed, which may change the editing icon and the completion's title.
Function<void()> on_suggestions_change;
+ // The popup opened, closed, or shows other rows.
+ Function<void()> on_popup_change;
+ // Another row is selected, in the suggestions and, while the popup shows them, in the popup.
Function<void()> on_selection_change;
Function<void(String)> on_commit;
@@ -166,7 +185,7 @@ private:
};
void start_query();
- void received_suggestions(AutocompleteQueryID, Vector<AutocompleteSuggestion>);
+ void received_suggestions(AutocompleteQueryID, Vector<AutocompleteSuggestion>, AutocompleteResultKind);
void stabilize_automatic_default(Vector<AutocompleteSuggestion>&, bool is_same_generation_refresh) const;
Optional<size_t> update_completion_for_suggestions(Vector<AutocompleteSuggestion> const&);
bool select_adjacent_suggestion(StepDirection);
@@ -175,7 +194,7 @@ private:
void move_typed_text_row_to_front(Vector<AutocompleteSuggestion>&) const;
bool return_goes_to_typed_text_regardless_of_suggestions() const;
Optional<size_t> suggestion_index_for_return() const;
- void commit_suggestion(size_t suggestion_index, bool record_engagement, bool was_explicit);
+ void commit_suggestion(AutocompleteSuggestion, bool record_engagement, bool was_explicit);
void commit_suggestion_text(String, OmniboxDestinationKind);
void commit_verbatim(String);
void adopt_display_text_as_query();
@@ -185,6 +204,7 @@ private:
void set_display(String text, Optional<size_t> selection_start);
void show_popup();
void close_popup();
+ void present_popup();
void abandon_popup_session();
void set_selection(Optional<Selection>);
void commit(String text, OmniboxDestinationKind);
@@ -207,6 +227,7 @@ private:
struct HeldDelivery {
AutocompleteQueryID query_id;
Vector<AutocompleteSuggestion> suggestions;
+ AutocompleteResultKind kind { AutocompleteResultKind::Final };
};
Optional<HeldDelivery> m_delivery_held_while_suspended;
@@ -243,6 +264,10 @@ private:
Vector<AutocompleteSuggestion> m_suggestions;
Optional<Selection> m_selection;
+ Popup m_popup;
+ // Whether the popup shows the suggestions as they are now, so that a row has the same index in both.
+ bool m_popup_shows_current_suggestions { false };
+
u64 m_next_query_id { 0 };
Optional<AutocompleteQueryID> m_active_query_id;
OmniboxDestinationKind m_destination_kind_for_last_commit { OmniboxDestinationKind::URL };
diff --git a/Tests/LibWebView/TestOmnibox.cpp b/Tests/LibWebView/TestOmnibox.cpp
index b0caeac67a9..5a434bca725 100644
--- a/Tests/LibWebView/TestOmnibox.cpp
+++ b/Tests/LibWebView/TestOmnibox.cpp
@@ -100,13 +100,20 @@ public:
deliver(query_ids.last(), move(suggestions));
}
- void deliver(WebView::AutocompleteQueryID query_id, Vector<AutocompleteSuggestion> suggestions)
+ void deliver(WebView::AutocompleteQueryID query_id, Vector<AutocompleteSuggestion> suggestions, WebView::AutocompleteResultKind kind = WebView::AutocompleteResultKind::Final)
{
- on_suggestions(query_id, move(suggestions));
+ on_suggestions(query_id, move(suggestions), kind);
if (after_delivery)
after_delivery();
}
+ // Rows that more are to follow for, such as the local rows while the remote ones load.
+ void deliver_intermediate(Vector<AutocompleteSuggestion> suggestions)
+ {
+ VERIFY(!query_ids.is_empty());
+ deliver(query_ids.last(), move(suggestions), WebView::AutocompleteResultKind::Intermediate);
+ }
+
Function<void()> after_delivery;
Vector<String> queries;
@@ -142,6 +149,11 @@ struct Harness {
};
omnibox.on_selection_change = [this] {
visible_selection = omnibox.selected_suggestion();
+ shown_popup.selected_suggestion = omnibox.popup().selected_suggestion;
+ };
+ omnibox.on_popup_change = [this] {
+ ++popup_changes;
+ shown_popup = omnibox.popup();
};
provider->after_delivery = [this] { check_invariants(); };
}
@@ -168,6 +180,24 @@ struct Harness {
if (omnibox.is_popup_visible() && !rows_match(visible_rows, omnibox.suggestions()))
fail("the chrome shows different rows than the model"sv);
+ // The chrome is told about every change to the popup too.
+ auto const& popup = omnibox.popup();
+ if (shown_popup.is_visible != popup.is_visible)
+ fail("the chrome shows the popup open or closed, unlike the popup of the model"sv);
+ if (popup.is_visible && shown_popup.selected_suggestion != popup.selected_suggestion)
+ fail("the chrome highlights a different row than the popup of the model"sv);
+ if (popup.is_visible && !rows_match(shown_popup.suggestions, popup.suggestions))
+ fail("the chrome shows different rows than the popup of the model"sv);
+ // Once the final rows for the text are here, the popup shows them.
+ if (omnibox.is_editing() && !omnibox.has_pending_suggestions() && popup_follows_every_delivery) {
+ if (popup.is_visible != omnibox.is_popup_visible())
+ fail("the popup is open or closed, unlike the model"sv);
+ if (popup.is_visible && !rows_match(popup.suggestions, omnibox.suggestions()))
+ fail("the popup shows other rows than the final ones"sv);
+ if (popup.is_visible && popup.selected_suggestion != omnibox.selected_suggestion())
+ fail("the popup highlights another row than the model"sv);
+ }
+
if (!omnibox.is_editing() || !omnibox.is_popup_visible())
return;
@@ -301,6 +331,12 @@ struct Harness {
Vector<String> commits;
Vector<WebView::OmniboxDestinationKind> commit_destination_kinds;
+ // The popup as the chrome draws it.
+ size_t popup_changes { 0 };
+ Omnibox::Popup shown_popup;
+ // Unset by a test that delivers intermediate rows, which the popup does not show.
+ bool popup_follows_every_delivery { true };
+
size_t popup_repaints { 0 };
bool visible_popup { false };
Vector<AutocompleteSuggestion> visible_rows;
@@ -2028,3 +2064,134 @@ TEST_CASE(scenario_typed_text_with_a_scheme_does_not_offer_a_search)
EXPECT_EQ(scenario.top_row().source, AutocompleteSuggestionSource::LiteralURL);
EXPECT(!scenario.harness.omnibox.suggestions().contains([](auto const& row) { return row.source == AutocompleteSuggestionSource::Search; }));
}
+
+TEST_CASE(the_popup_waits_for_the_final_rows)
+{
+ Harness harness;
+ harness.popup_follows_every_delivery = false;
+ harness.begin_editing();
+
+ // The local rows complete the text at once, and Return goes to them, but the popup stays closed.
+ harness.press_key('t');
+ harness.provider->deliver_intermediate({ history_row("https://www.twin.example/"sv), search_row("t"sv) });
+ EXPECT_EQ(harness.display_text, "twin.example"sv);
+ EXPECT(harness.omnibox.is_popup_visible());
+ EXPECT(!harness.shown_popup.is_visible);
+ EXPECT_EQ(harness.popup_changes, 0u);
+
+ // The popup opens with the final rows.
+ harness.provider->deliver({ history_row("https://www.twin.example/"sv), search_row("t"sv), search_row("tea"sv) });
+ EXPECT(harness.shown_popup.is_visible);
+ EXPECT_EQ(harness.shown_popup.suggestions.size(), 3u);
+ EXPECT_EQ(harness.shown_popup.selected_suggestion, 0u);
+ EXPECT_EQ(harness.popup_changes, 1u);
+
+ // It keeps those rows as the text changes and as the local rows for the new text arrive.
+ harness.press_key('h');
+ harness.provider->deliver_intermediate({ history_row("https://www.thee.example/"sv), search_row("th"sv) });
+ EXPECT_EQ(harness.display_text, "thee.example"sv);
+ EXPECT_EQ(harness.omnibox.suggestions().size(), 2u);
+ EXPECT_EQ(harness.shown_popup.suggestions.size(), 3u);
+ EXPECT_EQ(harness.shown_popup.suggestions.first().text, "https://www.twin.example/"sv);
+ EXPECT_EQ(harness.popup_changes, 1u);
+
+ // It changes once for the key press, to the final rows.
+ harness.provider->deliver({ history_row("https://www.thee.example/"sv), search_row("th"sv), search_row("the"sv), search_row("they"sv) });
+ EXPECT_EQ(harness.shown_popup.suggestions.size(), 4u);
+ EXPECT_EQ(harness.shown_popup.suggestions.first().text, "https://www.thee.example/"sv);
+ EXPECT_EQ(harness.popup_changes, 2u);
+
+ // Return goes to the completion without waiting for the popup.
+ harness.press_key('e');
+ harness.provider->deliver_intermediate({ history_row("https://www.thee.example/"sv), search_row("the"sv) });
+ harness.omnibox.return_pressed();
+ EXPECT_EQ(harness.commits.size(), 1u);
+ EXPECT_EQ(harness.commits.last(), "https://www.thee.example/"sv);
+ EXPECT(!harness.shown_popup.is_visible);
+}
+
+TEST_CASE(stepping_through_the_rows_shows_them_before_the_final_ones)
+{
+ Harness harness;
+ harness.popup_follows_every_delivery = false;
+ harness.begin_editing();
+
+ harness.press_key('t');
+ harness.provider->deliver({ search_row("t"sv), search_row("tea"sv) });
+ harness.press_key('h');
+ harness.provider->deliver_intermediate({ search_row("th"sv), history_row("https://www.thee.example/"sv) });
+ EXPECT_EQ(harness.shown_popup.suggestions.first().text, "t"sv);
+
+ // The arrow keys step through the rows as they are now, so the popup shows them.
+ EXPECT(harness.omnibox.select_next_suggestion());
+ EXPECT_EQ(harness.shown_popup.suggestions.size(), 2u);
+ EXPECT_EQ(harness.shown_popup.suggestions.first().text, "th"sv);
+ EXPECT_EQ(harness.shown_popup.selected_suggestion, 1u);
+ EXPECT_EQ(harness.display_text, "thee.example"sv);
+
+ // The chosen row stays chosen in the final rows.
+ harness.provider->deliver({ search_row("th"sv), search_row("the"sv), history_row("https://www.thee.example/"sv) });
+ EXPECT_EQ(harness.shown_popup.suggestions.size(), 3u);
+ EXPECT_EQ(harness.shown_popup.selected_suggestion, 2u);
+ harness.omnibox.return_pressed();
+ EXPECT_EQ(harness.commits.last(), "https://www.thee.example/"sv);
+}
+
+TEST_CASE(stepping_through_the_rows_after_deleting_a_completion_shows_their_new_order)
+{
+ Harness harness;
+ harness.popup_follows_every_delivery = false;
+ harness.begin_editing();
+
+ harness.press_key('t');
+ harness.provider->deliver({ history_row("https://www.twin.example/"sv), search_row("t"sv) });
+ EXPECT_EQ(harness.display_text, "twin.example"sv);
+
+ // Deleting the completion moves the row for the typed text to the top, which the popup shows with the final rows.
+ harness.press_backspace();
+ EXPECT_EQ(harness.display_text, "t"sv);
+ EXPECT_EQ(harness.shown_popup.suggestions.first().text, "https://www.twin.example/"sv);
+
+ // The arrow keys step through the rows in their new order, so the popup shows that order first.
+ EXPECT(harness.omnibox.select_next_suggestion());
+ EXPECT_EQ(harness.shown_popup.suggestions.first().text, "t"sv);
+ EXPECT_EQ(harness.shown_popup.selected_suggestion, 1u);
+ harness.omnibox.return_pressed();
+ EXPECT_EQ(harness.commits.last(), "https://www.twin.example/"sv);
+}
+
+TEST_CASE(clicking_a_row_the_popup_still_shows_goes_to_that_row)
+{
+ Harness harness;
+ harness.popup_follows_every_delivery = false;
+ harness.begin_editing();
+
+ harness.press_key('t');
+ harness.provider->deliver({ search_row("t"sv), history_row("https://www.twin.example/"sv) });
+ harness.press_key('h');
+ harness.provider->deliver_intermediate({ search_row("th"sv), history_row("https://www.thee.example/"sv) });
+
+ // The popup still shows the rows for "t", and the click is on what it shows.
+ harness.omnibox.suggestion_clicked(1);
+ EXPECT_EQ(harness.commits.size(), 1u);
+ EXPECT_EQ(harness.commits.last(), "https://www.twin.example/"sv);
+ EXPECT(!harness.shown_popup.is_visible);
+}
+
+TEST_CASE(escape_closes_a_popup_that_shows_older_rows)
+{
+ Harness harness;
+ harness.popup_follows_every_delivery = false;
+ harness.begin_editing();
+
+ harness.press_key('t');
+ harness.provider->deliver({ search_row("t"sv), search_row("tea"sv) });
+ harness.press_key('x');
+ harness.provider->deliver_intermediate({});
+ EXPECT(!harness.omnibox.is_popup_visible());
+ EXPECT(harness.shown_popup.is_visible);
+
+ EXPECT_EQ(harness.omnibox.escape_pressed(), Omnibox::EscapeAction::ClosedPopup);
+ EXPECT(!harness.shown_popup.is_visible);
+ EXPECT_EQ(harness.omnibox.escape_pressed(), Omnibox::EscapeAction::EndEditing);
+}
diff --git a/UI/Qt/LocationEdit.cpp b/UI/Qt/LocationEdit.cpp
index aac63120728..87d269ca59f 100644
--- a/UI/Qt/LocationEdit.cpp
+++ b/UI/Qt/LocationEdit.cpp
@@ -458,15 +458,19 @@ LocationEdit::LocationEdit(QWidget* parent, WebView::IsPrivate is_private)
m_omnibox.on_suggestions_change = [this] {
update_completion_title();
- if (!m_omnibox.is_popup_visible()) {
+ };
+
+ m_omnibox.on_popup_change = [this] {
+ auto const& popup = m_omnibox.popup();
+ if (!popup.is_visible) {
m_autocomplete->close();
return;
}
- m_autocomplete->show_with_suggestions(m_omnibox.suggestions(), m_omnibox.selected_suggestion());
+ m_autocomplete->show_with_suggestions(popup.suggestions, popup.selected_suggestion);
};
m_omnibox.on_selection_change = [this] {
- m_autocomplete->set_selected_suggestion(m_omnibox.selected_suggestion());
+ m_autocomplete->set_selected_suggestion(m_omnibox.popup().selected_suggestion);
update_location_icon();
};
@@ -864,8 +868,8 @@ void LocationEdit::focusInEvent(QFocusEvent* event)
// NB: Resuming shows rows that arrived while parked, which may complete the text, so the parked selection is
// restored first. Those rows may already have shown the popup.
m_omnibox.set_suspended(false);
- if (m_omnibox.is_popup_visible() && !m_autocomplete->is_visible())
- m_autocomplete->show_with_suggestions(m_omnibox.suggestions(), m_omnibox.selected_suggestion());
+ if (auto const& popup = m_omnibox.popup(); popup.is_visible && !m_autocomplete->is_visible())
+ m_autocomplete->show_with_suggestions(popup.suggestions, popup.selected_suggestion);
show_focus_ring();
return;
}
diff --git a/UI/Qt/SuggestionProvider.cpp b/UI/Qt/SuggestionProvider.cpp
index a95fde15074..6c9794ed9a1 100644
--- a/UI/Qt/SuggestionProvider.cpp
+++ b/UI/Qt/SuggestionProvider.cpp
@@ -13,9 +13,9 @@ namespace Ladybird {
SuggestionProvider::SuggestionProvider(WebView::IsPrivate is_private)
: m_autocomplete(Application::the(), is_private)
{
- m_autocomplete.on_autocomplete_query_complete = [this](auto query_id, auto suggestions, auto) {
+ m_autocomplete.on_autocomplete_query_complete = [this](auto query_id, auto suggestions, auto kind) {
if (on_suggestions)
- on_suggestions(query_id, move(suggestions));
+ on_suggestions(query_id, move(suggestions), kind);
};
}