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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "ash/system/tray/tray_bubble_wrapper.h" | 44 #include "ash/system/tray/tray_bubble_wrapper.h" |
45 #include "ash/system/tray/tray_constants.h" | 45 #include "ash/system/tray/tray_constants.h" |
46 #include "ash/system/tray/tray_container.h" | 46 #include "ash/system/tray/tray_container.h" |
47 #include "ash/system/tray_accessibility.h" | 47 #include "ash/system/tray_accessibility.h" |
48 #include "ash/system/tray_caps_lock.h" | 48 #include "ash/system/tray_caps_lock.h" |
49 #include "ash/system/tray_tracing.h" | 49 #include "ash/system/tray_tracing.h" |
50 #include "ash/system/update/tray_update.h" | 50 #include "ash/system/update/tray_update.h" |
51 #include "ash/system/user/tray_user.h" | 51 #include "ash/system/user/tray_user.h" |
52 #include "ash/system/web_notification/web_notification_tray.h" | 52 #include "ash/system/web_notification/web_notification_tray.h" |
53 #include "ash/wm/container_finder.h" | 53 #include "ash/wm/container_finder.h" |
| 54 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
54 #include "ash/wm/widget_finder.h" | 55 #include "ash/wm/widget_finder.h" |
55 #include "base/logging.h" | 56 #include "base/logging.h" |
56 #include "base/memory/ptr_util.h" | 57 #include "base/memory/ptr_util.h" |
57 #include "base/metrics/histogram_macros.h" | 58 #include "base/metrics/histogram_macros.h" |
58 #include "base/timer/timer.h" | 59 #include "base/timer/timer.h" |
59 #include "ui/base/accelerators/accelerator.h" | 60 #include "ui/base/accelerators/accelerator.h" |
60 #include "ui/base/l10n/l10n_util.h" | 61 #include "ui/base/l10n/l10n_util.h" |
61 #include "ui/compositor/layer.h" | 62 #include "ui/compositor/layer.h" |
62 #include "ui/display/display.h" | 63 #include "ui/display/display.h" |
63 #include "ui/display/screen.h" | 64 #include "ui/display/screen.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // WmActivationObserver: | 167 // WmActivationObserver: |
167 void OnWindowActivated(ActivationReason reason, | 168 void OnWindowActivated(ActivationReason reason, |
168 aura::Window* gained_active, | 169 aura::Window* gained_active, |
169 aura::Window* lost_active) override { | 170 aura::Window* lost_active) override { |
170 if (!tray_->HasSystemBubble() || !gained_active) | 171 if (!tray_->HasSystemBubble() || !gained_active) |
171 return; | 172 return; |
172 | 173 |
173 int container_id = wm::GetContainerForWindow(gained_active)->id(); | 174 int container_id = wm::GetContainerForWindow(gained_active)->id(); |
174 | 175 |
175 // Don't close the bubble if a popup notification is activated. | 176 // Don't close the bubble if a popup notification is activated. |
176 if (container_id == kShellWindowId_StatusContainer) | 177 if (container_id == kShellWindowId_StatusContainer || |
| 178 container_id == kShellWindowId_SettingBubbleContainer) { |
177 return; | 179 return; |
| 180 } |
178 | 181 |
179 views::Widget* bubble_widget = | 182 views::Widget* bubble_widget = |
180 tray_->GetSystemBubble()->bubble_view()->GetWidget(); | 183 tray_->GetSystemBubble()->bubble_view()->GetWidget(); |
181 // Don't close the bubble if a transient child is gaining or losing | 184 // Don't close the bubble if a transient child is gaining or losing |
182 // activation. | 185 // activation. |
183 if (bubble_widget == GetInternalWidgetForWindow(gained_active) || | 186 if (bubble_widget == GetInternalWidgetForWindow(gained_active) || |
184 ::wm::HasTransientAncestor(gained_active, | 187 ::wm::HasTransientAncestor(gained_active, |
185 bubble_widget->GetNativeWindow()) || | 188 bubble_widget->GetNativeWindow()) || |
186 (lost_active && ::wm::HasTransientAncestor( | 189 (lost_active && ::wm::HasTransientAncestor( |
187 lost_active, bubble_widget->GetNativeWindow()))) { | 190 lost_active, bubble_widget->GetNativeWindow()))) { |
188 return; | 191 return; |
189 } | 192 } |
190 | 193 |
191 tray_->CloseSystemBubble(); | 194 tray_->CloseSystemBubble(); |
192 } | 195 } |
193 | 196 |
194 private: | 197 private: |
195 SystemTray* tray_; | 198 SystemTray* tray_; |
196 | 199 |
197 DISALLOW_COPY_AND_ASSIGN(ActivationObserver); | 200 DISALLOW_COPY_AND_ASSIGN(ActivationObserver); |
198 }; | 201 }; |
199 | 202 |
200 // SystemTray | 203 // SystemTray |
201 | 204 |
202 SystemTray::SystemTray(Shelf* shelf) : TrayBackgroundView(shelf) { | 205 SystemTray::SystemTray(Shelf* shelf) |
| 206 : TrayBackgroundView(shelf), shelf_(shelf) { |
203 SetInkDropMode(InkDropMode::ON); | 207 SetInkDropMode(InkDropMode::ON); |
204 | 208 |
205 // Since user avatar is on the right hand side of System tray of a | 209 // 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 | 210 // horizontal shelf and that is sufficient to indicate separation, no |
207 // separator is required. | 211 // separator is required. |
208 set_separator_visibility(false); | 212 set_separator_visibility(false); |
209 } | 213 } |
210 | 214 |
211 SystemTray::~SystemTray() { | 215 SystemTray::~SystemTray() { |
212 // Destroy any child views that might have back pointers before ~View(). | 216 // Destroy any child views that might have back pointers before ~View(). |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 void SystemTray::ActivateBubble() { | 629 void SystemTray::ActivateBubble() { |
626 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); | 630 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view(); |
627 // If system tray bubble is in the process of closing, do not try to activate | 631 // If system tray bubble is in the process of closing, do not try to activate |
628 // bubble. | 632 // bubble. |
629 if (bubble_view->GetWidget()->IsClosed()) | 633 if (bubble_view->GetWidget()->IsClosed()) |
630 return; | 634 return; |
631 bubble_view->set_can_activate(true); | 635 bubble_view->set_can_activate(true); |
632 bubble_view->GetWidget()->Activate(); | 636 bubble_view->GetWidget()->Activate(); |
633 } | 637 } |
634 | 638 |
| 639 void SystemTray::OnGestureEvent(ui::GestureEvent* event) { |
| 640 if (Shell::Get() |
| 641 ->maximize_mode_controller() |
| 642 ->IsMaximizeModeWindowManagerEnabled() && |
| 643 shelf_->IsHorizontalAlignment() && ProcessGestureEvent(*event)) { |
| 644 event->SetHandled(); |
| 645 } else { |
| 646 TrayBackgroundView::OnGestureEvent(event); |
| 647 } |
| 648 } |
| 649 |
| 650 gfx::Rect SystemTray::GetWorkAreaBoundsInScreen() const { |
| 651 return shelf_->GetUserWorkAreaBounds(); |
| 652 } |
| 653 |
635 bool SystemTray::PerformAction(const ui::Event& event) { | 654 bool SystemTray::PerformAction(const ui::Event& event) { |
636 // If we're already showing a full system tray menu, either default or | 655 // If we're already showing a full system tray menu, either default or |
637 // detailed menu, hide it; otherwise, show it (and hide any popup that's | 656 // detailed menu, hide it; otherwise, show it (and hide any popup that's |
638 // currently shown). | 657 // currently shown). |
639 if (HasSystemBubble() && full_system_tray_menu_) { | 658 if (HasSystemBubble() && full_system_tray_menu_) { |
640 system_bubble_->bubble()->Close(); | 659 system_bubble_->bubble()->Close(); |
641 } else { | 660 } else { |
642 ShowDefaultView(BUBBLE_CREATE_NEW); | 661 ShowDefaultView(BUBBLE_CREATE_NEW); |
643 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) | 662 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) |
644 ActivateBubble(); | 663 ActivateBubble(); |
645 } | 664 } |
646 return true; | 665 return true; |
647 } | 666 } |
648 | 667 |
| 668 bool SystemTray::ProcessGestureEvent(const ui::GestureEvent& event) { |
| 669 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) |
| 670 return StartGestureDrag(event); |
| 671 |
| 672 if (!HasSystemBubble() || !is_in_drag_) |
| 673 return false; |
| 674 |
| 675 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) { |
| 676 UpdateGestureDrag(event); |
| 677 return true; |
| 678 } |
| 679 |
| 680 if (event.type() == ui::ET_GESTURE_SCROLL_END || |
| 681 event.type() == ui::ET_SCROLL_FLING_START) { |
| 682 CompleteGestureDrag(event); |
| 683 return true; |
| 684 } |
| 685 |
| 686 // Unexpected event. Reset the drag state and close the bubble. |
| 687 is_in_drag_ = false; |
| 688 CloseSystemBubble(); |
| 689 return false; |
| 690 } |
| 691 |
| 692 bool SystemTray::StartGestureDrag(const ui::GestureEvent& gesture) { |
| 693 // Close the system bubble if there is already a full one opened. And return |
| 694 // false to let shelf handle the event. |
| 695 if (HasSystemBubble() && full_system_tray_menu_) { |
| 696 system_bubble_->bubble()->Close(); |
| 697 return false; |
| 698 } |
| 699 |
| 700 // If the scroll sequence begins to scroll downward, return false so that the |
| 701 // event will instead by handled by the shelf. |
| 702 if (gesture.details().scroll_y_hint() > 0) |
| 703 return false; |
| 704 |
| 705 is_in_drag_ = true; |
| 706 gesture_drag_amount_ = 0.f; |
| 707 ShowDefaultView(BUBBLE_CREATE_NEW); |
| 708 system_tray_bubble_bounds_ = |
| 709 system_bubble_->bubble_view()->GetWidget()->GetWindowBoundsInScreen(); |
| 710 SetBubbleBounds(gesture.location()); |
| 711 return true; |
| 712 } |
| 713 |
| 714 void SystemTray::UpdateGestureDrag(const ui::GestureEvent& gesture) { |
| 715 SetBubbleBounds(gesture.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 is_in_drag_ = false; |
| 728 } |
| 729 |
| 730 void SystemTray::SetBubbleBounds(const gfx::Point& location) { |
| 731 gfx::Point location_in_screen_coordinates(location); |
| 732 View::ConvertPointToScreen(this, &location_in_screen_coordinates); |
| 733 |
| 734 // System tray bubble should not be dragged higher than its original height. |
| 735 if (location_in_screen_coordinates.y() < system_tray_bubble_bounds_.y()) |
| 736 location_in_screen_coordinates.set_y(system_tray_bubble_bounds_.y()); |
| 737 |
| 738 gfx::Rect bounds_on_location = system_tray_bubble_bounds_; |
| 739 bounds_on_location.set_y(location_in_screen_coordinates.y()); |
| 740 system_bubble_->bubble_view()->GetWidget()->SetBounds(bounds_on_location); |
| 741 } |
| 742 |
| 743 bool SystemTray::ShouldShowSystemBubbleAfterScrollSequence( |
| 744 const ui::GestureEvent& sequence_end) { |
| 745 // If the scroll sequence terminates with a fling, show the system menu if the |
| 746 // fling was fast enough and in the correct direction. |
| 747 if (sequence_end.type() == ui::ET_SCROLL_FLING_START && |
| 748 fabs(sequence_end.details().velocity_y()) > kFlingVelocity) { |
| 749 return sequence_end.details().velocity_y() < 0; |
| 750 } |
| 751 |
| 752 DCHECK(sequence_end.type() == ui::ET_GESTURE_SCROLL_END || |
| 753 sequence_end.type() == ui::ET_SCROLL_FLING_START); |
| 754 // Show the system menu if it is already at least one-third visible. |
| 755 return -gesture_drag_amount_ >= system_tray_bubble_bounds_.height() / 3.0; |
| 756 } |
| 757 |
649 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { | 758 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { |
650 activation_observer_.reset(); | 759 activation_observer_.reset(); |
651 key_event_watcher_.reset(); | 760 key_event_watcher_.reset(); |
652 system_bubble_.reset(); | 761 system_bubble_.reset(); |
653 // When closing a system bubble with the alternate shelf layout, we need to | 762 // When closing a system bubble with the alternate shelf layout, we need to |
654 // turn off the active tinting of the shelf. | 763 // turn off the active tinting of the shelf. |
655 if (full_system_tray_menu_) { | 764 if (full_system_tray_menu_) { |
656 SetIsActive(false); | 765 SetIsActive(false); |
657 full_system_tray_menu_ = false; | 766 full_system_tray_menu_ = false; |
658 } | 767 } |
(...skipping 20 matching lines...) Expand all Loading... |
679 .work_area() | 788 .work_area() |
680 .height(); | 789 .height(); |
681 if (work_area_height > 0) { | 790 if (work_area_height > 0) { |
682 UMA_HISTOGRAM_CUSTOM_COUNTS( | 791 UMA_HISTOGRAM_CUSTOM_COUNTS( |
683 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", | 792 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", |
684 100 * bubble_view->height() / work_area_height, 1, 300, 100); | 793 100 * bubble_view->height() / work_area_height, 1, 300, 100); |
685 } | 794 } |
686 } | 795 } |
687 | 796 |
688 } // namespace ash | 797 } // namespace ash |
OLD | NEW |