OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef UI_APP_LIST_VIEWS_SEARCH_RESULT_TILE_ITEM_VIEW_H_ | 5 #ifndef UI_APP_LIST_VIEWS_SEARCH_RESULT_TILE_ITEM_VIEW_H_ |
6 #define UI_APP_LIST_VIEWS_SEARCH_RESULT_TILE_ITEM_VIEW_H_ | 6 #define UI_APP_LIST_VIEWS_SEARCH_RESULT_TILE_ITEM_VIEW_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "ui/app_list/search_result_observer.h" | 9 #include "ui/app_list/search_result_observer.h" |
10 #include "ui/app_list/views/tile_item_view.h" | 10 #include "ui/app_list/views/tile_item_view.h" |
11 #include "ui/views/context_menu_controller.h" | 11 #include "ui/views/context_menu_controller.h" |
12 | 12 |
13 namespace views { | 13 namespace views { |
14 class MenuRunner; | 14 class MenuRunner; |
15 class Label; | |
16 } | 15 } |
17 | 16 |
18 namespace app_list { | 17 namespace app_list { |
19 | 18 |
20 class AppListViewDelegate; | 19 class AppListViewDelegate; |
21 class SearchResult; | 20 class SearchResult; |
22 class SearchResultContainerView; | 21 class SearchResultContainerView; |
23 | 22 |
24 // A TileItemView that displays a search result. | 23 // A TileItemView that displays a search result. |
25 class APP_LIST_EXPORT SearchResultTileItemView | 24 class APP_LIST_EXPORT SearchResultTileItemView |
26 : public TileItemView, | 25 : public TileItemView, |
27 public views::ContextMenuController, | 26 public views::ContextMenuController, |
28 public SearchResultObserver { | 27 public SearchResultObserver { |
29 public: | 28 public: |
30 explicit SearchResultTileItemView(SearchResultContainerView* result_container, | 29 explicit SearchResultTileItemView(SearchResultContainerView* result_container, |
31 AppListViewDelegate* view_delegate); | 30 AppListViewDelegate* view_delegate); |
32 ~SearchResultTileItemView() override; | 31 ~SearchResultTileItemView() override; |
33 | 32 |
34 SearchResult* result() { return item_; } | 33 SearchResult* result() { return item_; } |
35 void SetSearchResult(SearchResult* item); | 34 void SetSearchResult(SearchResult* item); |
36 | 35 |
37 // Overridden from TileItemView: | 36 // Overridden from TileItemView: |
38 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 37 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
39 bool OnKeyPressed(const ui::KeyEvent& event) override; | 38 bool OnKeyPressed(const ui::KeyEvent& event) override; |
40 | 39 |
41 // Overridden from SearchResultObserver: | 40 // Overridden from SearchResultObserver: |
42 void OnIconChanged() override; | 41 void OnIconChanged() override; |
43 void OnBadgeIconChanged() override; | 42 void OnBadgeIconChanged() override; |
44 void OnRatingChanged() override; | |
45 void OnFormattedPriceChanged() override; | |
46 void OnResultDestroying() override; | 43 void OnResultDestroying() override; |
47 | 44 |
48 // views::ContextMenuController overrides: | 45 // views::ContextMenuController overrides: |
49 void ShowContextMenuForView(views::View* source, | 46 void ShowContextMenuForView(views::View* source, |
50 const gfx::Point& point, | 47 const gfx::Point& point, |
51 ui::MenuSourceType source_type) override; | 48 ui::MenuSourceType source_type) override; |
52 | 49 |
53 private: | 50 private: |
54 // Shows rating in proper format if |rating| is not negative. Otherwise, hides | |
55 // the rating label. | |
56 void SetRating(float rating); | |
57 | |
58 // Shows price if |price| is not empty. Otherwise, hides the price label. | |
59 void SetPrice(const base::string16& price); | |
60 | |
61 // Overridden from views::View: | 51 // Overridden from views::View: |
62 void Layout() override; | 52 void Layout() override; |
63 gfx::Size CalculatePreferredSize() const override; | 53 gfx::Size CalculatePreferredSize() const override; |
64 | 54 |
65 SearchResultContainerView* result_container_; // Parent view | 55 SearchResultContainerView* result_container_; // Parent view |
66 | 56 |
67 // Owned by the model provided by the AppListViewDelegate. | 57 // Owned by the model provided by the AppListViewDelegate. |
68 SearchResult* item_ = nullptr; | 58 SearchResult* item_; |
69 | |
70 views::Label* rating_ = nullptr; // Owned by views hierarchy. | |
71 views::Label* price_ = nullptr; // Owned by views hierarchy. | |
72 | 59 |
73 AppListViewDelegate* view_delegate_; | 60 AppListViewDelegate* view_delegate_; |
74 | 61 |
75 const bool is_fullscreen_app_list_enabled_; | 62 const bool is_fullscreen_app_list_enabled_; |
76 | 63 |
77 std::unique_ptr<views::MenuRunner> context_menu_runner_; | 64 std::unique_ptr<views::MenuRunner> context_menu_runner_; |
78 | 65 |
79 DISALLOW_COPY_AND_ASSIGN(SearchResultTileItemView); | 66 DISALLOW_COPY_AND_ASSIGN(SearchResultTileItemView); |
80 }; | 67 }; |
81 | 68 |
82 } // namespace app_list | 69 } // namespace app_list |
83 | 70 |
84 #endif // UI_APP_LIST_VIEWS_SEARCH_RESULT_TILE_ITEM_VIEW_H_ | 71 #endif // UI_APP_LIST_VIEWS_SEARCH_RESULT_TILE_ITEM_VIEW_H_ |
OLD | NEW |