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
3 // found in the LICENSE file.
5 #ifndef UI_APP_LIST_VIEWS_SEARCH_RESULT_VIEW_H_
6 #define UI_APP_LIST_VIEWS_SEARCH_RESULT_VIEW_H_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "ui/app_list/search_result_observer.h"
14 #include "ui/app_list/views/search_result_actions_view_delegate.h"
15 #include "ui/views/context_menu_controller.h"
16 #include "ui/views/controls/button/custom_button.h"
30 class SearchResultListViewTest;
33 class ProgressBarView;
35 class SearchResultListView;
36 class SearchResultViewDelegate;
37 class SearchResultActionsView;
39 // SearchResultView displays a SearchResult.
40 class SearchResultView : public views::CustomButton,
41 public views::ButtonListener,
42 public views::ContextMenuController,
43 public SearchResultObserver,
44 public SearchResultActionsViewDelegate {
46 // Internal class name.
47 static const char kViewClassName[];
49 explicit SearchResultView(SearchResultListView* list_view);
50 ~SearchResultView() override;
52 // Sets/gets SearchResult displayed by this view.
53 void SetResult(SearchResult* result);
54 SearchResult* result() { return result_; }
56 // Clears reference to SearchResult but don't schedule repaint.
57 void ClearResultNoRepaint();
59 // Clears the selected action.
60 void ClearSelectedAction();
63 friend class app_list::test::SearchResultListViewTest;
65 void UpdateTitleText();
66 void UpdateDetailsText();
68 // views::View overrides:
69 const char* GetClassName() const override;
70 gfx::Size GetPreferredSize() const override;
71 void Layout() override;
72 bool OnKeyPressed(const ui::KeyEvent& event) override;
73 void ChildPreferredSizeChanged(views::View* child) override;
74 void OnPaint(gfx::Canvas* canvas) override;
76 // views::ButtonListener overrides:
77 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
79 // views::ContextMenuController overrides:
80 void ShowContextMenuForView(views::View* source,
81 const gfx::Point& point,
82 ui::MenuSourceType source_type) override;
84 // SearchResultObserver overrides:
85 void OnIconChanged() override;
86 void OnActionsChanged() override;
87 void OnIsInstallingChanged() override;
88 void OnPercentDownloadedChanged() override;
89 void OnItemInstalled() override;
90 void OnItemUninstalled() override;
92 // SearchResultActionsViewDelegate overrides:
93 void OnSearchResultActionActivated(size_t index, int event_flags) override;
95 SearchResult* result_; // Owned by AppListModel::SearchResults.
97 // Parent list view. Owned by views hierarchy.
98 SearchResultListView* list_view_;
100 views::ImageView* icon_; // Owned by views hierarchy.
101 scoped_ptr<gfx::RenderText> title_text_;
102 scoped_ptr<gfx::RenderText> details_text_;
103 SearchResultActionsView* actions_view_; // Owned by the views hierarchy.
104 ProgressBarView* progress_bar_; // Owned by views hierarchy.
106 scoped_ptr<views::MenuRunner> context_menu_runner_;
108 DISALLOW_COPY_AND_ASSIGN(SearchResultView);
111 } // namespace app_list
113 #endif // UI_APP_LIST_VIEWS_SEARCH_RESULT_VIEW_H_