Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: athena/home/app_list_view_delegate.cc

Issue 311113005: AppModelBuilder to athena. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « athena/home/app_list_view_delegate.h ('k') | athena/home/home_card_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "athena/home/app_list_view_delegate.h" 5 #include "athena/home/app_list_view_delegate.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "athena/home/public/app_model_builder.h"
9 #include "base/basictypes.h" 10 #include "base/basictypes.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 14 #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" 15 #include "ui/app_list/app_list_model.h"
17 #include "ui/app_list/search_box_model.h" 16 #include "ui/app_list/search_box_model.h"
18 #include "ui/app_list/search_result.h" 17 #include "ui/app_list/search_result.h"
19 #include "ui/app_list/speech_ui_model.h" 18 #include "ui/app_list/speech_ui_model.h"
20 #include "ui/gfx/image/image_skia.h" 19 #include "ui/gfx/image/image_skia.h"
21 20
22 namespace athena { 21 namespace athena {
23 22
24 namespace { 23 AppListViewDelegate::AppListViewDelegate(AppModelBuilder* model_builder)
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), 24 : model_(new app_list::AppListModel),
108 speech_ui_(new app_list::SpeechUIModel( 25 speech_ui_(new app_list::SpeechUIModel(
109 app_list::SPEECH_RECOGNITION_OFF)) { 26 app_list::SPEECH_RECOGNITION_OFF)) {
110 PopulateApps(); 27 model_builder->PopulateApps(model_.get());
111 // TODO(mukai): get the text from the resources. 28 // TODO(mukai): get the text from the resources.
112 model_->search_box()->SetHintText(base::ASCIIToUTF16("Search")); 29 model_->search_box()->SetHintText(base::ASCIIToUTF16("Search"));
113 } 30 }
114 31
115 AppListViewDelegate::~AppListViewDelegate() { 32 AppListViewDelegate::~AppListViewDelegate() {
116 } 33 }
117 34
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 { 35 bool AppListViewDelegate::ForceNativeDesktop() const {
126 return false; 36 return false;
127 } 37 }
128 38
129 void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) { 39 void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) {
130 // Nothing needs to be done. 40 // Nothing needs to be done.
131 } 41 }
132 42
133 app_list::AppListModel* AppListViewDelegate::GetModel() { 43 app_list::AppListModel* AppListViewDelegate::GetModel() {
134 return model_.get(); 44 return model_.get();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 const app_list::AppListViewDelegate::Users& 136 const app_list::AppListViewDelegate::Users&
227 AppListViewDelegate::GetUsers() const { 137 AppListViewDelegate::GetUsers() const {
228 return users_; 138 return users_;
229 } 139 }
230 140
231 bool AppListViewDelegate::ShouldCenterWindow() const { 141 bool AppListViewDelegate::ShouldCenterWindow() const {
232 return true; 142 return true;
233 } 143 }
234 144
235 } // namespace athena 145 } // namespace athena
OLDNEW
« no previous file with comments | « athena/home/app_list_view_delegate.h ('k') | athena/home/home_card_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698