Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / app_list / views / search_result_container_view.h
blobc2fafe326966ced80ca319021c10b3bb70c49b69
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 SearchResultContainerView();
23 ~SearchResultContainerView() override;
25 // Sets the search results to listen to.
26 void SetResults(AppListModel::SearchResults* results);
27 AppListModel::SearchResults* results() { return results_; }
29 // Sets the index of the selected search result within this container. This
30 // must be a valid index.
31 void SetSelectedIndex(int selected_index);
33 void ClearSelectedIndex();
35 // The currently selected index. Returns -1 on no selection.
36 int selected_index() const { return selected_index_; }
38 // Returns whether |index| is a valid index for selection.
39 bool IsValidSelectionIndex(int index) const;
41 int num_results() const { return num_results_; }
43 void set_container_score(double score) { container_score_ = score; }
44 double container_score() const { return container_score_; }
46 // Schedules an Update call using |update_factory_|. Do nothing if there is a
47 // pending call.
48 void ScheduleUpdate();
50 // Overridden from ui::ListModelObserver:
51 void ListItemsAdded(size_t start, size_t count) override;
52 void ListItemsRemoved(size_t start, size_t count) override;
53 void ListItemMoved(size_t index, size_t target_index) override;
54 void ListItemsChanged(size_t start, size_t count) override;
56 // Updates the container for being selected. |from_bottom| is true if the view
57 // was entered into from a selected view below it; false if entered into from
58 // above. |directional_movement| is true if the navigation was caused by
59 // directional controls (eg, arrow keys), as opposed to linear controls (eg,
60 // Tab).
61 virtual void OnContainerSelected(bool from_bottom,
62 bool directional_movement) = 0;
64 private:
65 // Updates UI with model. Returns the number of visible results.
66 virtual int Update() = 0;
68 // Updates UI for a change in the selected index.
69 virtual void UpdateSelectedIndex(int old_selected, int new_selected) = 0;
71 // Batching method that actually performs the update and updates layout.
72 void DoUpdate();
74 int selected_index_;
75 int num_results_;
77 double container_score_;
79 AppListModel::SearchResults* results_; // Owned by AppListModel.
81 // The factory that consolidates multiple Update calls into one.
82 base::WeakPtrFactory<SearchResultContainerView> update_factory_;
84 DISALLOW_COPY_AND_ASSIGN(SearchResultContainerView);
87 } // namespace app_list
89 #endif // UI_APP_LIST_VIEWS_SEARCH_RESULT_CONTAINER_VIEW_H_