OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/app_list/app_list_item_model.h" | |
6 #include "ash/app_list/app_list_item_view.h" | |
7 #include "ash/app_list/app_list_model.h" | |
8 #include "ash/app_list/app_list_view.h" | |
9 #include "ash/app_list/app_list_view_delegate.h" | |
10 #include "ash/shell.h" | 5 #include "ash/shell.h" |
11 #include "ash/shell_delegate.h" | 6 #include "ash/shell_delegate.h" |
12 #include "ash/shell/example_factory.h" | 7 #include "ash/shell/example_factory.h" |
13 #include "ash/shell/toplevel_window.h" | 8 #include "ash/shell/toplevel_window.h" |
14 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "ui/app_list/app_list_item_model.h" |
| 11 #include "ui/app_list/app_list_item_view.h" |
| 12 #include "ui/app_list/app_list_model.h" |
| 13 #include "ui/app_list/app_list_view.h" |
| 14 #include "ui/app_list/app_list_view_delegate.h" |
15 #include "ui/views/examples/examples_window.h" | 15 #include "ui/views/examples/examples_window.h" |
16 | 16 |
17 namespace ash { | 17 namespace ash { |
18 namespace shell { | 18 namespace shell { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 class WindowTypeLauncherItem : public ash::AppListItemModel { | 22 class WindowTypeLauncherItem : public app_list::AppListItemModel { |
23 public: | 23 public: |
24 enum Type { | 24 enum Type { |
25 TOPLEVEL_WINDOW = 0, | 25 TOPLEVEL_WINDOW = 0, |
26 NON_RESIZABLE_WINDOW, | 26 NON_RESIZABLE_WINDOW, |
27 LOCK_SCREEN, | 27 LOCK_SCREEN, |
28 WIDGETS_WINDOW, | 28 WIDGETS_WINDOW, |
29 EXAMPLES_WINDOW, | 29 EXAMPLES_WINDOW, |
30 LAST_TYPE, | 30 LAST_TYPE, |
31 }; | 31 }; |
32 | 32 |
33 WindowTypeLauncherItem(Type type) : type_(type) { | 33 explicit WindowTypeLauncherItem(Type type) : type_(type) { |
34 SetIcon(GetIcon(type)); | 34 SetIcon(GetIcon(type)); |
35 SetTitle(GetTitle(type)); | 35 SetTitle(GetTitle(type)); |
36 } | 36 } |
37 | 37 |
38 static SkBitmap GetIcon(Type type) { | 38 static SkBitmap GetIcon(Type type) { |
39 static const SkColor kColors[] = { | 39 static const SkColor kColors[] = { |
40 SK_ColorRED, | 40 SK_ColorRED, |
41 SK_ColorGREEN, | 41 SK_ColorGREEN, |
42 SK_ColorBLUE, | 42 SK_ColorBLUE, |
43 SK_ColorYELLOW, | 43 SK_ColorYELLOW, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 break; | 101 break; |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 private: | 105 private: |
106 Type type_; | 106 Type type_; |
107 | 107 |
108 DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncherItem); | 108 DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncherItem); |
109 }; | 109 }; |
110 | 110 |
111 class ExampleAppListViewDelegate : public ash::AppListViewDelegate { | 111 class ExampleAppListViewDelegate : public app_list::AppListViewDelegate { |
112 public: | 112 public: |
113 ExampleAppListViewDelegate() : model_(NULL) {} | 113 ExampleAppListViewDelegate() : model_(NULL) {} |
114 | 114 |
115 private: | 115 private: |
116 // Overridden from ash::AppListViewDelegate: | 116 // Overridden from ash::AppListViewDelegate: |
117 virtual void SetModel(AppListModel* model) OVERRIDE { | 117 virtual void SetModel(app_list::AppListModel* model) OVERRIDE { |
118 model_ = model; | 118 model_ = model; |
119 } | 119 } |
120 | 120 |
121 virtual void UpdateModel(const std::string& query) OVERRIDE { | 121 virtual void UpdateModel(const std::string& query) OVERRIDE { |
122 DCHECK(model_ && model_->item_count() == 0); | 122 DCHECK(model_ && model_->item_count() == 0); |
123 | 123 |
124 for (int i = 0; | 124 for (int i = 0; |
125 i < static_cast<int>(WindowTypeLauncherItem::LAST_TYPE); | 125 i < static_cast<int>(WindowTypeLauncherItem::LAST_TYPE); |
126 ++i) { | 126 ++i) { |
127 WindowTypeLauncherItem::Type type = | 127 WindowTypeLauncherItem::Type type = |
128 static_cast<WindowTypeLauncherItem::Type>(i); | 128 static_cast<WindowTypeLauncherItem::Type>(i); |
129 | 129 |
130 std::string title = WindowTypeLauncherItem::GetTitle(type); | 130 std::string title = WindowTypeLauncherItem::GetTitle(type); |
131 if (title.find(query) != std::string::npos) | 131 if (title.find(query) != std::string::npos) |
132 model_->AddItem(new WindowTypeLauncherItem(type)); | 132 model_->AddItem(new WindowTypeLauncherItem(type)); |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 virtual void OnAppListItemActivated(ash::AppListItemModel* item, | 136 virtual void OnAppListItemActivated(app_list::AppListItemModel* item, |
137 int event_flags) OVERRIDE { | 137 int event_flags) OVERRIDE { |
138 static_cast<WindowTypeLauncherItem*>(item)->Activate(event_flags); | 138 static_cast<WindowTypeLauncherItem*>(item)->Activate(event_flags); |
139 } | 139 } |
140 | 140 |
141 AppListModel* model_; | 141 virtual void Close() OVERRIDE { |
| 142 DCHECK(ash::Shell::HasInstance()); |
| 143 if (Shell::GetInstance()->GetAppListTargetVisibility()) |
| 144 Shell::GetInstance()->ToggleAppList(); |
| 145 } |
| 146 |
| 147 app_list::AppListModel* model_; |
142 | 148 |
143 DISALLOW_COPY_AND_ASSIGN(ExampleAppListViewDelegate); | 149 DISALLOW_COPY_AND_ASSIGN(ExampleAppListViewDelegate); |
144 }; | 150 }; |
145 | 151 |
146 } // namespace | 152 } // namespace |
147 | 153 |
148 ash::AppListViewDelegate* CreateAppListViewDelegate() { | 154 app_list::AppListViewDelegate* CreateAppListViewDelegate() { |
149 return new ExampleAppListViewDelegate; | 155 return new ExampleAppListViewDelegate; |
150 } | 156 } |
151 | 157 |
152 } // namespace shell | 158 } // namespace shell |
153 } // namespace ash | 159 } // namespace ash |
OLD | NEW |