| 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_group_model.h" | |
| 6 #include "ash/app_list/app_list_item_model.h" | 5 #include "ash/app_list/app_list_item_model.h" |
| 7 #include "ash/app_list/app_list_item_view.h" | 6 #include "ash/app_list/app_list_item_view.h" |
| 8 #include "ash/app_list/app_list_model.h" | 7 #include "ash/app_list/app_list_model.h" |
| 9 #include "ash/app_list/app_list_view_delegate.h" | 8 #include "ash/app_list/app_list_view_delegate.h" |
| 10 #include "ash/app_list/app_list_view.h" | 9 #include "ash/app_list/app_list_view.h" |
| 11 #include "ash/shell/example_factory.h" | 10 #include "ash/shell/example_factory.h" |
| 12 #include "ash/shell/toplevel_window.h" | 11 #include "ash/shell/toplevel_window.h" |
| 13 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 14 #include "ui/views/examples/examples_window.h" | 13 #include "ui/views/examples/examples_window.h" |
| 15 | 14 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 29 LAST_TYPE, | 28 LAST_TYPE, |
| 30 }; | 29 }; |
| 31 | 30 |
| 32 WindowTypeLauncherItem(Type type) : type_(type) { | 31 WindowTypeLauncherItem(Type type) : type_(type) { |
| 33 SetIcon(GetIcon(type)); | 32 SetIcon(GetIcon(type)); |
| 34 SetTitle(GetTitle(type)); | 33 SetTitle(GetTitle(type)); |
| 35 } | 34 } |
| 36 | 35 |
| 37 static SkBitmap GetIcon(Type type) { | 36 static SkBitmap GetIcon(Type type) { |
| 38 static const SkColor kColors[] = { | 37 static const SkColor kColors[] = { |
| 39 SkColorSetA(SK_ColorRED, 0x4F), | 38 SK_ColorRED, |
| 40 SkColorSetA(SK_ColorGREEN, 0x4F), | 39 SK_ColorGREEN, |
| 41 SkColorSetA(SK_ColorBLUE, 0x4F), | 40 SK_ColorBLUE, |
| 42 SkColorSetA(SK_ColorYELLOW, 0x4F), | 41 SK_ColorYELLOW, |
| 43 SkColorSetA(SK_ColorCYAN, 0x4F), | 42 SK_ColorCYAN, |
| 44 }; | 43 }; |
| 45 | 44 |
| 45 const int kIconSize = 128; |
| 46 SkBitmap icon; | 46 SkBitmap icon; |
| 47 icon.setConfig(SkBitmap::kARGB_8888_Config, | 47 icon.setConfig(SkBitmap::kARGB_8888_Config, kIconSize, kIconSize); |
| 48 ash::AppListItemView::kIconSize, | |
| 49 ash::AppListItemView::kIconSize); | |
| 50 icon.allocPixels(); | 48 icon.allocPixels(); |
| 51 icon.eraseColor(kColors[static_cast<int>(type) % arraysize(kColors)]); | 49 icon.eraseColor(kColors[static_cast<int>(type) % arraysize(kColors)]); |
| 52 return icon; | 50 return icon; |
| 53 } | 51 } |
| 54 | 52 |
| 55 static std::string GetTitle(Type type) { | 53 static std::string GetTitle(Type type) { |
| 56 switch (type) { | 54 switch (type) { |
| 57 case TOPLEVEL_WINDOW: | 55 case TOPLEVEL_WINDOW: |
| 58 return "Create Window"; | 56 return "Create Window"; |
| 59 case NON_RESIZABLE_WINDOW: | 57 case NON_RESIZABLE_WINDOW: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 Type type_; | 102 Type type_; |
| 105 | 103 |
| 106 DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncherItem); | 104 DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncherItem); |
| 107 }; | 105 }; |
| 108 | 106 |
| 109 class ExampleAppListViewDelegate : public ash::AppListViewDelegate { | 107 class ExampleAppListViewDelegate : public ash::AppListViewDelegate { |
| 110 public: | 108 public: |
| 111 ExampleAppListViewDelegate() {} | 109 ExampleAppListViewDelegate() {} |
| 112 | 110 |
| 113 private: | 111 private: |
| 112 // Overridden from ash::AppListViewDelegate: |
| 113 virtual void BuildAppListModel(const std::string& query, |
| 114 AppListModel* model) OVERRIDE { |
| 115 for (int i = 0; |
| 116 i < static_cast<int>(WindowTypeLauncherItem::LAST_TYPE); |
| 117 ++i) { |
| 118 WindowTypeLauncherItem::Type type = |
| 119 static_cast<WindowTypeLauncherItem::Type>(i); |
| 120 |
| 121 std::string title = WindowTypeLauncherItem::GetTitle(type); |
| 122 if (title.find(query) != std::string::npos) |
| 123 model->AddItem(new WindowTypeLauncherItem(type)); |
| 124 } |
| 125 } |
| 126 |
| 114 virtual void OnAppListItemActivated(ash::AppListItemModel* item, | 127 virtual void OnAppListItemActivated(ash::AppListItemModel* item, |
| 115 int event_flags) OVERRIDE { | 128 int event_flags) OVERRIDE { |
| 116 static_cast<WindowTypeLauncherItem*>(item)->Activate(event_flags); | 129 static_cast<WindowTypeLauncherItem*>(item)->Activate(event_flags); |
| 117 } | 130 } |
| 118 | 131 |
| 119 DISALLOW_COPY_AND_ASSIGN(ExampleAppListViewDelegate); | 132 DISALLOW_COPY_AND_ASSIGN(ExampleAppListViewDelegate); |
| 120 }; | 133 }; |
| 121 | 134 |
| 122 ash::AppListItemGroupModel* CreateGroup( | |
| 123 const std::string& title, | |
| 124 WindowTypeLauncherItem::Type start_type, | |
| 125 WindowTypeLauncherItem::Type end_type) { | |
| 126 ash::AppListItemGroupModel* group = | |
| 127 new ash::AppListItemGroupModel(title); | |
| 128 for (int i = static_cast<int>(start_type); | |
| 129 i < static_cast<int>(end_type); | |
| 130 ++i) { | |
| 131 WindowTypeLauncherItem::Type type = | |
| 132 static_cast<WindowTypeLauncherItem::Type>(i); | |
| 133 group->AddItem(new WindowTypeLauncherItem(type)); | |
| 134 } | |
| 135 return group; | |
| 136 } | |
| 137 | |
| 138 } // namespace | 135 } // namespace |
| 139 | 136 |
| 140 void BuildAppListModel(ash::AppListModel* model) { | |
| 141 model->AddGroup(CreateGroup("Windows", | |
| 142 WindowTypeLauncherItem::TOPLEVEL_WINDOW, | |
| 143 WindowTypeLauncherItem::WIDGETS_WINDOW)); | |
| 144 model->AddGroup(CreateGroup("Samples", | |
| 145 WindowTypeLauncherItem::WIDGETS_WINDOW, | |
| 146 WindowTypeLauncherItem::LAST_TYPE)); | |
| 147 } | |
| 148 | |
| 149 ash::AppListViewDelegate* CreateAppListViewDelegate() { | 137 ash::AppListViewDelegate* CreateAppListViewDelegate() { |
| 150 return new ExampleAppListViewDelegate; | 138 return new ExampleAppListViewDelegate; |
| 151 } | 139 } |
| 152 | 140 |
| 153 } // namespace shell | 141 } // namespace shell |
| 154 } // namespace ash | 142 } // namespace ash |
| OLD | NEW |