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); |
208 } | 212 } |
209 | 213 |
210 SystemTray::~SystemTray() { | 214 SystemTray::~SystemTray() { |
211 // Destroy any child views that might have back pointers before ~View(). | 215 // Destroy any child views that might have back pointers before ~View(). |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 void SystemTray::ActivateBubble() { | 627 void SystemTray::ActivateBubble() { |
624 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); | 628 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); |
625 // If system tray bubble is in the process of closing, do not try to activate | 629 // If system tray bubble is in the process of closing, do not try to activate |
626 // bubble. | 630 // bubble. |
627 if (bubble_view->GetWidget()->IsClosed()) | 631 if (bubble_view->GetWidget()->IsClosed()) |
628 return; | 632 return; |
629 bubble_view->set_can_activate(true); | 633 bubble_view->set_can_activate(true); |
630 bubble_view->GetWidget()->Activate(); | 634 bubble_view->GetWidget()->Activate(); |
631 } | 635 } |
632 | 636 |
637 void SystemTray::OnGestureEvent(ui::GestureEvent* event) { | |
638 if (Shell::Get() | |
639 ->maximize_mode_controller() | |
640 ->IsMaximizeModeWindowManagerEnabled() && | |
641 shelf_->IsHorizontalAlignment() && ProcessGestureEvent(*event)) { | |
642 event->SetHandled(); | |
643 } else { | |
644 TrayBackgroundView::OnGestureEvent(event); | |
645 } | |
646 } | |
647 | |
648 gfx::Rect SystemTray::GetWorkAreaBoundsInScreen() const { | |
649 return shelf_->GetUserWorkAreaBounds(); | |
650 } | |
651 | |
633 bool SystemTray::PerformAction(const ui::Event& event) { | 652 bool SystemTray::PerformAction(const ui::Event& event) { |
634 // If we're already showing a full system tray menu, either default or | 653 // 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 | 654 // detailed menu, hide it; otherwise, show it (and hide any popup that's |
636 // currently shown). | 655 // currently shown). |
637 if (HasSystemBubble() && full_system_tray_menu_) { | 656 if (HasSystemBubble() && full_system_tray_menu_) { |
638 system_bubble_->bubble()->Close(); | 657 system_bubble_->bubble()->Close(); |
639 } else { | 658 } else { |
640 ShowDefaultView(BUBBLE_CREATE_NEW); | 659 ShowDefaultView(BUBBLE_CREATE_NEW); |
641 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) | 660 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) |
642 ActivateBubble(); | 661 ActivateBubble(); |
643 } | 662 } |
644 return true; | 663 return true; |
645 } | 664 } |
646 | 665 |
666 bool SystemTray::ProcessGestureEvent(const ui::GestureEvent& event) { | |
667 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) | |
668 return StartGestureDrag(event); | |
669 | |
670 if (!HasSystemBubble()) | |
671 return false; | |
672 | |
673 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) { | |
674 UpdateGestureDrag(event); | |
675 return true; | |
676 } | |
677 | |
678 if (event.type() == ui::ET_GESTURE_SCROLL_END || | |
679 event.type() == ui::ET_SCROLL_FLING_START) { | |
680 CompleteGestureDrag(event); | |
681 return true; | |
682 } | |
683 gesture_drag_amount_ = 0.f; | |
tdanderson
2017/06/22 20:21:42
You should also reset this member upon completing
minch1
2017/06/23 22:39:56
I am not sure following cl will change this or not
tdanderson
2017/06/26 18:13:01
Acknowledged.
| |
684 return false; | |
685 } | |
686 | |
687 bool SystemTray::StartGestureDrag(const ui::GestureEvent& gesture) { | |
688 // Close the system bubble if there is already a full one opened. And return | |
689 // false to let shelf handle the event. | |
690 if ((HasSystemBubble() && full_system_tray_menu_)) { | |
tdanderson
2017/06/22 20:21:42
nit: unnecessary extra ()
minch1
2017/06/23 22:39:56
Done.
| |
691 system_bubble_->bubble()->Close(); | |
tdanderson
2017/06/22 20:21:42
I tried this patch set locally, and as far as I ca
minch1
2017/06/23 22:39:56
I think that should because you only swiping on th
tdanderson
2017/06/26 18:13:01
OK, this makes sense, thank you for the explanatio
| |
692 return false; | |
693 } | |
694 | |
695 // If the scroll sequence begins to scroll downward, return false so that the | |
696 // event will instead by handled by the shelf. | |
697 if (gesture.details().scroll_y_hint() > 0) | |
698 return false; | |
699 | |
700 ShellPort::Get()->RecordUserMetricsAction( | |
701 UMA_STATUS_AREA_SYSTEM_TRAY_SWIPING); | |
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 | |
708 gfx::Point location(gesture.location()); | |
709 SetBubbleBounds(&location); | |
710 return true; | |
711 } | |
712 | |
713 void SystemTray::UpdateGestureDrag(const ui::GestureEvent& gesture) { | |
714 gfx::Point location(gesture.location()); | |
715 SetBubbleBounds(&location); | |
716 gesture_drag_amount_ += gesture.details().scroll_y(); | |
717 } | |
718 | |
719 void SystemTray::CompleteGestureDrag(const ui::GestureEvent& gesture) { | |
720 const bool hide_bubble = !ShouldShowSystemBubbleAfterScrollSequence(gesture); | |
721 gfx::Rect target_bounds = system_tray_bubble_bounds_; | |
722 | |
723 if (hide_bubble) | |
724 target_bounds.set_y(shelf_->GetIdealBounds().y()); | |
725 | |
726 system_bubble_->bubble()->AnimateToTargetBounds(target_bounds, hide_bubble); | |
727 } | |
728 | |
729 void SystemTray::SetBubbleBounds(gfx::Point* location) { | |
tdanderson
2017/06/22 20:21:42
There doesn't seem to be any need for this paramet
minch1
2017/06/23 22:39:57
Done.
| |
730 View::ConvertPointToScreen(this, location); | |
731 | |
732 // System tray bubble should not be dragged higher than its original height. | |
733 if (location->y() < system_tray_bubble_bounds_.y()) | |
734 location->set_y(system_tray_bubble_bounds_.y()); | |
735 | |
736 gfx::Rect bounds_on_location = system_tray_bubble_bounds_; | |
737 bounds_on_location.set_y(location->y()); | |
738 system_bubble_->bubble_view()->GetWidget()->SetBounds(bounds_on_location); | |
739 } | |
740 | |
741 bool SystemTray::ShouldShowSystemBubbleAfterScrollSequence( | |
742 const ui::GestureEvent& gesture) { | |
743 // If the scroll sequence terminates with a fling, show the system menu if the | |
744 // fling was fast enough and in the correct direction. | |
745 if (gesture.type() == ui::ET_SCROLL_FLING_START && | |
746 fabs(gesture.details().velocity_y()) > kFlingVelocity) { | |
747 return gesture.details().velocity_y() < 0; | |
748 } | |
749 | |
750 // Show the system menu if it is already at least one-third visible. | |
751 return -gesture_drag_amount_ >= system_tray_bubble_bounds_.height() / 3.0; | |
752 } | |
753 | |
647 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { | 754 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { |
648 activation_observer_.reset(); | 755 activation_observer_.reset(); |
649 key_event_watcher_.reset(); | 756 key_event_watcher_.reset(); |
650 system_bubble_.reset(); | 757 system_bubble_.reset(); |
651 // When closing a system bubble with the alternate shelf layout, we need to | 758 // When closing a system bubble with the alternate shelf layout, we need to |
652 // turn off the active tinting of the shelf. | 759 // turn off the active tinting of the shelf. |
653 if (full_system_tray_menu_) { | 760 if (full_system_tray_menu_) { |
654 SetIsActive(false); | 761 SetIsActive(false); |
655 full_system_tray_menu_ = false; | 762 full_system_tray_menu_ = false; |
656 } | 763 } |
(...skipping 20 matching lines...) Expand all Loading... | |
677 .work_area() | 784 .work_area() |
678 .height(); | 785 .height(); |
679 if (work_area_height > 0) { | 786 if (work_area_height > 0) { |
680 UMA_HISTOGRAM_CUSTOM_COUNTS( | 787 UMA_HISTOGRAM_CUSTOM_COUNTS( |
681 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", | 788 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", |
682 100 * bubble_view->height() / work_area_height, 1, 300, 100); | 789 100 * bubble_view->height() / work_area_height, 1, 300, 100); |
683 } | 790 } |
684 } | 791 } |
685 | 792 |
686 } // namespace ash | 793 } // namespace ash |
OLD | NEW |