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

Unified Diff: ui/aura_shell/examples/app_list_model.cc

Issue 8890049: [Aura] Implement views-based applist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased and refactored 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 side-by-side diff with in-line comments
Download patch
Index: ui/aura_shell/examples/app_list_model.cc
diff --git a/ui/aura_shell/examples/app_list_model.cc b/ui/aura_shell/examples/app_list_model.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0365120c7ba198db0eb4c600d0e089e658363b9a
--- /dev/null
+++ b/ui/aura_shell/examples/app_list_model.cc
@@ -0,0 +1,133 @@
+// Copyright (c) 2011 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 "base/basictypes.h"
+#include "ui/aura_shell/app_list/app_list_item_model.h"
+#include "ui/aura_shell/app_list/app_list_item_group_model.h"
+#include "ui/aura_shell/app_list/app_list_model.h"
+#include "ui/aura_shell/app_list/tile_view.h"
+#include "ui/aura_shell/examples/example_factory.h"
+#include "ui/aura_shell/examples/toplevel_window.h"
+#include "ui/views/examples/examples_window.h"
+
+namespace aura_shell {
+namespace examples {
+
+namespace {
+
+class WindowTypeLauncherItem : public AppListItemModel {
+ public:
+ enum Type {
+ TOPLEVEL_WINDOW = 0,
+ NON_RESIZABLE_WINDOW,
+ LOCK_SCREEN,
+ WIDGETS_WINDOW,
+ EXAMPLES_WINDOW,
+ LAST_TYPE,
+ };
+
+ WindowTypeLauncherItem(Type type)
+ : AppListItemModel(GetIcon(type), GetTitle(type)),
+ type_(type) {
+ }
+
+ static SkBitmap GetIcon(Type type) {
+ static const SkColor kColors[] = {
+ SkColorSetA(SK_ColorRED, 0x4F),
+ SkColorSetA(SK_ColorGREEN, 0x4F),
+ SkColorSetA(SK_ColorBLUE, 0x4F),
+ SkColorSetA(SK_ColorYELLOW, 0x4F),
+ SkColorSetA(SK_ColorCYAN, 0x4F),
+ };
+
+ SkBitmap icon;
+ icon.setConfig(SkBitmap::kARGB_8888_Config,
+ TileView::kIconSize,
+ TileView::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.";
+ }
+ }
+
+ private:
+ virtual void Activate(int event_flags) OVERRIDE {
+ 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: {
+ views::examples::ShowExamplesWindow(false);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ Type type_;
+
+ DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncherItem);
+};
+
+AppListItemGroupModel* CreateGroup(const std::string& title,
+ WindowTypeLauncherItem::Type start_type,
+ WindowTypeLauncherItem::Type end_type) {
+ AppListItemGroupModel* group = new AppListItemGroupModel(title);
+ for (int i = static_cast<int>(start_type);
+ i < static_cast<int>(end_type);
+ ++i) {
+ WindowTypeLauncherItem::Type type =
+ static_cast<WindowTypeLauncherItem::Type>(i);
+ group->Add(new WindowTypeLauncherItem(type));
+ }
+ return group;
+}
+
+} // namespace
+
+AppListModel* CreateAppListModel() {
+ AppListModel* model = new AppListModel();
+ model->Add(CreateGroup("Window",
+ WindowTypeLauncherItem::TOPLEVEL_WINDOW,
+ WindowTypeLauncherItem::WIDGETS_WINDOW));
+ model->Add(CreateGroup("Samples",
+ WindowTypeLauncherItem::WIDGETS_WINDOW,
+ WindowTypeLauncherItem::LAST_TYPE));
+ return model;
+}
+
+} // namespace examples
+} // namespace aura_shell

Powered by Google App Engine
This is Rietveld 408576698