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); |
| 212 | |
| 213 Shell::Get()->AddShellObserver(this); | |
| 214 in_maximize_mode_ = Shell::Get() | |
| 215 ->maximize_mode_controller() | |
| 216 ->IsMaximizeModeWindowManagerEnabled(); | |
| 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 in_maximize_mode_ = true; | |
| 604 } | |
| 605 | |
| 606 void SystemTray::OnMaximizeModeEnded() { | |
| 607 in_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 void SystemTray::OnGestureEvent(ui::GestureEvent* event) { | |
|
tdanderson
2017/06/19 16:19:38
Why are you restricting this to just a horizontall
minch1
2017/06/20 16:45:34
Since tablet will has horizontal shelf only in the
tdanderson
2017/06/20 22:42:19
Acknowledged.
| |
| 652 if (in_maximize_mode_ && shelf_->IsHorizontalAlignment() && | |
|
tdanderson
2017/06/19 16:19:38
Side question to ask UX (OK to handle in a follow-
minch1
2017/06/20 16:45:34
Yes, that's right. We definitely need that, I will
tdanderson
2017/06/20 22:42:20
Acknowledged.
| |
| 653 ProcessGestureEvent(*event)) { | |
| 654 event->StopPropagation(); | |
| 655 } else { | |
| 656 CustomButton::OnGestureEvent(event); | |
|
tdanderson
2017/06/19 16:19:38
I think you'd instead want to call up to TrayBackr
minch1
2017/06/20 16:45:34
Done.
| |
| 657 } | |
| 658 } | |
| 659 | |
| 660 gfx::Rect SystemTray::GetWorkAreaBoundsInScreen() const { | |
| 661 return shelf_->GetUserWorkAreaBounds(); | |
| 662 } | |
| 663 | |
| 633 bool SystemTray::PerformAction(const ui::Event& event) { | 664 bool SystemTray::PerformAction(const ui::Event& event) { |
| 634 // If we're already showing a full system tray menu, either default or | 665 // 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 | 666 // detailed menu, hide it; otherwise, show it (and hide any popup that's |
| 636 // currently shown). | 667 // currently shown). |
| 637 if (HasSystemBubble() && full_system_tray_menu_) { | 668 if (HasSystemBubble() && full_system_tray_menu_) { |
| 638 system_bubble_->bubble()->Close(); | 669 system_bubble_->bubble()->Close(); |
| 639 } else { | 670 } else { |
| 640 ShowDefaultView(BUBBLE_CREATE_NEW); | 671 ShowDefaultView(BUBBLE_CREATE_NEW); |
| 641 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) | 672 if (event.IsKeyEvent() || (event.flags() & ui::EF_TOUCH_ACCESSIBILITY)) |
| 642 ActivateBubble(); | 673 ActivateBubble(); |
| 643 } | 674 } |
| 644 return true; | 675 return true; |
| 645 } | 676 } |
| 646 | 677 |
| 678 bool SystemTray::ProcessGestureEvent(const ui::GestureEvent& event) { | |
|
tdanderson
2017/06/19 16:19:38
When building and trying out this CL locally, I ca
minch1
2017/06/20 16:45:34
I am sorry I cannot repro this locally. But I gues
tdanderson
2017/06/20 22:42:20
I can still repro locally with Patch Set 8. I will
| |
| 679 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) | |
|
xdai1
2017/06/19 19:01:30
I think "switch case" might make the code cleaner
minch1
2017/06/20 16:45:34
I think "switch case" is not so good after update.
| |
| 680 return StartGestureDrag(event); | |
| 681 | |
| 682 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) { | |
| 683 UpdateGestureDrag(event); | |
| 684 return true; | |
| 685 } | |
| 686 | |
| 687 if (event.type() == ui::ET_GESTURE_SCROLL_END || | |
| 688 event.type() == ui::ET_SCROLL_FLING_START) { | |
| 689 CompleteGestureDrag(event); | |
| 690 return true; | |
| 691 } | |
| 692 return false; | |
| 693 } | |
| 694 | |
| 695 bool SystemTray::StartGestureDrag(const ui::GestureEvent& gesture) { | |
| 696 if ((HasSystemBubble() && full_system_tray_menu_) || | |
| 697 IsDraggingDownOnShelf(gesture)) { | |
|
tdanderson
2017/06/19 16:19:38
I don't understand what the check IsDraggingDownOn
minch1
2017/06/20 16:45:34
When there is no bubble. Swiping down on the syste
| |
| 698 return false; | |
| 699 } | |
| 700 | |
| 701 gesture_drag_amount_ = 0.f; | |
| 702 ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 703 system_tray_bubble_bounds_ = | |
| 704 system_bubble_->bubble_view()->GetWidget()->GetWindowBoundsInScreen(); | |
| 705 UpdateBoundsOnDragging(gesture); | |
| 706 return true; | |
| 707 } | |
| 708 | |
| 709 void SystemTray::UpdateGestureDrag(const ui::GestureEvent& gesture) { | |
| 710 UpdateBoundsOnDragging(gesture); | |
| 711 gesture_drag_amount_ += gesture.details().scroll_y(); | |
| 712 } | |
| 713 | |
| 714 void SystemTray::CompleteGestureDrag(const ui::GestureEvent& gesture) { | |
| 715 gfx::Rect target_bounds = system_tray_bubble_bounds_; | |
| 716 if (ShouldShowSystemBubbleForDragging(gesture)) { | |
| 717 system_bubble_->bubble()->UpdateBounds(target_bounds, false); | |
| 718 } else { | |
| 719 target_bounds.set_y(shelf_->GetIdealBounds().y()); | |
| 720 system_bubble_->bubble()->UpdateBounds(target_bounds, true); | |
| 721 } | |
| 722 } | |
| 723 | |
| 724 bool SystemTray::IsDraggingDownOnShelf(const ui::GestureEvent& gesture) { | |
| 725 gfx::Point gesture_location = gesture.location(); | |
| 726 View::ConvertPointToScreen(this, &gesture_location); | |
| 727 | |
| 728 if (gesture_location.y() >= shelf_->GetIdealBounds().y() && | |
| 729 gesture.details().scroll_y_hint() > 0) { | |
| 730 return true; | |
| 731 } | |
| 732 return false; | |
| 733 } | |
| 734 | |
| 735 void SystemTray::UpdateBoundsOnDragging(const ui::GestureEvent& gesture) { | |
| 736 gfx::Point gesture_location = gesture.location(); | |
| 737 View::ConvertPointToScreen(this, &gesture_location); | |
| 738 | |
| 739 // System tray bubble should not be dragged higher than its original height. | |
| 740 if (gesture_location.y() < system_tray_bubble_bounds_.y()) | |
| 741 gesture_location.set_y(system_tray_bubble_bounds_.y()); | |
| 742 | |
| 743 gfx::Rect bounds_on_gesture( | |
| 744 system_tray_bubble_bounds_.x(), gesture_location.y(), | |
| 745 system_tray_bubble_bounds_.width(), system_tray_bubble_bounds_.height()); | |
| 746 system_bubble_->bubble_view()->GetWidget()->SetBounds(bounds_on_gesture); | |
| 747 } | |
| 748 | |
| 749 bool SystemTray::ShouldShowSystemBubbleBasedOnDragAmount() { | |
| 750 if (gesture_drag_amount_ > 0) | |
| 751 return false; | |
| 752 | |
| 753 int system_bubble_height = system_tray_bubble_bounds_.height(); | |
| 754 float one_third = system_bubble_height / 3.0; | |
| 755 | |
| 756 return fabs(gesture_drag_amount_) >= one_third; | |
| 757 } | |
| 758 | |
| 759 bool SystemTray::ShouldShowSystemBubbleForDragging( | |
| 760 const ui::GestureEvent& gesture) { | |
| 761 if (gesture.type() == ui::ET_GESTURE_SCROLL_END) | |
| 762 return ShouldShowSystemBubbleBasedOnDragAmount(); | |
| 763 | |
| 764 const float kSwipingVelocity = 100.0f; | |
| 765 if (fabs(gesture.details().velocity_y()) > kSwipingVelocity) | |
|
tdanderson
2017/06/19 16:19:38
Consider setting kSwipingVelocity to -100 and inli
minch1
2017/06/20 16:45:34
Thanks. Done the change for ShouldShowSystemBubble
tdanderson
2017/06/20 22:42:20
Acknowledged.
| |
| 766 return gesture.details().velocity_y() < 0; | |
| 767 return ShouldShowSystemBubbleBasedOnDragAmount(); | |
| 768 } | |
| 769 | |
| 647 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { | 770 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { |
| 648 activation_observer_.reset(); | 771 activation_observer_.reset(); |
| 649 key_event_watcher_.reset(); | 772 key_event_watcher_.reset(); |
| 650 system_bubble_.reset(); | 773 system_bubble_.reset(); |
| 651 // When closing a system bubble with the alternate shelf layout, we need to | 774 // When closing a system bubble with the alternate shelf layout, we need to |
| 652 // turn off the active tinting of the shelf. | 775 // turn off the active tinting of the shelf. |
| 653 if (full_system_tray_menu_) { | 776 if (full_system_tray_menu_) { |
| 654 SetIsActive(false); | 777 SetIsActive(false); |
| 655 full_system_tray_menu_ = false; | 778 full_system_tray_menu_ = false; |
| 656 } | 779 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 677 .work_area() | 800 .work_area() |
| 678 .height(); | 801 .height(); |
| 679 if (work_area_height > 0) { | 802 if (work_area_height > 0) { |
| 680 UMA_HISTOGRAM_CUSTOM_COUNTS( | 803 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 681 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", | 804 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", |
| 682 100 * bubble_view->height() / work_area_height, 1, 300, 100); | 805 100 * bubble_view->height() / work_area_height, 1, 300, 100); |
| 683 } | 806 } |
| 684 } | 807 } |
| 685 | 808 |
| 686 } // namespace ash | 809 } // namespace ash |
| OLD | NEW |