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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 search_box_view_ = search_box_view; | 129 search_box_view_ = search_box_view; |
130 AddContentsViews(); | 130 AddContentsViews(); |
131 | 131 |
132 // Switch the apps grid view to the specified page. | 132 // Switch the apps grid view to the specified page. |
133 app_list::PaginationModel* pagination_model = GetAppsPaginationModel(); | 133 app_list::PaginationModel* pagination_model = GetAppsPaginationModel(); |
134 if (pagination_model->is_valid_page(initial_apps_page)) | 134 if (pagination_model->is_valid_page(initial_apps_page)) |
135 pagination_model->SelectPage(initial_apps_page, false); | 135 pagination_model->SelectPage(initial_apps_page, false); |
136 | 136 |
137 // Starts icon loading early. | 137 // Starts icon loading early. |
138 PreloadIcons(parent); | 138 PreloadIcons(parent); |
| 139 |
| 140 OnSearchEngineIsGoogleChanged(model_->search_engine_is_google()); |
139 } | 141 } |
140 | 142 |
141 void AppListMainView::AddContentsViews() { | 143 void AppListMainView::AddContentsViews() { |
142 DCHECK(search_box_view_); | 144 DCHECK(search_box_view_); |
143 | 145 |
144 contents_view_ = new ContentsView(this); | 146 contents_view_ = new ContentsView(this); |
145 contents_view_->Init(model_); | 147 contents_view_->Init(model_); |
146 AddChildView(contents_view_); | 148 AddChildView(contents_view_); |
147 | 149 |
148 search_box_view_->set_contents_view(contents_view_); | 150 search_box_view_->set_contents_view(contents_view_); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 303 |
302 // Create a widget for the custom page click zone. This widget masks click | 304 // Create a widget for the custom page click zone. This widget masks click |
303 // events from the WebContents that rests underneath it. (It has to be a | 305 // events from the WebContents that rests underneath it. (It has to be a |
304 // widget, not an ordinary view, so that it can be placed in front of the | 306 // widget, not an ordinary view, so that it can be placed in front of the |
305 // WebContents.) | 307 // WebContents.) |
306 custom_page_clickzone_ = new views::Widget; | 308 custom_page_clickzone_ = new views::Widget; |
307 custom_page_clickzone_->Init(custom_page_clickzone_params); | 309 custom_page_clickzone_->Init(custom_page_clickzone_params); |
308 custom_page_clickzone_->SetContentsView(new CustomPageButton(this)); | 310 custom_page_clickzone_->SetContentsView(new CustomPageButton(this)); |
309 // The widget is shown by default. If the ContentsView determines that we do | 311 // The widget is shown by default. If the ContentsView determines that we do |
310 // not need a clickzone upon startup, hide it. | 312 // not need a clickzone upon startup, hide it. |
311 if (!contents_view_->ShouldShowCustomPageClickzone()) | 313 if (!ShouldShowCustomLauncherPage() || |
| 314 !contents_view_->IsStateActive(AppListModel::STATE_START)) |
312 custom_page_clickzone_->Hide(); | 315 custom_page_clickzone_->Hide(); |
313 } | 316 } |
314 | 317 |
| 318 bool AppListMainView::ShouldShowCustomLauncherPage() const { |
| 319 return contents_view_->custom_page_view() && |
| 320 model_->custom_launcher_page_enabled() && |
| 321 model_->search_engine_is_google(); |
| 322 } |
| 323 |
| 324 void AppListMainView::UpdateCustomLauncherPageVisibility() { |
| 325 if (ShouldShowCustomLauncherPage()) { |
| 326 // Make the custom page view visible again. |
| 327 contents_view_->custom_page_view()->SetVisible(true); |
| 328 } else if (contents_view_->IsStateActive( |
| 329 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) { |
| 330 // Animate to the start page if currently on the custom page view. The view |
| 331 // will hide on animation completion. |
| 332 contents_view_->SetActivePage( |
| 333 contents_view_->GetPageIndexForState(AppListModel::STATE_START)); |
| 334 } else { |
| 335 // Hide the view immediately otherwise. |
| 336 contents_view_->custom_page_view()->SetVisible(false); |
| 337 } |
| 338 } |
| 339 |
315 void AppListMainView::OnCustomLauncherPageEnabledStateChanged(bool enabled) { | 340 void AppListMainView::OnCustomLauncherPageEnabledStateChanged(bool enabled) { |
316 if (enabled) { | 341 if (enabled) { |
317 // Make the custom page view visible again. | 342 // Make the custom page view visible again. |
318 contents_view_->custom_page_view()->SetVisible(true); | 343 contents_view_->custom_page_view()->SetVisible(true); |
319 } else if (contents_view_->IsStateActive( | 344 } else if (contents_view_->IsStateActive( |
320 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) { | 345 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) { |
321 // Animate to the start page if currently on the custom page view. The view | 346 // Animate to the start page if currently on the custom page view. The view |
322 // will hide on animation completion. | 347 // will hide on animation completion. |
323 contents_view_->SetActivePage( | 348 contents_view_->SetActivePage( |
324 contents_view_->GetPageIndexForState(AppListModel::STATE_START)); | 349 contents_view_->GetPageIndexForState(AppListModel::STATE_START)); |
325 } else { | 350 } else { |
326 // Hide the view immediately otherwise. | 351 // Hide the view immediately otherwise. |
327 contents_view_->custom_page_view()->SetVisible(false); | 352 contents_view_->custom_page_view()->SetVisible(false); |
328 } | 353 } |
329 // Allow the start page to update |custom_page_clickzone_|. | 354 // Allow the start page to update |custom_page_clickzone_|. |
330 contents_view_->start_page_view()->UpdateCustomPageClickzoneVisibility(); | 355 contents_view_->start_page_view()->UpdateCustomPageClickzoneVisibility(); |
331 } | 356 } |
332 | 357 |
| 358 void AppListMainView::OnSearchEngineIsGoogleChanged(bool is_google) { |
| 359 if (contents_view_->custom_page_view()) |
| 360 contents_view_->custom_page_view()->SetVisible(is_google); |
| 361 |
| 362 if (contents_view_->start_page_view()) { |
| 363 contents_view_->start_page_view()->instant_container()->SetVisible( |
| 364 is_google); |
| 365 contents_view_->start_page_view()->UpdateCustomPageClickzoneVisibility(); |
| 366 } |
| 367 } |
| 368 |
333 void AppListMainView::ActivateApp(AppListItem* item, int event_flags) { | 369 void AppListMainView::ActivateApp(AppListItem* item, int event_flags) { |
334 // TODO(jennyz): Activate the folder via AppListModel notification. | 370 // TODO(jennyz): Activate the folder via AppListModel notification. |
335 if (item->GetItemType() == AppListFolderItem::kItemType) | 371 if (item->GetItemType() == AppListFolderItem::kItemType) |
336 contents_view_->ShowFolderContent(static_cast<AppListFolderItem*>(item)); | 372 contents_view_->ShowFolderContent(static_cast<AppListFolderItem*>(item)); |
337 else | 373 else |
338 item->Activate(event_flags); | 374 item->Activate(event_flags); |
339 } | 375 } |
340 | 376 |
341 void AppListMainView::GetShortcutPathForApp( | 377 void AppListMainView::GetShortcutPathForApp( |
342 const std::string& app_id, | 378 const std::string& app_id, |
(...skipping 21 matching lines...) Expand all Loading... |
364 contents_view_->Back(); | 400 contents_view_->Back(); |
365 } | 401 } |
366 | 402 |
367 void AppListMainView::OnResultInstalled(SearchResult* result) { | 403 void AppListMainView::OnResultInstalled(SearchResult* result) { |
368 // Clears the search to show the apps grid. The last installed app | 404 // Clears the search to show the apps grid. The last installed app |
369 // should be highlighted and made visible already. | 405 // should be highlighted and made visible already. |
370 search_box_view_->ClearSearch(); | 406 search_box_view_->ClearSearch(); |
371 } | 407 } |
372 | 408 |
373 } // namespace app_list | 409 } // namespace app_list |
OLD | NEW |