Commit 3dca1ba0 authored by calamity@chromium.org's avatar calamity@chromium.org

Remove SetModel in ContentsView and SearchBoxView.

SetModel is only ever used for initialization. Moving the functionality
into the constructor allows for easier reasoning about the state of the
View.

This change is in preparation of the refactor in
https://codereview.chromium.org/20656002/.

Review URL: https://chromiumcodereview.appspot.com/22354002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215861 0039d316-1c4b-4281-b951-d872f2087c98
parent a42acb6f
......@@ -90,10 +90,10 @@ AppListMainView::AppListMainView(AppListViewDelegate* delegate,
kInnerPadding,
kInnerPadding));
search_box_view_ = new SearchBoxView(this, delegate);
search_box_view_ = new SearchBoxView(this, delegate, model_);
AddChildView(search_box_view_);
contents_view_ = new ContentsView(this, pagination_model);
contents_view_ = new ContentsView(this, pagination_model, model_);
AddChildView(contents_view_);
search_box_view_->set_contents_view(contents_view_);
......@@ -103,9 +103,6 @@ AppListMainView::AppListMainView(AppListViewDelegate* delegate,
contents_view_->SetFillsBoundsOpaquely(false);
contents_view_->layer()->SetMasksToBounds(true);
#endif
search_box_view_->SetModel(model_->search_box());
contents_view_->SetModel(model_);
}
AppListMainView::~AppListMainView() {
......
......@@ -46,11 +46,13 @@ SearchResultListView* GetSearchResultListView(views::ViewModel* model) {
} // namespace
ContentsView::ContentsView(AppListMainView* app_list_main_view,
PaginationModel* pagination_model)
PaginationModel* pagination_model,
AppListModel* model)
: show_state_(SHOW_APPS),
pagination_model_(pagination_model),
view_model_(new views::ViewModel),
bounds_animator_(new views::BoundsAnimator(this)) {
DCHECK(model);
pagination_model_->SetTransitionDurations(
kPageTransitionDurationInMs,
kOverscrollPageTransitionDurationMs);
......@@ -66,19 +68,12 @@ ContentsView::ContentsView(AppListMainView* app_list_main_view,
app_list_main_view);
AddChildView(search_results_view);
view_model_->Add(search_results_view, kIndexSearchResults);
}
ContentsView::~ContentsView() {
GetAppsGridView(view_model_.get())->SetModel(model);
GetSearchResultListView(view_model_.get())->SetResults(model->results());
}
void ContentsView::SetModel(AppListModel* model) {
if (model) {
GetAppsGridView(view_model_.get())->SetModel(model);
GetSearchResultListView(view_model_.get())->SetResults(model->results());
} else {
GetAppsGridView(view_model_.get())->SetModel(NULL);
GetSearchResultListView(view_model_.get())->SetResults(NULL);
}
ContentsView::~ContentsView() {
}
void ContentsView::SetDragAndDropHostOfCurrentAppList(
......
......@@ -30,11 +30,10 @@ class PaginationModel;
class ContentsView : public views::View {
public:
ContentsView(AppListMainView* app_list_main_view,
PaginationModel* pagination_model);
PaginationModel* pagination_model,
AppListModel* model);
virtual ~ContentsView();
void SetModel(AppListModel* model);
// If |drag_and_drop| is not NULL it will be called upon drag and drop
// operations outside the application list.
void SetDragAndDropHostOfCurrentAppList(
......
......@@ -7,6 +7,7 @@
#include <algorithm>
#include "grit/ui_resources.h"
#include "ui/app_list/app_list_model.h"
#include "ui/app_list/search_box_model.h"
#include "ui/app_list/search_box_view_delegate.h"
#include "ui/app_list/views/app_list_menu_views.h"
......@@ -31,13 +32,15 @@ const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0);
} // namespace
SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
AppListViewDelegate* view_delegate)
AppListViewDelegate* view_delegate,
AppListModel* model)
: delegate_(delegate),
view_delegate_(view_delegate),
model_(NULL),
model_(model->search_box()),
icon_view_(new views::ImageView),
search_box_(new views::Textfield),
contents_view_(NULL) {
DCHECK(model_);
AddChildView(icon_view_);
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
......@@ -57,26 +60,14 @@ SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
search_box_->set_placeholder_text_color(kHintTextColor);
search_box_->SetController(this);
AddChildView(search_box_);
}
SearchBoxView::~SearchBoxView() {
if (model_)
model_->RemoveObserver(this);
model_->AddObserver(this);
IconChanged();
HintTextChanged();
}
void SearchBoxView::SetModel(SearchBoxModel* model) {
if (model_ == model)
return;
if (model_)
model_->RemoveObserver(this);
model_ = model;
if (model_) {
model_->AddObserver(this);
IconChanged();
HintTextChanged();
}
SearchBoxView::~SearchBoxView() {
model_->RemoveObserver(this);
}
bool SearchBoxView::HasSearch() const {
......
......@@ -22,6 +22,7 @@ namespace app_list {
class AppListMenuViews;
class AppListViewDelegate;
class AppListModel;
class SearchBoxModel;
class SearchBoxViewDelegate;
......@@ -35,11 +36,10 @@ class SearchBoxView : public views::View,
public SearchBoxModelObserver {
public:
SearchBoxView(SearchBoxViewDelegate* delegate,
AppListViewDelegate* view_delegate);
AppListViewDelegate* view_delegate,
AppListModel* model);
virtual ~SearchBoxView();
void SetModel(SearchBoxModel* model);
bool HasSearch() const;
void ClearSearch();
void InvalidateMenu();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment