Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: ui/app_list/views/app_list_main_view.cc

Issue 657653002: Move app list search box into AppListView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/app_list/views/app_list_main_view.h" 5 #include "ui/app_list/views/app_list_main_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 21 matching lines...) Expand all
32 #include "ui/views/layout/fill_layout.h" 32 #include "ui/views/layout/fill_layout.h"
33 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
34 34
35 namespace app_list { 35 namespace app_list {
36 36
37 namespace { 37 namespace {
38 38
39 // The maximum allowed time to wait for icon loading in milliseconds. 39 // The maximum allowed time to wait for icon loading in milliseconds.
40 const int kMaxIconLoadingWaitTimeInMs = 50; 40 const int kMaxIconLoadingWaitTimeInMs = 50;
41 41
42 // A view that holds another view and takes its preferred size. This is used for
43 // wrapping the search box view so it still gets laid out while hidden. This is
44 // a separate class so it can notify the main view on search box visibility
45 // change.
46 class SearchBoxContainerView : public views::View {
47 public:
48 SearchBoxContainerView(AppListMainView* host, SearchBoxView* search_box)
49 : host_(host), search_box_(search_box) {
50 SetLayoutManager(new views::FillLayout());
51 AddChildView(search_box);
52 }
53 virtual ~SearchBoxContainerView() {}
54
55 private:
56 // Overridden from views::View:
57 virtual void ChildVisibilityChanged(views::View* child) override {
58 DCHECK_EQ(search_box_, child);
59 host_->NotifySearchBoxVisibilityChanged();
60 }
61
62 AppListMainView* host_;
63 SearchBoxView* search_box_;
64
65 DISALLOW_COPY_AND_ASSIGN(SearchBoxContainerView);
66 };
67
68 } // namespace 42 } // namespace
69 43
70 //////////////////////////////////////////////////////////////////////////////// 44 ////////////////////////////////////////////////////////////////////////////////
71 // AppListMainView::IconLoader 45 // AppListMainView::IconLoader
72 46
73 class AppListMainView::IconLoader : public AppListItemObserver { 47 class AppListMainView::IconLoader : public AppListItemObserver {
74 public: 48 public:
75 IconLoader(AppListMainView* owner, 49 IconLoader(AppListMainView* owner,
76 AppListItem* item, 50 AppListItem* item,
77 float scale) 51 float scale)
(...skipping 25 matching lines...) Expand all
103 //////////////////////////////////////////////////////////////////////////////// 77 ////////////////////////////////////////////////////////////////////////////////
104 // AppListMainView: 78 // AppListMainView:
105 79
106 AppListMainView::AppListMainView(AppListViewDelegate* delegate) 80 AppListMainView::AppListMainView(AppListViewDelegate* delegate)
107 : delegate_(delegate), 81 : delegate_(delegate),
108 model_(delegate->GetModel()), 82 model_(delegate->GetModel()),
109 search_box_view_(NULL), 83 search_box_view_(NULL),
110 contents_view_(NULL), 84 contents_view_(NULL),
111 contents_switcher_view_(NULL), 85 contents_switcher_view_(NULL),
112 weak_ptr_factory_(this) { 86 weak_ptr_factory_(this) {
113 SetLayoutManager( 87 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
114 new views::BoxLayout(views::BoxLayout::kVertical,
115 0,
116 0,
117 switches::IsExperimentalAppListEnabled() ? 0 : 1));
118
119 search_box_view_ = new SearchBoxView(this, delegate);
120 views::View* container = new SearchBoxContainerView(this, search_box_view_);
121 if (switches::IsExperimentalAppListEnabled()) {
122 container->SetBorder(
123 views::Border::CreateEmptyBorder(kExperimentalWindowPadding,
124 kExperimentalWindowPadding,
125 0,
126 kExperimentalWindowPadding));
127 }
128 AddChildView(container);
129 } 88 }
130 89
131 AppListMainView::~AppListMainView() { 90 AppListMainView::~AppListMainView() {
132 pending_icon_loaders_.clear(); 91 pending_icon_loaders_.clear();
133 } 92 }
134 93
135 void AppListMainView::Init(gfx::NativeView parent, int initial_apps_page) { 94 void AppListMainView::Init(gfx::NativeView parent,
95 int initial_apps_page,
96 SearchBoxView* search_box_view) {
97 search_box_view_ = search_box_view;
136 AddContentsViews(); 98 AddContentsViews();
137 99
138 // Switch the apps grid view to the specified page. 100 // Switch the apps grid view to the specified page.
139 app_list::PaginationModel* pagination_model = GetAppsPaginationModel(); 101 app_list::PaginationModel* pagination_model = GetAppsPaginationModel();
140 if (pagination_model->is_valid_page(initial_apps_page)) 102 if (pagination_model->is_valid_page(initial_apps_page))
141 pagination_model->SelectPage(initial_apps_page, false); 103 pagination_model->SelectPage(initial_apps_page, false);
142 104
143 // Starts icon loading early. 105 // Starts icon loading early.
144 PreloadIcons(parent); 106 PreloadIcons(parent);
145 } 107 }
146 108
147 void AppListMainView::AddContentsViews() { 109 void AppListMainView::AddContentsViews() {
110 DCHECK(search_box_view_);
111
148 contents_view_ = new ContentsView(this); 112 contents_view_ = new ContentsView(this);
149 if (app_list::switches::IsExperimentalAppListEnabled()) { 113 if (app_list::switches::IsExperimentalAppListEnabled()) {
150 contents_switcher_view_ = new ContentsSwitcherView(contents_view_); 114 contents_switcher_view_ = new ContentsSwitcherView(contents_view_);
151 contents_view_->SetContentsSwitcherView(contents_switcher_view_); 115 contents_view_->SetContentsSwitcherView(contents_switcher_view_);
152 } 116 }
153 contents_view_->InitNamedPages(model_, delegate_); 117 contents_view_->InitNamedPages(model_, delegate_);
154 AddChildView(contents_view_); 118 AddChildView(contents_view_);
155 if (contents_switcher_view_) 119 if (contents_switcher_view_)
156 AddChildView(contents_switcher_view_); 120 AddChildView(contents_switcher_view_);
157 121
158 search_box_view_->set_contents_view(contents_view_); 122 search_box_view_->set_contents_view(contents_view_);
123 UpdateSearchBoxVisibility();
159 124
160 contents_view_->SetPaintToLayer(true); 125 contents_view_->SetPaintToLayer(true);
161 contents_view_->SetFillsBoundsOpaquely(false); 126 contents_view_->SetFillsBoundsOpaquely(false);
162 contents_view_->layer()->SetMasksToBounds(true); 127 contents_view_->layer()->SetMasksToBounds(true);
163 128
164 delegate_->StartSearch(); 129 delegate_->StartSearch();
165 } 130 }
166 131
167 void AppListMainView::ShowAppListWhenReady() { 132 void AppListMainView::ShowAppListWhenReady() {
168 if (pending_icon_loaders_.empty()) { 133 if (pending_icon_loaders_.empty()) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 // Resubmit the query via a posted task so that all observers for the 305 // Resubmit the query via a posted task so that all observers for the
341 // uninstall notification are notified. 306 // uninstall notification are notified.
342 base::MessageLoop::current()->PostTask( 307 base::MessageLoop::current()->PostTask(
343 FROM_HERE, 308 FROM_HERE,
344 base::Bind(&AppListMainView::QueryChanged, 309 base::Bind(&AppListMainView::QueryChanged,
345 weak_ptr_factory_.GetWeakPtr(), 310 weak_ptr_factory_.GetWeakPtr(),
346 search_box_view_)); 311 search_box_view_));
347 } 312 }
348 313
349 } // namespace app_list 314 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/app_list_main_view.h ('k') | ui/app_list/views/app_list_main_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698