Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: ash/system/tray/system_tray.cc

Issue 2930123002: Tablet WM : Swiping on system tray bubble. (Closed)
Patch Set: Addressed comments. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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->StopPropagation();
tdanderson 2017/06/20 22:42:27 I think that event->SetHandled() should do the tri
minch1 2017/06/22 17:42:11 Done.
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;
xdai1 2017/06/20 17:00:31 Why don't put this if-clause at the top?
xdai1 2017/06/20 17:02:53 I think I get it...
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 if ((HasSystemBubble() && full_system_tray_menu_) ||
688 IsDraggingDownOnShelf(gesture)) {
tdanderson 2017/06/20 22:42:24 Now I understand what IsDraggingDownOnShelf() is d
minch1 2017/06/22 17:42:11 Yes, you are right, thanks.
689 return false;
690 }
691
692 gesture_drag_amount_ = 0.f;
tdanderson 2017/06/20 22:42:23 It looks like you are only resetting |gesture_drag
minch1 2017/06/22 17:42:11 Done.
693 ShowDefaultView(BUBBLE_CREATE_NEW);
694 system_tray_bubble_bounds_ =
695 system_bubble_->bubble_view()->GetWidget()->GetWindowBoundsInScreen();
696 UpdateBoundsOnDragging(gesture);
697 return true;
698 }
699
700 void SystemTray::UpdateGestureDrag(const ui::GestureEvent& gesture) {
701 UpdateBoundsOnDragging(gesture);
702 gesture_drag_amount_ += gesture.details().scroll_y();
703 }
704
705 void SystemTray::CompleteGestureDrag(const ui::GestureEvent& gesture) {
706 gfx::Rect target_bounds = system_tray_bubble_bounds_;
tdanderson 2017/06/20 22:42:25 Consider simplifying the implementation of this fu
minch1 2017/06/22 17:42:11 Done.
707 if (ShouldShowSystemBubbleForDragging(gesture)) {
708 system_bubble_->bubble()->UpdateBounds(target_bounds, false);
709 } else {
710 target_bounds.set_y(shelf_->GetIdealBounds().y());
711 system_bubble_->bubble()->UpdateBounds(target_bounds, true);
712 }
713 }
714
715 bool SystemTray::IsDraggingDownOnShelf(const ui::GestureEvent& gesture) {
716 gfx::Point gesture_location = gesture.location();
717 View::ConvertPointToScreen(this, &gesture_location);
718
719 if (gesture_location.y() >= shelf_->GetIdealBounds().y() &&
tdanderson 2017/06/20 22:42:23 In StartGestureDrag() I suggest just inlining this
minch1 2017/06/22 17:42:11 Acknowledged.
720 gesture.details().scroll_y_hint() > 0) {
721 return true;
722 }
723 return false;
724 }
725
726 void SystemTray::UpdateBoundsOnDragging(const ui::GestureEvent& gesture) {
tdanderson 2017/06/20 22:42:26 Since the only property of |gesture| you use is it
minch1 2017/06/22 17:42:11 Done.
727 gfx::Point gesture_location = gesture.location();
728 View::ConvertPointToScreen(this, &gesture_location);
729
730 // System tray bubble should not be dragged higher than its original height.
731 if (gesture_location.y() < system_tray_bubble_bounds_.y())
732 gesture_location.set_y(system_tray_bubble_bounds_.y());
733
734 gfx::Rect bounds_on_gesture(
735 system_tray_bubble_bounds_.x(), gesture_location.y(),
736 system_tray_bubble_bounds_.width(), system_tray_bubble_bounds_.height());
737 system_bubble_->bubble_view()->GetWidget()->SetBounds(bounds_on_gesture);
738 }
739
740 bool SystemTray::ShouldShowSystemBubbleForDragging(
741 const ui::GestureEvent& gesture) {
742 const float kFlingVelocity = 100.0f;
743 if (gesture.type() == ui::ET_SCROLL_FLING_START &&
tdanderson 2017/06/20 22:42:20 Suggestion for inline documentation here: "If the
minch1 2017/06/22 17:42:11 Done.
744 fabs(gesture.details().velocity_y()) > kFlingVelocity) {
745 return gesture.details().velocity_y() < 0;
746 }
747
tdanderson 2017/06/20 22:42:20 Consider adding a DCHECK here to verify that the g
minch1 2017/06/22 17:42:11 It is not correct to add a DCHECK to verify that t
tdanderson 2017/06/22 20:21:42 Ah yes, you're right. Then perhaps add a DCHECK to
minch1 2017/06/23 22:39:56 Done.
748 return -gesture_drag_amount_ >= system_tray_bubble_bounds_.height() / 3.0;
tdanderson 2017/06/20 22:42:21 Suggestion for inline documentation here: "Show th
minch1 2017/06/22 17:42:11 Done.
749 }
750
647 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { 751 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() {
648 activation_observer_.reset(); 752 activation_observer_.reset();
649 key_event_watcher_.reset(); 753 key_event_watcher_.reset();
650 system_bubble_.reset(); 754 system_bubble_.reset();
651 // When closing a system bubble with the alternate shelf layout, we need to 755 // When closing a system bubble with the alternate shelf layout, we need to
652 // turn off the active tinting of the shelf. 756 // turn off the active tinting of the shelf.
653 if (full_system_tray_menu_) { 757 if (full_system_tray_menu_) {
654 SetIsActive(false); 758 SetIsActive(false);
655 full_system_tray_menu_ = false; 759 full_system_tray_menu_ = false;
656 } 760 }
(...skipping 20 matching lines...) Expand all
677 .work_area() 781 .work_area()
678 .height(); 782 .height();
679 if (work_area_height > 0) { 783 if (work_area_height > 0) {
680 UMA_HISTOGRAM_CUSTOM_COUNTS( 784 UMA_HISTOGRAM_CUSTOM_COUNTS(
681 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", 785 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu",
682 100 * bubble_view->height() / work_area_height, 1, 300, 100); 786 100 * bubble_view->height() / work_area_height, 1, 300, 100);
683 } 787 }
684 } 788 }
685 789
686 } // namespace ash 790 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698