app_list_test_view_delegate.cc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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
  3. // found in the LICENSE file.
  4. #include "ash/app_list/app_list_test_view_delegate.h"
  5. #include <string>
  6. #include <utility>
  7. #include <vector>
  8. #include "ash/app_list/model/app_list_model.h"
  9. #include "ash/public/cpp/app_list/app_list_switches.h"
  10. #include "base/callback.h"
  11. #include "base/files/file_path.h"
  12. #include "base/strings/utf_string_conversions.h"
  13. #include "ui/gfx/image/image_skia.h"
  14. namespace ash {
  15. namespace test {
  16. AppListTestViewDelegate::AppListTestViewDelegate()
  17. : model_(std::make_unique<AppListTestModel>()),
  18. search_model_(std::make_unique<SearchModel>()) {
  19. model_provider_.SetActiveModel(model_.get(), search_model_.get());
  20. }
  21. AppListTestViewDelegate::~AppListTestViewDelegate() = default;
  22. bool AppListTestViewDelegate::KeyboardTraversalEngaged() {
  23. return true;
  24. }
  25. void AppListTestViewDelegate::StartZeroStateSearch(base::OnceClosure callback,
  26. base::TimeDelta timeout) {
  27. std::move(callback).Run();
  28. }
  29. void AppListTestViewDelegate::OpenSearchResult(
  30. const std::string& result_id,
  31. int event_flags,
  32. ash::AppListLaunchedFrom launched_from,
  33. ash::AppListLaunchType launch_type,
  34. int suggestion_index,
  35. bool launch_as_default) {
  36. const SearchModel::SearchResults* results = search_model_->results();
  37. for (size_t i = 0; i < results->item_count(); ++i) {
  38. if (results->GetItemAt(i)->id() == result_id) {
  39. open_search_result_counts_[i]++;
  40. if (results->GetItemAt(i)->is_omnibox_search()) {
  41. ++open_assistant_ui_count_;
  42. }
  43. break;
  44. }
  45. }
  46. ++open_search_result_count_;
  47. if (launch_type == ash::AppListLaunchType::kAppSearchResult) {
  48. switch (launched_from) {
  49. case ash::AppListLaunchedFrom::kLaunchedFromSearchBox:
  50. case ash::AppListLaunchedFrom::kLaunchedFromSuggestionChip:
  51. case ash::AppListLaunchedFrom::kLaunchedFromRecentApps:
  52. RecordAppLaunched(launched_from);
  53. return;
  54. case ash::AppListLaunchedFrom::kLaunchedFromGrid:
  55. case ash::AppListLaunchedFrom::kLaunchedFromShelf:
  56. case ash::AppListLaunchedFrom::kLaunchedFromContinueTask:
  57. return;
  58. }
  59. }
  60. }
  61. void AppListTestViewDelegate::DismissAppList() {
  62. ++dismiss_count_;
  63. }
  64. void AppListTestViewDelegate::ReplaceTestModel(int item_count) {
  65. search_model_ = std::make_unique<SearchModel>();
  66. model_ = std::make_unique<AppListTestModel>();
  67. model_->PopulateApps(item_count);
  68. model_provider_.SetActiveModel(model_.get(), search_model_.get());
  69. }
  70. void AppListTestViewDelegate::SetSearchEngineIsGoogle(bool is_google) {
  71. search_model_->SetSearchEngineIsGoogle(is_google);
  72. }
  73. void AppListTestViewDelegate::SetIsTabletModeEnabled(bool is_tablet_mode) {
  74. is_tablet_mode_ = is_tablet_mode;
  75. }
  76. void AppListTestViewDelegate::SetShouldShowSuggestedContentInfo(
  77. bool should_show) {
  78. should_show_suggested_content_info_ = should_show;
  79. }
  80. const std::vector<SkColor>&
  81. AppListTestViewDelegate::GetWallpaperProminentColors() {
  82. return wallpaper_prominent_colors_;
  83. }
  84. void AppListTestViewDelegate::ActivateItem(
  85. const std::string& id,
  86. int event_flags,
  87. ash::AppListLaunchedFrom launched_from) {
  88. AppListItem* item = model_->FindItem(id);
  89. if (!item)
  90. return;
  91. DCHECK(!item->is_folder());
  92. static_cast<AppListTestModel::AppListTestItem*>(item)->Activate(event_flags);
  93. RecordAppLaunched(launched_from);
  94. }
  95. void AppListTestViewDelegate::GetContextMenuModel(
  96. const std::string& id,
  97. AppListItemContext item_context,
  98. GetContextMenuModelCallback callback) {
  99. AppListItem* item = model_->FindItem(id);
  100. // TODO(stevenjb/jennyz): Implement this for folder items
  101. std::unique_ptr<ui::SimpleMenuModel> menu_model;
  102. if (item && !item->is_folder()) {
  103. menu_model = static_cast<AppListTestModel::AppListTestItem*>(item)
  104. ->CreateContextMenuModel();
  105. }
  106. std::move(callback).Run(std::move(menu_model));
  107. }
  108. ui::ImplicitAnimationObserver* AppListTestViewDelegate::GetAnimationObserver(
  109. ash::AppListViewState target_state) {
  110. return nullptr;
  111. }
  112. void AppListTestViewDelegate::ShowWallpaperContextMenu(
  113. const gfx::Point& onscreen_location,
  114. ui::MenuSourceType source_type) {
  115. ++show_wallpaper_context_menu_count_;
  116. }
  117. bool AppListTestViewDelegate::CanProcessEventsOnApplistViews() {
  118. return true;
  119. }
  120. bool AppListTestViewDelegate::ShouldDismissImmediately() {
  121. return false;
  122. }
  123. int AppListTestViewDelegate::GetTargetYForAppListHide(
  124. aura::Window* root_window) {
  125. return 0;
  126. }
  127. int AppListTestViewDelegate::AdjustAppListViewScrollOffset(int offset,
  128. ui::EventType type) {
  129. return offset;
  130. }
  131. bool AppListTestViewDelegate::HasValidProfile() const {
  132. return true;
  133. }
  134. bool AppListTestViewDelegate::ShouldHideContinueSection() const {
  135. return false;
  136. }
  137. void AppListTestViewDelegate::SetHideContinueSection(bool hide) {}
  138. void AppListTestViewDelegate::GetSearchResultContextMenuModel(
  139. const std::string& result_id,
  140. GetContextMenuModelCallback callback) {
  141. auto menu = std::make_unique<ui::SimpleMenuModel>(this);
  142. // Change items if needed.
  143. int command_id = 0;
  144. menu->AddItem(command_id++, u"Item0");
  145. menu->AddItem(command_id++, u"Item1");
  146. std::move(callback).Run(std::move(menu));
  147. }
  148. ash::AssistantViewDelegate*
  149. AppListTestViewDelegate::GetAssistantViewDelegate() {
  150. return nullptr;
  151. }
  152. void AppListTestViewDelegate::OnSearchResultVisibilityChanged(
  153. const std::string& id,
  154. bool visibility) {}
  155. void AppListTestViewDelegate::MaybeIncreaseSuggestedContentInfoShownCount() {}
  156. bool AppListTestViewDelegate::IsAssistantAllowedAndEnabled() const {
  157. return false;
  158. }
  159. bool AppListTestViewDelegate::ShouldShowSuggestedContentInfo() const {
  160. return should_show_suggested_content_info_;
  161. }
  162. void AppListTestViewDelegate::MarkSuggestedContentInfoDismissed() {
  163. should_show_suggested_content_info_ = false;
  164. }
  165. void AppListTestViewDelegate::OnStateTransitionAnimationCompleted(
  166. AppListViewState state,
  167. bool was_animation_interrupted) {}
  168. AppListState AppListTestViewDelegate::GetCurrentAppListPage() const {
  169. return app_list_page_;
  170. }
  171. void AppListTestViewDelegate::OnAppListPageChanged(AppListState page) {
  172. app_list_page_ = page;
  173. }
  174. AppListViewState AppListTestViewDelegate::GetAppListViewState() const {
  175. return app_list_view_state_;
  176. }
  177. void AppListTestViewDelegate::OnViewStateChanged(AppListViewState state) {
  178. app_list_view_state_ = state;
  179. }
  180. void AppListTestViewDelegate::GetAppLaunchedMetricParams(
  181. AppLaunchedMetricParams* metric_params) {}
  182. gfx::Rect AppListTestViewDelegate::SnapBoundsToDisplayEdge(
  183. const gfx::Rect& bounds) {
  184. return bounds;
  185. }
  186. int AppListTestViewDelegate::GetShelfSize() {
  187. // TODO(mmourgos): change this to 48 once shelf-hotseat flag is enabled.
  188. // Return the height of the shelf when clamshell mode is active.
  189. return 56;
  190. }
  191. bool AppListTestViewDelegate::AppListTargetVisibility() const {
  192. return true;
  193. }
  194. bool AppListTestViewDelegate::IsInTabletMode() {
  195. return is_tablet_mode_;
  196. }
  197. AppListNotifier* AppListTestViewDelegate::GetNotifier() {
  198. return nullptr;
  199. }
  200. void AppListTestViewDelegate::RecordAppLaunched(
  201. ash::AppListLaunchedFrom launched_from) {
  202. RecordAppListAppLaunched(launched_from, app_list_view_state_,
  203. false /*tablet mode*/,
  204. false /*home launcher shown*/);
  205. }
  206. bool AppListTestViewDelegate::IsCommandIdChecked(int command_id) const {
  207. return true;
  208. }
  209. bool AppListTestViewDelegate::IsCommandIdEnabled(int command_id) const {
  210. return true;
  211. }
  212. void AppListTestViewDelegate::ExecuteCommand(int command_id, int event_flags) {}
  213. } // namespace test
  214. } // namespace ash