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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 #include "ash/system/tray/tray_bubble_wrapper.h" | 43 #include "ash/system/tray/tray_bubble_wrapper.h" |
44 #include "ash/system/tray/tray_constants.h" | 44 #include "ash/system/tray/tray_constants.h" |
45 #include "ash/system/tray/tray_container.h" | 45 #include "ash/system/tray/tray_container.h" |
46 #include "ash/system/tray_accessibility.h" | 46 #include "ash/system/tray_accessibility.h" |
47 #include "ash/system/tray_caps_lock.h" | 47 #include "ash/system/tray_caps_lock.h" |
48 #include "ash/system/tray_tracing.h" | 48 #include "ash/system/tray_tracing.h" |
49 #include "ash/system/update/tray_update.h" | 49 #include "ash/system/update/tray_update.h" |
50 #include "ash/system/user/tray_user.h" | 50 #include "ash/system/user/tray_user.h" |
51 #include "ash/system/web_notification/web_notification_tray.h" | 51 #include "ash/system/web_notification/web_notification_tray.h" |
52 #include "ash/wm/container_finder.h" | 52 #include "ash/wm/container_finder.h" |
53 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | |
53 #include "ash/wm/widget_finder.h" | 54 #include "ash/wm/widget_finder.h" |
54 #include "base/logging.h" | 55 #include "base/logging.h" |
55 #include "base/memory/ptr_util.h" | 56 #include "base/memory/ptr_util.h" |
56 #include "base/metrics/histogram_macros.h" | 57 #include "base/metrics/histogram_macros.h" |
57 #include "base/timer/timer.h" | 58 #include "base/timer/timer.h" |
58 #include "ui/base/accelerators/accelerator.h" | 59 #include "ui/base/accelerators/accelerator.h" |
59 #include "ui/base/l10n/l10n_util.h" | 60 #include "ui/base/l10n/l10n_util.h" |
60 #include "ui/compositor/layer.h" | 61 #include "ui/compositor/layer.h" |
61 #include "ui/display/display.h" | 62 #include "ui/display/display.h" |
62 #include "ui/display/screen.h" | 63 #include "ui/display/screen.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 // WmActivationObserver: | 166 // WmActivationObserver: |
166 void OnWindowActivated(ActivationReason reason, | 167 void OnWindowActivated(ActivationReason reason, |
167 aura::Window* gained_active, | 168 aura::Window* gained_active, |
168 aura::Window* lost_active) override { | 169 aura::Window* lost_active) override { |
169 if (!tray_->HasSystemBubble() || !gained_active) | 170 if (!tray_->HasSystemBubble() || !gained_active) |
170 return; | 171 return; |
171 | 172 |
172 int container_id = wm::GetContainerForWindow(gained_active)->id(); | 173 int container_id = wm::GetContainerForWindow(gained_active)->id(); |
173 | 174 |
174 // Don't close the bubble if a popup notification is activated. | 175 // Don't close the bubble if a popup notification is activated. |
175 if (container_id == kShellWindowId_StatusContainer) | 176 if (container_id == kShellWindowId_StatusContainer || |
177 container_id == kShellWindowId_SettingBubbleContainer) { | |
176 return; | 178 return; |
179 } | |
177 | 180 |
178 views::Widget* bubble_widget = | 181 views::Widget* bubble_widget = |
179 tray_->GetSystemBubble()->bubble_view()->GetWidget(); | 182 tray_->GetSystemBubble()->bubble_view()->GetWidget(); |
180 // Don't close the bubble if a transient child is gaining or losing | 183 // Don't close the bubble if a transient child is gaining or losing |
181 // activation. | 184 // activation. |
182 if (bubble_widget == GetInternalWidgetForWindow(gained_active) || | 185 if (bubble_widget == GetInternalWidgetForWindow(gained_active) || |
183 ::wm::HasTransientAncestor(gained_active, | 186 ::wm::HasTransientAncestor(gained_active, |
184 bubble_widget->GetNativeWindow()) || | 187 bubble_widget->GetNativeWindow()) || |
185 (lost_active && ::wm::HasTransientAncestor( | 188 (lost_active && ::wm::HasTransientAncestor( |
186 lost_active, bubble_widget->GetNativeWindow()))) { | 189 lost_active, bubble_widget->GetNativeWindow()))) { |
187 return; | 190 return; |
188 } | 191 } |
189 | 192 |
190 tray_->CloseSystemBubble(); | 193 tray_->CloseSystemBubble(); |
191 } | 194 } |
192 | 195 |
193 private: | 196 private: |
194 SystemTray* tray_; | 197 SystemTray* tray_; |
195 | 198 |
196 DISALLOW_COPY_AND_ASSIGN(ActivationObserver); | 199 DISALLOW_COPY_AND_ASSIGN(ActivationObserver); |
197 }; | 200 }; |
198 | 201 |
199 // SystemTray | 202 // SystemTray |
200 | 203 |
201 SystemTray::SystemTray(Shelf* shelf) : TrayBackgroundView(shelf) { | 204 SystemTray::SystemTray(Shelf* shelf) |
205 : TrayBackgroundView(shelf), shelf_(shelf) { | |
202 SetInkDropMode(InkDropMode::ON); | 206 SetInkDropMode(InkDropMode::ON); |
203 | 207 |
204 // Since user avatar is on the right hand side of System tray of a | 208 // 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 | 209 // horizontal shelf and that is sufficient to indicate separation, no |
206 // separator is required. | 210 // separator is required. |
207 set_separator_visibility(false); | 211 set_separator_visibility(false); |
212 | |
213 Shell::Get()->AddShellObserver(this); | |
214 if (Shell::Get() | |
215 ->maximize_mode_controller() | |
216 ->IsMaximizeModeWindowManagerEnabled()) { | |
217 in_maximize_mode_ = true; | |
xiyuan
2017/06/16 17:33:42
nit: just do
in_maximize_mode_ = Shell::Get()
minch1
2017/06/16 22:11:51
Done.
| |
218 } | |
208 } | 219 } |
209 | 220 |
210 SystemTray::~SystemTray() { | 221 SystemTray::~SystemTray() { |
211 // Destroy any child views that might have back pointers before ~View(). | 222 // Destroy any child views that might have back pointers before ~View(). |
212 activation_observer_.reset(); | 223 activation_observer_.reset(); |
213 key_event_watcher_.reset(); | 224 key_event_watcher_.reset(); |
214 system_bubble_.reset(); | 225 system_bubble_.reset(); |
215 for (const auto& item : items_) | 226 for (const auto& item : items_) |
216 item->OnTrayViewDestroyed(); | 227 item->OnTrayViewDestroyed(); |
228 Shell::Get()->RemoveShellObserver(this); | |
217 } | 229 } |
218 | 230 |
219 void SystemTray::InitializeTrayItems( | 231 void SystemTray::InitializeTrayItems( |
220 SystemTrayDelegate* delegate, | 232 SystemTrayDelegate* delegate, |
221 WebNotificationTray* web_notification_tray) { | 233 WebNotificationTray* web_notification_tray) { |
222 DCHECK(web_notification_tray); | 234 DCHECK(web_notification_tray); |
223 web_notification_tray_ = web_notification_tray; | 235 web_notification_tray_ = web_notification_tray; |
224 TrayBackgroundView::Initialize(); | 236 TrayBackgroundView::Initialize(); |
225 CreateItems(delegate); | 237 CreateItems(delegate); |
226 } | 238 } |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 } | 594 } |
583 | 595 |
584 base::string16 SystemTray::GetAccessibleNameForBubble() { | 596 base::string16 SystemTray::GetAccessibleNameForBubble() { |
585 return GetAccessibleNameForTray(); | 597 return GetAccessibleNameForTray(); |
586 } | 598 } |
587 | 599 |
588 void SystemTray::HideBubble(const TrayBubbleView* bubble_view) { | 600 void SystemTray::HideBubble(const TrayBubbleView* bubble_view) { |
589 HideBubbleWithView(bubble_view); | 601 HideBubbleWithView(bubble_view); |
590 } | 602 } |
591 | 603 |
604 void SystemTray::OnMaximizeModeStarted() { | |
605 in_maximize_mode_ = true; | |
606 } | |
607 | |
608 void SystemTray::OnMaximizeModeEnded() { | |
609 in_maximize_mode_ = false; | |
610 } | |
611 | |
592 void SystemTray::CloseBubble(const ui::KeyEvent& key_event) { | 612 void SystemTray::CloseBubble(const ui::KeyEvent& key_event) { |
593 CloseSystemBubble(); | 613 CloseSystemBubble(); |
594 } | 614 } |
595 | 615 |
596 void SystemTray::ActivateAndStartNavigation(const ui::KeyEvent& key_event) { | 616 void SystemTray::ActivateAndStartNavigation(const ui::KeyEvent& key_event) { |
597 if (!system_bubble_) | 617 if (!system_bubble_) |
598 return; | 618 return; |
599 ActivateBubble(); | 619 ActivateBubble(); |
600 | 620 |
601 views::Widget* widget = GetSystemBubble()->bubble_view()->GetWidget(); | 621 views::Widget* widget = GetSystemBubble()->bubble_view()->GetWidget(); |
(...skipping 21 matching lines...) Expand all Loading... | |
623 void SystemTray::ActivateBubble() { | 643 void SystemTray::ActivateBubble() { |
624 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); | 644 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); |
625 // If system tray bubble is in the process of closing, do not try to activate | 645 // If system tray bubble is in the process of closing, do not try to activate |
626 // bubble. | 646 // bubble. |
627 if (bubble_view->GetWidget()->IsClosed()) | 647 if (bubble_view->GetWidget()->IsClosed()) |
628 return; | 648 return; |
629 bubble_view->set_can_activate(true); | 649 bubble_view->set_can_activate(true); |
630 bubble_view->GetWidget()->Activate(); | 650 bubble_view->GetWidget()->Activate(); |
631 } | 651 } |
632 | 652 |
653 gfx::Rect SystemTray::GetWorkAreaBoundsInScreen() const { | |
654 return shelf_->GetUserWorkAreaBounds(); | |
655 } | |
656 | |
633 bool SystemTray::PerformAction(const ui::Event& event) { | 657 bool SystemTray::PerformAction(const ui::Event& event) { |
634 // If we're already showing a full system tray menu, either default or | 658 // If we're already showing a full system tray menu, either default or |
635 // detailed menu, hide it; otherwise, show it (and hide any popup that's | 659 // detailed menu, hide it; otherwise, show it (and hide any popup that's |
636 // currently shown). | 660 // currently shown). |
637 if (HasSystemBubble() && full_system_tray_menu_) { | 661 if (HasSystemBubble() && full_system_tray_menu_) { |
638 system_bubble_->bubble()->Close(); | 662 system_bubble_->bubble()->Close(); |
639 } else { | 663 } else { |
640 ShowDefaultView(BUBBLE_CREATE_NEW); | 664 ShowDefaultView(BUBBLE_CREATE_NEW); |
641 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) | 665 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) |
642 ActivateBubble(); | 666 ActivateBubble(); |
643 } | 667 } |
644 return true; | 668 return true; |
645 } | 669 } |
646 | 670 |
671 void SystemTray::OnGestureEvent(ui::GestureEvent* event) { | |
672 if (in_maximize_mode_ && shelf_->IsHorizontalAlignment() && | |
673 ProcessGestureEvent(*event)) { | |
674 event->StopPropagation(); | |
675 } else { | |
676 CustomButton::OnGestureEvent(event); | |
677 } | |
678 } | |
679 | |
680 bool SystemTray::ProcessGestureEvent(const ui::GestureEvent& event) { | |
681 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) | |
682 return StartGestureDrag(event); | |
683 | |
684 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) { | |
685 UpdateGestureDrag(event); | |
686 return true; | |
687 } | |
688 | |
689 if (event.type() == ui::ET_GESTURE_SCROLL_END || | |
690 event.type() == ui::ET_SCROLL_FLING_START) { | |
691 CompleteGestureDrag(event); | |
692 return true; | |
693 } | |
694 return false; | |
695 } | |
696 | |
697 bool SystemTray::StartGestureDrag(const ui::GestureEvent& gesture) { | |
698 if ((HasSystemBubble() && full_system_tray_menu_) || | |
699 IsSwipingDownOnShelf(gesture)) { | |
700 return false; | |
701 } | |
702 | |
703 gesture_drag_amount_ = 0.f; | |
704 ShowDefaultView(BUBBLE_CREATE_NEW); | |
705 system_tray_bubble_bounds_ = | |
706 system_bubble_->bubble_view()->GetWidget()->GetWindowBoundsInScreen(); | |
707 UpdateBoundsOnGesture(gesture); | |
708 return true; | |
709 } | |
710 | |
711 void SystemTray::UpdateGestureDrag(const ui::GestureEvent& gesture) { | |
712 UpdateBoundsOnGesture(gesture); | |
713 gesture_drag_amount_ += gesture.details().scroll_y(); | |
714 } | |
715 | |
716 void SystemTray::CompleteGestureDrag(const ui::GestureEvent& gesture) { | |
717 gfx::Rect target_bounds = system_tray_bubble_bounds_; | |
718 if (ShouldShowSystemBubbleForSwiping(gesture)) { | |
719 system_bubble_->bubble()->UpdateBounds(target_bounds, false); | |
720 } else { | |
721 target_bounds.set_y(shelf_->GetIdealBounds().y()); | |
722 system_bubble_->bubble()->UpdateBounds(target_bounds, true); | |
723 } | |
724 } | |
725 | |
726 bool SystemTray::IsSwipingDownOnShelf(const ui::GestureEvent& gesture) { | |
727 gfx::Point gesture_location = gesture.location(); | |
728 View::ConvertPointToScreen(this, &gesture_location); | |
729 | |
730 if (gesture_location.y() >= shelf_->GetIdealBounds().y() && | |
731 gesture.details().scroll_y_hint() > 0) { | |
732 return true; | |
733 } | |
734 return false; | |
735 } | |
736 | |
737 void SystemTray::UpdateBoundsOnGesture(const ui::GestureEvent& gesture) { | |
738 gfx::Point gesture_location = gesture.location(); | |
739 View::ConvertPointToScreen(this, &gesture_location); | |
740 | |
741 // System tray bubble should not be dragged higher than its original height. | |
742 if (gesture_location.y() < system_tray_bubble_bounds_.y()) | |
743 gesture_location.set_y(system_tray_bubble_bounds_.y()); | |
744 | |
745 gfx::Rect bounds_on_gesture( | |
746 system_tray_bubble_bounds_.x(), gesture_location.y(), | |
747 system_tray_bubble_bounds_.width(), system_tray_bubble_bounds_.height()); | |
748 system_bubble_->bubble_view()->GetWidget()->SetBounds(bounds_on_gesture); | |
749 } | |
750 | |
751 bool SystemTray::ShouldShowSystemBubbleBasedOnPosition() { | |
752 if (gesture_drag_amount_ > 0) | |
753 return false; | |
754 | |
755 int system_bubble_height = system_tray_bubble_bounds_.height(); | |
756 float one_third = system_bubble_height / 3.0; | |
757 | |
758 if (fabs(gesture_drag_amount_) < one_third) | |
759 return false; | |
760 return true; | |
xiyuan
2017/06/16 17:33:42
nit: Line 758-760 can be this
return fabs(gestu
minch1
2017/06/16 22:11:51
Done.
| |
761 } | |
762 | |
763 bool SystemTray::ShouldShowSystemBubbleForSwiping( | |
764 const ui::GestureEvent& gesture) { | |
765 if (gesture.type() == ui::ET_GESTURE_SCROLL_END) | |
766 return ShouldShowSystemBubbleBasedOnPosition(); | |
767 | |
768 const float kSwipingVelocity = 100.0; | |
xiyuan
2017/06/16 17:33:42
nit: 100.0 -> 100.0f since default is double, appe
minch1
2017/06/16 22:11:51
Done.
| |
769 if (fabs(gesture.details().velocity_y()) > kSwipingVelocity) | |
770 return gesture.details().velocity_y() < 0; | |
771 return ShouldShowSystemBubbleBasedOnPosition(); | |
772 } | |
773 | |
647 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { | 774 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { |
648 activation_observer_.reset(); | 775 activation_observer_.reset(); |
649 key_event_watcher_.reset(); | 776 key_event_watcher_.reset(); |
650 system_bubble_.reset(); | 777 system_bubble_.reset(); |
651 // When closing a system bubble with the alternate shelf layout, we need to | 778 // When closing a system bubble with the alternate shelf layout, we need to |
652 // turn off the active tinting of the shelf. | 779 // turn off the active tinting of the shelf. |
653 if (full_system_tray_menu_) { | 780 if (full_system_tray_menu_) { |
654 SetIsActive(false); | 781 SetIsActive(false); |
655 full_system_tray_menu_ = false; | 782 full_system_tray_menu_ = false; |
656 } | 783 } |
(...skipping 20 matching lines...) Expand all Loading... | |
677 .work_area() | 804 .work_area() |
678 .height(); | 805 .height(); |
679 if (work_area_height > 0) { | 806 if (work_area_height > 0) { |
680 UMA_HISTOGRAM_CUSTOM_COUNTS( | 807 UMA_HISTOGRAM_CUSTOM_COUNTS( |
681 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", | 808 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", |
682 100 * bubble_view->height() / work_area_height, 1, 300, 100); | 809 100 * bubble_view->height() / work_area_height, 1, 300, 100); |
683 } | 810 } |
684 } | 811 } |
685 | 812 |
686 } // namespace ash | 813 } // namespace ash |
OLD | NEW |