OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/app_list/test/app_list_test_model.h" | 5 #include "ui/app_list/test/app_list_test_model.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "grit/ui_resources.h" | 9 #include "grit/ui_resources.h" |
| 10 #include "third_party/skia/include/core/SkBitmap.h" |
| 11 #include "ui/app_list/app_list_constants.h" |
10 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 13 #include "ui/gfx/image/image_skia.h" |
11 | 14 |
12 namespace app_list { | 15 namespace app_list { |
13 namespace test { | 16 namespace test { |
14 | 17 |
| 18 gfx::ImageSkia CreateImageSkia(int width, int height) { |
| 19 SkBitmap bitmap; |
| 20 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 21 bitmap.allocPixels(); |
| 22 bitmap.eraseARGB(255, 0, 255, 0); |
| 23 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 24 } |
| 25 |
15 // static | 26 // static |
16 const char AppListTestModel::kItemType[] = "TestItem"; | 27 const char AppListTestModel::kItemType[] = "TestItem"; |
17 | 28 |
18 // AppListTestModel::AppListTestItem | 29 // AppListTestModel::AppListTestItem |
19 | 30 |
20 AppListTestModel::AppListTestItem::AppListTestItem( | 31 AppListTestModel::AppListTestItem::AppListTestItem( |
21 const std::string& id, | 32 const std::string& id, |
22 AppListTestModel* model) | 33 AppListTestModel* model) |
23 : AppListItem(id), | 34 : AppListItem(id), |
24 model_(model) { | 35 model_(model) { |
| 36 SetIcon(CreateImageSkia(kPreferredIconDimension, kPreferredIconDimension), |
| 37 false /* has_shadow */); |
25 } | 38 } |
26 | 39 |
27 AppListTestModel::AppListTestItem::~AppListTestItem() { | 40 AppListTestModel::AppListTestItem::~AppListTestItem() { |
28 } | 41 } |
29 | 42 |
30 void AppListTestModel::AppListTestItem::Activate(int event_flags) { | 43 void AppListTestModel::AppListTestItem::Activate(int event_flags) { |
31 model_->ItemActivated(this); | 44 model_->ItemActivated(this); |
32 } | 45 } |
33 | 46 |
34 const char* AppListTestModel::AppListTestItem::GetItemType() const { | 47 const char* AppListTestModel::AppListTestItem::GetItemType() const { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 return static_cast<AppListFolderItem*>(merged_item); | 99 return static_cast<AppListFolderItem*>(merged_item); |
87 } | 100 } |
88 | 101 |
89 AppListFolderItem* AppListTestModel::CreateAndAddOemFolder( | 102 AppListFolderItem* AppListTestModel::CreateAndAddOemFolder( |
90 const std::string& id) { | 103 const std::string& id) { |
91 AppListFolderItem* folder = | 104 AppListFolderItem* folder = |
92 new AppListFolderItem(id, AppListFolderItem::FOLDER_TYPE_OEM); | 105 new AppListFolderItem(id, AppListFolderItem::FOLDER_TYPE_OEM); |
93 return static_cast<AppListFolderItem*>(AddItem(folder)); | 106 return static_cast<AppListFolderItem*>(AddItem(folder)); |
94 } | 107 } |
95 | 108 |
| 109 AppListFolderItem* AppListTestModel::CreateSingleItemFolder( |
| 110 const std::string& folder_id, |
| 111 const std::string& item_id) { |
| 112 AppListTestItem* item = CreateItem(item_id); |
| 113 AddItemToFolder(item, folder_id); |
| 114 AppListItem* folder_item = FindItem(folder_id); |
| 115 DCHECK(folder_item->GetItemType() == AppListFolderItem::kItemType); |
| 116 return static_cast<AppListFolderItem*>(folder_item); |
| 117 } |
| 118 |
96 void AppListTestModel::PopulateAppWithId(int id) { | 119 void AppListTestModel::PopulateAppWithId(int id) { |
97 CreateAndAddItem(GetItemName(id)); | 120 CreateAndAddItem(GetItemName(id)); |
98 } | 121 } |
99 | 122 |
100 std::string AppListTestModel::GetModelContent() { | 123 std::string AppListTestModel::GetModelContent() { |
101 std::string content; | 124 std::string content; |
102 for (size_t i = 0; i < top_level_item_list()->item_count(); ++i) { | 125 for (size_t i = 0; i < top_level_item_list()->item_count(); ++i) { |
103 if (i > 0) | 126 if (i > 0) |
104 content += ','; | 127 content += ','; |
105 content += top_level_item_list()->item_at(i)->id(); | 128 content += top_level_item_list()->item_at(i)->id(); |
(...skipping 28 matching lines...) Expand all Loading... |
134 item->SetHighlighted(true); | 157 item->SetHighlighted(true); |
135 } | 158 } |
136 | 159 |
137 void AppListTestModel::ItemActivated(AppListTestItem* item) { | 160 void AppListTestModel::ItemActivated(AppListTestItem* item) { |
138 last_activated_ = item; | 161 last_activated_ = item; |
139 ++activate_count_; | 162 ++activate_count_; |
140 } | 163 } |
141 | 164 |
142 } // namespace test | 165 } // namespace test |
143 } // namespace app_list | 166 } // namespace app_list |
OLD | NEW |