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

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

Issue 2982453002: New AppListView Scroll Behavior. (Closed)
Patch Set: Created 3 years, 5 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
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/app_list_view.h" 5 #include "ui/app_list/views/app_list_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 17 matching lines...) Expand all
28 #include "ui/aura/window.h" 28 #include "ui/aura/window.h"
29 #include "ui/aura/window_tree_host.h" 29 #include "ui/aura/window_tree_host.h"
30 #include "ui/base/ui_base_switches.h" 30 #include "ui/base/ui_base_switches.h"
31 #include "ui/compositor/layer.h" 31 #include "ui/compositor/layer.h"
32 #include "ui/compositor/layer_animation_observer.h" 32 #include "ui/compositor/layer_animation_observer.h"
33 #include "ui/compositor/scoped_layer_animation_settings.h" 33 #include "ui/compositor/scoped_layer_animation_settings.h"
34 #include "ui/display/display.h" 34 #include "ui/display/display.h"
35 #include "ui/display/screen.h" 35 #include "ui/display/screen.h"
36 #include "ui/gfx/canvas.h" 36 #include "ui/gfx/canvas.h"
37 #include "ui/gfx/geometry/insets.h" 37 #include "ui/gfx/geometry/insets.h"
38 #include "ui/gfx/geometry/vector2d_conversions.h"
38 #include "ui/gfx/image/image_skia.h" 39 #include "ui/gfx/image/image_skia.h"
39 #include "ui/gfx/path.h" 40 #include "ui/gfx/path.h"
40 #include "ui/gfx/skia_util.h" 41 #include "ui/gfx/skia_util.h"
41 #include "ui/views/bubble/bubble_frame_view.h" 42 #include "ui/views/bubble/bubble_frame_view.h"
42 #include "ui/views/bubble/bubble_window_targeter.h" 43 #include "ui/views/bubble/bubble_window_targeter.h"
43 #include "ui/views/controls/image_view.h" 44 #include "ui/views/controls/image_view.h"
44 #include "ui/views/controls/textfield/textfield.h" 45 #include "ui/views/controls/textfield/textfield.h"
45 #include "ui/views/layout/fill_layout.h" 46 #include "ui/views/layout/fill_layout.h"
46 #include "ui/views/views_delegate.h" 47 #include "ui/views/views_delegate.h"
47 #include "ui/views/widget/widget.h" 48 #include "ui/views/widget/widget.h"
(...skipping 17 matching lines...) Expand all
65 constexpr int kHalfAppListHeight = 561; 66 constexpr int kHalfAppListHeight = 561;
66 67
67 // The fraction of app list height that the app list must be released at in 68 // The fraction of app list height that the app list must be released at in
68 // order to transition to the next state. 69 // order to transition to the next state.
69 constexpr int kAppListThresholdDenominator = 3; 70 constexpr int kAppListThresholdDenominator = 3;
70 71
71 // The velocity the app list must be dragged in order to transition to the next 72 // The velocity the app list must be dragged in order to transition to the next
72 // state, measured in DIPs/event. 73 // state, measured in DIPs/event.
73 constexpr int kAppListDragVelocityThreshold = 25; 74 constexpr int kAppListDragVelocityThreshold = 25;
74 75
76 // The scroll offset in order to transition from PEEKING to FULLSCREEN
77 constexpr int kAppListMinScrollToSwitchStates = 20;
78
75 // The DIP distance from the bezel that a drag event must end within to transfer 79 // The DIP distance from the bezel that a drag event must end within to transfer
76 // the |app_list_state_|. 80 // the |app_list_state_|.
77 constexpr int kAppListBezelMargin = 50; 81 constexpr int kAppListBezelMargin = 50;
78 82
79 // The opacity of the app list background. 83 // The opacity of the app list background.
80 constexpr float kAppListOpacity = 0.8; 84 constexpr float kAppListOpacity = 0.8;
81 85
82 // The vertical position for the appearing animation of the speech UI. 86 // The vertical position for the appearing animation of the speech UI.
83 constexpr float kSpeechUIAppearingPosition = 12; 87 constexpr float kSpeechUIAppearingPosition = 12;
84 88
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 661
658 void AppListView::OnMaximizeModeChanged(bool started) { 662 void AppListView::OnMaximizeModeChanged(bool started) {
659 is_maximize_mode_ = started; 663 is_maximize_mode_ = started;
660 if (is_maximize_mode_ && !is_fullscreen()) { 664 if (is_maximize_mode_ && !is_fullscreen()) {
661 // Set |app_list_state_| to a maximize mode friendly state. 665 // Set |app_list_state_| to a maximize mode friendly state.
662 SetState(app_list_state_ == PEEKING ? FULLSCREEN_ALL_APPS 666 SetState(app_list_state_ == PEEKING ? FULLSCREEN_ALL_APPS
663 : FULLSCREEN_SEARCH); 667 : FULLSCREEN_SEARCH);
664 } 668 }
665 } 669 }
666 670
671 bool AppListView::HandleScroll(const ui::Event* event) {
672 if (app_list_state_ != PEEKING)
673 return false;
674
675 switch (event->type()) {
676 case ui::ET_MOUSEWHEEL:
677 SetState(event->AsMouseWheelEvent()->y_offset() < 0 ? FULLSCREEN_ALL_APPS
678 : CLOSED);
679 return true;
680 break;
vadimt 2017/07/11 23:32:56 No need to break after unconditional return.
newcomer 2017/07/12 16:56:00 Done.
681 case ui::ET_SCROLL:
682 case ui::ET_SCROLL_FLING_START: {
683 int offset = event->AsScrollEvent()->y_offset();
684 if (abs(offset) > kAppListMinScrollToSwitchStates) {
685 SetState(offset < 0 ? FULLSCREEN_ALL_APPS : CLOSED);
686 return true;
687 }
688 break;
689 }
690 default:
691 break;
692 }
693 return false;
694 }
695
667 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, 696 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
668 views::Widget* widget) const { 697 views::Widget* widget) const {
669 if (!params->native_widget) { 698 if (!params->native_widget) {
670 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); 699 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance();
671 if (views_delegate && !views_delegate->native_widget_factory().is_null()) { 700 if (views_delegate && !views_delegate->native_widget_factory().is_null()) {
672 params->native_widget = 701 params->native_widget =
673 views_delegate->native_widget_factory().Run(*params, widget); 702 views_delegate->native_widget_factory().Run(*params, widget);
674 } 703 }
675 } 704 }
676 // Apply a WM-provided shadow (see ui/wm/core/). 705 // Apply a WM-provided shadow (see ui/wm/core/).
(...skipping 13 matching lines...) Expand all
690 return GetBubbleFrameView() != nullptr; 719 return GetBubbleFrameView() != nullptr;
691 } 720 }
692 721
693 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { 722 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const {
694 DCHECK(mask); 723 DCHECK(mask);
695 DCHECK(GetBubbleFrameView()); 724 DCHECK(GetBubbleFrameView());
696 725
697 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); 726 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds()));
698 } 727 }
699 728
729 void AppListView::OnScrollEvent(ui::ScrollEvent* event) {
730 if (!is_fullscreen_app_list_enabled_)
731 return;
732
733 if (event->type() == ui::ET_SCROLL_FLING_CANCEL)
734 return;
735
736 if (HandleScroll(event)) {
737 event->SetHandled();
738 event->StopPropagation();
739 }
740 }
741
700 void AppListView::OnMouseEvent(ui::MouseEvent* event) { 742 void AppListView::OnMouseEvent(ui::MouseEvent* event) {
701 if (!is_fullscreen_app_list_enabled_) 743 if (!is_fullscreen_app_list_enabled_)
702 return; 744 return;
703 745
704 switch (event->type()) { 746 switch (event->type()) {
705 case ui::ET_MOUSE_PRESSED: 747 case ui::ET_MOUSE_PRESSED:
706 StartDrag(event->location()); 748 StartDrag(event->location());
707 event->SetHandled(); 749 event->SetHandled();
708 break; 750 break;
709 case ui::ET_MOUSE_DRAGGED: 751 case ui::ET_MOUSE_DRAGGED:
710 UpdateDrag(event->location()); 752 UpdateDrag(event->location());
711 event->SetHandled(); 753 event->SetHandled();
712 break; 754 break;
713 case ui::ET_MOUSE_RELEASED: 755 case ui::ET_MOUSE_RELEASED:
714 EndDrag(event->location()); 756 EndDrag(event->location());
715 event->SetHandled(); 757 event->SetHandled();
716 break; 758 break;
759 case ui::ET_MOUSEWHEEL: {
760 if (HandleScroll(event))
761 event->SetHandled();
762 break;
763 }
717 default: 764 default:
718 break; 765 break;
719 } 766 }
720 } 767 }
721 768
722 void AppListView::OnGestureEvent(ui::GestureEvent* event) { 769 void AppListView::OnGestureEvent(ui::GestureEvent* event) {
723 if (!is_fullscreen_app_list_enabled_) 770 if (!is_fullscreen_app_list_enabled_)
724 return; 771 return;
725 772
726 switch (event->type()) { 773 switch (event->type()) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 GetWidget()->Deactivate(); 805 GetWidget()->Deactivate();
759 } 806 }
760 807
761 // Don't let DialogClientView handle the accelerator. 808 // Don't let DialogClientView handle the accelerator.
762 return true; 809 return true;
763 } 810 }
764 811
765 void AppListView::Layout() { 812 void AppListView::Layout() {
766 const gfx::Rect contents_bounds = GetContentsBounds(); 813 const gfx::Rect contents_bounds = GetContentsBounds();
767 814
768 // Make sure to layout |app_list_main_view_| and |speech_view_| at the center 815 // Make sure to layout |app_list_main_view_| and |speech_view_| at the
769 // of the widget. 816 // center of the widget.
770 gfx::Rect centered_bounds = contents_bounds; 817 gfx::Rect centered_bounds = contents_bounds;
771 centered_bounds.ClampToCenteredSize(gfx::Size( 818 centered_bounds.ClampToCenteredSize(gfx::Size(
772 app_list_main_view_->contents_view()->GetDefaultContentsBounds().width(), 819 app_list_main_view_->contents_view()->GetDefaultContentsBounds().width(),
773 contents_bounds.height())); 820 contents_bounds.height()));
774 821
775 app_list_main_view_->SetBoundsRect(centered_bounds); 822 app_list_main_view_->SetBoundsRect(centered_bounds);
776 823
777 if (speech_view_) { 824 if (speech_view_) {
778 gfx::Rect speech_bounds = centered_bounds; 825 gfx::Rect speech_bounds = centered_bounds;
779 int preferred_height = speech_view_->GetPreferredSize().height(); 826 int preferred_height = speech_view_->GetPreferredSize().height();
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 } 988 }
942 989
943 // Prevent the search box from receiving events when hidden. 990 // Prevent the search box from receiving events when hidden.
944 search_box_view_->SetEnabled(!will_appear); 991 search_box_view_->SetEnabled(!will_appear);
945 992
946 if (will_appear) { 993 if (will_appear) {
947 speech_view_->SetVisible(true); 994 speech_view_->SetVisible(true);
948 } else { 995 } else {
949 app_list_main_view_->SetVisible(true); 996 app_list_main_view_->SetVisible(true);
950 // Refocus the search box. However, if the app list widget does not have 997 // Refocus the search box. However, if the app list widget does not have
951 // focus, it means another window has already taken focus, and we *must not* 998 // focus, it means another window has already taken focus, and we *must
952 // focus the search box (or we would steal focus back into the app list). 999 // not* focus the search box (or we would steal focus back into the app
1000 // list).
953 if (GetWidget()->IsActive()) 1001 if (GetWidget()->IsActive())
954 search_box_view_->search_box()->RequestFocus(); 1002 search_box_view_->search_box()->RequestFocus();
955 } 1003 }
956 } 1004 }
957 1005
958 void AppListView::OnDisplayMetricsChanged(const display::Display& display, 1006 void AppListView::OnDisplayMetricsChanged(const display::Display& display,
959 uint32_t changed_metrics) { 1007 uint32_t changed_metrics) {
960 if (!is_fullscreen_app_list_enabled_) 1008 if (!is_fullscreen_app_list_enabled_)
961 return; 1009 return;
962 1010
963 // Set the |fullscreen_widget_| size to fit the new display metrics. 1011 // Set the |fullscreen_widget_| size to fit the new display metrics.
964 gfx::Size size = display::Screen::GetScreen() 1012 gfx::Size size = display::Screen::GetScreen()
965 ->GetDisplayNearestView(parent_window()) 1013 ->GetDisplayNearestView(parent_window())
966 .work_area() 1014 .work_area()
967 .size(); 1015 .size();
968 size.Enlarge(0, kShelfSize); 1016 size.Enlarge(0, kShelfSize);
969 fullscreen_widget_->SetSize(size); 1017 fullscreen_widget_->SetSize(size);
970 1018
971 // Update the |fullscreen_widget_| bounds to accomodate the new work area. 1019 // Update the |fullscreen_widget_| bounds to accomodate the new work area.
972 SetState(app_list_state_); 1020 SetState(app_list_state_);
973 } 1021 }
974 1022
975 } // namespace app_list 1023 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698