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_LIST_VIEW_H_
6 #define UI_APP_LIST_VIEWS_SEARCH_RESULT_LIST_VIEW_H_
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"
17 class LinearAnimation;
22 class SearchResultListViewTest;
25 class AppListViewDelegate;
26 class SearchResultListViewDelegate;
27 class SearchResultView;
29 // SearchResultListView displays SearchResultList with a list of
31 class APP_LIST_EXPORT SearchResultListView : public views::View,
32 public gfx::AnimationDelegate,
33 public ui::ListModelObserver,
34 public SearchResultViewDelegate {
36 SearchResultListView(SearchResultListViewDelegate* delegate,
37 AppListViewDelegate* view_delegate);
38 virtual ~SearchResultListView();
40 void SetResults(AppListModel::SearchResults* results);
42 void SetSelectedIndex(int selected_index);
44 void UpdateAutoLaunchState();
46 bool IsResultViewSelected(const SearchResultView* result_view) const;
48 // Overridden from views::View:
49 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
50 virtual gfx::Size GetPreferredSize() OVERRIDE;
53 friend class test::SearchResultListViewTest;
55 // Updates the auto launch states.
56 void SetAutoLaunchTimeout(const base::TimeDelta& timeout);
57 void CancelAutoLaunchTimeout();
59 // Helper function to get SearchResultView at given |index|.
60 SearchResultView* GetResultViewAt(int index);
62 // Updates UI with model.
65 // Schedules an Update call using |update_factory_|. Do nothing if there is a
67 void ScheduleUpdate();
69 // Forcibly auto-launch for test if it is in auto-launching state.
70 void ForceAutoLaunchForTest();
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;
78 // Overridden from gfx::AnimationDelegate:
79 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
80 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
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;
88 // Overridden from SearchResultViewDelegate:
89 virtual void SearchResultActivated(SearchResultView* view,
90 int event_flags) OVERRIDE;
91 virtual void SearchResultActionActivated(SearchResultView* view,
93 int event_flags) OVERRIDE;
94 virtual void OnSearchResultInstalled(SearchResultView* view) OVERRIDE;
95 virtual void OnSearchResultUninstalled(SearchResultView* view) OVERRIDE;
97 SearchResultListViewDelegate* delegate_; // Not owned.
98 AppListViewDelegate* view_delegate_; // Not owned.
99 AppListModel::SearchResults* results_; // Owned by AppListModel.
101 views::View* results_container_;
102 views::View* auto_launch_indicator_;
103 scoped_ptr<gfx::LinearAnimation> auto_launch_animation_;
105 int last_visible_index_;
108 // The factory that consolidates multiple Update calls into one.
109 base::WeakPtrFactory<SearchResultListView> update_factory_;
111 DISALLOW_COPY_AND_ASSIGN(SearchResultListView);
114 } // namespace app_list
116 #endif // UI_APP_LIST_VIEWS_SEARCH_RESULT_LIST_VIEW_H_