search_result_tile_item_view.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // Copyright 2014 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. #ifndef ASH_APP_LIST_VIEWS_SEARCH_RESULT_TILE_ITEM_VIEW_H_
  5. #define ASH_APP_LIST_VIEWS_SEARCH_RESULT_TILE_ITEM_VIEW_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "ash/app_list/views/app_list_menu_model_adapter.h"
  9. #include "ash/app_list/views/search_result_base_view.h"
  10. #include "ash/ash_export.h"
  11. #include "ash/public/cpp/app_list/app_list_types.h"
  12. #include "ui/views/context_menu_controller.h"
  13. namespace ui {
  14. class ImageModel;
  15. } // namespace ui
  16. namespace views {
  17. class ImageView;
  18. class Label;
  19. } // namespace views
  20. namespace ash {
  21. class AppListViewDelegate;
  22. class SearchResult;
  23. // A tile view that displays a search result. It hosts view for search result
  24. // that has SearchResult::DisplayType DISPLAY_TILE or DISPLAY_RECOMMENDATION.
  25. class ASH_EXPORT SearchResultTileItemView
  26. : public SearchResultBaseView,
  27. public views::ContextMenuController {
  28. public:
  29. explicit SearchResultTileItemView(AppListViewDelegate* view_delegate);
  30. SearchResultTileItemView(const SearchResultTileItemView&) = delete;
  31. SearchResultTileItemView& operator=(const SearchResultTileItemView&) = delete;
  32. ~SearchResultTileItemView() override;
  33. void OnResultChanged() override;
  34. // Informs the SearchResultTileItemView of its parent's background color. The
  35. // controls within the SearchResultTileItemView will adapt to suit the given
  36. // color.
  37. void SetParentBackgroundColor(SkColor color);
  38. void set_group_index_in_container_view(int index) {
  39. group_index_in_container_view_ = index;
  40. }
  41. int group_index_in_container_view() const {
  42. return group_index_in_container_view_;
  43. }
  44. // Overridden from views::Button:
  45. void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
  46. bool OnKeyPressed(const ui::KeyEvent& event) override;
  47. void StateChanged(ButtonState old_state) override;
  48. void PaintButtonContents(gfx::Canvas* canvas) override;
  49. // Overridden from SearchResultObserver:
  50. void OnMetadataChanged() override;
  51. // views::ContextMenuController overrides:
  52. void ShowContextMenuForViewImpl(views::View* source,
  53. const gfx::Point& point,
  54. ui::MenuSourceType source_type) override;
  55. private:
  56. // Launch the result and log to various histograms.
  57. // |by_button_press|: True if |result_| is activated by button pressing;
  58. // otherwise |result| is activated by ENTER key pressing.
  59. void ActivateResult(int event_flags, bool by_button_press);
  60. // Bound by ShowContextMenuForViewImpl().
  61. void OnGetContextMenuModel(views::View* source,
  62. const gfx::Point& point,
  63. ui::MenuSourceType source_type,
  64. std::unique_ptr<ui::SimpleMenuModel> menu_model);
  65. // The callback used when a menu closes.
  66. void OnMenuClosed();
  67. void OnButtonPressed(const ui::Event& event);
  68. void SetIcon(const gfx::ImageSkia& icon);
  69. void SetBadgeIcon(const ui::ImageModel& badge_icon,
  70. bool use_badge_icon_background);
  71. void SetTitle(const std::u16string& title);
  72. void SetTitleTags(const SearchResultTags& tags);
  73. void SetRating(float rating);
  74. void SetPrice(const std::u16string& price);
  75. AppListMenuModelAdapter::AppListViewAppType GetAppType() const;
  76. // Whether the tile view is a suggested app.
  77. bool IsSuggestedAppTile() const;
  78. // Records an app being launched.
  79. void LogAppLaunchForSuggestedApp() const;
  80. void UpdateBackgroundColor();
  81. // Gets the bounds for the selection ring (shown when the result is selected).
  82. gfx::RectF GetSelectionRingBounds() const;
  83. // Overridden from views::View:
  84. void Layout() override;
  85. const char* GetClassName() const override;
  86. gfx::Size CalculatePreferredSize() const override;
  87. std::u16string GetTooltipText(const gfx::Point& p) const override;
  88. AppListViewDelegate* const view_delegate_; // Owned by AppListView.
  89. views::ImageView* icon_ = nullptr; // Owned by views hierarchy.
  90. views::ImageView* badge_ = nullptr; // Owned by views hierarchy.
  91. views::Label* title_ = nullptr; // Owned by views hierarchy.
  92. views::Label* rating_ = nullptr; // Owned by views hierarchy.
  93. views::Label* price_ = nullptr; // Owned by views hierarchy.
  94. views::ImageView* rating_star_ = nullptr; // Owned by views hierarchy.
  95. SkColor parent_background_color_ = SK_ColorTRANSPARENT;
  96. // The index of the app in its display group in its container view. Currently,
  97. // there are three separately displayed groups for apps in launcher's
  98. // suggestion window: Installed apps, play store apps, play store reinstalled
  99. // app.
  100. int group_index_in_container_view_;
  101. const bool is_app_reinstall_recommendation_enabled_;
  102. // Whether the result view moved into selected state only because a context
  103. // menu was shown.
  104. bool selected_for_context_menu_ = false;
  105. std::unique_ptr<AppListMenuModelAdapter> context_menu_;
  106. base::WeakPtrFactory<SearchResultTileItemView> weak_ptr_factory_{this};
  107. };
  108. } // namespace ash
  109. #endif // ASH_APP_LIST_VIEWS_SEARCH_RESULT_TILE_ITEM_VIEW_H_