Home | History | Annotate | Download | only in views
      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 
     30 class ProgressBarView;
     31 class SearchResult;
     32 class SearchResultListView;
     33 class SearchResultViewDelegate;
     34 class SearchResultActionsView;
     35 
     36 // SearchResultView displays a SearchResult.
     37 class SearchResultView : public views::CustomButton,
     38                          public views::ButtonListener,
     39                          public views::ContextMenuController,
     40                          public SearchResultObserver,
     41                          public SearchResultActionsViewDelegate {
     42  public:
     43   // Internal class name.
     44   static const char kViewClassName[];
     45 
     46   SearchResultView(SearchResultListView* list_view,
     47                    SearchResultViewDelegate* delegate);
     48   virtual ~SearchResultView();
     49 
     50   // Sets/gets SearchResult displayed by this view.
     51   void SetResult(SearchResult* result);
     52   SearchResult* result() { return result_; }
     53 
     54   // Clears reference to SearchResult but don't schedule repaint.
     55   void ClearResultNoRepaint();
     56 
     57  private:
     58   void UpdateTitleText();
     59   void UpdateDetailsText();
     60 
     61   // views::View overrides:
     62   virtual const char* GetClassName() const OVERRIDE;
     63   virtual gfx::Size GetPreferredSize() OVERRIDE;
     64   virtual void Layout() OVERRIDE;
     65   virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
     66   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     67 
     68   // views::ButtonListener overrides:
     69   virtual void ButtonPressed(views::Button* sender,
     70                              const ui::Event& event) OVERRIDE;
     71 
     72   // views::ContextMenuController overrides:
     73   virtual void ShowContextMenuForView(views::View* source,
     74                                       const gfx::Point& point,
     75                                       ui::MenuSourceType source_type) OVERRIDE;
     76 
     77   // SearchResultObserver overrides:
     78   virtual void OnIconChanged() OVERRIDE;
     79   virtual void OnActionsChanged() OVERRIDE;
     80   virtual void OnIsInstallingChanged() OVERRIDE;
     81   virtual void OnPercentDownloadedChanged() OVERRIDE;
     82   virtual void OnItemInstalled() OVERRIDE;
     83   virtual void OnItemUninstalled() OVERRIDE;
     84 
     85   // SearchResultActionsViewDelegate overrides:
     86   virtual void OnSearchResultActionActivated(size_t index,
     87                                              int event_flags) OVERRIDE;
     88 
     89   SearchResult* result_;  // Owned by AppListModel::SearchResults.
     90 
     91   // Parent list view. Owned by views hierarchy.
     92   SearchResultListView* list_view_;
     93 
     94   // Not owned by us.
     95   SearchResultViewDelegate* delegate_;
     96 
     97   views::ImageView* icon_;  // Owned by views hierarchy.
     98   scoped_ptr<gfx::RenderText> title_text_;
     99   scoped_ptr<gfx::RenderText> details_text_;
    100   SearchResultActionsView* actions_view_;  // Owned by the views hierarchy.
    101   ProgressBarView* progress_bar_;  // Owned by views hierarchy.
    102 
    103   scoped_ptr<views::MenuRunner> context_menu_runner_;
    104 
    105   DISALLOW_COPY_AND_ASSIGN(SearchResultView);
    106 };
    107 
    108 }  // namespace app_list
    109 
    110 #endif  // UI_APP_LIST_VIEWS_SEARCH_RESULT_VIEW_H_
    111