| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // AppListView: | 192 // AppListView: |
| 193 | 193 |
| 194 AppListView::AppListView(AppListViewDelegate* delegate) | 194 AppListView::AppListView(AppListViewDelegate* delegate) |
| 195 : delegate_(delegate), | 195 : delegate_(delegate), |
| 196 app_list_main_view_(nullptr), | 196 app_list_main_view_(nullptr), |
| 197 speech_view_(nullptr), | 197 speech_view_(nullptr), |
| 198 search_box_focus_host_(nullptr), | 198 search_box_focus_host_(nullptr), |
| 199 search_box_widget_(nullptr), | 199 search_box_widget_(nullptr), |
| 200 search_box_view_(nullptr), | 200 search_box_view_(nullptr), |
| 201 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()), | 201 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()), |
| 202 processing_scroll_event_series_(false), |
| 202 app_list_state_(PEEKING), | 203 app_list_state_(PEEKING), |
| 203 display_observer_(this), | 204 display_observer_(this), |
| 204 overlay_view_(nullptr), | 205 overlay_view_(nullptr), |
| 205 animation_observer_(new HideViewAnimationObserver()) { | 206 animation_observer_(new HideViewAnimationObserver()) { |
| 206 CHECK(delegate); | 207 CHECK(delegate); |
| 207 delegate_->GetSpeechUI()->AddObserver(this); | 208 delegate_->GetSpeechUI()->AddObserver(this); |
| 208 | 209 |
| 209 if (is_fullscreen_app_list_enabled_) | 210 if (is_fullscreen_app_list_enabled_) |
| 210 display_observer_.Add(display::Screen::GetScreen()); | 211 display_observer_.Add(display::Screen::GetScreen()); |
| 211 } | 212 } |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 | 489 |
| 489 aura::Window* window = GetWidget()->GetNativeWindow(); | 490 aura::Window* window = GetWidget()->GetNativeWindow(); |
| 490 window->SetEventTargeter(base::MakeUnique<views::BubbleWindowTargeter>(this)); | 491 window->SetEventTargeter(base::MakeUnique<views::BubbleWindowTargeter>(this)); |
| 491 | 492 |
| 492 const int kOverlayCornerRadius = | 493 const int kOverlayCornerRadius = |
| 493 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); | 494 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); |
| 494 overlay_view_ = new AppListOverlayView(kOverlayCornerRadius); | 495 overlay_view_ = new AppListOverlayView(kOverlayCornerRadius); |
| 495 overlay_view_->SetBoundsRect(GetContentsBounds()); | 496 overlay_view_->SetBoundsRect(GetContentsBounds()); |
| 496 } | 497 } |
| 497 | 498 |
| 499 void AppListView::HandleClickOrTap() { |
| 500 switch (app_list_state_) { |
| 501 case HALF: |
| 502 case FULLSCREEN_SEARCH: |
| 503 search_box_view_->ClearSearch(); |
| 504 SetState(app_list_state_ == HALF ? PEEKING : FULLSCREEN_ALL_APPS); |
| 505 break; |
| 506 case PEEKING: |
| 507 case FULLSCREEN_ALL_APPS: |
| 508 if (search_box_view_->is_search_box_active()) |
| 509 search_box_view_->ClearSearch(); |
| 510 else |
| 511 SetState(CLOSED); |
| 512 break; |
| 513 case CLOSED: |
| 514 break; |
| 515 } |
| 516 } |
| 517 |
| 498 void AppListView::StartDrag(const gfx::Point& location) { | 518 void AppListView::StartDrag(const gfx::Point& location) { |
| 499 initial_drag_point_ = location; | 519 initial_drag_point_ = location; |
| 500 } | 520 } |
| 501 | 521 |
| 502 void AppListView::UpdateDrag(const gfx::Point& location) { | 522 void AppListView::UpdateDrag(const gfx::Point& location) { |
| 503 // Update the bounds of the widget while maintaining the | 523 // Update the bounds of the widget while maintaining the |
| 504 // relative position of the top of the widget and the mouse/gesture. | 524 // relative position of the top of the widget and the mouse/gesture. |
| 505 // Block drags north of 0 and recalculate the initial_drag_point_. | 525 // Block drags north of 0 and recalculate the initial_drag_point_. |
| 506 int const new_y_position = location.y() - initial_drag_point_.y() + | 526 int const new_y_position = location.y() - initial_drag_point_.y() + |
| 507 fullscreen_widget_->GetWindowBoundsInScreen().y(); | 527 fullscreen_widget_->GetWindowBoundsInScreen().y(); |
| 508 gfx::Rect new_widget_bounds = fullscreen_widget_->GetWindowBoundsInScreen(); | 528 gfx::Rect new_widget_bounds = fullscreen_widget_->GetWindowBoundsInScreen(); |
| 509 if (new_y_position < 0) { | 529 if (new_y_position < 0) { |
| 510 new_widget_bounds.set_y(0); | 530 new_widget_bounds.set_y(0); |
| 511 initial_drag_point_ = location; | 531 initial_drag_point_ = location; |
| 512 } else { | 532 } else { |
| 513 new_widget_bounds.set_y(new_y_position); | 533 new_widget_bounds.set_y(new_y_position); |
| 514 } | 534 } |
| 515 fullscreen_widget_->SetBounds(new_widget_bounds); | 535 fullscreen_widget_->SetBounds(new_widget_bounds); |
| 516 } | 536 } |
| 517 | 537 |
| 518 void AppListView::EndDrag(const gfx::Point& location) { | 538 void AppListView::EndDrag(const gfx::Point& location) { |
| 539 // When the SearchBoxView closes the app list, ignore the final event. |
| 540 if (app_list_state_ == CLOSED) |
| 541 return; |
| 519 // Change the app list state based on where the drag ended. If fling velocity | 542 // Change the app list state based on where the drag ended. If fling velocity |
| 520 // was over the threshold, snap to the next state in the direction of the | 543 // was over the threshold, snap to the next state in the direction of the |
| 521 // fling. | 544 // fling. |
| 522 int const new_y_position = location.y() - initial_drag_point_.y() + | 545 int const new_y_position = location.y() - initial_drag_point_.y() + |
| 523 fullscreen_widget_->GetWindowBoundsInScreen().y(); | 546 fullscreen_widget_->GetWindowBoundsInScreen().y(); |
| 524 if (std::abs(last_fling_velocity_) >= kAppListDragVelocityThreshold) { | 547 if (std::abs(last_fling_velocity_) >= kAppListDragVelocityThreshold) { |
| 525 // If the user releases drag with velocity over the threshold, snap to | 548 // If the user releases drag with velocity over the threshold, snap to |
| 526 // the next state, ignoring the drag release position. | 549 // the next state, ignoring the drag release position. |
| 527 | 550 |
| 528 if (last_fling_velocity_ > 0) { | 551 if (last_fling_velocity_ > 0) { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 | 719 |
| 697 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); | 720 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); |
| 698 } | 721 } |
| 699 | 722 |
| 700 void AppListView::OnMouseEvent(ui::MouseEvent* event) { | 723 void AppListView::OnMouseEvent(ui::MouseEvent* event) { |
| 701 if (!is_fullscreen_app_list_enabled_) | 724 if (!is_fullscreen_app_list_enabled_) |
| 702 return; | 725 return; |
| 703 | 726 |
| 704 switch (event->type()) { | 727 switch (event->type()) { |
| 705 case ui::ET_MOUSE_PRESSED: | 728 case ui::ET_MOUSE_PRESSED: |
| 706 StartDrag(event->location()); | |
| 707 event->SetHandled(); | 729 event->SetHandled(); |
| 708 break; | 730 HandleClickOrTap(); |
| 709 case ui::ET_MOUSE_DRAGGED: | |
| 710 UpdateDrag(event->location()); | |
| 711 event->SetHandled(); | |
| 712 break; | |
| 713 case ui::ET_MOUSE_RELEASED: | |
| 714 EndDrag(event->location()); | |
| 715 event->SetHandled(); | |
| 716 break; | 731 break; |
| 717 default: | 732 default: |
| 718 break; | 733 break; |
| 719 } | 734 } |
| 720 } | 735 } |
| 721 | 736 |
| 722 void AppListView::OnGestureEvent(ui::GestureEvent* event) { | 737 void AppListView::OnGestureEvent(ui::GestureEvent* event) { |
| 723 if (!is_fullscreen_app_list_enabled_) | 738 if (!is_fullscreen_app_list_enabled_) |
| 724 return; | 739 return; |
| 725 | 740 |
| 726 switch (event->type()) { | 741 switch (event->type()) { |
| 742 case ui::ET_GESTURE_TAP: |
| 743 processing_scroll_event_series_ = false; |
| 744 event->SetHandled(); |
| 745 HandleClickOrTap(); |
| 746 break; |
| 727 case ui::ET_SCROLL_FLING_START: | 747 case ui::ET_SCROLL_FLING_START: |
| 728 case ui::ET_GESTURE_SCROLL_BEGIN: | 748 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 749 processing_scroll_event_series_ = true; |
| 729 StartDrag(event->location()); | 750 StartDrag(event->location()); |
| 730 event->SetHandled(); | 751 event->SetHandled(); |
| 731 break; | 752 break; |
| 732 case ui::ET_GESTURE_SCROLL_UPDATE: | 753 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 754 processing_scroll_event_series_ = true; |
| 733 last_fling_velocity_ = event->details().scroll_y(); | 755 last_fling_velocity_ = event->details().scroll_y(); |
| 734 UpdateDrag(event->location()); | 756 UpdateDrag(event->location()); |
| 735 event->SetHandled(); | 757 event->SetHandled(); |
| 736 break; | 758 break; |
| 737 case ui::ET_GESTURE_END: | 759 case ui::ET_GESTURE_END: |
| 760 if (!processing_scroll_event_series_) |
| 761 break; |
| 762 |
| 763 processing_scroll_event_series_ = false; |
| 738 EndDrag(event->location()); | 764 EndDrag(event->location()); |
| 739 event->SetHandled(); | 765 event->SetHandled(); |
| 740 break; | 766 break; |
| 741 default: | 767 default: |
| 742 break; | 768 break; |
| 743 } | 769 } |
| 744 } | 770 } |
| 745 | 771 |
| 746 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 772 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 747 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 773 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 .work_area() | 992 .work_area() |
| 967 .size(); | 993 .size(); |
| 968 size.Enlarge(0, kShelfSize); | 994 size.Enlarge(0, kShelfSize); |
| 969 fullscreen_widget_->SetSize(size); | 995 fullscreen_widget_->SetSize(size); |
| 970 | 996 |
| 971 // Update the |fullscreen_widget_| bounds to accomodate the new work area. | 997 // Update the |fullscreen_widget_| bounds to accomodate the new work area. |
| 972 SetState(app_list_state_); | 998 SetState(app_list_state_); |
| 973 } | 999 } |
| 974 | 1000 |
| 975 } // namespace app_list | 1001 } // namespace app_list |
| OLD | NEW |