Commit 58cccbbd authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

[ash] Fix app list search behavior

This fixes some regressions which caused Answer Card display handling to
interfere with normal search UI behavior in the app list. Namely,
automatic selection of top non-Answer-Card results, and autocomplete of
text in the input box.

Bug: 902563
Change-Id: Ie45672ae64184d7ed6116752bad1c7a0ca38c646
Reviewed-on: https://chromium-review.googlesource.com/c/1325081Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#606269}
parent 015c2542
...@@ -88,6 +88,15 @@ SearchResult* SearchModel::FindSearchResult(const std::string& id) { ...@@ -88,6 +88,15 @@ SearchResult* SearchModel::FindSearchResult(const std::string& id) {
return nullptr; return nullptr;
} }
SearchResult* SearchModel::GetFirstVisibleResult() {
for (const auto& result : *results_) {
if (result->is_visible())
return result.get();
}
return nullptr;
}
void SearchModel::DeleteAllResults() { void SearchModel::DeleteAllResults() {
PublishResults(std::vector<std::unique_ptr<SearchResult>>()); PublishResults(std::vector<std::unique_ptr<SearchResult>>());
} }
......
...@@ -54,6 +54,10 @@ class APP_LIST_MODEL_EXPORT SearchModel { ...@@ -54,6 +54,10 @@ class APP_LIST_MODEL_EXPORT SearchModel {
SearchResult* FindSearchResult(const std::string& id); SearchResult* FindSearchResult(const std::string& id);
// Returns the first available SearchResult which has not been marked as
// hidden by its source. Returns null if no such result exists.
SearchResult* GetFirstVisibleResult();
// Deletes all search results. This is used in profile switches. // Deletes all search results. This is used in profile switches.
void DeleteAllResults(); void DeleteAllResults();
......
...@@ -119,6 +119,9 @@ class APP_LIST_MODEL_EXPORT SearchResult { ...@@ -119,6 +119,9 @@ class APP_LIST_MODEL_EXPORT SearchResult {
metadata_->is_omnibox_search = is_omnibox_search; metadata_->is_omnibox_search = is_omnibox_search;
} }
bool is_visible() const { return is_visible_; }
void set_is_visible(bool is_visible) { is_visible_ = is_visible; }
void NotifyItemInstalled(); void NotifyItemInstalled();
void AddObserver(SearchResultObserver* observer); void AddObserver(SearchResultObserver* observer);
...@@ -147,6 +150,7 @@ class APP_LIST_MODEL_EXPORT SearchResult { ...@@ -147,6 +150,7 @@ class APP_LIST_MODEL_EXPORT SearchResult {
bool is_installing_ = false; bool is_installing_ = false;
int percent_downloaded_ = 0; int percent_downloaded_ = 0;
bool is_visible_ = true;
ash::mojom::SearchResultMetadataPtr metadata_; ash::mojom::SearchResultMetadataPtr metadata_;
......
...@@ -365,24 +365,24 @@ void SearchBoxView::ProcessAutocomplete() { ...@@ -365,24 +365,24 @@ void SearchBoxView::ProcessAutocomplete() {
if (!is_app_list_search_autocomplete_enabled_) if (!is_app_list_search_autocomplete_enabled_)
return; return;
SearchResult* const first_visible_result =
search_model_->GetFirstVisibleResult();
// Current non-autocompleted text. // Current non-autocompleted text.
const base::string16& user_typed_text = const base::string16& user_typed_text =
search_box()->text().substr(0, highlight_range_.start()); search_box()->text().substr(0, highlight_range_.start());
if (last_key_pressed_ == ui::VKEY_BACK || last_key_pressed_ == ui::VKEY_UP || if (last_key_pressed_ == ui::VKEY_BACK || last_key_pressed_ == ui::VKEY_UP ||
last_key_pressed_ == ui::VKEY_DOWN || last_key_pressed_ == ui::VKEY_DOWN ||
last_key_pressed_ == ui::VKEY_LEFT || last_key_pressed_ == ui::VKEY_LEFT ||
last_key_pressed_ == ui::VKEY_RIGHT || last_key_pressed_ == ui::VKEY_RIGHT || !first_visible_result ||
search_model_->results()->item_count() == 0 ||
user_typed_text.length() < kMinimumLengthToAutocomplete) { user_typed_text.length() < kMinimumLengthToAutocomplete) {
// Backspace or arrow keys were pressed, no results exist, or current text // Backspace or arrow keys were pressed, no results exist, or current text
// is too short for a confident autocomplete suggestion. // is too short for a confident autocomplete suggestion.
return; return;
} }
const base::string16& details = const base::string16& details = first_visible_result->details();
search_model_->results()->GetItemAt(0)->details(); const base::string16& search_text = first_visible_result->title();
const base::string16& search_text =
search_model_->results()->GetItemAt(0)->title();
if (base::StartsWith(details, user_typed_text, if (base::StartsWith(details, user_typed_text,
base::CompareCase::INSENSITIVE_ASCII)) { base::CompareCase::INSENSITIVE_ASCII)) {
// Current text in the search_box matches the first result's url. // Current text in the search_box matches the first result's url.
......
...@@ -341,14 +341,17 @@ int SearchResultAnswerCardView::DoUpdate() { ...@@ -341,14 +341,17 @@ int SearchResultAnswerCardView::DoUpdate() {
SearchResult* top_result = SearchResult* top_result =
display_results.empty() ? nullptr : display_results.front(); display_results.empty() ? nullptr : display_results.front();
const bool have_result = const bool has_valid_answer_card =
search_answer_container_view_->has_valid_answer_card(); search_answer_container_view_->has_valid_answer_card();
search_answer_container_view_->SetSearchResult(top_result); search_answer_container_view_->SetSearchResult(top_result);
parent()->SetVisible(have_result); parent()->SetVisible(has_valid_answer_card);
set_container_score(top_result ? top_result->display_score() : 0); set_container_score(
has_valid_answer_card && top_result ? top_result->display_score() : 0);
if (top_result)
top_result->set_is_visible(has_valid_answer_card);
return have_result ? 1 : 0; return has_valid_answer_card ? 1 : 0;
} }
bool SearchResultAnswerCardView::OnKeyPressed(const ui::KeyEvent& event) { bool SearchResultAnswerCardView::OnKeyPressed(const ui::KeyEvent& event) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment