disable two ClientCertStoreChromeOSTest.* unit_tests on Valgrind bots
[chromium-blink-merge.git] / ui / app_list / views / search_result_container_view.h
blobcb7bcb60a9ad663c195d4716698f7b0ac5333bfb
1 // Copyright (c) 2014 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_CONTAINER_VIEW_H_
6 #define UI_APP_LIST_VIEWS_SEARCH_RESULT_CONTAINER_VIEW_H_
8 #include "base/memory/weak_ptr.h"
9 #include "ui/app_list/app_list_model.h"
10 #include "ui/views/view.h"
12 namespace app_list {
14 // SearchResultContainerView is a base class for views that contain multiple
15 // search results. SearchPageView holds these in a list and manages which one is
16 // selected. There can be one result within one SearchResultContainerView
17 // selected at a time; moving off the end of one container view selects the
18 // first element of the next container view, and vice versa
19 class APP_LIST_EXPORT SearchResultContainerView : public views::View,
20 public ui::ListModelObserver {
21 public:
22 class Delegate {
23 public:
24 virtual void OnSearchResultContainerResultsChanged() = 0;
26 SearchResultContainerView();
27 ~SearchResultContainerView() override;
29 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
31 // Sets the search results to listen to.
32 void SetResults(AppListModel::SearchResults* results);
33 AppListModel::SearchResults* results() { return results_; }
35 // Sets the index of the selected search result within this container. This
36 // must be a valid index.
37 void SetSelectedIndex(int selected_index);
39 void ClearSelectedIndex();
41 // The currently selected index. Returns -1 on no selection.
42 int selected_index() const { return selected_index_; }
44 // Returns whether |index| is a valid index for selection.
45 bool IsValidSelectionIndex(int index) const;
47 int num_results() const { return num_results_; }
49 void set_container_score(double score) { container_score_ = score; }
50 double container_score() const { return container_score_; }
52 // Updates the distance_from_origin() properties of the results in this
53 // container. |y_index| is the absolute y-index of the first result of this
54 // container (counting from the top of the app list).
55 virtual void NotifyFirstResultYIndex(int y_index) = 0;
57 // Gets the number of down keystrokes from the beginning to the end of this
58 // container.
59 virtual int GetYSize() = 0;
61 // Schedules an Update call using |update_factory_|. Do nothing if there is a
62 // pending call.
63 void ScheduleUpdate();
65 // Returns whether an update is currently scheduled for this container.
66 bool UpdateScheduled();
68 // Overridden from ui::ListModelObserver:
69 void ListItemsAdded(size_t start, size_t count) override;
70 void ListItemsRemoved(size_t start, size_t count) override;
71 void ListItemMoved(size_t index, size_t target_index) override;
72 void ListItemsChanged(size_t start, size_t count) override;
74 // Updates the container for being selected. |from_bottom| is true if the view
75 // was entered into from a selected view below it; false if entered into from
76 // above. |directional_movement| is true if the navigation was caused by
77 // directional controls (eg, arrow keys), as opposed to linear controls (eg,
78 // Tab).
79 virtual void OnContainerSelected(bool from_bottom,
80 bool directional_movement) = 0;
82 private:
83 // Updates UI with model. Returns the number of visible results.
84 virtual int Update() = 0;
86 // Updates UI for a change in the selected index.
87 virtual void UpdateSelectedIndex(int old_selected, int new_selected) = 0;
89 // Batching method that actually performs the update and updates layout.
90 void DoUpdate();
92 Delegate* delegate_;
94 int selected_index_;
95 int num_results_;
97 double container_score_;
99 AppListModel::SearchResults* results_; // Owned by AppListModel.
101 // The factory that consolidates multiple Update calls into one.
102 base::WeakPtrFactory<SearchResultContainerView> update_factory_;
104 DISALLOW_COPY_AND_ASSIGN(SearchResultContainerView);
107 } // namespace app_list
109 #endif // UI_APP_LIST_VIEWS_SEARCH_RESULT_CONTAINER_VIEW_H_