1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/app_list/app_list_item_model.h"
#include "ash/app_list/app_list_item_view.h"
#include "ash/app_list/app_list_model.h"
#include "ash/app_list/app_list_view_delegate.h"
#include "ash/app_list/app_list_view.h"
#include "ash/shell/example_factory.h"
#include "ash/shell/toplevel_window.h"
#include "base/basictypes.h"
#include "ui/views/examples/examples_window.h"
namespace ash {
namespace shell {
namespace {
class WindowTypeLauncherItem : public ash::AppListItemModel {
public:
enum Type {
TOPLEVEL_WINDOW = 0,
NON_RESIZABLE_WINDOW,
LOCK_SCREEN,
WIDGETS_WINDOW,
EXAMPLES_WINDOW,
LAST_TYPE,
};
WindowTypeLauncherItem(Type type) : type_(type) {
SetIcon(GetIcon(type));
SetTitle(GetTitle(type));
}
static SkBitmap GetIcon(Type type) {
static const SkColor kColors[] = {
SK_ColorRED,
SK_ColorGREEN,
SK_ColorBLUE,
SK_ColorYELLOW,
SK_ColorCYAN,
};
const int kIconSize = 128;
SkBitmap icon;
icon.setConfig(SkBitmap::kARGB_8888_Config, kIconSize, kIconSize);
icon.allocPixels();
icon.eraseColor(kColors[static_cast<int>(type) % arraysize(kColors)]);
return icon;
}
static std::string GetTitle(Type type) {
switch (type) {
case TOPLEVEL_WINDOW:
return "Create Window";
case NON_RESIZABLE_WINDOW:
return "Create Non-Resizable Window";
case LOCK_SCREEN:
return "Lock Screen";
case WIDGETS_WINDOW:
return "Show Example Widgets";
case EXAMPLES_WINDOW:
return "Open Views Examples Window";
default:
return "Unknown window type.";
}
}
void Activate(int event_flags) {
switch (type_) {
case TOPLEVEL_WINDOW: {
ToplevelWindow::CreateParams params;
params.can_resize = true;
ToplevelWindow::CreateToplevelWindow(params);
break;
}
case NON_RESIZABLE_WINDOW: {
ToplevelWindow::CreateToplevelWindow(ToplevelWindow::CreateParams());
break;
}
case LOCK_SCREEN: {
CreateLockScreen();
break;
}
case WIDGETS_WINDOW: {
CreateWidgetsWindow();
break;
}
case EXAMPLES_WINDOW: {
#if !defined(OS_MACOSX)
views::examples::ShowExamplesWindow(false);
#endif
break;
}
default:
break;
}
}
private:
Type type_;
DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncherItem);
};
class ExampleAppListViewDelegate : public ash::AppListViewDelegate {
public:
ExampleAppListViewDelegate() : model_(NULL) {}
private:
// Overridden from ash::AppListViewDelegate:
virtual void SetModel(AppListModel* model) OVERRIDE {
model_ = model;
}
virtual void UpdateModel(const std::string& query) OVERRIDE {
DCHECK(model_ && model_->item_count() == 0);
for (int i = 0;
i < static_cast<int>(WindowTypeLauncherItem::LAST_TYPE);
++i) {
WindowTypeLauncherItem::Type type =
static_cast<WindowTypeLauncherItem::Type>(i);
std::string title = WindowTypeLauncherItem::GetTitle(type);
if (title.find(query) != std::string::npos)
model_->AddItem(new WindowTypeLauncherItem(type));
}
}
virtual void OnAppListItemActivated(ash::AppListItemModel* item,
int event_flags) OVERRIDE {
static_cast<WindowTypeLauncherItem*>(item)->Activate(event_flags);
}
AppListModel* model_;
DISALLOW_COPY_AND_ASSIGN(ExampleAppListViewDelegate);
};
} // namespace
ash::AppListViewDelegate* CreateAppListViewDelegate() {
return new ExampleAppListViewDelegate;
}
} // namespace shell
} // namespace ash
|