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. 4 5 #ifndef UI_APP_LIST_VIEWS_SEARCH_RESULT_VIEW_H_ 6 #define UI_APP_LIST_VIEWS_SEARCH_RESULT_VIEW_H_ 7 8 #include <string> 9 #include <vector> 10 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" 17 18 namespace gfx { 19 class RenderText; 20 } 21 22 namespace views { 23 class ImageButton; 24 class ImageView; 25 class MenuRunner; 26 } 27 28 namespace app_list { 29 namespace test { 30 class SearchResultListViewTest; 31 } // namespace test 32 33 class ProgressBarView; 34 class SearchResult; 35 class SearchResultListView; 36 class SearchResultViewDelegate; 37 class SearchResultActionsView; 38 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 { 45 public: 46 // Internal class name. 47 static const char kViewClassName[]; 48 49 explicit SearchResultView(SearchResultListView* list_view); 50 virtual ~SearchResultView(); 51 52 // Sets/gets SearchResult displayed by this view. 53 void SetResult(SearchResult* result); result()54 SearchResult* result() { return result_; } 55 56 // Clears reference to SearchResult but don't schedule repaint. 57 void ClearResultNoRepaint(); 58 59 // Clears the selected action. 60 void ClearSelectedAction(); 61 62 private: 63 friend class app_list::test::SearchResultListViewTest; 64 65 void UpdateTitleText(); 66 void UpdateDetailsText(); 67 68 // views::View overrides: 69 virtual const char* GetClassName() const OVERRIDE; 70 virtual gfx::Size GetPreferredSize() const OVERRIDE; 71 virtual void Layout() OVERRIDE; 72 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; 73 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; 74 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 75 76 // views::ButtonListener overrides: 77 virtual void ButtonPressed(views::Button* sender, 78 const ui::Event& event) OVERRIDE; 79 80 // views::ContextMenuController overrides: 81 virtual void ShowContextMenuForView(views::View* source, 82 const gfx::Point& point, 83 ui::MenuSourceType source_type) OVERRIDE; 84 85 // SearchResultObserver overrides: 86 virtual void OnIconChanged() OVERRIDE; 87 virtual void OnActionsChanged() OVERRIDE; 88 virtual void OnIsInstallingChanged() OVERRIDE; 89 virtual void OnPercentDownloadedChanged() OVERRIDE; 90 virtual void OnItemInstalled() OVERRIDE; 91 virtual void OnItemUninstalled() OVERRIDE; 92 93 // SearchResultActionsViewDelegate overrides: 94 virtual void OnSearchResultActionActivated(size_t index, 95 int event_flags) OVERRIDE; 96 97 SearchResult* result_; // Owned by AppListModel::SearchResults. 98 99 // Parent list view. Owned by views hierarchy. 100 SearchResultListView* list_view_; 101 102 views::ImageView* icon_; // Owned by views hierarchy. 103 scoped_ptr<gfx::RenderText> title_text_; 104 scoped_ptr<gfx::RenderText> details_text_; 105 SearchResultActionsView* actions_view_; // Owned by the views hierarchy. 106 ProgressBarView* progress_bar_; // Owned by views hierarchy. 107 108 scoped_ptr<views::MenuRunner> context_menu_runner_; 109 110 DISALLOW_COPY_AND_ASSIGN(SearchResultView); 111 }; 112 113 } // namespace app_list 114 115 #endif // UI_APP_LIST_VIEWS_SEARCH_RESULT_VIEW_H_ 116