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/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 Loading... |
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 Loading... |
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 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 | 684 |
681 void AppListView::OnMaximizeModeChanged(bool started) { | 685 void AppListView::OnMaximizeModeChanged(bool started) { |
682 is_maximize_mode_ = started; | 686 is_maximize_mode_ = started; |
683 if (is_maximize_mode_ && !is_fullscreen()) { | 687 if (is_maximize_mode_ && !is_fullscreen()) { |
684 // Set |app_list_state_| to a maximize mode friendly state. | 688 // Set |app_list_state_| to a maximize mode friendly state. |
685 SetState(app_list_state_ == PEEKING ? FULLSCREEN_ALL_APPS | 689 SetState(app_list_state_ == PEEKING ? FULLSCREEN_ALL_APPS |
686 : FULLSCREEN_SEARCH); | 690 : FULLSCREEN_SEARCH); |
687 } | 691 } |
688 } | 692 } |
689 | 693 |
| 694 bool AppListView::HandleScroll(const ui::Event* event) { |
| 695 if (app_list_state_ != PEEKING) |
| 696 return false; |
| 697 |
| 698 switch (event->type()) { |
| 699 case ui::ET_MOUSEWHEEL: |
| 700 SetState(event->AsMouseWheelEvent()->y_offset() < 0 ? FULLSCREEN_ALL_APPS |
| 701 : CLOSED); |
| 702 return true; |
| 703 case ui::ET_SCROLL: |
| 704 case ui::ET_SCROLL_FLING_START: { |
| 705 if (fabs(event->AsScrollEvent()->y_offset()) > |
| 706 kAppListMinScrollToSwitchStates) { |
| 707 SetState(event->AsScrollEvent()->y_offset() < 0 ? FULLSCREEN_ALL_APPS |
| 708 : CLOSED); |
| 709 return true; |
| 710 } |
| 711 break; |
| 712 } |
| 713 default: |
| 714 break; |
| 715 } |
| 716 return false; |
| 717 } |
| 718 |
690 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, | 719 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, |
691 views::Widget* widget) const { | 720 views::Widget* widget) const { |
692 if (!params->native_widget) { | 721 if (!params->native_widget) { |
693 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); | 722 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); |
694 if (views_delegate && !views_delegate->native_widget_factory().is_null()) { | 723 if (views_delegate && !views_delegate->native_widget_factory().is_null()) { |
695 params->native_widget = | 724 params->native_widget = |
696 views_delegate->native_widget_factory().Run(*params, widget); | 725 views_delegate->native_widget_factory().Run(*params, widget); |
697 } | 726 } |
698 } | 727 } |
699 // Apply a WM-provided shadow (see ui/wm/core/). | 728 // Apply a WM-provided shadow (see ui/wm/core/). |
(...skipping 13 matching lines...) Expand all Loading... |
713 return GetBubbleFrameView() != nullptr; | 742 return GetBubbleFrameView() != nullptr; |
714 } | 743 } |
715 | 744 |
716 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { | 745 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { |
717 DCHECK(mask); | 746 DCHECK(mask); |
718 DCHECK(GetBubbleFrameView()); | 747 DCHECK(GetBubbleFrameView()); |
719 | 748 |
720 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); | 749 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); |
721 } | 750 } |
722 | 751 |
| 752 void AppListView::OnScrollEvent(ui::ScrollEvent* event) { |
| 753 if (!is_fullscreen_app_list_enabled_) |
| 754 return; |
| 755 |
| 756 if (event->type() == ui::ET_SCROLL_FLING_CANCEL) |
| 757 return; |
| 758 |
| 759 if (!HandleScroll(event)) |
| 760 return; |
| 761 |
| 762 event->SetHandled(); |
| 763 event->StopPropagation(); |
| 764 } |
| 765 |
723 void AppListView::OnMouseEvent(ui::MouseEvent* event) { | 766 void AppListView::OnMouseEvent(ui::MouseEvent* event) { |
724 if (!is_fullscreen_app_list_enabled_) | 767 if (!is_fullscreen_app_list_enabled_) |
725 return; | 768 return; |
726 | 769 |
727 switch (event->type()) { | 770 switch (event->type()) { |
728 case ui::ET_MOUSE_PRESSED: | 771 case ui::ET_MOUSE_PRESSED: |
729 event->SetHandled(); | 772 event->SetHandled(); |
730 HandleClickOrTap(); | 773 HandleClickOrTap(); |
731 break; | 774 break; |
| 775 case ui::ET_MOUSEWHEEL: |
| 776 if (HandleScroll(event)) |
| 777 event->SetHandled(); |
| 778 break; |
732 default: | 779 default: |
733 break; | 780 break; |
734 } | 781 } |
735 } | 782 } |
736 | 783 |
737 void AppListView::OnGestureEvent(ui::GestureEvent* event) { | 784 void AppListView::OnGestureEvent(ui::GestureEvent* event) { |
738 if (!is_fullscreen_app_list_enabled_) | 785 if (!is_fullscreen_app_list_enabled_) |
739 return; | 786 return; |
740 | 787 |
741 switch (event->type()) { | 788 switch (event->type()) { |
(...skipping 15 matching lines...) Expand all Loading... |
757 event->SetHandled(); | 804 event->SetHandled(); |
758 break; | 805 break; |
759 case ui::ET_GESTURE_END: | 806 case ui::ET_GESTURE_END: |
760 if (!processing_scroll_event_series_) | 807 if (!processing_scroll_event_series_) |
761 break; | 808 break; |
762 | 809 |
763 processing_scroll_event_series_ = false; | 810 processing_scroll_event_series_ = false; |
764 EndDrag(event->location()); | 811 EndDrag(event->location()); |
765 event->SetHandled(); | 812 event->SetHandled(); |
766 break; | 813 break; |
| 814 case ui::ET_MOUSEWHEEL: { |
| 815 if (HandleScroll(event)) |
| 816 event->SetHandled(); |
| 817 break; |
| 818 } |
767 default: | 819 default: |
768 break; | 820 break; |
769 } | 821 } |
770 } | 822 } |
771 | 823 |
772 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 824 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
773 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 825 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); |
774 | 826 |
775 // If the ContentsView does not handle the back action, then this is the | 827 // If the ContentsView does not handle the back action, then this is the |
776 // top level, so we close the app list. | 828 // top level, so we close the app list. |
777 if (!app_list_main_view_->contents_view()->Back()) { | 829 if (!app_list_main_view_->contents_view()->Back()) { |
778 if (is_fullscreen_app_list_enabled_) { | 830 if (is_fullscreen_app_list_enabled_) { |
779 SetState(CLOSED); | 831 SetState(CLOSED); |
780 } else { | 832 } else { |
781 app_list_main_view_->Close(); | 833 app_list_main_view_->Close(); |
782 delegate_->Dismiss(); | 834 delegate_->Dismiss(); |
783 } | 835 } |
784 GetWidget()->Deactivate(); | 836 GetWidget()->Deactivate(); |
785 } | 837 } |
786 | 838 |
787 // Don't let DialogClientView handle the accelerator. | 839 // Don't let DialogClientView handle the accelerator. |
788 return true; | 840 return true; |
789 } | 841 } |
790 | 842 |
791 void AppListView::Layout() { | 843 void AppListView::Layout() { |
792 const gfx::Rect contents_bounds = GetContentsBounds(); | 844 const gfx::Rect contents_bounds = GetContentsBounds(); |
793 | 845 |
794 // Make sure to layout |app_list_main_view_| and |speech_view_| at the center | 846 // Make sure to layout |app_list_main_view_| and |speech_view_| at the |
795 // of the widget. | 847 // center of the widget. |
796 gfx::Rect centered_bounds = contents_bounds; | 848 gfx::Rect centered_bounds = contents_bounds; |
797 centered_bounds.ClampToCenteredSize(gfx::Size( | 849 centered_bounds.ClampToCenteredSize(gfx::Size( |
798 app_list_main_view_->contents_view()->GetDefaultContentsBounds().width(), | 850 app_list_main_view_->contents_view()->GetDefaultContentsBounds().width(), |
799 contents_bounds.height())); | 851 contents_bounds.height())); |
800 | 852 |
801 app_list_main_view_->SetBoundsRect(centered_bounds); | 853 app_list_main_view_->SetBoundsRect(centered_bounds); |
802 | 854 |
803 if (speech_view_) { | 855 if (speech_view_) { |
804 gfx::Rect speech_bounds = centered_bounds; | 856 gfx::Rect speech_bounds = centered_bounds; |
805 int preferred_height = speech_view_->GetPreferredSize().height(); | 857 int preferred_height = speech_view_->GetPreferredSize().height(); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 } | 1019 } |
968 | 1020 |
969 // Prevent the search box from receiving events when hidden. | 1021 // Prevent the search box from receiving events when hidden. |
970 search_box_view_->SetEnabled(!will_appear); | 1022 search_box_view_->SetEnabled(!will_appear); |
971 | 1023 |
972 if (will_appear) { | 1024 if (will_appear) { |
973 speech_view_->SetVisible(true); | 1025 speech_view_->SetVisible(true); |
974 } else { | 1026 } else { |
975 app_list_main_view_->SetVisible(true); | 1027 app_list_main_view_->SetVisible(true); |
976 // Refocus the search box. However, if the app list widget does not have | 1028 // Refocus the search box. However, if the app list widget does not have |
977 // focus, it means another window has already taken focus, and we *must not* | 1029 // focus, it means another window has already taken focus, and we *must |
978 // focus the search box (or we would steal focus back into the app list). | 1030 // not* focus the search box (or we would steal focus back into the app |
| 1031 // list). |
979 if (GetWidget()->IsActive()) | 1032 if (GetWidget()->IsActive()) |
980 search_box_view_->search_box()->RequestFocus(); | 1033 search_box_view_->search_box()->RequestFocus(); |
981 } | 1034 } |
982 } | 1035 } |
983 | 1036 |
984 void AppListView::OnDisplayMetricsChanged(const display::Display& display, | 1037 void AppListView::OnDisplayMetricsChanged(const display::Display& display, |
985 uint32_t changed_metrics) { | 1038 uint32_t changed_metrics) { |
986 if (!is_fullscreen_app_list_enabled_) | 1039 if (!is_fullscreen_app_list_enabled_) |
987 return; | 1040 return; |
988 | 1041 |
989 // Set the |fullscreen_widget_| size to fit the new display metrics. | 1042 // Set the |fullscreen_widget_| size to fit the new display metrics. |
990 gfx::Size size = display::Screen::GetScreen() | 1043 gfx::Size size = display::Screen::GetScreen() |
991 ->GetDisplayNearestView(parent_window()) | 1044 ->GetDisplayNearestView(parent_window()) |
992 .work_area() | 1045 .work_area() |
993 .size(); | 1046 .size(); |
994 size.Enlarge(0, kShelfSize); | 1047 size.Enlarge(0, kShelfSize); |
995 fullscreen_widget_->SetSize(size); | 1048 fullscreen_widget_->SetSize(size); |
996 | 1049 |
997 // Update the |fullscreen_widget_| bounds to accomodate the new work area. | 1050 // Update the |fullscreen_widget_| bounds to accomodate the new work area. |
998 SetState(app_list_state_); | 1051 SetState(app_list_state_); |
999 } | 1052 } |
1000 | 1053 |
1001 } // namespace app_list | 1054 } // namespace app_list |
OLD | NEW |