forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract a SearchResultContainerView base class from SearchResultListV…
…iew. This CL extracts a SearchResultContainerView which is responsible for dealing with the batching of updates from AppListModel::SearchResults. This dedupes code from StartPageView and sets up work for adding a SearchResultTileItemListView which will use this as a base. BUG=425444 Review URL: https://codereview.chromium.org/680233002 Cr-Commit-Position: refs/heads/master@{#302979}
- Loading branch information
Showing
8 changed files
with
152 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ui/app_list/views/search_result_container_view.h" | ||
|
||
#include "base/bind.h" | ||
#include "base/message_loop/message_loop.h" | ||
|
||
namespace app_list { | ||
|
||
SearchResultContainerView::SearchResultContainerView() | ||
: results_(NULL), update_factory_(this) { | ||
} | ||
|
||
SearchResultContainerView::~SearchResultContainerView() { | ||
if (results_) | ||
results_->RemoveObserver(this); | ||
} | ||
|
||
void SearchResultContainerView::SetResults( | ||
AppListModel::SearchResults* results) { | ||
if (results_) | ||
results_->RemoveObserver(this); | ||
|
||
results_ = results; | ||
if (results_) | ||
results_->AddObserver(this); | ||
|
||
Update(); | ||
} | ||
|
||
void SearchResultContainerView::ScheduleUpdate() { | ||
// When search results are added one by one, each addition generates an update | ||
// request. Consolidates those update requests into one Update call. | ||
if (!update_factory_.HasWeakPtrs()) { | ||
base::MessageLoop::current()->PostTask( | ||
FROM_HERE, | ||
base::Bind(&SearchResultContainerView::DoUpdate, | ||
update_factory_.GetWeakPtr())); | ||
} | ||
} | ||
|
||
void SearchResultContainerView::ListItemsAdded(size_t start, size_t count) { | ||
ScheduleUpdate(); | ||
} | ||
|
||
void SearchResultContainerView::ListItemsRemoved(size_t start, size_t count) { | ||
ScheduleUpdate(); | ||
} | ||
|
||
void SearchResultContainerView::ListItemMoved(size_t index, | ||
size_t target_index) { | ||
ScheduleUpdate(); | ||
} | ||
|
||
void SearchResultContainerView::ListItemsChanged(size_t start, size_t count) { | ||
ScheduleUpdate(); | ||
} | ||
|
||
void SearchResultContainerView::DoUpdate() { | ||
Update(); | ||
update_factory_.InvalidateWeakPtrs(); | ||
} | ||
|
||
} // namespace app_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef UI_APP_LIST_VIEWS_SEARCH_RESULT_CONTAINER_VIEW_H_ | ||
#define UI_APP_LIST_VIEWS_SEARCH_RESULT_CONTAINER_VIEW_H_ | ||
|
||
#include "base/memory/weak_ptr.h" | ||
#include "ui/app_list/app_list_model.h" | ||
#include "ui/views/view.h" | ||
|
||
namespace app_list { | ||
|
||
// SearchResultContainerView is a base class that batches updates from a | ||
// ListModelObserver. | ||
class APP_LIST_EXPORT SearchResultContainerView : public views::View, | ||
public ui::ListModelObserver { | ||
public: | ||
SearchResultContainerView(); | ||
~SearchResultContainerView() override; | ||
|
||
void SetResults(AppListModel::SearchResults* results); | ||
|
||
AppListModel::SearchResults* results() { return results_; } | ||
|
||
// Schedules an Update call using |update_factory_|. Do nothing if there is a | ||
// pending call. | ||
void ScheduleUpdate(); | ||
|
||
// Overridden from ui::ListModelObserver: | ||
void ListItemsAdded(size_t start, size_t count) override; | ||
void ListItemsRemoved(size_t start, size_t count) override; | ||
void ListItemMoved(size_t index, size_t target_index) override; | ||
void ListItemsChanged(size_t start, size_t count) override; | ||
|
||
// Updates UI with model. | ||
virtual void Update() = 0; | ||
|
||
private: | ||
void DoUpdate(); | ||
|
||
AppListModel::SearchResults* results_; // Owned by AppListModel. | ||
|
||
// The factory that consolidates multiple Update calls into one. | ||
base::WeakPtrFactory<SearchResultContainerView> update_factory_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(SearchResultContainerView); | ||
}; | ||
|
||
} // namespace app_list | ||
|
||
#endif // UI_APP_LIST_VIEWS_SEARCH_RESULT_CONTAINER_VIEW_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.