Chromium Code Reviews| 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() || !is_in_drag_) | |
| 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 return false; | |
| 684 } | |
| 685 | |
| 686 bool SystemTray::StartGestureDrag(const ui::GestureEvent& gesture) { | |
| 687 // Close the system bubble if there is already a full one opened. And return | |
| 688 // false to let shelf handle the event. | |
| 689 is_in_drag_ = true; | |
|
tdanderson
2017/06/26 18:13:02
Should this be placed just above line 703 (past th
minch1
2017/06/26 23:26:48
Yeah, you are right, thanks.
| |
| 690 if (HasSystemBubble() && full_system_tray_menu_) { | |
| 691 system_bubble_->bubble()->Close(); | |
| 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_SWIPE_TO_OPEN); | |
| 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 SetBubbleBounds(gesture.location()); | |
| 708 return true; | |
| 709 } | |
| 710 | |
| 711 void SystemTray::UpdateGestureDrag(const ui::GestureEvent& gesture) { | |
|
tdanderson
2017/06/26 18:13:01
Consider adding DCHECK(is_in_drag_);
| |
| 712 SetBubbleBounds(gesture.location()); | |
| 713 gesture_drag_amount_ += gesture.details().scroll_y(); | |
| 714 } | |
| 715 | |
| 716 void SystemTray::CompleteGestureDrag(const ui::GestureEvent& gesture) { | |
|
tdanderson
2017/06/26 18:13:02
Consider adding DCHECK(is_in_drag_);
| |
| 717 const bool hide_bubble = !ShouldShowSystemBubbleAfterScrollSequence(gesture); | |
| 718 gfx::Rect target_bounds = system_tray_bubble_bounds_; | |
| 719 | |
| 720 if (hide_bubble) | |
| 721 target_bounds.set_y(shelf_->GetIdealBounds().y()); | |
| 722 | |
| 723 system_bubble_->bubble()->AnimateToTargetBounds(target_bounds, hide_bubble); | |
| 724 is_in_drag_ = false; | |
|
tdanderson
2017/06/26 18:13:02
What do you think of doing the following:
In Star
minch1
2017/06/26 23:26:48
Sorry, I think I made a mistake here. It should al
| |
| 725 } | |
| 726 | |
| 727 void SystemTray::SetBubbleBounds(const gfx::Point& location) { | |
| 728 gfx::Point location_in_screen_coordinates(location); | |
| 729 View::ConvertPointToScreen(this, &location_in_screen_coordinates); | |
| 730 | |
| 731 // System tray bubble should not be dragged higher than its original height. | |
| 732 if (location_in_screen_coordinates.y() < system_tray_bubble_bounds_.y()) | |
| 733 location_in_screen_coordinates.set_y(system_tray_bubble_bounds_.y()); | |
| 734 | |
| 735 gfx::Rect bounds_on_location = system_tray_bubble_bounds_; | |
| 736 bounds_on_location.set_y(location_in_screen_coordinates.y()); | |
| 737 system_bubble_->bubble_view()->GetWidget()->SetBounds(bounds_on_location); | |
| 738 } | |
| 739 | |
| 740 bool SystemTray::ShouldShowSystemBubbleAfterScrollSequence( | |
| 741 const ui::GestureEvent& gesture) { | |
| 742 // If the scroll sequence terminates with a fling, show the system menu if the | |
| 743 // fling was fast enough and in the correct direction. | |
| 744 if (gesture.type() == ui::ET_SCROLL_FLING_START && | |
| 745 fabs(gesture.details().velocity_y()) > kFlingVelocity) { | |
| 746 return gesture.details().velocity_y() < 0; | |
| 747 } | |
| 748 | |
| 749 DCHECK(gesture.type() == ui::ET_GESTURE_SCROLL_END || | |
| 750 gesture.type() == ui::ET_SCROLL_FLING_START); | |
| 751 // Show the system menu if it is already at least one-third visible. | |
| 752 return -gesture_drag_amount_ >= system_tray_bubble_bounds_.height() / 3.0; | |
| 753 } | |
| 754 | |
| 647 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { | 755 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { |
| 648 activation_observer_.reset(); | 756 activation_observer_.reset(); |
| 649 key_event_watcher_.reset(); | 757 key_event_watcher_.reset(); |
| 650 system_bubble_.reset(); | 758 system_bubble_.reset(); |
| 651 // When closing a system bubble with the alternate shelf layout, we need to | 759 // When closing a system bubble with the alternate shelf layout, we need to |
| 652 // turn off the active tinting of the shelf. | 760 // turn off the active tinting of the shelf. |
| 653 if (full_system_tray_menu_) { | 761 if (full_system_tray_menu_) { |
| 654 SetIsActive(false); | 762 SetIsActive(false); |
| 655 full_system_tray_menu_ = false; | 763 full_system_tray_menu_ = false; |
| 656 } | 764 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 677 .work_area() | 785 .work_area() |
| 678 .height(); | 786 .height(); |
| 679 if (work_area_height > 0) { | 787 if (work_area_height > 0) { |
| 680 UMA_HISTOGRAM_CUSTOM_COUNTS( | 788 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 681 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", | 789 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", |
| 682 100 * bubble_view->height() / work_area_height, 1, 300, 100); | 790 100 * bubble_view->height() / work_area_height, 1, 300, 100); |
| 683 } | 791 } |
| 684 } | 792 } |
| 685 | 793 |
| 686 } // namespace ash | 794 } // namespace ash |
| OLD | NEW |