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

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

Issue 2961313003: Touch gestures for System Tray/ IME/ Stylus/ Notifications (Closed)
Patch Set: Create SystemTrayBubbleView instead of Delegate. 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 private: 193 private:
194 SystemTray* tray_; 194 SystemTray* tray_;
195 195
196 DISALLOW_COPY_AND_ASSIGN(ActivationObserver); 196 DISALLOW_COPY_AND_ASSIGN(ActivationObserver);
197 }; 197 };
198 198
199 // SystemTray 199 // SystemTray
200 200
201 SystemTray::SystemTray(Shelf* shelf) 201 SystemTray::SystemTray(Shelf* shelf)
202 : TrayBackgroundView(shelf), shelf_(shelf) { 202 : TrayBackgroundView(shelf), shelf_(shelf) {
203 target_view_ = this;
204
203 SetInkDropMode(InkDropMode::ON); 205 SetInkDropMode(InkDropMode::ON);
204 206
205 // Since user avatar is on the right hand side of System tray of a 207 // Since user avatar is on the right hand side of System tray of a
206 // horizontal shelf and that is sufficient to indicate separation, no 208 // horizontal shelf and that is sufficient to indicate separation, no
207 // separator is required. 209 // separator is required.
208 set_separator_visibility(false); 210 set_separator_visibility(false);
209 } 211 }
210 212
211 SystemTray::~SystemTray() { 213 SystemTray::~SystemTray() {
212 // Destroy any child views that might have back pointers before ~View(). 214 // Destroy any child views that might have back pointers before ~View().
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); 620 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view();
619 // If system tray bubble is in the process of closing, do not try to activate 621 // If system tray bubble is in the process of closing, do not try to activate
620 // bubble. 622 // bubble.
621 if (bubble_view->GetWidget()->IsClosed()) 623 if (bubble_view->GetWidget()->IsClosed())
622 return; 624 return;
623 bubble_view->set_can_activate(true); 625 bubble_view->set_can_activate(true);
624 bubble_view->GetWidget()->Activate(); 626 bubble_view->GetWidget()->Activate();
625 } 627 }
626 628
627 void SystemTray::OnGestureEvent(ui::GestureEvent* event) { 629 void SystemTray::OnGestureEvent(ui::GestureEvent* event) {
628 if (Shell::Get() 630 target_view_ = this;
xdai1 2017/06/30 17:46:54 What if you press and drag on a bubble view and th
minch1 2017/06/30 19:08:04 Add |is_on_bubble_| instead, please check.
629 ->maximize_mode_controller() 631 if (ProcessGestureEvent(*event))
630 ->IsMaximizeModeWindowManagerEnabled() &&
631 shelf_->IsHorizontalAlignment() && ProcessGestureEvent(*event)) {
632 event->SetHandled(); 632 event->SetHandled();
633 } else { 633 else
634 TrayBackgroundView::OnGestureEvent(event); 634 TrayBackgroundView::OnGestureEvent(event);
635 }
636 } 635 }
637 636
638 gfx::Rect SystemTray::GetWorkAreaBoundsInScreen() const { 637 gfx::Rect SystemTray::GetWorkAreaBoundsInScreen() const {
639 return shelf_->GetUserWorkAreaBounds(); 638 return shelf_->GetUserWorkAreaBounds();
640 } 639 }
641 640
642 bool SystemTray::PerformAction(const ui::Event& event) { 641 bool SystemTray::PerformAction(const ui::Event& event) {
643 // If we're already showing a full system tray menu, either default or 642 // 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 643 // detailed menu, hide it; otherwise, show it (and hide any popup that's
645 // currently shown). 644 // currently shown).
646 if (HasSystemBubble() && full_system_tray_menu_) { 645 if (HasSystemBubble() && full_system_tray_menu_) {
647 system_bubble_->bubble()->Close(); 646 system_bubble_->bubble()->Close();
648 } else { 647 } else {
649 ShowDefaultView(BUBBLE_CREATE_NEW); 648 ShowDefaultView(BUBBLE_CREATE_NEW);
650 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) 649 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY))
651 ActivateBubble(); 650 ActivateBubble();
652 } 651 }
653 return true; 652 return true;
654 } 653 }
655 654
656 bool SystemTray::ProcessGestureEvent(const ui::GestureEvent& event) { 655 bool SystemTray::ProcessGestureEvent(const ui::GestureEvent& event) {
656 if (!Shell::Get()
657 ->maximize_mode_controller()
658 ->IsMaximizeModeWindowManagerEnabled() ||
659 !shelf_->IsHorizontalAlignment()) {
660 return false;
661 }
662
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 (target_view_ == this) {
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 SetBubbleBounds(gesture.location());
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 SetBubbleBounds(gesture.location());
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::SetBubbleBounds(const gfx::Point& location) {
xdai1 2017/06/30 17:46:54 From the function's name, it may be better to make
minch1 2017/06/30 19:08:04 Sorry, I found after change the rule for SetBubble
719 gfx::Point location_in_screen_coordinates(location); 729 gfx::Point location_in_screen_coordinates(location);
720 View::ConvertPointToScreen(this, &location_in_screen_coordinates); 730 View::ConvertPointToScreen(target_view_, &location_in_screen_coordinates);
721
722 // System tray bubble should not be dragged higher than its original height.
723 if (location_in_screen_coordinates.y() < system_tray_bubble_bounds_.y())
724 location_in_screen_coordinates.set_y(system_tray_bubble_bounds_.y());
725 731
726 gfx::Rect bounds_on_location = system_tray_bubble_bounds_; 732 gfx::Rect bounds_on_location = system_tray_bubble_bounds_;
727 bounds_on_location.set_y(location_in_screen_coordinates.y()); 733 // System tray bubble should not be dragged higher than its original height.
734 int bounds_y = (target_view_ == this ? shelf_->GetIdealBounds().y()
735 : system_tray_bubble_bounds_.y()) +
736 gesture_drag_amount_;
737 bounds_on_location.set_y(std::max(bounds_y, system_tray_bubble_bounds_.y()));
728 system_bubble_->bubble_view()->GetWidget()->SetBounds(bounds_on_location); 738 system_bubble_->bubble_view()->GetWidget()->SetBounds(bounds_on_location);
729 } 739 }
730 740
731 bool SystemTray::ShouldShowSystemBubbleAfterScrollSequence( 741 bool SystemTray::ShouldShowSystemBubbleAfterScrollSequence(
732 const ui::GestureEvent& sequence_end) { 742 const ui::GestureEvent& sequence_end) {
733 // If the scroll sequence terminates with a fling, show the system menu if the 743 // If the scroll sequence terminates with a fling, show the system menu if the
734 // fling was fast enough and in the correct direction. 744 // fling was fast enough and in the correct direction.
735 if (sequence_end.type() == ui::ET_SCROLL_FLING_START && 745 if (sequence_end.type() == ui::ET_SCROLL_FLING_START &&
736 fabs(sequence_end.details().velocity_y()) > kFlingVelocity) { 746 fabs(sequence_end.details().velocity_y()) > kFlingVelocity) {
737 return sequence_end.details().velocity_y() < 0; 747 return sequence_end.details().velocity_y() < 0;
738 } 748 }
739 749
740 DCHECK(sequence_end.type() == ui::ET_GESTURE_SCROLL_END || 750 DCHECK(sequence_end.type() == ui::ET_GESTURE_SCROLL_END ||
741 sequence_end.type() == ui::ET_SCROLL_FLING_START); 751 sequence_end.type() == ui::ET_SCROLL_FLING_START);
742 // Show the system menu if it is already at least one-third visible. 752
743 return -gesture_drag_amount_ >= system_tray_bubble_bounds_.height() / 3.0; 753 // Keep the bubble's original state if the |gesture_drag_amount_| doesn't
754 // exceed one-third of the bubble's height.
755 if (target_view_ == this)
756 return -gesture_drag_amount_ >= system_tray_bubble_bounds_.height() / 3.0;
757 return gesture_drag_amount_ < system_tray_bubble_bounds_.height() / 3.0;
744 } 758 }
745 759
746 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { 760 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() {
747 activation_observer_.reset(); 761 activation_observer_.reset();
748 system_bubble_.reset(); 762 system_bubble_.reset();
749 // When closing a system bubble with the alternate shelf layout, we need to 763 // When closing a system bubble with the alternate shelf layout, we need to
750 // turn off the active tinting of the shelf. 764 // turn off the active tinting of the shelf.
751 if (full_system_tray_menu_) { 765 if (full_system_tray_menu_) {
752 SetIsActive(false); 766 SetIsActive(false);
753 full_system_tray_menu_ = false; 767 full_system_tray_menu_ = false;
(...skipping 21 matching lines...) Expand all
775 .work_area() 789 .work_area()
776 .height(); 790 .height();
777 if (work_area_height > 0) { 791 if (work_area_height > 0) {
778 UMA_HISTOGRAM_CUSTOM_COUNTS( 792 UMA_HISTOGRAM_CUSTOM_COUNTS(
779 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", 793 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu",
780 100 * bubble_view->height() / work_area_height, 1, 300, 100); 794 100 * bubble_view->height() / work_area_height, 1, 300, 100);
781 } 795 }
782 } 796 }
783 797
784 } // namespace ash 798 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698