Commit 063efefe authored by Jiaquan He's avatar Jiaquan He Committed by Commit Bot

app_list: move some search stuff in chrome to the model updater.

We're gradually breaking app list search logic into a chrome part and an
ash part, which will be bound via a model updater and an observer.
Specifically, this commit:
- moves all search box references in SearchResourceManager into the
  model updater;
- removes some unused "ash/app_list/*" inclusions in chrome codes.

Bug: 733662
Change-Id: Ied882c477a53aef70c94465a00420e363d974a9c
Reviewed-on: https://chromium-review.googlesource.com/845138
Commit-Queue: Jiaquan He <hejq@google.com>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#526843}
parent 4c667a42
......@@ -56,6 +56,7 @@ component("search_model") {
defines = [ "APP_LIST_MODEL_IMPLEMENTATION" ]
deps = [
":speech_ui_model",
"//base:i18n",
"//ui/base",
"//ui/gfx",
......
......@@ -12,6 +12,18 @@
namespace app_list {
namespace {
std::unique_ptr<SearchBoxModel::SpeechButtonProperty> CreateNewProperty(
SpeechRecognitionState state) {
// Currently no speech support in app list.
// TODO(xiaohuic): when implementing speech support in new app list, we should
// either reuse this and related logic or delete them.
return nullptr;
}
} // namespace
SearchBoxModel::SpeechButtonProperty::SpeechButtonProperty(
const gfx::ImageSkia& icon,
const base::string16& tooltip,
......@@ -24,9 +36,8 @@ SearchBoxModel::SearchBoxModel() : is_tablet_mode_(false) {}
SearchBoxModel::~SearchBoxModel() = default;
void SearchBoxModel::SetSpeechRecognitionButton(
std::unique_ptr<SearchBoxModel::SpeechButtonProperty> speech_button) {
speech_button_ = std::move(speech_button);
void SearchBoxModel::SetSpeechRecognitionButton(SpeechRecognitionState state) {
speech_button_ = CreateNewProperty(state);
for (auto& observer : observers_)
observer.SpeechRecognitionButtonPropChanged();
}
......
......@@ -8,6 +8,7 @@
#include <memory>
#include "ash/app_list/model/app_list_model_export.h"
#include "ash/app_list/model/speech/speech_ui_model_observer.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/strings/string16.h"
......@@ -18,7 +19,7 @@ namespace app_list {
class SearchBoxModelObserver;
// SearchBoxModel consisits of an icon, a hint text, a user text and a selection
// SearchBoxModel consists of an icon, a hint text, a user text and a selection
// model. The icon is rendered to the side of the query editor. The hint text
// is used as query edit control's placeholder text and displayed when there is
// no user text in the control. The selection model and the text represents the
......@@ -43,8 +44,7 @@ class APP_LIST_MODEL_EXPORT SearchBoxModel {
~SearchBoxModel();
// Sets/gets the properties for the button of speech recognition.
void SetSpeechRecognitionButton(
std::unique_ptr<SpeechButtonProperty> speech_button);
void SetSpeechRecognitionButton(SpeechRecognitionState state);
const SpeechButtonProperty* speech_button() const {
return speech_button_.get();
}
......
......@@ -9,6 +9,8 @@
#include <algorithm>
#include <limits>
#include "ash/app_list/model/speech/speech_ui_model_observer.h"
namespace app_list {
namespace {
......
......@@ -8,7 +8,6 @@
#include <stdint.h>
#include "ash/app_list/model/app_list_model_export.h"
#include "ash/app_list/model/speech/speech_ui_model_observer.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/strings/string16.h"
......@@ -16,6 +15,17 @@
namespace app_list {
class SpeechUIModelObserver;
enum SpeechRecognitionState {
SPEECH_RECOGNITION_OFF = 0,
SPEECH_RECOGNITION_READY,
SPEECH_RECOGNITION_RECOGNIZING,
SPEECH_RECOGNITION_IN_SPEECH,
SPEECH_RECOGNITION_STOPPING,
SPEECH_RECOGNITION_NETWORK_ERROR,
};
// SpeechUIModel provides the interface to update the UI for speech recognition.
class APP_LIST_MODEL_EXPORT SpeechUIModel {
public:
......
......@@ -8,19 +8,11 @@
#include <stdint.h>
#include "ash/app_list/model/app_list_model_export.h"
#include "ash/app_list/model/speech/speech_ui_model.h"
#include "base/strings/string16.h"
namespace app_list {
enum SpeechRecognitionState {
SPEECH_RECOGNITION_OFF = 0,
SPEECH_RECOGNITION_READY,
SPEECH_RECOGNITION_RECOGNIZING,
SPEECH_RECOGNITION_IN_SPEECH,
SPEECH_RECOGNITION_STOPPING,
SPEECH_RECOGNITION_NETWORK_ERROR,
};
class APP_LIST_MODEL_EXPORT SpeechUIModelObserver {
public:
// Invoked when sound level for the speech recognition has changed. |level|
......
......@@ -4,7 +4,6 @@
#include <stddef.h>
#include "ash/app_list/model/search/search_box_model.h"
#include "ash/app_list/model/search/search_model.h"
#include "ash/app_list/model/search/search_result.h"
#include "ash/app_list/model/search/search_result_observer.h"
......
......@@ -11,6 +11,8 @@
#include "ash/app_list/model/app_list_folder_item.h"
#include "ash/app_list/model/app_list_model.h"
#include "ash/app_list/model/speech/speech_ui_model.h"
#include "base/strings/string16.h"
class ChromeAppListItem;
......@@ -45,6 +47,14 @@ class AppListModelUpdater {
virtual void HighlightItemInstalledFromUI(const std::string& id) {}
// For SearchModel:
virtual void SetSearchEngineIsGoogle(bool is_google) {}
virtual void SetSearchTabletAndClamshellAccessibleName(
const base::string16& tablet_accessible_name,
const base::string16& clamshell_accessible_name) {}
virtual void SetSearchHintText(const base::string16& hint_text) {}
virtual void SetSearchSpeechRecognitionButton(
app_list::SpeechRecognitionState state) {}
virtual void UpdateSearchBox(const base::string16& text,
bool initiated_by_user) {}
// For AppListModel:
virtual ChromeAppListItem* FindItem(const std::string& id) = 0;
......
......@@ -11,7 +11,6 @@
#include "ash/app_list/model/app_list_model.h"
#include "ash/app_list/model/app_list_view_state.h"
#include "ash/app_list/model/search/search_box_model.h"
#include "ash/app_list/model/speech/speech_ui_model.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "base/command_line.h"
......@@ -187,8 +186,8 @@ void AppListViewDelegate::SetProfile(Profile* new_profile) {
OnTemplateURLServiceChanged();
// Clear search query.
search_model_->search_box()->Update(base::string16(),
false /* initiated_by_user */);
model_updater_->UpdateSearchBox(base::string16(),
false /* initiated_by_user */);
}
void AppListViewDelegate::OnGetWallpaperColorsCallback(
......@@ -208,7 +207,7 @@ void AppListViewDelegate::SetUpSearchUI() {
false);
search_resource_manager_.reset(new app_list::SearchResourceManager(
profile_, search_model_->search_box(), speech_ui_.get()));
profile_, model_updater_, speech_ui_.get()));
search_controller_ = CreateSearchController(profile_, model_updater_,
search_model_, controller_);
......@@ -377,7 +376,7 @@ void AppListViewDelegate::OnTemplateURLServiceChanged() {
default_provider->GetEngineType(
template_url_service->search_terms_data()) == SEARCH_ENGINE_GOOGLE;
search_model_->SetSearchEngineIsGoogle(is_google);
model_updater_->SetSearchEngineIsGoogle(is_google);
app_list::StartPageService* start_page_service =
app_list::StartPageService::Get(profile_);
......
......@@ -63,6 +63,28 @@ void ChromeAppListModelUpdater::SetSearchEngineIsGoogle(bool is_google) {
search_model_->SetSearchEngineIsGoogle(is_google);
}
void ChromeAppListModelUpdater::SetSearchTabletAndClamshellAccessibleName(
const base::string16& tablet_accessible_name,
const base::string16& clamshell_accessible_name) {
search_model_->search_box()->SetTabletAndClamshellAccessibleName(
tablet_accessible_name, clamshell_accessible_name);
}
void ChromeAppListModelUpdater::SetSearchHintText(
const base::string16& hint_text) {
search_model_->search_box()->SetHintText(hint_text);
}
void ChromeAppListModelUpdater::SetSearchSpeechRecognitionButton(
app_list::SpeechRecognitionState state) {
search_model_->search_box()->SetSpeechRecognitionButton(state);
}
void ChromeAppListModelUpdater::UpdateSearchBox(const base::string16& text,
bool initiated_by_user) {
search_model_->search_box()->Update(text, initiated_by_user);
}
////////////////////////////////////////////////////////////////////////////////
// Methods only used by ChromeAppListItem that talk to ash directly.
......
......@@ -32,6 +32,14 @@ class ChromeAppListModelUpdater : public AppListModelUpdater {
void SetState(app_list::AppListModel::State state) override;
void HighlightItemInstalledFromUI(const std::string& id) override;
void SetSearchEngineIsGoogle(bool is_google) override;
void SetSearchTabletAndClamshellAccessibleName(
const base::string16& tablet_accessible_name,
const base::string16& clamshell_accessible_name) override;
void SetSearchHintText(const base::string16& hint_text) override;
void SetSearchSpeechRecognitionButton(
app_list::SpeechRecognitionState state) override;
void UpdateSearchBox(const base::string16& text,
bool initiated_by_user) override;
// Methods for item querying.
ChromeAppListItem* FindItem(const std::string& id) override;
......
......@@ -4,7 +4,6 @@
#include "chrome/browser/ui/app_list/search/omnibox_provider.h"
#include "ash/app_list/model/search/search_result.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
......
......@@ -6,9 +6,9 @@
#include <memory>
#include "ash/app_list/model/search/search_box_model.h"
#include "ash/app_list/model/speech/speech_ui_model.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/ui/app_list/app_list_model_updater.h"
#include "chrome/browser/ui/app_list/start_page_service.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
......@@ -18,27 +18,15 @@
namespace app_list {
namespace {
std::unique_ptr<SearchBoxModel::SpeechButtonProperty> CreateNewProperty(
SpeechRecognitionState state) {
// Currently no speech support in app list.
// TODO(xiaohuic): when implementing speech support in new app list, we should
// either reuse this and related logic or delete them.
return nullptr;
}
} // namespace
SearchResourceManager::SearchResourceManager(Profile* profile,
SearchBoxModel* search_box,
AppListModelUpdater* model_updater,
SpeechUIModel* speech_ui)
: search_box_(search_box),
: model_updater_(model_updater),
speech_ui_(speech_ui),
is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) {
speech_ui_->AddObserver(this);
// Give |SearchBoxModel| tablet and clamshell A11y Announcements.
search_box_->SetTabletAndClamshellAccessibleName(
model_updater_->SetSearchTabletAndClamshellAccessibleName(
l10n_util::GetStringUTF16(IDS_SEARCH_BOX_ACCESSIBILITY_NAME_TABLET),
l10n_util::GetStringUTF16(IDS_SEARCH_BOX_ACCESSIBILITY_NAME));
OnSpeechRecognitionStateChanged(speech_ui_->state());
......@@ -51,11 +39,12 @@ SearchResourceManager::~SearchResourceManager() {
void SearchResourceManager::OnSpeechRecognitionStateChanged(
SpeechRecognitionState new_state) {
if (is_fullscreen_app_list_enabled_) {
search_box_->SetHintText(
model_updater_->SetSearchHintText(
l10n_util::GetStringUTF16(IDS_SEARCH_BOX_HINT_FULLSCREEN));
} else {
search_box_->SetHintText(l10n_util::GetStringUTF16(IDS_SEARCH_BOX_HINT));
search_box_->SetSpeechRecognitionButton(CreateNewProperty(new_state));
model_updater_->SetSearchHintText(
l10n_util::GetStringUTF16(IDS_SEARCH_BOX_HINT));
model_updater_->SetSearchSpeechRecognitionButton(new_state);
}
}
......
......@@ -8,18 +8,18 @@
#include "ash/app_list/model/speech/speech_ui_model_observer.h"
#include "base/macros.h"
class AppListModelUpdater;
class Profile;
namespace app_list {
class SearchBoxModel;
class SpeechUIModel;
// Manages the strings and assets of the app-list search box.
class SearchResourceManager : public SpeechUIModelObserver {
public:
SearchResourceManager(Profile* profile,
SearchBoxModel* search_box,
AppListModelUpdater* model_updater,
SpeechUIModel* speech_ui);
~SearchResourceManager() override;
......@@ -28,7 +28,7 @@ class SearchResourceManager : public SpeechUIModelObserver {
void OnSpeechRecognitionStateChanged(
SpeechRecognitionState new_state) override;
SearchBoxModel* search_box_;
AppListModelUpdater* model_updater_;
SpeechUIModel* speech_ui_;
const bool is_fullscreen_app_list_enabled_;
......
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