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

Side by Side Diff: ash/system/tray/system_tray.cc

Issue 2961313003: Touch gestures for System Tray/ IME/ Stylus/ Notifications (Closed)
Patch Set: Fixed comments. 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 "ash/system/tray/system_tray.h" 5 #include "ash/system/tray/system_tray.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); 618 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view();
619 // If system tray bubble is in the process of closing, do not try to activate 619 // If system tray bubble is in the process of closing, do not try to activate
620 // bubble. 620 // bubble.
621 if (bubble_view->GetWidget()->IsClosed()) 621 if (bubble_view->GetWidget()->IsClosed())
622 return; 622 return;
623 bubble_view->set_can_activate(true); 623 bubble_view->set_can_activate(true);
624 bubble_view->GetWidget()->Activate(); 624 bubble_view->GetWidget()->Activate();
625 } 625 }
626 626
627 void SystemTray::OnGestureEvent(ui::GestureEvent* event) { 627 void SystemTray::OnGestureEvent(ui::GestureEvent* event) {
628 if (Shell::Get() 628 if (ProcessGestureEvent(*event, false /* is_on_bubble */))
629 ->maximize_mode_controller()
630 ->IsMaximizeModeWindowManagerEnabled() &&
631 shelf_->IsHorizontalAlignment() && ProcessGestureEvent(*event)) {
632 event->SetHandled(); 629 event->SetHandled();
633 } else { 630 else
634 TrayBackgroundView::OnGestureEvent(event); 631 TrayBackgroundView::OnGestureEvent(event);
635 }
636 } 632 }
637 633
638 gfx::Rect SystemTray::GetWorkAreaBoundsInScreen() const { 634 gfx::Rect SystemTray::GetWorkAreaBoundsInScreen() const {
639 return shelf_->GetUserWorkAreaBounds(); 635 return shelf_->GetUserWorkAreaBounds();
640 } 636 }
641 637
642 bool SystemTray::PerformAction(const ui::Event& event) { 638 bool SystemTray::PerformAction(const ui::Event& event) {
643 // If we're already showing a full system tray menu, either default or 639 // If we're already showing a full system tray menu, either default or
644 // detailed menu, hide it; otherwise, show it (and hide any popup that's 640 // detailed menu, hide it; otherwise, show it (and hide any popup that's
645 // currently shown). 641 // currently shown).
646 if (HasSystemBubble() && full_system_tray_menu_) { 642 if (HasSystemBubble() && full_system_tray_menu_) {
647 system_bubble_->bubble()->Close(); 643 system_bubble_->bubble()->Close();
648 } else { 644 } else {
649 ShowDefaultView(BUBBLE_CREATE_NEW); 645 ShowDefaultView(BUBBLE_CREATE_NEW);
650 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) 646 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY))
651 ActivateBubble(); 647 ActivateBubble();
652 } 648 }
653 return true; 649 return true;
654 } 650 }
655 651
656 bool SystemTray::ProcessGestureEvent(const ui::GestureEvent& event) { 652 bool SystemTray::ProcessGestureEvent(const ui::GestureEvent& event,
653 bool is_on_bubble) {
654 if (!Shell::Get()
655 ->maximize_mode_controller()
656 ->IsMaximizeModeWindowManagerEnabled() ||
657 !shelf_->IsHorizontalAlignment()) {
658 return false;
659 }
660
661 // Set |is_on_bubble_| before process the events.
662 is_on_bubble_ = is_on_bubble;
657 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) 663 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
658 return StartGestureDrag(event); 664 return StartGestureDrag(event);
659 665
660 if (!HasSystemBubble() || !is_in_drag_) 666 if (!HasSystemBubble() || !is_in_drag_)
661 return false; 667 return false;
662 668
663 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) { 669 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) {
664 UpdateGestureDrag(event); 670 UpdateGestureDrag(event);
665 return true; 671 return true;
666 } 672 }
667 673
668 if (event.type() == ui::ET_GESTURE_SCROLL_END || 674 if (event.type() == ui::ET_GESTURE_SCROLL_END ||
669 event.type() == ui::ET_SCROLL_FLING_START) { 675 event.type() == ui::ET_SCROLL_FLING_START) {
670 CompleteGestureDrag(event); 676 CompleteGestureDrag(event);
671 return true; 677 return true;
672 } 678 }
673 679
674 // Unexpected event. Reset the drag state and close the bubble. 680 // Unexpected event. Reset the drag state and close the bubble.
675 is_in_drag_ = false; 681 is_in_drag_ = false;
676 CloseSystemBubble(); 682 CloseSystemBubble();
677 return false; 683 return false;
678 } 684 }
679 685
680 bool SystemTray::StartGestureDrag(const ui::GestureEvent& gesture) { 686 bool SystemTray::StartGestureDrag(const ui::GestureEvent& gesture) {
681 // Close the system bubble if there is already a full one opened. And return 687 if (!is_on_bubble_) {
682 // false to let shelf handle the event. 688 // Dragging happens on the system tray. Close the system bubble if there is
683 if (HasSystemBubble() && full_system_tray_menu_) { 689 // already a full one opened. And return false to let shelf handle the
684 system_bubble_->bubble()->Close(); 690 // event.
685 return false; 691 if (HasSystemBubble() && full_system_tray_menu_) {
692 system_bubble_->bubble()->Close();
693 return false;
694 }
695
696 // If the scroll sequence begins to scroll downward, return false so that
697 // the event will instead by handled by the shelf.
698 if (gesture.details().scroll_y_hint() > 0)
699 return false;
700
701 ShowDefaultView(BUBBLE_CREATE_NEW);
686 } 702 }
687 703
688 // If the scroll sequence begins to scroll downward, return false so that the
689 // event will instead by handled by the shelf.
690 if (gesture.details().scroll_y_hint() > 0)
691 return false;
692
693 is_in_drag_ = true; 704 is_in_drag_ = true;
694 gesture_drag_amount_ = 0.f; 705 gesture_drag_amount_ = 0.f;
695 ShowDefaultView(BUBBLE_CREATE_NEW);
696 system_tray_bubble_bounds_ = 706 system_tray_bubble_bounds_ =
697 system_bubble_->bubble_view()->GetWidget()->GetWindowBoundsInScreen(); 707 system_bubble_->bubble_view()->GetWidget()->GetWindowBoundsInScreen();
698 SetBubbleBounds(gesture.location()); 708 UpdateBubbleBounds();
699 return true; 709 return true;
700 } 710 }
701 711
702 void SystemTray::UpdateGestureDrag(const ui::GestureEvent& gesture) { 712 void SystemTray::UpdateGestureDrag(const ui::GestureEvent& gesture) {
703 SetBubbleBounds(gesture.location()); 713 UpdateBubbleBounds();
704 gesture_drag_amount_ += gesture.details().scroll_y(); 714 gesture_drag_amount_ += gesture.details().scroll_y();
705 } 715 }
706 716
707 void SystemTray::CompleteGestureDrag(const ui::GestureEvent& gesture) { 717 void SystemTray::CompleteGestureDrag(const ui::GestureEvent& gesture) {
708 const bool hide_bubble = !ShouldShowSystemBubbleAfterScrollSequence(gesture); 718 const bool hide_bubble = !ShouldShowSystemBubbleAfterScrollSequence(gesture);
709 gfx::Rect target_bounds = system_tray_bubble_bounds_; 719 gfx::Rect target_bounds = system_tray_bubble_bounds_;
710 720
711 if (hide_bubble) 721 if (hide_bubble)
712 target_bounds.set_y(shelf_->GetIdealBounds().y()); 722 target_bounds.set_y(shelf_->GetIdealBounds().y());
713 723
714 system_bubble_->bubble()->AnimateToTargetBounds(target_bounds, hide_bubble); 724 system_bubble_->bubble()->AnimateToTargetBounds(target_bounds, hide_bubble);
715 is_in_drag_ = false; 725 is_in_drag_ = false;
716 } 726 }
717 727
718 void SystemTray::SetBubbleBounds(const gfx::Point& location) { 728 void SystemTray::UpdateBubbleBounds() {
719 gfx::Point location_in_screen_coordinates(location); 729 gfx::Rect bounds_on_location = system_tray_bubble_bounds_;
720 View::ConvertPointToScreen(this, &location_in_screen_coordinates);
721
722 // System tray bubble should not be dragged higher than its original height. 730 // System tray bubble should not be dragged higher than its original height.
723 if (location_in_screen_coordinates.y() < system_tray_bubble_bounds_.y()) 731 int bounds_y = (is_on_bubble_ ? system_tray_bubble_bounds_.y()
724 location_in_screen_coordinates.set_y(system_tray_bubble_bounds_.y()); 732 : shelf_->GetIdealBounds().y()) +
725 733 gesture_drag_amount_;
726 gfx::Rect bounds_on_location = system_tray_bubble_bounds_; 734 bounds_on_location.set_y(std::max(bounds_y, system_tray_bubble_bounds_.y()));
727 bounds_on_location.set_y(location_in_screen_coordinates.y());
728 system_bubble_->bubble_view()->GetWidget()->SetBounds(bounds_on_location); 735 system_bubble_->bubble_view()->GetWidget()->SetBounds(bounds_on_location);
729 } 736 }
730 737
731 bool SystemTray::ShouldShowSystemBubbleAfterScrollSequence( 738 bool SystemTray::ShouldShowSystemBubbleAfterScrollSequence(
732 const ui::GestureEvent& sequence_end) { 739 const ui::GestureEvent& sequence_end) {
733 // If the scroll sequence terminates with a fling, show the system menu if the 740 // If the scroll sequence terminates with a fling, show the system menu if the
734 // fling was fast enough and in the correct direction. 741 // fling was fast enough and in the correct direction.
735 if (sequence_end.type() == ui::ET_SCROLL_FLING_START && 742 if (sequence_end.type() == ui::ET_SCROLL_FLING_START &&
736 fabs(sequence_end.details().velocity_y()) > kFlingVelocity) { 743 fabs(sequence_end.details().velocity_y()) > kFlingVelocity) {
737 return sequence_end.details().velocity_y() < 0; 744 return sequence_end.details().velocity_y() < 0;
738 } 745 }
739 746
740 DCHECK(sequence_end.type() == ui::ET_GESTURE_SCROLL_END || 747 DCHECK(sequence_end.type() == ui::ET_GESTURE_SCROLL_END ||
741 sequence_end.type() == ui::ET_SCROLL_FLING_START); 748 sequence_end.type() == ui::ET_SCROLL_FLING_START);
742 // Show the system menu if it is already at least one-third visible. 749
750 // Keep the bubble's original state if the |gesture_drag_amount_| doesn't
751 // exceed one-third of the bubble's height.
752 if (is_on_bubble_)
753 return gesture_drag_amount_ < system_tray_bubble_bounds_.height() / 3.0;
743 return -gesture_drag_amount_ >= system_tray_bubble_bounds_.height() / 3.0; 754 return -gesture_drag_amount_ >= system_tray_bubble_bounds_.height() / 3.0;
744 } 755 }
745 756
746 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { 757 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() {
747 activation_observer_.reset(); 758 activation_observer_.reset();
748 system_bubble_.reset(); 759 system_bubble_.reset();
749 // When closing a system bubble with the alternate shelf layout, we need to 760 // When closing a system bubble with the alternate shelf layout, we need to
750 // turn off the active tinting of the shelf. 761 // turn off the active tinting of the shelf.
751 if (full_system_tray_menu_) { 762 if (full_system_tray_menu_) {
752 SetIsActive(false); 763 SetIsActive(false);
(...skipping 22 matching lines...) Expand all
775 .work_area() 786 .work_area()
776 .height(); 787 .height();
777 if (work_area_height > 0) { 788 if (work_area_height > 0) {
778 UMA_HISTOGRAM_CUSTOM_COUNTS( 789 UMA_HISTOGRAM_CUSTOM_COUNTS(
779 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", 790 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu",
780 100 * bubble_view->height() / work_area_height, 1, 300, 100); 791 100 * bubble_view->height() / work_area_height, 1, 300, 100);
781 } 792 }
782 } 793 }
783 794
784 } // namespace ash 795 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698