| OLD | NEW |
| (Empty) |
| 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 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/callback.h" | |
| 11 #include "base/files/file_path.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | |
| 13 #include "third_party/skia/include/core/SkBitmap.h" | |
| 14 #include "ui/app_list/app_list_item.h" | |
| 15 #include "ui/app_list/app_list_item_list.h" | |
| 16 #include "ui/app_list/app_list_model.h" | |
| 17 #include "ui/app_list/search_box_model.h" | |
| 18 #include "ui/app_list/search_result.h" | |
| 19 #include "ui/app_list/speech_ui_model.h" | |
| 20 #include "ui/gfx/image/image_skia.h" | |
| 21 | |
| 22 namespace athena { | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 const int kIconSize = 64; | |
| 27 | |
| 28 class DummyItem : public app_list::AppListItem { | |
| 29 public: | |
| 30 enum Type { | |
| 31 DUMMY_MAIL, | |
| 32 DUMMY_CALENDAR, | |
| 33 DUMMY_VIDEO, | |
| 34 DUMMY_MUSIC, | |
| 35 DUMMY_CONTACT, | |
| 36 LAST_TYPE, | |
| 37 }; | |
| 38 | |
| 39 static std::string GetTitle(Type type) { | |
| 40 switch (type) { | |
| 41 case DUMMY_MAIL: | |
| 42 return "mail"; | |
| 43 case DUMMY_CALENDAR: | |
| 44 return "calendar"; | |
| 45 case DUMMY_VIDEO: | |
| 46 return "video"; | |
| 47 case DUMMY_MUSIC: | |
| 48 return "music"; | |
| 49 case DUMMY_CONTACT: | |
| 50 return "contact"; | |
| 51 case LAST_TYPE: | |
| 52 break; | |
| 53 } | |
| 54 NOTREACHED(); | |
| 55 return ""; | |
| 56 } | |
| 57 | |
| 58 static std::string GetId(Type type) { | |
| 59 return std::string("id-") + GetTitle(type); | |
| 60 } | |
| 61 | |
| 62 explicit DummyItem(Type type) | |
| 63 : app_list::AppListItem(GetId(type)), | |
| 64 type_(type) { | |
| 65 SetIcon(GetIcon(), false /* has_shadow */); | |
| 66 SetName(GetTitle(type_)); | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 gfx::ImageSkia GetIcon() const { | |
| 71 SkColor color = SK_ColorWHITE; | |
| 72 switch (type_) { | |
| 73 case DUMMY_MAIL: | |
| 74 color = SK_ColorRED; | |
| 75 break; | |
| 76 case DUMMY_CALENDAR: | |
| 77 color = SK_ColorBLUE; | |
| 78 break; | |
| 79 case DUMMY_VIDEO: | |
| 80 color = SK_ColorGREEN; | |
| 81 break; | |
| 82 case DUMMY_MUSIC: | |
| 83 color = SK_ColorYELLOW; | |
| 84 break; | |
| 85 case DUMMY_CONTACT: | |
| 86 color = SK_ColorCYAN; | |
| 87 break; | |
| 88 case LAST_TYPE: | |
| 89 NOTREACHED(); | |
| 90 break; | |
| 91 } | |
| 92 SkBitmap bitmap; | |
| 93 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kIconSize, kIconSize); | |
| 94 bitmap.allocPixels(); | |
| 95 bitmap.eraseColor(color); | |
| 96 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | |
| 97 } | |
| 98 | |
| 99 Type type_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(DummyItem); | |
| 102 }; | |
| 103 | |
| 104 } // namespace | |
| 105 | |
| 106 AppListViewDelegate::AppListViewDelegate() | |
| 107 : model_(new app_list::AppListModel), | |
| 108 speech_ui_(new app_list::SpeechUIModel( | |
| 109 app_list::SPEECH_RECOGNITION_OFF)) { | |
| 110 PopulateApps(); | |
| 111 // TODO(mukai): get the text from the resources. | |
| 112 model_->search_box()->SetHintText(base::ASCIIToUTF16("Search")); | |
| 113 } | |
| 114 | |
| 115 AppListViewDelegate::~AppListViewDelegate() { | |
| 116 } | |
| 117 | |
| 118 void AppListViewDelegate::PopulateApps() { | |
| 119 for (int i = 0; i < static_cast<int>(DummyItem::LAST_TYPE); ++i) { | |
| 120 model_->AddItem(scoped_ptr<app_list::AppListItem>( | |
| 121 new DummyItem(static_cast<DummyItem::Type>(i)))); | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 bool AppListViewDelegate::ForceNativeDesktop() const { | |
| 126 return false; | |
| 127 } | |
| 128 | |
| 129 void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) { | |
| 130 // Nothing needs to be done. | |
| 131 } | |
| 132 | |
| 133 app_list::AppListModel* AppListViewDelegate::GetModel() { | |
| 134 return model_.get(); | |
| 135 } | |
| 136 | |
| 137 app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() { | |
| 138 return speech_ui_.get(); | |
| 139 } | |
| 140 | |
| 141 void AppListViewDelegate::GetShortcutPathForApp( | |
| 142 const std::string& app_id, | |
| 143 const base::Callback<void(const base::FilePath&)>& callback) { | |
| 144 // Windows only, nothing is necessary. | |
| 145 } | |
| 146 | |
| 147 void AppListViewDelegate::StartSearch() { | |
| 148 // TODO(mukai): implement this. | |
| 149 } | |
| 150 | |
| 151 void AppListViewDelegate::StopSearch() { | |
| 152 // TODO(mukai): implement this. | |
| 153 } | |
| 154 | |
| 155 void AppListViewDelegate::OpenSearchResult(app_list::SearchResult* result, | |
| 156 bool auto_launch, | |
| 157 int event_flags) { | |
| 158 // TODO(mukai): implement this. | |
| 159 } | |
| 160 | |
| 161 void AppListViewDelegate::InvokeSearchResultAction( | |
| 162 app_list::SearchResult* result, | |
| 163 int action_index, | |
| 164 int event_flags) { | |
| 165 // TODO(mukai): implement this. | |
| 166 } | |
| 167 | |
| 168 base::TimeDelta AppListViewDelegate::GetAutoLaunchTimeout() { | |
| 169 // Used by voice search, nothing needs to be done for now. | |
| 170 return base::TimeDelta(); | |
| 171 } | |
| 172 | |
| 173 void AppListViewDelegate::AutoLaunchCanceled() { | |
| 174 // Used by voice search, nothing needs to be done for now. | |
| 175 } | |
| 176 | |
| 177 void AppListViewDelegate::ViewInitialized() { | |
| 178 // Nothing needs to be done. | |
| 179 } | |
| 180 | |
| 181 void AppListViewDelegate::Dismiss() { | |
| 182 // Nothing needs to be done. | |
| 183 } | |
| 184 | |
| 185 void AppListViewDelegate::ViewClosing() { | |
| 186 // Nothing needs to be done. | |
| 187 } | |
| 188 | |
| 189 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { | |
| 190 return gfx::ImageSkia(); | |
| 191 } | |
| 192 | |
| 193 void AppListViewDelegate::OpenSettings() { | |
| 194 // Nothing needs to be done for now. | |
| 195 // TODO(mukai): should invoke the settings app. | |
| 196 } | |
| 197 | |
| 198 void AppListViewDelegate::OpenHelp() { | |
| 199 // Nothing needs to be done for now. | |
| 200 // TODO(mukai): should invoke the help app. | |
| 201 } | |
| 202 | |
| 203 void AppListViewDelegate::OpenFeedback() { | |
| 204 // Nothing needs to be done for now. | |
| 205 // TODO(mukai): should invoke the feedback app. | |
| 206 } | |
| 207 | |
| 208 void AppListViewDelegate::ToggleSpeechRecognition() { | |
| 209 // Nothing needs to be done. | |
| 210 } | |
| 211 | |
| 212 void AppListViewDelegate::ShowForProfileByPath( | |
| 213 const base::FilePath& profile_path) { | |
| 214 // Nothing needs to be done. | |
| 215 } | |
| 216 | |
| 217 content::WebContents* AppListViewDelegate::GetStartPageContents() { | |
| 218 return NULL; | |
| 219 } | |
| 220 | |
| 221 content::WebContents* AppListViewDelegate::GetSpeechRecognitionContents() { | |
| 222 return NULL; | |
| 223 } | |
| 224 | |
| 225 const app_list::AppListViewDelegate::Users& | |
| 226 AppListViewDelegate::GetUsers() const { | |
| 227 return users_; | |
| 228 } | |
| 229 | |
| 230 bool AppListViewDelegate::ShouldCenterWindow() const { | |
| 231 return true; | |
| 232 } | |
| 233 | |
| 234 } // namespace athena | |
| OLD | NEW |