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"
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"
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();
61 for (size_t i
= 0; i
< results
.size(); ++i
)
62 model_
->results()->Add(results
[i
]);
66 bool AppListViewDelegate::ForceNativeDesktop() const {
70 void AppListViewDelegate::SetProfileByPath(const base::FilePath
& profile_path
) {
71 // Nothing needs to be done.
74 app_list::AppListModel
* AppListViewDelegate::GetModel() {
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
,
101 result
->Open(event_flags
);
104 void AppListViewDelegate::InvokeSearchResultAction(
105 app_list::SearchResult
* result
,
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
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
);
172 std::vector
<views::View
*> AppListViewDelegate::CreateCustomPageWebViews(
173 const gfx::Size
& size
) {
174 return std::vector
<views::View
*>();
177 bool AppListViewDelegate::IsSpeechRecognitionEnabled() {
181 const app_list::AppListViewDelegate::Users
&
182 AppListViewDelegate::GetUsers() const {
186 bool AppListViewDelegate::ShouldCenterWindow() const {
190 } // namespace athena