Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / app_list / views / search_result_list_view.h
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_LIST_VIEW_H_
6 #define UI_APP_LIST_VIEWS_SEARCH_RESULT_LIST_VIEW_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/weak_ptr.h"
10 #include "ui/app_list/app_list_model.h"
11 #include "ui/app_list/views/search_result_view_delegate.h"
12 #include "ui/base/models/list_model_observer.h"
13 #include "ui/gfx/animation/animation_delegate.h"
14 #include "ui/views/view.h"
15
16 namespace gfx {
17 class LinearAnimation;
18 }
19
20 namespace app_list {
21 namespace test {
22 class SearchResultListViewTest;
23 }
24
25 class AppListViewDelegate;
26 class SearchResultListViewDelegate;
27 class SearchResultView;
28
29 // SearchResultListView displays SearchResultList with a list of
30 // SearchResultView.
31 class APP_LIST_EXPORT SearchResultListView : public views::View,
32                                              public gfx::AnimationDelegate,
33                                              public ui::ListModelObserver,
34                                              public SearchResultViewDelegate {
35  public:
36   SearchResultListView(SearchResultListViewDelegate* delegate,
37                        AppListViewDelegate* view_delegate);
38   virtual ~SearchResultListView();
39
40   void SetResults(AppListModel::SearchResults* results);
41
42   void SetSelectedIndex(int selected_index);
43
44   void UpdateAutoLaunchState();
45
46   bool IsResultViewSelected(const SearchResultView* result_view) const;
47
48   // Overridden from views::View:
49   virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
50   virtual gfx::Size GetPreferredSize() OVERRIDE;
51
52  private:
53   friend class test::SearchResultListViewTest;
54
55   // Updates the auto launch states.
56   void SetAutoLaunchTimeout(const base::TimeDelta& timeout);
57   void CancelAutoLaunchTimeout();
58
59   // Helper function to get SearchResultView at given |index|.
60   SearchResultView* GetResultViewAt(int index);
61
62   // Updates UI with model.
63   void Update();
64
65   // Schedules an Update call using |update_factory_|. Do nothing if there is a
66   // pending call.
67   void ScheduleUpdate();
68
69   // Forcibly auto-launch for test if it is in auto-launching state.
70   void ForceAutoLaunchForTest();
71
72   // Overridden from views::View:
73   virtual void Layout() OVERRIDE;
74   virtual int GetHeightForWidth(int w) OVERRIDE;
75   virtual void VisibilityChanged(
76       views::View* starting_from, bool is_visible) OVERRIDE;
77
78   // Overridden from gfx::AnimationDelegate:
79   virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
80   virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
81
82   // Overridden from ui::ListModelObserver:
83   virtual void ListItemsAdded(size_t start, size_t count) OVERRIDE;
84   virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE;
85   virtual void ListItemMoved(size_t index, size_t target_index) OVERRIDE;
86   virtual void ListItemsChanged(size_t start, size_t count) OVERRIDE;
87
88   // Overridden from SearchResultViewDelegate:
89   virtual void SearchResultActivated(SearchResultView* view,
90                                      int event_flags) OVERRIDE;
91   virtual void SearchResultActionActivated(SearchResultView* view,
92                                            size_t action_index,
93                                            int event_flags) OVERRIDE;
94   virtual void OnSearchResultInstalled(SearchResultView* view) OVERRIDE;
95   virtual void OnSearchResultUninstalled(SearchResultView* view) OVERRIDE;
96
97   SearchResultListViewDelegate* delegate_;  // Not owned.
98   AppListViewDelegate* view_delegate_;  // Not owned.
99   AppListModel::SearchResults* results_;  // Owned by AppListModel.
100
101   views::View* results_container_;
102   views::View* auto_launch_indicator_;
103   scoped_ptr<gfx::LinearAnimation> auto_launch_animation_;
104
105   int last_visible_index_;
106   int selected_index_;
107
108   // The factory that consolidates multiple Update calls into one.
109   base::WeakPtrFactory<SearchResultListView> update_factory_;
110
111   DISALLOW_COPY_AND_ASSIGN(SearchResultListView);
112 };
113
114 }  // namespace app_list
115
116 #endif  // UI_APP_LIST_VIEWS_SEARCH_RESULT_LIST_VIEW_H_