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. 4 5#include "athena/home/app_list_view_delegate.h" 6 7#include <string> 8#include <vector> 9 10#include "athena/home/public/app_model_builder.h" 11#include "athena/strings/grit/athena_strings.h" 12#include "base/basictypes.h" 13#include "base/bind.h" 14#include "base/callback.h" 15#include "base/files/file_path.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/l10n/l10n_util.h" 23#include "ui/base/resource/resource_bundle.h" 24#include "ui/gfx/image/image_skia.h" 25#include "ui/resources/grit/ui_resources.h" 26#include "ui/views/controls/image_view.h" 27 28namespace athena { 29 30AppListViewDelegate::AppListViewDelegate(AppModelBuilder* model_builder) 31 : model_(new app_list::AppListModel), 32 speech_ui_(new app_list::SpeechUIModel) { 33 model_builder->PopulateApps(model_.get()); 34 model_->search_box()->SetHintText( 35 l10n_util::GetStringUTF16(IDS_ATHENA_SEARCH_BOX_HINT)); 36} 37 38AppListViewDelegate::~AppListViewDelegate() { 39 for (size_t i = 0; i < search_providers_.size(); ++i) 40 search_providers_[i]->set_result_changed_callback(base::Closure()); 41} 42 43void 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); 51} 52 53void 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]); 63 } 64} 65 66bool AppListViewDelegate::ForceNativeDesktop() const { 67 return false; 68} 69 70void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) { 71 // Nothing needs to be done. 72} 73 74app_list::AppListModel* AppListViewDelegate::GetModel() { 75 return model_.get(); 76} 77 78app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() { 79 return speech_ui_.get(); 80} 81 82void AppListViewDelegate::GetShortcutPathForApp( 83 const std::string& app_id, 84 const base::Callback<void(const base::FilePath&)>& callback) { 85 // Windows only, nothing is necessary. 86} 87 88void AppListViewDelegate::StartSearch() { 89 for (size_t i = 0; i < search_providers_.size(); ++i) 90 search_providers_[i]->Start(model_->search_box()->text()); 91} 92 93void AppListViewDelegate::StopSearch() { 94 for (size_t i = 0; i < search_providers_.size(); ++i) 95 search_providers_[i]->Stop(); 96} 97 98void AppListViewDelegate::OpenSearchResult(app_list::SearchResult* result, 99 bool auto_launch, 100 int event_flags) { 101 result->Open(event_flags); 102} 103 104void AppListViewDelegate::InvokeSearchResultAction( 105 app_list::SearchResult* result, 106 int action_index, 107 int event_flags) { 108 // TODO(mukai): implement this. 109} 110 111base::TimeDelta AppListViewDelegate::GetAutoLaunchTimeout() { 112 // Used by voice search, nothing needs to be done for now. 113 return base::TimeDelta(); 114} 115 116void AppListViewDelegate::AutoLaunchCanceled() { 117 // Used by voice search, nothing needs to be done for now. 118} 119 120void AppListViewDelegate::ViewInitialized() { 121 // Nothing needs to be done. 122} 123 124void AppListViewDelegate::Dismiss() { 125 // Nothing needs to be done. 126} 127 128void AppListViewDelegate::ViewClosing() { 129 // Nothing needs to be done. 130} 131 132gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { 133 return gfx::ImageSkia(); 134} 135 136void AppListViewDelegate::OpenSettings() { 137 // Nothing needs to be done for now. 138 // TODO(mukai): should invoke the settings app. 139} 140 141void AppListViewDelegate::OpenHelp() { 142 // Nothing needs to be done for now. 143 // TODO(mukai): should invoke the help app. 144} 145 146void AppListViewDelegate::OpenFeedback() { 147 // Nothing needs to be done for now. 148 // TODO(mukai): should invoke the feedback app. 149} 150 151void AppListViewDelegate::ToggleSpeechRecognition() { 152 // Nothing needs to be done. 153} 154 155void AppListViewDelegate::ShowForProfileByPath( 156 const base::FilePath& profile_path) { 157 // Nothing needs to be done. 158} 159 160views::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; 170} 171 172std::vector<views::View*> AppListViewDelegate::CreateCustomPageWebViews( 173 const gfx::Size& size) { 174 return std::vector<views::View*>(); 175} 176 177bool AppListViewDelegate::IsSpeechRecognitionEnabled() { 178 return false; 179} 180 181const app_list::AppListViewDelegate::Users& 182AppListViewDelegate::GetUsers() const { 183 return users_; 184} 185 186bool AppListViewDelegate::ShouldCenterWindow() const { 187 return true; 188} 189 190} // namespace athena 191