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

Side by Side Diff: ui/aura_shell/examples/app_list.cc

Issue 8890049: [Aura] Implement views-based applist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win_aura Created 9 years 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 | « ui/aura_shell/aura_shell_switches.cc ('k') | ui/aura_shell/examples/aura_shell_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "base/basictypes.h"
6 #include "ui/aura_shell/app_list/app_list_item_group_model.h"
7 #include "ui/aura_shell/app_list/app_list_item_model.h"
8 #include "ui/aura_shell/app_list/app_list_item_view.h"
9 #include "ui/aura_shell/app_list/app_list_model.h"
10 #include "ui/aura_shell/app_list/app_list_view_delegate.h"
11 #include "ui/aura_shell/app_list/app_list_view.h"
12 #include "ui/aura_shell/examples/example_factory.h"
13 #include "ui/aura_shell/examples/toplevel_window.h"
14 #include "ui/views/examples/examples_window.h"
15
16 namespace aura_shell {
17 namespace examples {
18
19 namespace {
20
21 class WindowTypeLauncherItem : public AppListItemModel {
22 public:
23 enum Type {
24 TOPLEVEL_WINDOW = 0,
25 NON_RESIZABLE_WINDOW,
26 LOCK_SCREEN,
27 WIDGETS_WINDOW,
28 EXAMPLES_WINDOW,
29 LAST_TYPE,
30 };
31
32 WindowTypeLauncherItem(Type type) : type_(type) {
33 SetIcon(GetIcon(type));
34 SetTitle(GetTitle(type));
35 }
36
37 static SkBitmap GetIcon(Type type) {
38 static const SkColor kColors[] = {
39 SkColorSetA(SK_ColorRED, 0x4F),
40 SkColorSetA(SK_ColorGREEN, 0x4F),
41 SkColorSetA(SK_ColorBLUE, 0x4F),
42 SkColorSetA(SK_ColorYELLOW, 0x4F),
43 SkColorSetA(SK_ColorCYAN, 0x4F),
44 };
45
46 SkBitmap icon;
47 icon.setConfig(SkBitmap::kARGB_8888_Config,
48 AppListItemView::kIconSize,
49 AppListItemView::kIconSize);
50 icon.allocPixels();
51 icon.eraseColor(kColors[static_cast<int>(type) % arraysize(kColors)]);
52 return icon;
53 }
54
55 static std::string GetTitle(Type type) {
56 switch (type) {
57 case TOPLEVEL_WINDOW:
58 return "Create Window";
59 case NON_RESIZABLE_WINDOW:
60 return "Create Non-Resizable Window";
61 case LOCK_SCREEN:
62 return "Lock Screen";
63 case WIDGETS_WINDOW:
64 return "Show Example Widgets";
65 case EXAMPLES_WINDOW:
66 return "Open Views Examples Window";
67 default:
68 return "Unknown window type.";
69 }
70 }
71
72 void Activate(int event_flags) {
73 switch (type_) {
74 case TOPLEVEL_WINDOW: {
75 ToplevelWindow::CreateParams params;
76 params.can_resize = true;
77 ToplevelWindow::CreateToplevelWindow(params);
78 break;
79 }
80 case NON_RESIZABLE_WINDOW: {
81 ToplevelWindow::CreateToplevelWindow(ToplevelWindow::CreateParams());
82 break;
83 }
84 case LOCK_SCREEN: {
85 CreateLockScreen();
86 break;
87 }
88 case WIDGETS_WINDOW: {
89 CreateWidgetsWindow();
90 break;
91 }
92 case EXAMPLES_WINDOW: {
93 views::examples::ShowExamplesWindow(false);
94 break;
95 }
96 default:
97 break;
98 }
99 }
100
101 private:
102 Type type_;
103
104 DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncherItem);
105 };
106
107 class ExampleAppListViewDelegate : public AppListViewDelegate {
108 public:
109 ExampleAppListViewDelegate() {}
110
111 private:
112 virtual void OnAppListItemActivated(AppListItemModel* item,
113 int event_flags) OVERRIDE {
114 static_cast<WindowTypeLauncherItem*>(item)->Activate(event_flags);
115 }
116
117 DISALLOW_COPY_AND_ASSIGN(ExampleAppListViewDelegate);
118 };
119
120 AppListItemGroupModel* CreateGroup(const std::string& title,
121 WindowTypeLauncherItem::Type start_type,
122 WindowTypeLauncherItem::Type end_type) {
123 AppListItemGroupModel* group = new AppListItemGroupModel(title);
124 for (int i = static_cast<int>(start_type);
125 i < static_cast<int>(end_type);
126 ++i) {
127 WindowTypeLauncherItem::Type type =
128 static_cast<WindowTypeLauncherItem::Type>(i);
129 group->AddItem(new WindowTypeLauncherItem(type));
130 }
131 return group;
132 }
133
134 } // namespace
135
136 void BuildAppListModel(AppListModel* model) {
137 model->AddGroup(CreateGroup("Windows",
138 WindowTypeLauncherItem::TOPLEVEL_WINDOW,
139 WindowTypeLauncherItem::WIDGETS_WINDOW));
140 model->AddGroup(CreateGroup("Samples",
141 WindowTypeLauncherItem::WIDGETS_WINDOW,
142 WindowTypeLauncherItem::LAST_TYPE));
143 }
144
145 AppListViewDelegate* CreateAppListViewDelegate() {
146 return new ExampleAppListViewDelegate;
147 }
148
149 // TODO(xiyuan): Remove this.
150 void CreateAppList(const gfx::Rect& bounds,
151 const ShellDelegate::SetWidgetCallback& callback) {
152 AppListModel* model = new AppListModel();
153 BuildAppListModel(model);
154
155 new aura_shell::AppListView(
156 model,
157 CreateAppListViewDelegate(),
158 bounds,
159 callback);
160 }
161
162 } // namespace examples
163 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/aura_shell_switches.cc ('k') | ui/aura_shell/examples/aura_shell_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698