Make castv2 performance test work.
[chromium-blink-merge.git] / ui / app_list / views / search_result_container_view.cc
blob11ccb25bb97ae51edb25609a0e5461e0bd793499
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 #include "ui/app_list/views/search_result_container_view.h"
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
10 namespace app_list {
12 SearchResultContainerView::SearchResultContainerView()
13 : selected_index_(-1),
14 num_results_(0),
15 results_(NULL),
16 update_factory_(this) {
19 SearchResultContainerView::~SearchResultContainerView() {
20 if (results_)
21 results_->RemoveObserver(this);
24 void SearchResultContainerView::SetResults(
25 AppListModel::SearchResults* results) {
26 if (results_)
27 results_->RemoveObserver(this);
29 results_ = results;
30 if (results_)
31 results_->AddObserver(this);
33 DoUpdate();
36 void SearchResultContainerView::SetSelectedIndex(int selected_index) {
37 DCHECK(IsValidSelectionIndex(selected_index));
38 int old_selected = selected_index_;
39 selected_index_ = selected_index;
40 UpdateSelectedIndex(old_selected, selected_index_);
43 void SearchResultContainerView::ClearSelectedIndex() {
44 int old_selected = selected_index_;
45 selected_index_ = -1;
46 UpdateSelectedIndex(old_selected, selected_index_);
49 bool SearchResultContainerView::IsValidSelectionIndex(int index) const {
50 return index >= 0 && index <= num_results() - 1;
53 void SearchResultContainerView::ScheduleUpdate() {
54 // When search results are added one by one, each addition generates an update
55 // request. Consolidates those update requests into one Update call.
56 if (!update_factory_.HasWeakPtrs()) {
57 base::MessageLoop::current()->PostTask(
58 FROM_HERE,
59 base::Bind(&SearchResultContainerView::DoUpdate,
60 update_factory_.GetWeakPtr()));
64 void SearchResultContainerView::ListItemsAdded(size_t start, size_t count) {
65 ScheduleUpdate();
68 void SearchResultContainerView::ListItemsRemoved(size_t start, size_t count) {
69 ScheduleUpdate();
72 void SearchResultContainerView::ListItemMoved(size_t index,
73 size_t target_index) {
74 ScheduleUpdate();
77 void SearchResultContainerView::ListItemsChanged(size_t start, size_t count) {
78 ScheduleUpdate();
81 void SearchResultContainerView::DoUpdate() {
82 num_results_ = Update();
83 Layout();
84 PreferredSizeChanged();
85 update_factory_.InvalidateWeakPtrs();
88 } // namespace app_list