Chromium Code Reviews| 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 "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "ui/app_list/app_list_constants.h" | 14 #include "ui/app_list/app_list_constants.h" |
| 15 #include "ui/app_list/app_list_features.h" | |
| 15 #include "ui/app_list/app_list_folder_item.h" | 16 #include "ui/app_list/app_list_folder_item.h" |
| 16 #include "ui/app_list/app_list_item.h" | 17 #include "ui/app_list/app_list_item.h" |
| 17 #include "ui/app_list/app_list_switches.h" | 18 #include "ui/app_list/app_list_switches.h" |
| 18 #include "ui/app_list/pagination_controller.h" | 19 #include "ui/app_list/pagination_controller.h" |
| 19 #include "ui/app_list/views/app_list_drag_and_drop_host.h" | 20 #include "ui/app_list/views/app_list_drag_and_drop_host.h" |
| 20 #include "ui/app_list/views/app_list_folder_view.h" | 21 #include "ui/app_list/views/app_list_folder_view.h" |
| 21 #include "ui/app_list/views/app_list_item_view.h" | 22 #include "ui/app_list/views/app_list_item_view.h" |
| 22 #include "ui/app_list/views/apps_grid_view_delegate.h" | 23 #include "ui/app_list/views/apps_grid_view_delegate.h" |
| 23 #include "ui/app_list/views/page_switcher.h" | 24 #include "ui/app_list/views/page_switcher_horizontal.h" |
| 25 #include "ui/app_list/views/page_switcher_vertical.h" | |
| 24 #include "ui/app_list/views/pulsing_block_view.h" | 26 #include "ui/app_list/views/pulsing_block_view.h" |
| 25 #include "ui/app_list/views/top_icon_animation_view.h" | 27 #include "ui/app_list/views/top_icon_animation_view.h" |
| 26 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
| 27 #include "ui/aura/window_event_dispatcher.h" | 29 #include "ui/aura/window_event_dispatcher.h" |
| 28 #include "ui/compositor/scoped_layer_animation_settings.h" | 30 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 29 #include "ui/events/event.h" | 31 #include "ui/events/event.h" |
| 30 #include "ui/gfx/animation/animation.h" | 32 #include "ui/gfx/animation/animation.h" |
| 31 #include "ui/gfx/geometry/vector2d.h" | 33 #include "ui/gfx/geometry/vector2d.h" |
| 32 #include "ui/gfx/geometry/vector2d_conversions.h" | 34 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 33 #include "ui/views/border.h" | 35 #include "ui/views/border.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 SetPaintToLayer(); | 224 SetPaintToLayer(); |
| 223 // Clip any icons that are outside the grid view's bounds. These icons would | 225 // Clip any icons that are outside the grid view's bounds. These icons would |
| 224 // otherwise be visible to the user when the grid view is off screen. | 226 // otherwise be visible to the user when the grid view is off screen. |
| 225 layer()->SetMasksToBounds(true); | 227 layer()->SetMasksToBounds(true); |
| 226 layer()->SetFillsBoundsOpaquely(false); | 228 layer()->SetFillsBoundsOpaquely(false); |
| 227 | 229 |
| 228 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs, | 230 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs, |
| 229 kOverscrollPageTransitionDurationMs); | 231 kOverscrollPageTransitionDurationMs); |
| 230 | 232 |
| 231 pagination_model_.AddObserver(this); | 233 pagination_model_.AddObserver(this); |
| 232 pagination_controller_.reset(new PaginationController( | 234 |
| 233 &pagination_model_, PaginationController::SCROLL_AXIS_HORIZONTAL)); | 235 if (features::IsFullscreenAppListEnabled()) { |
|
newcomer
2017/06/15 15:07:02
Call this once and cache it please.
| |
| 234 page_switcher_view_ = new PageSwitcher(&pagination_model_); | 236 page_switcher_view_ = new PageSwitcherVertical(&pagination_model_); |
| 237 pagination_controller_.reset(new PaginationController( | |
| 238 &pagination_model_, PaginationController::SCROLL_AXIS_VERTICAL)); | |
| 239 } else { | |
| 240 page_switcher_view_ = new PageSwitcherHorizontal(&pagination_model_); | |
| 241 pagination_controller_.reset(new PaginationController( | |
| 242 &pagination_model_, PaginationController::SCROLL_AXIS_HORIZONTAL)); | |
| 243 } | |
| 235 AddChildView(page_switcher_view_); | 244 AddChildView(page_switcher_view_); |
| 236 } | 245 } |
| 237 | 246 |
| 238 AppsGridView::~AppsGridView() { | 247 AppsGridView::~AppsGridView() { |
| 239 // Coming here |drag_view_| should already be canceled since otherwise the | 248 // Coming here |drag_view_| should already be canceled since otherwise the |
| 240 // drag would disappear after the app list got animated away and closed, | 249 // drag would disappear after the app list got animated away and closed, |
| 241 // which would look odd. | 250 // which would look odd. |
| 242 DCHECK(!drag_view_); | 251 DCHECK(!drag_view_); |
| 243 if (drag_view_) | 252 if (drag_view_) |
| 244 EndDrag(true); | 253 EndDrag(true); |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 ApplicationDragAndDropHost* drag_and_drop_host) { | 632 ApplicationDragAndDropHost* drag_and_drop_host) { |
| 624 drag_and_drop_host_ = drag_and_drop_host; | 633 drag_and_drop_host_ = drag_and_drop_host; |
| 625 } | 634 } |
| 626 | 635 |
| 627 bool AppsGridView::IsAnimatingView(AppListItemView* view) { | 636 bool AppsGridView::IsAnimatingView(AppListItemView* view) { |
| 628 return bounds_animator_.IsAnimating(view); | 637 return bounds_animator_.IsAnimating(view); |
| 629 } | 638 } |
| 630 | 639 |
| 631 gfx::Size AppsGridView::CalculatePreferredSize() const { | 640 gfx::Size AppsGridView::CalculatePreferredSize() const { |
| 632 const gfx::Insets insets(GetInsets()); | 641 const gfx::Insets insets(GetInsets()); |
| 633 // If we are in a folder, ignore the page switcher for height calculations. | |
| 634 int page_switcher_height = | |
| 635 folder_delegate_ ? 0 : page_switcher_view_->GetPreferredSize().height(); | |
| 636 gfx::Size size = GetTileGridSize(); | 642 gfx::Size size = GetTileGridSize(); |
| 637 size.Enlarge(insets.width(), insets.height() + page_switcher_height); | 643 if (features::IsFullscreenAppListEnabled()) { |
|
newcomer
2017/06/15 15:07:02
Same as above.
| |
| 644 // If we are in a folder, ignore the page switcher for width calculations. | |
| 645 int page_switcher_width = | |
| 646 folder_delegate_ ? 0 : page_switcher_view_->GetPreferredSize().width(); | |
| 647 size.Enlarge(insets.width() + page_switcher_width, insets.height()); | |
| 648 } else { | |
| 649 // If we are in a folder, ignore the page switcher for height calculations. | |
| 650 int page_switcher_height = | |
| 651 folder_delegate_ ? 0 : page_switcher_view_->GetPreferredSize().height(); | |
| 652 size.Enlarge(insets.width(), insets.height() + page_switcher_height); | |
| 653 } | |
| 638 return size; | 654 return size; |
| 639 } | 655 } |
| 640 | 656 |
| 641 bool AppsGridView::GetDropFormats( | 657 bool AppsGridView::GetDropFormats( |
| 642 int* formats, | 658 int* formats, |
| 643 std::set<ui::Clipboard::FormatType>* format_types) { | 659 std::set<ui::Clipboard::FormatType>* format_types) { |
| 644 // TODO(koz): Only accept a specific drag type for app shortcuts. | 660 // TODO(koz): Only accept a specific drag type for app shortcuts. |
| 645 *formats = OSExchangeData::FILE_NAME; | 661 *formats = OSExchangeData::FILE_NAME; |
| 646 return true; | 662 return true; |
| 647 } | 663 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 659 bounds_animator_.Cancel(); | 675 bounds_animator_.Cancel(); |
| 660 | 676 |
| 661 CalculateIdealBounds(); | 677 CalculateIdealBounds(); |
| 662 for (int i = 0; i < view_model_.view_size(); ++i) { | 678 for (int i = 0; i < view_model_.view_size(); ++i) { |
| 663 AppListItemView* view = GetItemViewAt(i); | 679 AppListItemView* view = GetItemViewAt(i); |
| 664 if (view != drag_view_) | 680 if (view != drag_view_) |
| 665 view->SetBoundsRect(view_model_.ideal_bounds(i)); | 681 view->SetBoundsRect(view_model_.ideal_bounds(i)); |
| 666 } | 682 } |
| 667 views::ViewModelUtils::SetViewBoundsToIdealBounds(pulsing_blocks_model_); | 683 views::ViewModelUtils::SetViewBoundsToIdealBounds(pulsing_blocks_model_); |
| 668 | 684 |
| 669 const int page_switcher_height = | |
| 670 page_switcher_view_->GetPreferredSize().height(); | |
| 671 gfx::Rect rect(GetContentsBounds()); | 685 gfx::Rect rect(GetContentsBounds()); |
| 672 rect.set_y(rect.bottom() - page_switcher_height); | 686 if (features::IsFullscreenAppListEnabled()) { |
|
newcomer
2017/06/15 15:07:02
Same as above.
| |
| 673 rect.set_height(page_switcher_height); | 687 const int page_switcher_width = |
| 688 page_switcher_view_->GetPreferredSize().width(); | |
| 689 rect.set_x(rect.right() - page_switcher_width); | |
| 690 rect.set_width(page_switcher_width); | |
| 691 } else { | |
| 692 const int page_switcher_height = | |
| 693 page_switcher_view_->GetPreferredSize().height(); | |
| 694 rect.set_y(rect.bottom() - page_switcher_height); | |
| 695 rect.set_height(page_switcher_height); | |
| 696 } | |
| 674 page_switcher_view_->SetBoundsRect(rect); | 697 page_switcher_view_->SetBoundsRect(rect); |
| 675 } | 698 } |
| 676 | 699 |
| 677 bool AppsGridView::OnKeyPressed(const ui::KeyEvent& event) { | 700 bool AppsGridView::OnKeyPressed(const ui::KeyEvent& event) { |
| 678 bool handled = false; | 701 bool handled = false; |
| 679 if (selected_view_) | 702 if (selected_view_) |
| 680 handled = static_cast<views::View*>(selected_view_)->OnKeyPressed(event); | 703 handled = static_cast<views::View*>(selected_view_)->OnKeyPressed(event); |
| 681 | 704 |
| 682 if (!handled) { | 705 if (!handled) { |
| 683 const int forward_dir = base::i18n::IsRTL() ? -1 : 1; | 706 const int forward_dir = base::i18n::IsRTL() ? -1 : 1; |
| (...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1910 | 1933 |
| 1911 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 1934 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
| 1912 bool is_target_folder) { | 1935 bool is_target_folder) { |
| 1913 AppListItemView* target_view = | 1936 AppListItemView* target_view = |
| 1914 GetViewDisplayedAtSlotOnCurrentPage(target_index.slot); | 1937 GetViewDisplayedAtSlotOnCurrentPage(target_index.slot); |
| 1915 if (target_view) | 1938 if (target_view) |
| 1916 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 1939 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
| 1917 } | 1940 } |
| 1918 | 1941 |
| 1919 } // namespace app_list | 1942 } // namespace app_list |
| OLD | NEW |