Chromium Code Reviews| 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() { | |
|
oshima
2014/05/31 14:30:35
const
Jun Mukai
2014/06/02 01:44:28
Done.
| |
| 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 model_->search_box()->SetHintText(base::ASCIIToUTF16("Search")); | |
| 112 } | |
| 113 | |
| 114 AppListViewDelegate::~AppListViewDelegate() { | |
| 115 } | |
| 116 | |
| 117 void AppListViewDelegate::PopulateApps() { | |
| 118 for (int i = 0; i < static_cast<int>(DummyItem::LAST_TYPE); ++i) { | |
| 119 model_->AddItem(scoped_ptr<app_list::AppListItem>( | |
| 120 new DummyItem(static_cast<DummyItem::Type>(i)))); | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 bool AppListViewDelegate::ForceNativeDesktop() const { | |
| 125 return false; | |
| 126 } | |
| 127 | |
| 128 void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) { | |
| 129 // Nothing needs to be done. | |
| 130 } | |
| 131 | |
| 132 app_list::AppListModel* AppListViewDelegate::GetModel() { | |
| 133 return model_.get(); | |
| 134 } | |
| 135 | |
| 136 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { | |
| 137 return NULL; | |
| 138 } | |
| 139 | |
| 140 app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() { | |
| 141 return speech_ui_.get(); | |
| 142 } | |
| 143 | |
| 144 void AppListViewDelegate::GetShortcutPathForApp( | |
| 145 const std::string& app_id, | |
| 146 const base::Callback<void(const base::FilePath&)>& callback) { | |
| 147 // Windows only, nothing is necessary. | |
| 148 } | |
| 149 | |
| 150 void AppListViewDelegate::StartSearch() { | |
| 151 // TODO(mukai): implement this. | |
| 152 } | |
| 153 | |
| 154 void AppListViewDelegate::StopSearch() { | |
| 155 // TODO(mukai): implement this. | |
| 156 } | |
| 157 | |
| 158 void AppListViewDelegate::OpenSearchResult(app_list::SearchResult* result, | |
| 159 bool auto_launch, | |
| 160 int event_flags) { | |
| 161 // TODO(mukai): implement this. | |
| 162 } | |
| 163 | |
| 164 void AppListViewDelegate::InvokeSearchResultAction( | |
| 165 app_list::SearchResult* result, | |
| 166 int action_index, | |
| 167 int event_flags) { | |
| 168 // TODO(mukai): implement this. | |
| 169 } | |
| 170 | |
| 171 base::TimeDelta AppListViewDelegate::GetAutoLaunchTimeout() { | |
| 172 // Used by voice search, nothing needs to be done for now. | |
| 173 return base::TimeDelta(); | |
| 174 } | |
| 175 | |
| 176 void AppListViewDelegate::AutoLaunchCanceled() { | |
| 177 // Used by voice search, nothing needs to be done for now. | |
| 178 } | |
| 179 | |
| 180 void AppListViewDelegate::ViewInitialized() { | |
| 181 // Nothing needs to be done. | |
| 182 } | |
| 183 | |
| 184 void AppListViewDelegate::Dismiss() { | |
| 185 // Nothing needs to be done. | |
| 186 } | |
| 187 | |
| 188 void AppListViewDelegate::ViewClosing() { | |
| 189 // Nothing needs to be done. | |
| 190 } | |
| 191 | |
| 192 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { | |
| 193 return gfx::ImageSkia(); | |
| 194 } | |
| 195 | |
| 196 void AppListViewDelegate::OpenSettings() { | |
| 197 // Nothing needs to be done for now. | |
| 198 // TODO(mukai): should invoke the settings app. | |
| 199 } | |
| 200 | |
| 201 void AppListViewDelegate::OpenHelp() { | |
| 202 // Nothing needs to be done for now. | |
| 203 // TODO(mukai): should invoke the help app. | |
| 204 } | |
| 205 | |
| 206 void AppListViewDelegate::OpenFeedback() { | |
| 207 // Nothing needs to be done for now. | |
| 208 // TODO(mukai): should invoke the feedback app. | |
| 209 } | |
| 210 | |
| 211 void AppListViewDelegate::ToggleSpeechRecognition() { | |
| 212 // Nothing needs to be done. | |
| 213 } | |
| 214 | |
| 215 void AppListViewDelegate::ShowForProfileByPath( | |
| 216 const base::FilePath& profile_path) { | |
| 217 // Nothing needs to be done. | |
| 218 } | |
| 219 | |
| 220 content::WebContents* AppListViewDelegate::GetStartPageContents() { | |
| 221 return NULL; | |
| 222 } | |
| 223 | |
| 224 content::WebContents* AppListViewDelegate::GetSpeechRecognitionContents() { | |
| 225 return NULL; | |
| 226 } | |
| 227 | |
| 228 const app_list::AppListViewDelegate::Users& | |
| 229 AppListViewDelegate::GetUsers() const { | |
| 230 return users_; | |
| 231 } | |
| 232 | |
| 233 bool AppListViewDelegate::ShouldCenterWindow() const { | |
| 234 return true; | |
| 235 } | |
| 236 | |
| 237 } | |
|
oshima
2014/05/31 14:30:35
// namespace athena
Jun Mukai
2014/06/02 01:44:28
Done.
| |
| OLD | NEW |