Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / athena / home / app_list_view_delegate.cc
blobd4a7f531d6ec4b329fe150bb845f65890fb5eb36
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "athena/home/app_list_view_delegate.h"
7 #include <string>
8 #include <vector>
10 #include "athena/home/public/app_model_builder.h"
11 #include "base/basictypes.h"
12 #include "base/bind.h"
13 #include "base/callback.h"
14 #include "base/files/file_path.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "third_party/skia/include/core/SkBitmap.h"
17 #include "ui/app_list/app_list_model.h"
18 #include "ui/app_list/search_box_model.h"
19 #include "ui/app_list/search_provider.h"
20 #include "ui/app_list/search_result.h"
21 #include "ui/app_list/speech_ui_model.h"
22 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/image/image_skia.h"
24 #include "ui/resources/grit/ui_resources.h"
25 #include "ui/views/controls/image_view.h"
27 namespace athena {
29 AppListViewDelegate::AppListViewDelegate(AppModelBuilder* model_builder)
30 : model_(new app_list::AppListModel),
31 speech_ui_(new app_list::SpeechUIModel(
32 app_list::SPEECH_RECOGNITION_OFF)) {
33 model_builder->PopulateApps(model_.get());
34 // TODO(mukai): get the text from the resources.
35 model_->search_box()->SetHintText(base::ASCIIToUTF16("Search"));
38 AppListViewDelegate::~AppListViewDelegate() {
39 for (size_t i = 0; i < search_providers_.size(); ++i)
40 search_providers_[i]->set_result_changed_callback(base::Closure());
43 void AppListViewDelegate::RegisterSearchProvider(
44 app_list::SearchProvider* search_provider) {
45 // Right now we allow only one provider.
46 // TODO(mukai): port app-list's mixer and remove this restriction.
47 DCHECK(search_providers_.empty());
48 search_provider->set_result_changed_callback(base::Bind(
49 &AppListViewDelegate::SearchResultChanged, base::Unretained(this)));
50 search_providers_.push_back(search_provider);
53 void AppListViewDelegate::SearchResultChanged() {
54 // TODO(mukai): port app-list's Mixer to reorder the results properly.
55 app_list::SearchProvider* search_provider = search_providers_[0];
56 std::vector<app_list::SearchResult*> results;
57 search_provider->ReleaseResult(&results);
58 if (results.empty()) {
59 model_->results()->DeleteAll();
60 } else {
61 for (size_t i = 0; i < results.size(); ++i)
62 model_->results()->Add(results[i]);
66 bool AppListViewDelegate::ForceNativeDesktop() const {
67 return false;
70 void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) {
71 // Nothing needs to be done.
74 app_list::AppListModel* AppListViewDelegate::GetModel() {
75 return model_.get();
78 app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() {
79 return speech_ui_.get();
82 void AppListViewDelegate::GetShortcutPathForApp(
83 const std::string& app_id,
84 const base::Callback<void(const base::FilePath&)>& callback) {
85 // Windows only, nothing is necessary.
88 void AppListViewDelegate::StartSearch() {
89 for (size_t i = 0; i < search_providers_.size(); ++i)
90 search_providers_[i]->Start(model_->search_box()->text());
93 void AppListViewDelegate::StopSearch() {
94 for (size_t i = 0; i < search_providers_.size(); ++i)
95 search_providers_[i]->Stop();
98 void AppListViewDelegate::OpenSearchResult(app_list::SearchResult* result,
99 bool auto_launch,
100 int event_flags) {
101 result->Open(event_flags);
104 void AppListViewDelegate::InvokeSearchResultAction(
105 app_list::SearchResult* result,
106 int action_index,
107 int event_flags) {
108 // TODO(mukai): implement this.
111 base::TimeDelta AppListViewDelegate::GetAutoLaunchTimeout() {
112 // Used by voice search, nothing needs to be done for now.
113 return base::TimeDelta();
116 void AppListViewDelegate::AutoLaunchCanceled() {
117 // Used by voice search, nothing needs to be done for now.
120 void AppListViewDelegate::ViewInitialized() {
121 // Nothing needs to be done.
124 void AppListViewDelegate::Dismiss() {
125 // Nothing needs to be done.
128 void AppListViewDelegate::ViewClosing() {
129 // Nothing needs to be done.
132 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() {
133 return gfx::ImageSkia();
136 void AppListViewDelegate::OpenSettings() {
137 // Nothing needs to be done for now.
138 // TODO(mukai): should invoke the settings app.
141 void AppListViewDelegate::OpenHelp() {
142 // Nothing needs to be done for now.
143 // TODO(mukai): should invoke the help app.
146 void AppListViewDelegate::OpenFeedback() {
147 // Nothing needs to be done for now.
148 // TODO(mukai): should invoke the feedback app.
151 void AppListViewDelegate::ToggleSpeechRecognition() {
152 // Nothing needs to be done.
155 void AppListViewDelegate::ShowForProfileByPath(
156 const base::FilePath& profile_path) {
157 // Nothing needs to be done.
160 views::View* AppListViewDelegate::CreateStartPageWebView(
161 const gfx::Size& size) {
162 // A static image of the logo. This needs to support dynamic Doodles
163 // eventually.
164 views::ImageView* logo_image = new views::ImageView();
165 logo_image->SetImage(ui::ResourceBundle::GetSharedInstance().
166 GetImageSkiaNamed(IDR_LOCAL_NTP_IMAGES_LOGO_PNG));
167 logo_image->SetHorizontalAlignment(views::ImageView::CENTER);
168 logo_image->SetVerticalAlignment(views::ImageView::CENTER);
169 return logo_image;
172 std::vector<views::View*> AppListViewDelegate::CreateCustomPageWebViews(
173 const gfx::Size& size) {
174 return std::vector<views::View*>();
177 bool AppListViewDelegate::IsSpeechRecognitionEnabled() {
178 return false;
181 const app_list::AppListViewDelegate::Users&
182 AppListViewDelegate::GetUsers() const {
183 return users_;
186 bool AppListViewDelegate::ShouldCenterWindow() const {
187 return true;
190 } // namespace athena