Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / ui / app_list / views / search_result_container_view.h
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.
4
5 #ifndef UI_APP_LIST_VIEWS_SEARCH_RESULT_CONTAINER_VIEW_H_
6 #define UI_APP_LIST_VIEWS_SEARCH_RESULT_CONTAINER_VIEW_H_
7
8 #include "base/memory/weak_ptr.h"
9 #include "ui/app_list/app_list_model.h"
10 #include "ui/views/view.h"
11
12 namespace app_list {
13
14 // SearchResultContainerView is a base class that batches updates from a
15 // ListModelObserver.
16 class APP_LIST_EXPORT SearchResultContainerView : public views::View,
17                                                   public ui::ListModelObserver {
18  public:
19   SearchResultContainerView();
20   ~SearchResultContainerView() override;
21
22   void SetResults(AppListModel::SearchResults* results);
23
24   AppListModel::SearchResults* results() { return results_; }
25
26   // Schedules an Update call using |update_factory_|. Do nothing if there is a
27   // pending call.
28   void ScheduleUpdate();
29
30   // Overridden from ui::ListModelObserver:
31   void ListItemsAdded(size_t start, size_t count) override;
32   void ListItemsRemoved(size_t start, size_t count) override;
33   void ListItemMoved(size_t index, size_t target_index) override;
34   void ListItemsChanged(size_t start, size_t count) override;
35
36   // Updates UI with model.
37   virtual void Update() = 0;
38
39  private:
40   void DoUpdate();
41
42   AppListModel::SearchResults* results_;  // Owned by AppListModel.
43
44   // The factory that consolidates multiple Update calls into one.
45   base::WeakPtrFactory<SearchResultContainerView> update_factory_;
46
47   DISALLOW_COPY_AND_ASSIGN(SearchResultContainerView);
48 };
49
50 }  // namespace app_list
51
52 #endif  // UI_APP_LIST_VIEWS_SEARCH_RESULT_CONTAINER_VIEW_H_