| 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 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 case ui::ET_SCROLL: |
| 681 case ui::ET_SCROLL_FLING_START: { |
| 682 int offset = event->AsScrollEvent()->y_offset(); |
| 683 if (abs(offset) > kAppListMinScrollToSwitchStates) { |
| 684 SetState(offset < 0 ? FULLSCREEN_ALL_APPS : CLOSED); |
| 685 return true; |
| 686 } |
| 687 break; |
| 688 } |
| 689 default: |
| 690 break; |
| 691 } |
| 692 return false; |
| 693 } |
| 694 |
| 667 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, | 695 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, |
| 668 views::Widget* widget) const { | 696 views::Widget* widget) const { |
| 669 if (!params->native_widget) { | 697 if (!params->native_widget) { |
| 670 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); | 698 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); |
| 671 if (views_delegate && !views_delegate->native_widget_factory().is_null()) { | 699 if (views_delegate && !views_delegate->native_widget_factory().is_null()) { |
| 672 params->native_widget = | 700 params->native_widget = |
| 673 views_delegate->native_widget_factory().Run(*params, widget); | 701 views_delegate->native_widget_factory().Run(*params, widget); |
| 674 } | 702 } |
| 675 } | 703 } |
| 676 // Apply a WM-provided shadow (see ui/wm/core/). | 704 // Apply a WM-provided shadow (see ui/wm/core/). |
| (...skipping 13 matching lines...) Expand all Loading... |
| 690 return GetBubbleFrameView() != nullptr; | 718 return GetBubbleFrameView() != nullptr; |
| 691 } | 719 } |
| 692 | 720 |
| 693 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { | 721 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { |
| 694 DCHECK(mask); | 722 DCHECK(mask); |
| 695 DCHECK(GetBubbleFrameView()); | 723 DCHECK(GetBubbleFrameView()); |
| 696 | 724 |
| 697 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); | 725 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); |
| 698 } | 726 } |
| 699 | 727 |
| 728 void AppListView::OnScrollEvent(ui::ScrollEvent* event) { |
| 729 if (!is_fullscreen_app_list_enabled_) |
| 730 return; |
| 731 |
| 732 if (event->type() == ui::ET_SCROLL_FLING_CANCEL) |
| 733 return; |
| 734 |
| 735 if (HandleScroll(event)) { |
| 736 event->SetHandled(); |
| 737 event->StopPropagation(); |
| 738 } |
| 739 } |
| 740 |
| 700 void AppListView::OnMouseEvent(ui::MouseEvent* event) { | 741 void AppListView::OnMouseEvent(ui::MouseEvent* event) { |
| 701 if (!is_fullscreen_app_list_enabled_) | 742 if (!is_fullscreen_app_list_enabled_) |
| 702 return; | 743 return; |
| 703 | 744 |
| 704 switch (event->type()) { | 745 switch (event->type()) { |
| 705 case ui::ET_MOUSE_PRESSED: | 746 case ui::ET_MOUSE_PRESSED: |
| 706 StartDrag(event->location()); | 747 StartDrag(event->location()); |
| 707 event->SetHandled(); | 748 event->SetHandled(); |
| 708 break; | 749 break; |
| 709 case ui::ET_MOUSE_DRAGGED: | 750 case ui::ET_MOUSE_DRAGGED: |
| 710 UpdateDrag(event->location()); | 751 UpdateDrag(event->location()); |
| 711 event->SetHandled(); | 752 event->SetHandled(); |
| 712 break; | 753 break; |
| 713 case ui::ET_MOUSE_RELEASED: | 754 case ui::ET_MOUSE_RELEASED: |
| 714 EndDrag(event->location()); | 755 EndDrag(event->location()); |
| 715 event->SetHandled(); | 756 event->SetHandled(); |
| 716 break; | 757 break; |
| 758 case ui::ET_MOUSEWHEEL: { |
| 759 if (HandleScroll(event)) |
| 760 event->SetHandled(); |
| 761 break; |
| 762 } |
| 717 default: | 763 default: |
| 718 break; | 764 break; |
| 719 } | 765 } |
| 720 } | 766 } |
| 721 | 767 |
| 722 void AppListView::OnGestureEvent(ui::GestureEvent* event) { | 768 void AppListView::OnGestureEvent(ui::GestureEvent* event) { |
| 723 if (!is_fullscreen_app_list_enabled_) | 769 if (!is_fullscreen_app_list_enabled_) |
| 724 return; | 770 return; |
| 725 | 771 |
| 726 switch (event->type()) { | 772 switch (event->type()) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 GetWidget()->Deactivate(); | 804 GetWidget()->Deactivate(); |
| 759 } | 805 } |
| 760 | 806 |
| 761 // Don't let DialogClientView handle the accelerator. | 807 // Don't let DialogClientView handle the accelerator. |
| 762 return true; | 808 return true; |
| 763 } | 809 } |
| 764 | 810 |
| 765 void AppListView::Layout() { | 811 void AppListView::Layout() { |
| 766 const gfx::Rect contents_bounds = GetContentsBounds(); | 812 const gfx::Rect contents_bounds = GetContentsBounds(); |
| 767 | 813 |
| 768 // Make sure to layout |app_list_main_view_| and |speech_view_| at the center | 814 // Make sure to layout |app_list_main_view_| and |speech_view_| at the |
| 769 // of the widget. | 815 // center of the widget. |
| 770 gfx::Rect centered_bounds = contents_bounds; | 816 gfx::Rect centered_bounds = contents_bounds; |
| 771 centered_bounds.ClampToCenteredSize(gfx::Size( | 817 centered_bounds.ClampToCenteredSize(gfx::Size( |
| 772 app_list_main_view_->contents_view()->GetDefaultContentsBounds().width(), | 818 app_list_main_view_->contents_view()->GetDefaultContentsBounds().width(), |
| 773 contents_bounds.height())); | 819 contents_bounds.height())); |
| 774 | 820 |
| 775 app_list_main_view_->SetBoundsRect(centered_bounds); | 821 app_list_main_view_->SetBoundsRect(centered_bounds); |
| 776 | 822 |
| 777 if (speech_view_) { | 823 if (speech_view_) { |
| 778 gfx::Rect speech_bounds = centered_bounds; | 824 gfx::Rect speech_bounds = centered_bounds; |
| 779 int preferred_height = speech_view_->GetPreferredSize().height(); | 825 int preferred_height = speech_view_->GetPreferredSize().height(); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 } | 987 } |
| 942 | 988 |
| 943 // Prevent the search box from receiving events when hidden. | 989 // Prevent the search box from receiving events when hidden. |
| 944 search_box_view_->SetEnabled(!will_appear); | 990 search_box_view_->SetEnabled(!will_appear); |
| 945 | 991 |
| 946 if (will_appear) { | 992 if (will_appear) { |
| 947 speech_view_->SetVisible(true); | 993 speech_view_->SetVisible(true); |
| 948 } else { | 994 } else { |
| 949 app_list_main_view_->SetVisible(true); | 995 app_list_main_view_->SetVisible(true); |
| 950 // Refocus the search box. However, if the app list widget does not have | 996 // 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* | 997 // 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). | 998 // not* focus the search box (or we would steal focus back into the app |
| 999 // list). |
| 953 if (GetWidget()->IsActive()) | 1000 if (GetWidget()->IsActive()) |
| 954 search_box_view_->search_box()->RequestFocus(); | 1001 search_box_view_->search_box()->RequestFocus(); |
| 955 } | 1002 } |
| 956 } | 1003 } |
| 957 | 1004 |
| 958 void AppListView::OnDisplayMetricsChanged(const display::Display& display, | 1005 void AppListView::OnDisplayMetricsChanged(const display::Display& display, |
| 959 uint32_t changed_metrics) { | 1006 uint32_t changed_metrics) { |
| 960 if (!is_fullscreen_app_list_enabled_) | 1007 if (!is_fullscreen_app_list_enabled_) |
| 961 return; | 1008 return; |
| 962 | 1009 |
| 963 // Set the |fullscreen_widget_| size to fit the new display metrics. | 1010 // Set the |fullscreen_widget_| size to fit the new display metrics. |
| 964 gfx::Size size = display::Screen::GetScreen() | 1011 gfx::Size size = display::Screen::GetScreen() |
| 965 ->GetDisplayNearestView(parent_window()) | 1012 ->GetDisplayNearestView(parent_window()) |
| 966 .work_area() | 1013 .work_area() |
| 967 .size(); | 1014 .size(); |
| 968 size.Enlarge(0, kShelfSize); | 1015 size.Enlarge(0, kShelfSize); |
| 969 fullscreen_widget_->SetSize(size); | 1016 fullscreen_widget_->SetSize(size); |
| 970 | 1017 |
| 971 // Update the |fullscreen_widget_| bounds to accomodate the new work area. | 1018 // Update the |fullscreen_widget_| bounds to accomodate the new work area. |
| 972 SetState(app_list_state_); | 1019 SetState(app_list_state_); |
| 973 } | 1020 } |
| 974 | 1021 |
| 975 } // namespace app_list | 1022 } // namespace app_list |
| OLD | NEW |