OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/apps_grid_view.h" | 5 #include "ui/app_list/views/apps_grid_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/guid.h" | 11 #include "base/guid.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "ui/app_list/app_list_constants.h" | 13 #include "ui/app_list/app_list_constants.h" |
14 #include "ui/app_list/app_list_folder_item.h" | 14 #include "ui/app_list/app_list_folder_item.h" |
15 #include "ui/app_list/app_list_item.h" | 15 #include "ui/app_list/app_list_item.h" |
16 #include "ui/app_list/app_list_switches.h" | 16 #include "ui/app_list/app_list_switches.h" |
17 #include "ui/app_list/pagination_model.h" | 17 #include "ui/app_list/pagination_model.h" |
18 #include "ui/app_list/views/app_list_drag_and_drop_host.h" | 18 #include "ui/app_list/views/app_list_drag_and_drop_host.h" |
| 19 #include "ui/app_list/views/app_list_folder_view.h" |
19 #include "ui/app_list/views/app_list_item_view.h" | 20 #include "ui/app_list/views/app_list_item_view.h" |
20 #include "ui/app_list/views/apps_grid_view_delegate.h" | 21 #include "ui/app_list/views/apps_grid_view_delegate.h" |
21 #include "ui/app_list/views/page_switcher.h" | 22 #include "ui/app_list/views/page_switcher.h" |
22 #include "ui/app_list/views/pulsing_block_view.h" | 23 #include "ui/app_list/views/pulsing_block_view.h" |
23 #include "ui/compositor/scoped_layer_animation_settings.h" | 24 #include "ui/compositor/scoped_layer_animation_settings.h" |
24 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
25 #include "ui/gfx/animation/animation.h" | 26 #include "ui/gfx/animation/animation.h" |
26 #include "ui/views/border.h" | 27 #include "ui/views/border.h" |
27 #include "ui/views/controls/webview/webview.h" | 28 #include "ui/views/controls/webview/webview.h" |
28 #include "ui/views/view_model_utils.h" | 29 #include "ui/views/view_model_utils.h" |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 selected_view_(NULL), | 341 selected_view_(NULL), |
341 drag_view_(NULL), | 342 drag_view_(NULL), |
342 drag_start_page_(-1), | 343 drag_start_page_(-1), |
343 drag_pointer_(NONE), | 344 drag_pointer_(NONE), |
344 drop_attempt_(DROP_FOR_NONE), | 345 drop_attempt_(DROP_FOR_NONE), |
345 drag_and_drop_host_(NULL), | 346 drag_and_drop_host_(NULL), |
346 forward_events_to_drag_and_drop_host_(false), | 347 forward_events_to_drag_and_drop_host_(false), |
347 page_flip_target_(-1), | 348 page_flip_target_(-1), |
348 page_flip_delay_in_ms_(kPageFlipDelayInMs), | 349 page_flip_delay_in_ms_(kPageFlipDelayInMs), |
349 bounds_animator_(this), | 350 bounds_animator_(this), |
350 is_root_level_(true) { | 351 is_root_level_(true), |
| 352 activated_item_view_(NULL) { |
| 353 SetPaintToLayer(true); |
| 354 SetFillsBoundsOpaquely(false); |
| 355 |
351 pagination_model_->AddObserver(this); | 356 pagination_model_->AddObserver(this); |
352 AddChildView(page_switcher_view_); | 357 AddChildView(page_switcher_view_); |
353 | 358 |
354 if (start_page_contents) { | 359 if (start_page_contents) { |
355 start_page_view_ = | 360 start_page_view_ = |
356 new views::WebView(start_page_contents->GetBrowserContext()); | 361 new views::WebView(start_page_contents->GetBrowserContext()); |
357 start_page_view_->SetWebContents(start_page_contents); | 362 start_page_view_->SetWebContents(start_page_contents); |
358 AddChildView(start_page_view_); | 363 AddChildView(start_page_view_); |
359 start_page_contents->GetWebUI()->CallJavascriptFunction( | 364 start_page_contents->GetWebUI()->CallJavascriptFunction( |
360 "appList.startPage.onAppListShown"); | 365 "appList.startPage.onAppListShown"); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 AnimateToIdealBounds(); | 656 AnimateToIdealBounds(); |
652 | 657 |
653 StopPageFlipTimer(); | 658 StopPageFlipTimer(); |
654 } | 659 } |
655 | 660 |
656 void AppsGridView::StopPageFlipTimer() { | 661 void AppsGridView::StopPageFlipTimer() { |
657 page_flip_timer_.Stop(); | 662 page_flip_timer_.Stop(); |
658 page_flip_target_ = -1; | 663 page_flip_target_ = -1; |
659 } | 664 } |
660 | 665 |
| 666 AppListItemView* AppsGridView::GetItemViewAt(int index) const { |
| 667 DCHECK(index >= 0 && index < view_model_.view_size()); |
| 668 return static_cast<AppListItemView*>(view_model_.view_at(index)); |
| 669 } |
| 670 |
| 671 void AppsGridView::SetTopItemViewsVisible(bool visible) { |
| 672 int top_item_count = std::min(static_cast<int>(kNumFolderTopItems), |
| 673 view_model_.view_size()); |
| 674 for (int i = 0; i < top_item_count; ++i) |
| 675 GetItemViewAt(i)->SetVisible(visible); |
| 676 } |
| 677 |
| 678 void AppsGridView::ScheduleShowHideAnimation(bool show) { |
| 679 // Stop any previous animation. |
| 680 layer()->GetAnimator()->StopAnimating(); |
| 681 |
| 682 // Set initial state. |
| 683 SetVisible(true); |
| 684 layer()->SetOpacity(show ? 0.0f : 1.0f); |
| 685 |
| 686 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); |
| 687 animation.AddObserver(this); |
| 688 animation.SetTweenType(gfx::Tween::EASE_IN_2); |
| 689 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 690 show ? kFolderTransitionInDurationMs : kFolderTransitionOutDurationMs)); |
| 691 |
| 692 layer()->SetOpacity(show ? 1.0f : 0.0f); |
| 693 } |
| 694 |
661 bool AppsGridView::IsDraggedView(const views::View* view) const { | 695 bool AppsGridView::IsDraggedView(const views::View* view) const { |
662 return drag_view_ == view; | 696 return drag_view_ == view; |
663 } | 697 } |
664 | 698 |
665 void AppsGridView::SetDragAndDropHostOfCurrentAppList( | 699 void AppsGridView::SetDragAndDropHostOfCurrentAppList( |
666 ApplicationDragAndDropHost* drag_and_drop_host) { | 700 ApplicationDragAndDropHost* drag_and_drop_host) { |
667 drag_and_drop_host_ = drag_and_drop_host; | 701 drag_and_drop_host_ = drag_and_drop_host; |
668 } | 702 } |
669 | 703 |
670 void AppsGridView::Prerender(int page_index) { | 704 void AppsGridView::Prerender(int page_index) { |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1394 | 1428 |
1395 void AppsGridView::ButtonPressed(views::Button* sender, | 1429 void AppsGridView::ButtonPressed(views::Button* sender, |
1396 const ui::Event& event) { | 1430 const ui::Event& event) { |
1397 if (dragging()) | 1431 if (dragging()) |
1398 return; | 1432 return; |
1399 | 1433 |
1400 if (strcmp(sender->GetClassName(), AppListItemView::kViewClassName)) | 1434 if (strcmp(sender->GetClassName(), AppListItemView::kViewClassName)) |
1401 return; | 1435 return; |
1402 | 1436 |
1403 if (delegate_) { | 1437 if (delegate_) { |
| 1438 activated_item_view_ = static_cast<AppListItemView*>(sender); |
1404 delegate_->ActivateApp(static_cast<AppListItemView*>(sender)->item(), | 1439 delegate_->ActivateApp(static_cast<AppListItemView*>(sender)->item(), |
1405 event.flags()); | 1440 event.flags()); |
1406 } | 1441 } |
1407 } | 1442 } |
1408 | 1443 |
1409 void AppsGridView::LayoutStartPage() { | 1444 void AppsGridView::LayoutStartPage() { |
1410 if (!start_page_view_) | 1445 if (!start_page_view_) |
1411 return; | 1446 return; |
1412 | 1447 |
1413 gfx::Rect start_page_bounds(GetLocalBounds()); | 1448 gfx::Rect start_page_bounds(GetLocalBounds()); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 void AppsGridView::SetViewHidden(views::View* view, bool hide, bool immediate) { | 1536 void AppsGridView::SetViewHidden(views::View* view, bool hide, bool immediate) { |
1502 #if defined(USE_AURA) | 1537 #if defined(USE_AURA) |
1503 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); | 1538 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); |
1504 animator.SetPreemptionStrategy( | 1539 animator.SetPreemptionStrategy( |
1505 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET : | 1540 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET : |
1506 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION); | 1541 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION); |
1507 view->layer()->SetOpacity(hide ? 0 : 1); | 1542 view->layer()->SetOpacity(hide ? 0 : 1); |
1508 #endif | 1543 #endif |
1509 } | 1544 } |
1510 | 1545 |
| 1546 void AppsGridView::OnImplicitAnimationsCompleted() { |
| 1547 if (layer()->opacity() == 0.0f) |
| 1548 SetVisible(false); |
| 1549 } |
| 1550 |
1511 bool AppsGridView::EnableFolderDragDropUI() { | 1551 bool AppsGridView::EnableFolderDragDropUI() { |
1512 // Enable drag and drop folder UI only if it is at the app list root level | 1552 // Enable drag and drop folder UI only if it is at the app list root level |
1513 // and the switch is on and the target folder can still accept new items. | 1553 // and the switch is on and the target folder can still accept new items. |
1514 return switches::IsFolderUIEnabled() && is_root_level_ && | 1554 return switches::IsFolderUIEnabled() && is_root_level_ && |
1515 CanDropIntoTarget(drop_target_); | 1555 CanDropIntoTarget(drop_target_); |
1516 } | 1556 } |
1517 | 1557 |
1518 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) { | 1558 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) { |
1519 views::View* target_view = GetViewAtSlotOnCurrentPage(drop_target.slot); | 1559 views::View* target_view = GetViewAtSlotOnCurrentPage(drop_target.slot); |
1520 if (!target_view) | 1560 if (!target_view) |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1662 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 1702 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
1663 bool is_target_folder) { | 1703 bool is_target_folder) { |
1664 AppListItemView* target_view = | 1704 AppListItemView* target_view = |
1665 static_cast<AppListItemView*>( | 1705 static_cast<AppListItemView*>( |
1666 GetViewAtSlotOnCurrentPage(target_index.slot)); | 1706 GetViewAtSlotOnCurrentPage(target_index.slot)); |
1667 if (target_view) | 1707 if (target_view) |
1668 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 1708 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
1669 } | 1709 } |
1670 | 1710 |
1671 } // namespace app_list | 1711 } // namespace app_list |
OLD | NEW |