OLD | NEW |
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 search_box_view_ = search_box_view; | 99 search_box_view_ = search_box_view; |
100 AddContentsViews(); | 100 AddContentsViews(); |
101 | 101 |
102 // Switch the apps grid view to the specified page. | 102 // Switch the apps grid view to the specified page. |
103 app_list::PaginationModel* pagination_model = GetAppsPaginationModel(); | 103 app_list::PaginationModel* pagination_model = GetAppsPaginationModel(); |
104 if (pagination_model->is_valid_page(initial_apps_page)) | 104 if (pagination_model->is_valid_page(initial_apps_page)) |
105 pagination_model->SelectPage(initial_apps_page, false); | 105 pagination_model->SelectPage(initial_apps_page, false); |
106 | 106 |
107 // Starts icon loading early. | 107 // Starts icon loading early. |
108 PreloadIcons(parent); | 108 PreloadIcons(parent); |
| 109 |
| 110 OnSearchEngineIsGoogleChanged(model_->search_engine_is_google()); |
109 } | 111 } |
110 | 112 |
111 void AppListMainView::AddContentsViews() { | 113 void AppListMainView::AddContentsViews() { |
112 DCHECK(search_box_view_); | 114 DCHECK(search_box_view_); |
113 | 115 |
114 contents_view_ = new ContentsView(this); | 116 contents_view_ = new ContentsView(this); |
115 contents_view_->Init(model_); | 117 contents_view_->Init(model_); |
116 AddChildView(contents_view_); | 118 AddChildView(contents_view_); |
117 | 119 |
118 search_box_view_->set_contents_view(contents_view_); | 120 search_box_view_->set_contents_view(contents_view_); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 236 } |
235 | 237 |
236 void AppListMainView::NotifySearchBoxVisibilityChanged() { | 238 void AppListMainView::NotifySearchBoxVisibilityChanged() { |
237 // Repaint the AppListView's background which will repaint the background for | 239 // Repaint the AppListView's background which will repaint the background for |
238 // the search box. This is needed because this view paints to a layer and | 240 // the search box. This is needed because this view paints to a layer and |
239 // won't propagate paints upward. | 241 // won't propagate paints upward. |
240 if (parent()) | 242 if (parent()) |
241 parent()->SchedulePaint(); | 243 parent()->SchedulePaint(); |
242 } | 244 } |
243 | 245 |
| 246 bool AppListMainView::ShouldShowCustomLauncherPage() const { |
| 247 return contents_view_->custom_page_view() && |
| 248 model_->custom_launcher_page_enabled() && |
| 249 model_->search_engine_is_google(); |
| 250 } |
| 251 |
| 252 void AppListMainView::UpdateCustomLauncherPageVisibility() { |
| 253 if (ShouldShowCustomLauncherPage()) { |
| 254 // Make the custom page view visible again. |
| 255 contents_view_->custom_page_view()->SetVisible(true); |
| 256 } else if (contents_view_->IsStateActive( |
| 257 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) { |
| 258 // Animate to the start page if currently on the custom page view. The view |
| 259 // will hide on animation completion. |
| 260 contents_view_->SetActivePage( |
| 261 contents_view_->GetPageIndexForState(AppListModel::STATE_START)); |
| 262 } else { |
| 263 // Hide the view immediately otherwise. |
| 264 contents_view_->custom_page_view()->SetVisible(false); |
| 265 } |
| 266 } |
| 267 |
244 void AppListMainView::OnCustomLauncherPageEnabledStateChanged(bool enabled) { | 268 void AppListMainView::OnCustomLauncherPageEnabledStateChanged(bool enabled) { |
245 if (enabled) { | 269 if (enabled) { |
246 // Make the custom page view visible again. | 270 // Make the custom page view visible again. |
247 contents_view_->custom_page_view()->SetVisible(true); | 271 contents_view_->custom_page_view()->SetVisible(true); |
248 } else if (contents_view_->IsStateActive( | 272 } else if (contents_view_->IsStateActive( |
249 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) { | 273 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) { |
250 // Animate to the start page if currently on the custom page view. The view | 274 // Animate to the start page if currently on the custom page view. The view |
251 // will hide on animation completion. | 275 // will hide on animation completion. |
252 contents_view_->SetActivePage( | 276 contents_view_->SetActivePage( |
253 contents_view_->GetPageIndexForState(AppListModel::STATE_START)); | 277 contents_view_->GetPageIndexForState(AppListModel::STATE_START)); |
254 } else { | 278 } else { |
255 // Hide the view immediately otherwise. | 279 // Hide the view immediately otherwise. |
256 contents_view_->custom_page_view()->SetVisible(false); | 280 contents_view_->custom_page_view()->SetVisible(false); |
257 } | 281 } |
258 } | 282 } |
259 | 283 |
| 284 void AppListMainView::OnSearchEngineIsGoogleChanged(bool is_google) { |
| 285 if (contents_view_->custom_page_view()) |
| 286 OnCustomLauncherPageEnabledStateChanged(is_google); |
| 287 |
| 288 if (contents_view_->start_page_view()) { |
| 289 contents_view_->start_page_view()->instant_container()->SetVisible( |
| 290 is_google); |
| 291 } |
| 292 } |
| 293 |
260 void AppListMainView::ActivateApp(AppListItem* item, int event_flags) { | 294 void AppListMainView::ActivateApp(AppListItem* item, int event_flags) { |
261 // TODO(jennyz): Activate the folder via AppListModel notification. | 295 // TODO(jennyz): Activate the folder via AppListModel notification. |
262 if (item->GetItemType() == AppListFolderItem::kItemType) | 296 if (item->GetItemType() == AppListFolderItem::kItemType) |
263 contents_view_->ShowFolderContent(static_cast<AppListFolderItem*>(item)); | 297 contents_view_->ShowFolderContent(static_cast<AppListFolderItem*>(item)); |
264 else | 298 else |
265 item->Activate(event_flags); | 299 item->Activate(event_flags); |
266 } | 300 } |
267 | 301 |
268 void AppListMainView::GetShortcutPathForApp( | 302 void AppListMainView::GetShortcutPathForApp( |
269 const std::string& app_id, | 303 const std::string& app_id, |
(...skipping 21 matching lines...) Expand all Loading... |
291 contents_view_->Back(); | 325 contents_view_->Back(); |
292 } | 326 } |
293 | 327 |
294 void AppListMainView::OnResultInstalled(SearchResult* result) { | 328 void AppListMainView::OnResultInstalled(SearchResult* result) { |
295 // Clears the search to show the apps grid. The last installed app | 329 // Clears the search to show the apps grid. The last installed app |
296 // should be highlighted and made visible already. | 330 // should be highlighted and made visible already. |
297 search_box_view_->ClearSearch(); | 331 search_box_view_->ClearSearch(); |
298 } | 332 } |
299 | 333 |
300 } // namespace app_list | 334 } // namespace app_list |
OLD | NEW |