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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 #include "ui/views/view.h" | 71 #include "ui/views/view.h" |
72 #include "ui/views/widget/widget.h" | 72 #include "ui/views/widget/widget.h" |
73 #include "ui/wm/core/window_util.h" | 73 #include "ui/wm/core/window_util.h" |
74 #include "ui/wm/public/activation_change_observer.h" | 74 #include "ui/wm/public/activation_change_observer.h" |
75 #include "ui/wm/public/activation_client.h" | 75 #include "ui/wm/public/activation_client.h" |
76 | 76 |
77 using views::TrayBubbleView; | 77 using views::TrayBubbleView; |
78 | 78 |
79 namespace ash { | 79 namespace ash { |
80 | 80 |
| 81 // The velocity of the swiping on the system bubble. |
| 82 constexpr float kSwipingVelocity = 100.0; |
| 83 |
81 namespace { | 84 namespace { |
82 | 85 |
83 // A tray item that just reserves space in the tray. | 86 // A tray item that just reserves space in the tray. |
84 class PaddingTrayItem : public SystemTrayItem { | 87 class PaddingTrayItem : public SystemTrayItem { |
85 public: | 88 public: |
86 PaddingTrayItem() : SystemTrayItem(nullptr, UMA_NOT_RECORDED) {} | 89 PaddingTrayItem() : SystemTrayItem(nullptr, UMA_NOT_RECORDED) {} |
87 ~PaddingTrayItem() override {} | 90 ~PaddingTrayItem() override {} |
88 | 91 |
89 // SystemTrayItem: | 92 // SystemTrayItem: |
90 views::View* CreateTrayView(LoginStatus status) override { | 93 views::View* CreateTrayView(LoginStatus status) override { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 167 |
165 // WmActivationObserver: | 168 // WmActivationObserver: |
166 void OnWindowActivated(ActivationReason reason, | 169 void OnWindowActivated(ActivationReason reason, |
167 aura::Window* gained_active, | 170 aura::Window* gained_active, |
168 aura::Window* lost_active) override { | 171 aura::Window* lost_active) override { |
169 if (!tray_->HasSystemBubble() || !gained_active) | 172 if (!tray_->HasSystemBubble() || !gained_active) |
170 return; | 173 return; |
171 | 174 |
172 int container_id = wm::GetContainerForWindow(gained_active)->id(); | 175 int container_id = wm::GetContainerForWindow(gained_active)->id(); |
173 | 176 |
174 // Don't close the bubble if a popup notification is activated. | 177 // Don't close the bubble if a popup notification is activated and don't |
175 if (container_id == kShellWindowId_StatusContainer) | 178 // close the the bubble if click the items in the default system tray bubble |
| 179 // on maximize mode. |
| 180 if (container_id == kShellWindowId_StatusContainer || |
| 181 container_id == kShellWindowId_SettingBubbleContainer) |
176 return; | 182 return; |
177 | 183 |
178 views::Widget* bubble_widget = | 184 views::Widget* bubble_widget = |
179 tray_->GetSystemBubble()->bubble_view()->GetWidget(); | 185 tray_->GetSystemBubble()->bubble_view()->GetWidget(); |
180 // Don't close the bubble if a transient child is gaining or losing | 186 // Don't close the bubble if a transient child is gaining or losing |
181 // activation. | 187 // activation. |
182 if (bubble_widget == GetInternalWidgetForWindow(gained_active) || | 188 if (bubble_widget == GetInternalWidgetForWindow(gained_active) || |
183 ::wm::HasTransientAncestor(gained_active, | 189 ::wm::HasTransientAncestor(gained_active, |
184 bubble_widget->GetNativeWindow()) || | 190 bubble_widget->GetNativeWindow()) || |
185 (lost_active && ::wm::HasTransientAncestor( | 191 (lost_active && ::wm::HasTransientAncestor( |
186 lost_active, bubble_widget->GetNativeWindow()))) { | 192 lost_active, bubble_widget->GetNativeWindow()))) { |
187 return; | 193 return; |
188 } | 194 } |
189 | 195 |
190 tray_->CloseSystemBubble(); | 196 tray_->CloseSystemBubble(); |
191 } | 197 } |
192 | 198 |
193 private: | 199 private: |
194 SystemTray* tray_; | 200 SystemTray* tray_; |
195 | 201 |
196 DISALLOW_COPY_AND_ASSIGN(ActivationObserver); | 202 DISALLOW_COPY_AND_ASSIGN(ActivationObserver); |
197 }; | 203 }; |
198 | 204 |
199 // SystemTray | 205 // SystemTray |
200 | 206 |
201 SystemTray::SystemTray(Shelf* shelf) : TrayBackgroundView(shelf) { | 207 SystemTray::SystemTray(Shelf* shelf) |
| 208 : TrayBackgroundView(shelf), shelf_(shelf) { |
202 SetInkDropMode(InkDropMode::ON); | 209 SetInkDropMode(InkDropMode::ON); |
203 | 210 |
204 // Since user avatar is on the right hand side of System tray of a | 211 // Since user avatar is on the right hand side of System tray of a |
205 // horizontal shelf and that is sufficient to indicate separation, no | 212 // horizontal shelf and that is sufficient to indicate separation, no |
206 // separator is required. | 213 // separator is required. |
207 set_separator_visibility(false); | 214 set_separator_visibility(false); |
| 215 |
| 216 Shell::Get()->AddShellObserver(this); |
208 } | 217 } |
209 | 218 |
210 SystemTray::~SystemTray() { | 219 SystemTray::~SystemTray() { |
211 // Destroy any child views that might have back pointers before ~View(). | 220 // Destroy any child views that might have back pointers before ~View(). |
212 activation_observer_.reset(); | 221 activation_observer_.reset(); |
213 key_event_watcher_.reset(); | 222 key_event_watcher_.reset(); |
214 system_bubble_.reset(); | 223 system_bubble_.reset(); |
215 for (const auto& item : items_) | 224 for (const auto& item : items_) |
216 item->OnTrayViewDestroyed(); | 225 item->OnTrayViewDestroyed(); |
| 226 Shell::Get()->RemoveShellObserver(this); |
217 } | 227 } |
218 | 228 |
219 void SystemTray::InitializeTrayItems( | 229 void SystemTray::InitializeTrayItems( |
220 SystemTrayDelegate* delegate, | 230 SystemTrayDelegate* delegate, |
221 WebNotificationTray* web_notification_tray) { | 231 WebNotificationTray* web_notification_tray) { |
222 DCHECK(web_notification_tray); | 232 DCHECK(web_notification_tray); |
223 web_notification_tray_ = web_notification_tray; | 233 web_notification_tray_ = web_notification_tray; |
224 TrayBackgroundView::Initialize(); | 234 TrayBackgroundView::Initialize(); |
225 CreateItems(delegate); | 235 CreateItems(delegate); |
226 } | 236 } |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 } | 592 } |
583 | 593 |
584 base::string16 SystemTray::GetAccessibleNameForBubble() { | 594 base::string16 SystemTray::GetAccessibleNameForBubble() { |
585 return GetAccessibleNameForTray(); | 595 return GetAccessibleNameForTray(); |
586 } | 596 } |
587 | 597 |
588 void SystemTray::HideBubble(const TrayBubbleView* bubble_view) { | 598 void SystemTray::HideBubble(const TrayBubbleView* bubble_view) { |
589 HideBubbleWithView(bubble_view); | 599 HideBubbleWithView(bubble_view); |
590 } | 600 } |
591 | 601 |
| 602 void SystemTray::OnMaximizeModeStarted() { |
| 603 on_maximize_mode_ = true; |
| 604 } |
| 605 |
| 606 void SystemTray::OnMaximizeModeEnded() { |
| 607 on_maximize_mode_ = false; |
| 608 } |
| 609 |
592 void SystemTray::CloseBubble(const ui::KeyEvent& key_event) { | 610 void SystemTray::CloseBubble(const ui::KeyEvent& key_event) { |
593 CloseSystemBubble(); | 611 CloseSystemBubble(); |
594 } | 612 } |
595 | 613 |
596 void SystemTray::ActivateAndStartNavigation(const ui::KeyEvent& key_event) { | 614 void SystemTray::ActivateAndStartNavigation(const ui::KeyEvent& key_event) { |
597 if (!system_bubble_) | 615 if (!system_bubble_) |
598 return; | 616 return; |
599 ActivateBubble(); | 617 ActivateBubble(); |
600 | 618 |
601 views::Widget* widget = GetSystemBubble()->bubble_view()->GetWidget(); | 619 views::Widget* widget = GetSystemBubble()->bubble_view()->GetWidget(); |
(...skipping 21 matching lines...) Expand all Loading... |
623 void SystemTray::ActivateBubble() { | 641 void SystemTray::ActivateBubble() { |
624 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); | 642 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); |
625 // If system tray bubble is in the process of closing, do not try to activate | 643 // If system tray bubble is in the process of closing, do not try to activate |
626 // bubble. | 644 // bubble. |
627 if (bubble_view->GetWidget()->IsClosed()) | 645 if (bubble_view->GetWidget()->IsClosed()) |
628 return; | 646 return; |
629 bubble_view->set_can_activate(true); | 647 bubble_view->set_can_activate(true); |
630 bubble_view->GetWidget()->Activate(); | 648 bubble_view->GetWidget()->Activate(); |
631 } | 649 } |
632 | 650 |
| 651 gfx::Rect SystemTray::GetWorkAreaBoundsInScreen() const { |
| 652 return shelf_->GetUserWorkAreaBounds(); |
| 653 } |
| 654 |
633 bool SystemTray::PerformAction(const ui::Event& event) { | 655 bool SystemTray::PerformAction(const ui::Event& event) { |
634 // If we're already showing the default view or detailed view in system menu, | 656 // If we're already showing the default view or detailed view in system menu, |
635 // hide it; otherwise, show it (and hide any popup that's currently shown). | 657 // hide it; otherwise, show it (and hide any popup that's currently shown). |
636 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT) || | 658 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT) || |
637 (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DETAILED) && | 659 (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DETAILED) && |
638 full_system_tray_menu_)) { | 660 full_system_tray_menu_)) { |
639 system_bubble_->bubble()->Close(); | 661 system_bubble_->bubble()->Close(); |
640 } else { | 662 } else { |
641 ShowDefaultView(BUBBLE_CREATE_NEW); | 663 ShowDefaultView(BUBBLE_CREATE_NEW); |
642 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) | 664 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) |
643 ActivateBubble(); | 665 ActivateBubble(); |
644 } | 666 } |
645 return true; | 667 return true; |
646 } | 668 } |
647 | 669 |
| 670 void SystemTray::OnGestureEvent(ui::GestureEvent* event) { |
| 671 if (on_maximize_mode_ && shelf_->IsHorizontalAlignment() && |
| 672 ProcessGestureEvent(*event)) |
| 673 event->StopPropagation(); |
| 674 else |
| 675 CustomButton::OnGestureEvent(event); |
| 676 } |
| 677 |
| 678 bool SystemTray::ProcessGestureEvent(const ui::GestureEvent& event) { |
| 679 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) { |
| 680 return StartGestureDrag(event); |
| 681 } |
| 682 |
| 683 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) { |
| 684 UpdateGestureDrag(event); |
| 685 return true; |
| 686 } |
| 687 |
| 688 if (event.type() == ui::ET_GESTURE_SCROLL_END || |
| 689 event.type() == ui::ET_SCROLL_FLING_START) { |
| 690 CompleteGestureDrag(event); |
| 691 return true; |
| 692 } |
| 693 return false; |
| 694 } |
| 695 |
| 696 bool SystemTray::StartGestureDrag(const ui::GestureEvent& gesture) { |
| 697 if (full_system_tray_menu_ || IsSwipingDownOnShelf(gesture)) |
| 698 return false; |
| 699 |
| 700 gesture_drag_amount_ = 0.f; |
| 701 ShowDefaultView(BUBBLE_CREATE_NEW); |
| 702 system_tray_bubble_bounds_ = |
| 703 system_bubble_->bubble_view()->GetWidget()->GetWindowBoundsInScreen(); |
| 704 system_bubble_->bubble_view()->GetWidget()->Hide(); |
| 705 return true; |
| 706 } |
| 707 |
| 708 void SystemTray::UpdateGestureDrag(const ui::GestureEvent& gesture) { |
| 709 gfx::Point gesture_location = gesture.location(); |
| 710 View::ConvertPointToScreen(this, &gesture_location); |
| 711 |
| 712 // System tray bubble should not be dragged higher than its original height. |
| 713 if (gesture_location.y() < system_tray_bubble_bounds_.y()) |
| 714 gesture_location.set_y(system_tray_bubble_bounds_.y()); |
| 715 gfx::Rect bounds_on_gesture( |
| 716 system_tray_bubble_bounds_.x(), gesture_location.y(), |
| 717 system_tray_bubble_bounds_.width(), system_tray_bubble_bounds_.height()); |
| 718 system_bubble_->bubble_view()->GetWidget()->SetBounds(bounds_on_gesture); |
| 719 system_bubble_->bubble_view()->GetWidget()->Show(); |
| 720 |
| 721 gesture_drag_amount_ += gesture.details().scroll_y(); |
| 722 final_scroll_y_ = gesture.details().scroll_y(); |
| 723 } |
| 724 |
| 725 void SystemTray::CompleteGestureDrag(const ui::GestureEvent& gesture) { |
| 726 if (gesture.details().scroll_y()) |
| 727 final_scroll_y_ = gesture.details().scroll_y(); |
| 728 if (ShouldShowSystemBubbleForSwiping(gesture)) |
| 729 system_bubble_->bubble_view()->GetWidget()->SetBounds( |
| 730 system_tray_bubble_bounds_); |
| 731 else |
| 732 system_bubble_->bubble()->Close(); |
| 733 } |
| 734 |
| 735 bool SystemTray::IsSwipingDownOnShelf(const ui::GestureEvent& gesture) { |
| 736 gfx::Point gesture_location = gesture.location(); |
| 737 View::ConvertPointToScreen(this, &gesture_location); |
| 738 |
| 739 if (gesture_location.y() >= shelf_->GetIdealBounds().y() && |
| 740 gesture.details().scroll_y() > 0) { |
| 741 return true; |
| 742 } |
| 743 return false; |
| 744 } |
| 745 |
| 746 bool SystemTray::ShouldShowSystemBubbleBasedOnPosition() { |
| 747 int system_bubble_height = system_tray_bubble_bounds_.height(); |
| 748 float one_third = system_bubble_height / 3.0; |
| 749 |
| 750 if (gesture_drag_amount_ > 0) |
| 751 return false; |
| 752 |
| 753 if (fabs(gesture_drag_amount_) < one_third) |
| 754 return false; |
| 755 else if (fabs(gesture_drag_amount_) > 2 * one_third) |
| 756 return true; |
| 757 else |
| 758 return final_scroll_y_ < 0; |
| 759 } |
| 760 |
| 761 bool SystemTray::ShouldShowSystemBubbleForSwiping( |
| 762 const ui::GestureEvent& gesture) { |
| 763 if (gesture.type() == ui::ET_GESTURE_SCROLL_END) { |
| 764 return ShouldShowSystemBubbleBasedOnPosition(); |
| 765 } else { |
| 766 if (fabs(gesture.details().velocity_y()) > kSwipingVelocity) |
| 767 return gesture.details().velocity_y() < 0; |
| 768 return ShouldShowSystemBubbleBasedOnPosition(); |
| 769 } |
| 770 } |
| 771 |
648 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { | 772 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { |
649 activation_observer_.reset(); | 773 activation_observer_.reset(); |
650 key_event_watcher_.reset(); | 774 key_event_watcher_.reset(); |
651 system_bubble_.reset(); | 775 system_bubble_.reset(); |
652 // When closing a system bubble with the alternate shelf layout, we need to | 776 // When closing a system bubble with the alternate shelf layout, we need to |
653 // turn off the active tinting of the shelf. | 777 // turn off the active tinting of the shelf. |
654 if (full_system_tray_menu_) { | 778 if (full_system_tray_menu_) { |
655 SetIsActive(false); | 779 SetIsActive(false); |
656 full_system_tray_menu_ = false; | 780 full_system_tray_menu_ = false; |
657 } | 781 } |
(...skipping 20 matching lines...) Expand all Loading... |
678 .work_area() | 802 .work_area() |
679 .height(); | 803 .height(); |
680 if (work_area_height > 0) { | 804 if (work_area_height > 0) { |
681 UMA_HISTOGRAM_CUSTOM_COUNTS( | 805 UMA_HISTOGRAM_CUSTOM_COUNTS( |
682 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", | 806 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", |
683 100 * bubble_view->height() / work_area_height, 1, 300, 100); | 807 100 * bubble_view->height() / work_area_height, 1, 300, 100); |
684 } | 808 } |
685 } | 809 } |
686 | 810 |
687 } // namespace ash | 811 } // namespace ash |
OLD | NEW |