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 "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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 #include "ash/system/tray/tray_bubble_wrapper.h" | 46 #include "ash/system/tray/tray_bubble_wrapper.h" |
47 #include "ash/system/tray/tray_constants.h" | 47 #include "ash/system/tray/tray_constants.h" |
48 #include "ash/system/tray/tray_container.h" | 48 #include "ash/system/tray/tray_container.h" |
49 #include "ash/system/tray_accessibility.h" | 49 #include "ash/system/tray_accessibility.h" |
50 #include "ash/system/tray_caps_lock.h" | 50 #include "ash/system/tray_caps_lock.h" |
51 #include "ash/system/tray_tracing.h" | 51 #include "ash/system/tray_tracing.h" |
52 #include "ash/system/update/tray_update.h" | 52 #include "ash/system/update/tray_update.h" |
53 #include "ash/system/user/tray_user.h" | 53 #include "ash/system/user/tray_user.h" |
54 #include "ash/system/web_notification/web_notification_tray.h" | 54 #include "ash/system/web_notification/web_notification_tray.h" |
55 #include "ash/wm/container_finder.h" | 55 #include "ash/wm/container_finder.h" |
56 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 56 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
msw
2017/07/12 05:04:51
nit: remove if no longer needed
minch1
2017/07/13 19:10:35
Done.
| |
57 #include "ash/wm/widget_finder.h" | 57 #include "ash/wm/widget_finder.h" |
58 #include "base/logging.h" | 58 #include "base/logging.h" |
59 #include "base/memory/ptr_util.h" | 59 #include "base/memory/ptr_util.h" |
60 #include "base/metrics/histogram_macros.h" | 60 #include "base/metrics/histogram_macros.h" |
61 #include "base/timer/timer.h" | 61 #include "base/timer/timer.h" |
62 #include "ui/base/accelerators/accelerator.h" | 62 #include "ui/base/accelerators/accelerator.h" |
63 #include "ui/base/l10n/l10n_util.h" | 63 #include "ui/base/l10n/l10n_util.h" |
64 #include "ui/compositor/layer.h" | 64 #include "ui/compositor/layer.h" |
65 #include "ui/display/display.h" | 65 #include "ui/display/display.h" |
66 #include "ui/display/screen.h" | 66 #include "ui/display/screen.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 } | 192 } |
193 | 193 |
194 private: | 194 private: |
195 SystemTray* tray_; | 195 SystemTray* tray_; |
196 | 196 |
197 DISALLOW_COPY_AND_ASSIGN(ActivationObserver); | 197 DISALLOW_COPY_AND_ASSIGN(ActivationObserver); |
198 }; | 198 }; |
199 | 199 |
200 // SystemTray | 200 // SystemTray |
201 | 201 |
202 SystemTray::SystemTray(Shelf* shelf) | 202 SystemTray::SystemTray(Shelf* shelf) : TrayBackgroundView(shelf) { |
203 : TrayBackgroundView(shelf), shelf_(shelf) { | |
204 SetInkDropMode(InkDropMode::ON); | 203 SetInkDropMode(InkDropMode::ON); |
205 | 204 |
206 // Since user avatar is on the right hand side of System tray of a | 205 // Since user avatar is on the right hand side of System tray of a |
207 // horizontal shelf and that is sufficient to indicate separation, no | 206 // horizontal shelf and that is sufficient to indicate separation, no |
208 // separator is required. | 207 // separator is required. |
209 set_separator_visibility(false); | 208 set_separator_visibility(false); |
210 } | 209 } |
211 | 210 |
212 SystemTray::~SystemTray() { | 211 SystemTray::~SystemTray() { |
213 // Destroy any child views that might have back pointers before ~View(). | 212 // Destroy any child views that might have back pointers before ~View(). |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 shelf()->UpdateAutoHideState(); | 551 shelf()->UpdateAutoHideState(); |
553 } | 552 } |
554 } | 553 } |
555 | 554 |
556 void SystemTray::ClickedOutsideBubble() { | 555 void SystemTray::ClickedOutsideBubble() { |
557 if (!system_bubble_ || system_bubble_->is_persistent()) | 556 if (!system_bubble_ || system_bubble_->is_persistent()) |
558 return; | 557 return; |
559 HideBubbleWithView(system_bubble_->bubble_view()); | 558 HideBubbleWithView(system_bubble_->bubble_view()); |
560 } | 559 } |
561 | 560 |
561 bool SystemTray::PerformAction(const ui::Event& event) { | |
562 // If we're already showing a full system tray menu, either default or | |
563 // detailed menu, hide it; otherwise, show it (and hide any popup that's | |
564 // currently shown). | |
565 if (HasSystemBubble() && full_system_tray_menu_) { | |
566 system_bubble_->bubble()->Close(); | |
567 } else { | |
568 ShowDefaultView(BUBBLE_CREATE_NEW); | |
569 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) | |
570 ActivateBubble(); | |
571 } | |
572 return true; | |
573 } | |
574 | |
575 bool SystemTray::HasBubble() { | |
576 return HasSystemBubble() && full_system_tray_menu_; | |
577 } | |
578 | |
579 void SystemTray::CloseBubble() { | |
580 CloseSystemBubble(); | |
581 } | |
582 | |
583 void SystemTray::ShowBubble() { | |
584 ShowDefaultView(BUBBLE_CREATE_NEW); | |
585 } | |
586 | |
587 views::TrayBubbleView* SystemTray::GetBubbleView() { | |
588 if (system_bubble_) | |
589 return system_bubble_->bubble_view(); | |
590 return nullptr; | |
591 } | |
592 | |
562 void SystemTray::BubbleViewDestroyed() { | 593 void SystemTray::BubbleViewDestroyed() { |
563 if (system_bubble_) { | 594 if (system_bubble_) { |
564 system_bubble_->bubble()->DestroyItemViews(); | 595 system_bubble_->bubble()->DestroyItemViews(); |
565 system_bubble_->bubble()->BubbleViewDestroyed(); | 596 system_bubble_->bubble()->BubbleViewDestroyed(); |
566 } | 597 } |
567 } | 598 } |
568 | 599 |
569 void SystemTray::OnMouseEnteredView() { | 600 void SystemTray::OnMouseEnteredView() { |
570 if (system_bubble_) | 601 if (system_bubble_) |
571 system_bubble_->bubble()->StopAutoCloseTimer(); | 602 system_bubble_->bubble()->StopAutoCloseTimer(); |
(...skipping 25 matching lines...) Expand all Loading... | |
597 // e.g. volume slider. Persistent system bubble is a bubble which is not | 628 // e.g. volume slider. Persistent system bubble is a bubble which is not |
598 // closed even if user clicks outside of the bubble. | 629 // closed even if user clicks outside of the bubble. |
599 return system_bubble_ && !system_bubble_->is_persistent() && | 630 return system_bubble_ && !system_bubble_->is_persistent() && |
600 Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled(); | 631 Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled(); |
601 } | 632 } |
602 | 633 |
603 void SystemTray::HideBubble(const TrayBubbleView* bubble_view) { | 634 void SystemTray::HideBubble(const TrayBubbleView* bubble_view) { |
604 HideBubbleWithView(bubble_view); | 635 HideBubbleWithView(bubble_view); |
605 } | 636 } |
606 | 637 |
638 bool SystemTray::ProcessGestureEventForBubble(ui::GestureEvent* event) { | |
msw
2017/07/12 05:04:51
It would be nice if we didn't need to have so many
minch1
2017/07/13 19:10:35
For the latter option, since TrayBubbleView::Deleg
msw
2017/07/14 02:00:45
Thanks for thinking about this, the code will be b
minch1
2017/07/14 19:45:17
I think TrayBakgroundView is already an abstract c
msw
2017/07/14 21:00:30
Using |this| in a TrayBackgroundView::ProcessGestu
minch1
2017/07/15 02:46:29
Done.
| |
639 return drag_controller()->ProcessGestureEvent(*event, this, | |
640 true /* is_on_bubble */); | |
641 } | |
642 | |
643 void SystemTray::OnGestureEvent(ui::GestureEvent* event) { | |
644 if (drag_controller()->ProcessGestureEvent(*event, this, | |
645 false /* is_on_bubble */)) { | |
646 event->SetHandled(); | |
647 } else { | |
648 TrayBackgroundView::OnGestureEvent(event); | |
649 } | |
650 } | |
651 | |
607 void SystemTray::CloseBubble(const ui::KeyEvent& key_event) { | 652 void SystemTray::CloseBubble(const ui::KeyEvent& key_event) { |
608 CloseSystemBubble(); | 653 CloseSystemBubble(); |
609 } | 654 } |
610 | 655 |
611 void SystemTray::ActivateAndStartNavigation(const ui::KeyEvent& key_event) { | 656 void SystemTray::ActivateAndStartNavigation(const ui::KeyEvent& key_event) { |
612 if (!system_bubble_) | 657 if (!system_bubble_) |
613 return; | 658 return; |
614 ActivateBubble(); | 659 ActivateBubble(); |
615 | 660 |
616 views::Widget* widget = GetSystemBubble()->bubble_view()->GetWidget(); | 661 views::Widget* widget = GetSystemBubble()->bubble_view()->GetWidget(); |
617 widget->GetFocusManager()->OnKeyEvent(key_event); | 662 widget->GetFocusManager()->OnKeyEvent(key_event); |
618 } | 663 } |
619 | 664 |
620 void SystemTray::ActivateBubble() { | 665 void SystemTray::ActivateBubble() { |
621 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); | 666 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); |
622 // If system tray bubble is in the process of closing, do not try to activate | 667 // If system tray bubble is in the process of closing, do not try to activate |
623 // bubble. | 668 // bubble. |
624 if (bubble_view->GetWidget()->IsClosed()) | 669 if (bubble_view->GetWidget()->IsClosed()) |
625 return; | 670 return; |
626 bubble_view->set_can_activate(true); | 671 bubble_view->set_can_activate(true); |
627 bubble_view->GetWidget()->Activate(); | 672 bubble_view->GetWidget()->Activate(); |
628 } | 673 } |
629 | 674 |
630 void SystemTray::OnGestureEvent(ui::GestureEvent* event) { | |
631 if (Shell::Get() | |
632 ->maximize_mode_controller() | |
633 ->IsMaximizeModeWindowManagerEnabled() && | |
634 shelf_->IsHorizontalAlignment() && ProcessGestureEvent(*event)) { | |
635 event->SetHandled(); | |
636 } else { | |
637 TrayBackgroundView::OnGestureEvent(event); | |
638 } | |
639 } | |
640 | |
641 gfx::Rect SystemTray::GetWorkAreaBoundsInScreen() const { | |
642 return shelf_->GetUserWorkAreaBounds(); | |
643 } | |
644 | |
645 bool SystemTray::PerformAction(const ui::Event& event) { | |
646 // If we're already showing a full system tray menu, either default or | |
647 // detailed menu, hide it; otherwise, show it (and hide any popup that's | |
648 // currently shown). | |
649 if (HasSystemBubble() && full_system_tray_menu_) { | |
650 system_bubble_->bubble()->Close(); | |
651 } else { | |
652 ShowDefaultView(BUBBLE_CREATE_NEW); | |
653 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) | |
654 ActivateBubble(); | |
655 } | |
656 return true; | |
657 } | |
658 | |
659 bool SystemTray::ProcessGestureEvent(const ui::GestureEvent& event) { | |
660 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) | |
661 return StartGestureDrag(event); | |
662 | |
663 if (!HasSystemBubble() || !is_in_drag_) | |
664 return false; | |
665 | |
666 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) { | |
667 UpdateGestureDrag(event); | |
668 return true; | |
669 } | |
670 | |
671 if (event.type() == ui::ET_GESTURE_SCROLL_END || | |
672 event.type() == ui::ET_SCROLL_FLING_START) { | |
673 CompleteGestureDrag(event); | |
674 return true; | |
675 } | |
676 | |
677 // Unexpected event. Reset the drag state and close the bubble. | |
678 is_in_drag_ = false; | |
679 CloseSystemBubble(); | |
680 return false; | |
681 } | |
682 | |
683 bool SystemTray::StartGestureDrag(const ui::GestureEvent& gesture) { | |
684 // Close the system bubble if there is already a full one opened. And return | |
685 // false to let shelf handle the event. | |
686 if (HasSystemBubble() && full_system_tray_menu_) { | |
687 system_bubble_->bubble()->Close(); | |
688 return false; | |
689 } | |
690 | |
691 // If the scroll sequence begins to scroll downward, return false so that the | |
692 // event will instead by handled by the shelf. | |
693 if (gesture.details().scroll_y_hint() > 0) | |
694 return false; | |
695 | |
696 is_in_drag_ = true; | |
697 gesture_drag_amount_ = 0.f; | |
698 ShowDefaultView(BUBBLE_CREATE_NEW); | |
699 system_tray_bubble_bounds_ = | |
700 system_bubble_->bubble_view()->GetWidget()->GetWindowBoundsInScreen(); | |
701 SetBubbleBounds(gesture.location()); | |
702 return true; | |
703 } | |
704 | |
705 void SystemTray::UpdateGestureDrag(const ui::GestureEvent& gesture) { | |
706 SetBubbleBounds(gesture.location()); | |
707 gesture_drag_amount_ += gesture.details().scroll_y(); | |
708 } | |
709 | |
710 void SystemTray::CompleteGestureDrag(const ui::GestureEvent& gesture) { | |
711 const bool hide_bubble = !ShouldShowSystemBubbleAfterScrollSequence(gesture); | |
712 gfx::Rect target_bounds = system_tray_bubble_bounds_; | |
713 | |
714 if (hide_bubble) | |
715 target_bounds.set_y(shelf_->GetIdealBounds().y()); | |
716 | |
717 system_bubble_->bubble()->AnimateToTargetBounds(target_bounds, hide_bubble); | |
718 is_in_drag_ = false; | |
719 } | |
720 | |
721 void SystemTray::SetBubbleBounds(const gfx::Point& location) { | |
722 gfx::Point location_in_screen_coordinates(location); | |
723 View::ConvertPointToScreen(this, &location_in_screen_coordinates); | |
724 | |
725 // System tray bubble should not be dragged higher than its original height. | |
726 if (location_in_screen_coordinates.y() < system_tray_bubble_bounds_.y()) | |
727 location_in_screen_coordinates.set_y(system_tray_bubble_bounds_.y()); | |
728 | |
729 gfx::Rect bounds_on_location = system_tray_bubble_bounds_; | |
730 bounds_on_location.set_y(location_in_screen_coordinates.y()); | |
731 system_bubble_->bubble_view()->GetWidget()->SetBounds(bounds_on_location); | |
732 } | |
733 | |
734 bool SystemTray::ShouldShowSystemBubbleAfterScrollSequence( | |
735 const ui::GestureEvent& sequence_end) { | |
736 // If the scroll sequence terminates with a fling, show the system menu if the | |
737 // fling was fast enough and in the correct direction. | |
738 if (sequence_end.type() == ui::ET_SCROLL_FLING_START && | |
739 fabs(sequence_end.details().velocity_y()) > kFlingVelocity) { | |
740 return sequence_end.details().velocity_y() < 0; | |
741 } | |
742 | |
743 DCHECK(sequence_end.type() == ui::ET_GESTURE_SCROLL_END || | |
744 sequence_end.type() == ui::ET_SCROLL_FLING_START); | |
745 // Show the system menu if it is already at least one-third visible. | |
746 return -gesture_drag_amount_ >= system_tray_bubble_bounds_.height() / 3.0; | |
747 } | |
748 | |
749 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { | 675 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { |
750 activation_observer_.reset(); | 676 activation_observer_.reset(); |
751 system_bubble_.reset(); | 677 system_bubble_.reset(); |
752 // When closing a system bubble with the alternate shelf layout, we need to | 678 // When closing a system bubble with the alternate shelf layout, we need to |
753 // turn off the active tinting of the shelf. | 679 // turn off the active tinting of the shelf. |
754 if (full_system_tray_menu_) { | 680 if (full_system_tray_menu_) { |
755 SetIsActive(false); | 681 SetIsActive(false); |
756 full_system_tray_menu_ = false; | 682 full_system_tray_menu_ = false; |
757 } | 683 } |
758 } | 684 } |
(...skipping 19 matching lines...) Expand all Loading... | |
778 .work_area() | 704 .work_area() |
779 .height(); | 705 .height(); |
780 if (work_area_height > 0) { | 706 if (work_area_height > 0) { |
781 UMA_HISTOGRAM_CUSTOM_COUNTS( | 707 UMA_HISTOGRAM_CUSTOM_COUNTS( |
782 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", | 708 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", |
783 100 * bubble_view->height() / work_area_height, 1, 300, 100); | 709 100 * bubble_view->height() / work_area_height, 1, 300, 100); |
784 } | 710 } |
785 } | 711 } |
786 | 712 |
787 } // namespace ash | 713 } // namespace ash |
OLD | NEW |