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

Unified Diff: ash/system/tray/system_tray.cc

Issue 2930123002: Tablet WM : Swiping on system tray bubble. (Closed)
Patch Set: Fixed tdanderson's 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 side-by-side diff with in-line comments
Download patch
Index: ash/system/tray/system_tray.cc
diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc
index 78f2929147dab3951ce59e4d5e0d922ef7483b9c..210406476cb9d705fc1ea0a755881fc95bf4d8d5 100644
--- a/ash/system/tray/system_tray.cc
+++ b/ash/system/tray/system_tray.cc
@@ -50,6 +50,7 @@
#include "ash/system/user/tray_user.h"
#include "ash/system/web_notification/web_notification_tray.h"
#include "ash/wm/container_finder.h"
+#include "ash/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/wm/widget_finder.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
@@ -172,8 +173,10 @@ class SystemTray::ActivationObserver : public ::wm::ActivationChangeObserver {
int container_id = wm::GetContainerForWindow(gained_active)->id();
// Don't close the bubble if a popup notification is activated.
- if (container_id == kShellWindowId_StatusContainer)
+ if (container_id == kShellWindowId_StatusContainer ||
+ container_id == kShellWindowId_SettingBubbleContainer) {
return;
+ }
views::Widget* bubble_widget =
tray_->GetSystemBubble()->bubble_view()->GetWidget();
@@ -198,7 +201,8 @@ class SystemTray::ActivationObserver : public ::wm::ActivationChangeObserver {
// SystemTray
-SystemTray::SystemTray(Shelf* shelf) : TrayBackgroundView(shelf) {
+SystemTray::SystemTray(Shelf* shelf)
+ : TrayBackgroundView(shelf), shelf_(shelf) {
SetInkDropMode(InkDropMode::ON);
// Since user avatar is on the right hand side of System tray of a
@@ -630,6 +634,21 @@ void SystemTray::ActivateBubble() {
bubble_view->GetWidget()->Activate();
}
+void SystemTray::OnGestureEvent(ui::GestureEvent* event) {
+ if (Shell::Get()
+ ->maximize_mode_controller()
+ ->IsMaximizeModeWindowManagerEnabled() &&
+ shelf_->IsHorizontalAlignment() && ProcessGestureEvent(*event)) {
+ event->SetHandled();
+ } else {
+ TrayBackgroundView::OnGestureEvent(event);
+ }
+}
+
+gfx::Rect SystemTray::GetWorkAreaBoundsInScreen() const {
+ return shelf_->GetUserWorkAreaBounds();
+}
+
bool SystemTray::PerformAction(const ui::Event& event) {
// If we're already showing a full system tray menu, either default or
// detailed menu, hide it; otherwise, show it (and hide any popup that's
@@ -644,6 +663,94 @@ bool SystemTray::PerformAction(const ui::Event& event) {
return true;
}
+bool SystemTray::ProcessGestureEvent(const ui::GestureEvent& event) {
+ if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
+ return StartGestureDrag(event);
+
+ if (!HasSystemBubble())
+ return false;
+
+ if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) {
+ UpdateGestureDrag(event);
+ return true;
+ }
+
+ if (event.type() == ui::ET_GESTURE_SCROLL_END ||
+ event.type() == ui::ET_SCROLL_FLING_START) {
+ CompleteGestureDrag(event);
+ return true;
+ }
+ 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.
+ return false;
+}
+
+bool SystemTray::StartGestureDrag(const ui::GestureEvent& gesture) {
+ // Close the system bubble if there is already a full one opened. And return
+ // false to let shelf handle the event.
+ if ((HasSystemBubble() && full_system_tray_menu_)) {
tdanderson 2017/06/22 20:21:42 nit: unnecessary extra ()
minch1 2017/06/23 22:39:56 Done.
+ 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
+ return false;
+ }
+
+ // If the scroll sequence begins to scroll downward, return false so that the
+ // event will instead by handled by the shelf.
+ if (gesture.details().scroll_y_hint() > 0)
+ return false;
+
+ ShellPort::Get()->RecordUserMetricsAction(
+ UMA_STATUS_AREA_SYSTEM_TRAY_SWIPING);
+
+ gesture_drag_amount_ = 0.f;
+ ShowDefaultView(BUBBLE_CREATE_NEW);
+ system_tray_bubble_bounds_ =
+ system_bubble_->bubble_view()->GetWidget()->GetWindowBoundsInScreen();
+
+ gfx::Point location(gesture.location());
+ SetBubbleBounds(&location);
+ return true;
+}
+
+void SystemTray::UpdateGestureDrag(const ui::GestureEvent& gesture) {
+ gfx::Point location(gesture.location());
+ SetBubbleBounds(&location);
+ gesture_drag_amount_ += gesture.details().scroll_y();
+}
+
+void SystemTray::CompleteGestureDrag(const ui::GestureEvent& gesture) {
+ const bool hide_bubble = !ShouldShowSystemBubbleAfterScrollSequence(gesture);
+ gfx::Rect target_bounds = system_tray_bubble_bounds_;
+
+ if (hide_bubble)
+ target_bounds.set_y(shelf_->GetIdealBounds().y());
+
+ system_bubble_->bubble()->AnimateToTargetBounds(target_bounds, hide_bubble);
+}
+
+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.
+ View::ConvertPointToScreen(this, location);
+
+ // System tray bubble should not be dragged higher than its original height.
+ if (location->y() < system_tray_bubble_bounds_.y())
+ location->set_y(system_tray_bubble_bounds_.y());
+
+ gfx::Rect bounds_on_location = system_tray_bubble_bounds_;
+ bounds_on_location.set_y(location->y());
+ system_bubble_->bubble_view()->GetWidget()->SetBounds(bounds_on_location);
+}
+
+bool SystemTray::ShouldShowSystemBubbleAfterScrollSequence(
+ const ui::GestureEvent& gesture) {
+ // If the scroll sequence terminates with a fling, show the system menu if the
+ // fling was fast enough and in the correct direction.
+ if (gesture.type() == ui::ET_SCROLL_FLING_START &&
+ fabs(gesture.details().velocity_y()) > kFlingVelocity) {
+ return gesture.details().velocity_y() < 0;
+ }
+
+ // Show the system menu if it is already at least one-third visible.
+ return -gesture_drag_amount_ >= system_tray_bubble_bounds_.height() / 3.0;
+}
+
void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() {
activation_observer_.reset();
key_event_watcher_.reset();

Powered by Google App Engine
This is Rietveld 408576698