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

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

Issue 140203003: Implement animation UI for opening/closing an app list folder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months 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 | Annotate | Revision Log
OLDNEW
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
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 animate_to_show_(false) {
354 SetPaintToLayer(true);
355 SetFillsBoundsOpaquely(false);
356
351 pagination_model_->AddObserver(this); 357 pagination_model_->AddObserver(this);
352 AddChildView(page_switcher_view_); 358 AddChildView(page_switcher_view_);
353 359
354 if (start_page_contents) { 360 if (start_page_contents) {
355 start_page_view_ = 361 start_page_view_ =
356 new views::WebView(start_page_contents->GetBrowserContext()); 362 new views::WebView(start_page_contents->GetBrowserContext());
357 start_page_view_->SetWebContents(start_page_contents); 363 start_page_view_->SetWebContents(start_page_contents);
358 AddChildView(start_page_view_); 364 AddChildView(start_page_view_);
359 start_page_contents->GetWebUI()->CallJavascriptFunction( 365 start_page_contents->GetWebUI()->CallJavascriptFunction(
360 "appList.startPage.onAppListShown"); 366 "appList.startPage.onAppListShown");
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 AnimateToIdealBounds(); 657 AnimateToIdealBounds();
652 658
653 StopPageFlipTimer(); 659 StopPageFlipTimer();
654 } 660 }
655 661
656 void AppsGridView::StopPageFlipTimer() { 662 void AppsGridView::StopPageFlipTimer() {
657 page_flip_timer_.Stop(); 663 page_flip_timer_.Stop();
658 page_flip_target_ = -1; 664 page_flip_target_ = -1;
659 } 665 }
660 666
667 AppListItemView* AppsGridView::GetItemViewAt(int index) const {
668 DCHECK(index >= 0 && index < view_model_.view_size());
669 return static_cast<AppListItemView*>(view_model_.view_at(index));
670 }
671
672 void AppsGridView::ShowTopItemViews(bool show) {
673 int top_item_count = std::min(static_cast<int>(kNumFolderTopItems),
674 view_model_.view_size());
675 for (int i = 0; i < top_item_count; ++i)
676 GetItemViewAt(i)->SetVisible(show);
677 }
678
679 void AppsGridView::ScheduleAnimationToShow(bool show) {
680 // Stop any previous animation.
681 layer()->GetAnimator()->StopAnimating();
682
683 animate_to_show_ = show;
684
685 // Set initial state.
686 SetVisible(true);
687 layer()->SetOpacity(show ? 0.0f : 1.0f);
688
689 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
690 animation.AddObserver(this);
691 animation.SetTweenType(gfx::Tween::EASE_IN_2);
692 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
693 show ? kFolderTransitionInDurationMs : kFolderTransitionOutDurationMs));
694
695 layer()->SetOpacity(show ? 1.0f : 0.0f);
696 }
697
661 bool AppsGridView::IsDraggedView(const views::View* view) const { 698 bool AppsGridView::IsDraggedView(const views::View* view) const {
662 return drag_view_ == view; 699 return drag_view_ == view;
663 } 700 }
664 701
665 void AppsGridView::SetDragAndDropHostOfCurrentAppList( 702 void AppsGridView::SetDragAndDropHostOfCurrentAppList(
666 ApplicationDragAndDropHost* drag_and_drop_host) { 703 ApplicationDragAndDropHost* drag_and_drop_host) {
667 drag_and_drop_host_ = drag_and_drop_host; 704 drag_and_drop_host_ = drag_and_drop_host;
668 } 705 }
669 706
670 void AppsGridView::Prerender(int page_index) { 707 void AppsGridView::Prerender(int page_index) {
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 1431
1395 void AppsGridView::ButtonPressed(views::Button* sender, 1432 void AppsGridView::ButtonPressed(views::Button* sender,
1396 const ui::Event& event) { 1433 const ui::Event& event) {
1397 if (dragging()) 1434 if (dragging())
1398 return; 1435 return;
1399 1436
1400 if (strcmp(sender->GetClassName(), AppListItemView::kViewClassName)) 1437 if (strcmp(sender->GetClassName(), AppListItemView::kViewClassName))
1401 return; 1438 return;
1402 1439
1403 if (delegate_) { 1440 if (delegate_) {
1441 activated_item_view_ = static_cast<AppListItemView*>(sender);
1404 delegate_->ActivateApp(static_cast<AppListItemView*>(sender)->item(), 1442 delegate_->ActivateApp(static_cast<AppListItemView*>(sender)->item(),
1405 event.flags()); 1443 event.flags());
1406 } 1444 }
1407 } 1445 }
1408 1446
1409 void AppsGridView::LayoutStartPage() { 1447 void AppsGridView::LayoutStartPage() {
1410 if (!start_page_view_) 1448 if (!start_page_view_)
1411 return; 1449 return;
1412 1450
1413 gfx::Rect start_page_bounds(GetLocalBounds()); 1451 gfx::Rect start_page_bounds(GetLocalBounds());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 void AppsGridView::SetViewHidden(views::View* view, bool hide, bool immediate) { 1539 void AppsGridView::SetViewHidden(views::View* view, bool hide, bool immediate) {
1502 #if defined(USE_AURA) 1540 #if defined(USE_AURA)
1503 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); 1541 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator());
1504 animator.SetPreemptionStrategy( 1542 animator.SetPreemptionStrategy(
1505 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET : 1543 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET :
1506 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION); 1544 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION);
1507 view->layer()->SetOpacity(hide ? 0 : 1); 1545 view->layer()->SetOpacity(hide ? 0 : 1);
1508 #endif 1546 #endif
1509 } 1547 }
1510 1548
1549 void AppsGridView::OnImplicitAnimationsCompleted() {
1550 if (!animate_to_show_)
1551 SetVisible(false);
1552 }
1553
1511 bool AppsGridView::EnableFolderDragDropUI() { 1554 bool AppsGridView::EnableFolderDragDropUI() {
1512 // Enable drag and drop folder UI only if it is at the app list root level 1555 // 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. 1556 // and the switch is on and the target folder can still accept new items.
1514 return switches::IsFolderUIEnabled() && is_root_level_ && 1557 return switches::IsFolderUIEnabled() && is_root_level_ &&
1515 CanDropIntoTarget(drop_target_); 1558 CanDropIntoTarget(drop_target_);
1516 } 1559 }
1517 1560
1518 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) { 1561 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) {
1519 views::View* target_view = GetViewAtSlotOnCurrentPage(drop_target.slot); 1562 views::View* target_view = GetViewAtSlotOnCurrentPage(drop_target.slot);
1520 if (!target_view) 1563 if (!target_view)
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, 1705 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index,
1663 bool is_target_folder) { 1706 bool is_target_folder) {
1664 AppListItemView* target_view = 1707 AppListItemView* target_view =
1665 static_cast<AppListItemView*>( 1708 static_cast<AppListItemView*>(
1666 GetViewAtSlotOnCurrentPage(target_index.slot)); 1709 GetViewAtSlotOnCurrentPage(target_index.slot));
1667 if (target_view) 1710 if (target_view)
1668 target_view->SetAsAttemptedFolderTarget(is_target_folder); 1711 target_view->SetAsAttemptedFolderTarget(is_target_folder);
1669 } 1712 }
1670 1713
1671 } // namespace app_list 1714 } // namespace app_list
OLDNEW
« ui/app_list/views/apps_grid_view.h ('K') | « ui/app_list/views/apps_grid_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698