Commit c3328909 authored by Min Chen's avatar Min Chen Committed by Commit Bot

Clean up gesture drag for system tray, IME etc.

Unified system tray has been launched and web notification has been moved
to the top of the system tray. The old system tray logic has been removed.
This cl removes the logic that swiping up on the status area tray to open
the corresponding bubble and swiping down on the tray bubble to close it.

cl that landed the feature:
https://codereview.chromium.org/2961313003/
cl that disabled the feature:
https://chromium-review.googlesource.com/c/chromium/src/+/674527/

Bug: 767679
Change-Id: Id81091360ee47c9763d2f716f246146b940ac1e2
Reviewed-on: https://chromium-review.googlesource.com/c/1334932Reviewed-by: default avatarJesse Doherty <jwd@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Min Chen <minch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608868}
parent b24393f3
......@@ -963,8 +963,6 @@ component("ash") {
"system/tray/tri_view.cc",
"system/tray/tri_view.h",
"system/tray/view_click_listener.h",
"system/tray_drag_controller.cc",
"system/tray_drag_controller.h",
"system/unified/collapse_button.cc",
"system/unified/collapse_button.h",
"system/unified/detailed_view_controller.h",
......
......@@ -80,10 +80,6 @@ enum UserMetricsAction {
UMA_TRAY_OVERVIEW,
UMA_TRAY_SETTINGS,
UMA_TRAY_SHUT_DOWN,
UMA_TRAY_SWIPE_TO_CLOSE_SUCCESSFUL,
UMA_TRAY_SWIPE_TO_CLOSE_UNSUCCESSFUL,
UMA_TRAY_SWIPE_TO_OPEN_SUCCESSFUL,
UMA_TRAY_SWIPE_TO_OPEN_UNSUCCESSFUL,
// DEPRECATED: Do not add new values. See top of file.
};
......
......@@ -426,18 +426,6 @@ void UserMetricsRecorder::RecordUserMetricsAction(UserMetricsAction action) {
case UMA_TRAY_SHUT_DOWN:
RecordAction(UserMetricsAction("Tray_ShutDown"));
break;
case UMA_TRAY_SWIPE_TO_CLOSE_SUCCESSFUL:
RecordAction(UserMetricsAction("Tray_SwipeToClose_Successful"));
break;
case UMA_TRAY_SWIPE_TO_CLOSE_UNSUCCESSFUL:
RecordAction(UserMetricsAction("Tray_SwipeToClose_Unsuccessful"));
break;
case UMA_TRAY_SWIPE_TO_OPEN_SUCCESSFUL:
RecordAction(UserMetricsAction("Tray_SwipeToOpen_Successful"));
break;
case UMA_TRAY_SWIPE_TO_OPEN_UNSUCCESSFUL:
RecordAction(UserMetricsAction("Tray_SwipeToOpen_Unsuccessful"));
break;
}
}
......
......@@ -430,10 +430,8 @@ aura::Window* PaletteTray::GetWindow() {
}
void PaletteTray::AnchorUpdated() {
if (bubble_) {
UpdateClippingWindowBounds();
if (bubble_)
bubble_->bubble_view()->UpdateBubble();
}
}
void PaletteTray::Initialize() {
......
......@@ -146,26 +146,6 @@ class TrayBackground : public views::Background {
DISALLOW_COPY_AND_ASSIGN(TrayBackground);
};
// CloseBubbleObserver is used to delay closing the tray bubbles until the
// animation completes.
class CloseBubbleObserver : public ui::ImplicitAnimationObserver {
public:
explicit CloseBubbleObserver(TrayBackgroundView* tray_background_view)
: tray_background_view_(tray_background_view) {}
~CloseBubbleObserver() override = default;
void OnImplicitAnimationsCompleted() override {
tray_background_view_->CloseBubble();
delete this;
}
private:
TrayBackgroundView* tray_background_view_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(CloseBubbleObserver);
};
////////////////////////////////////////////////////////////////////////////////
// TrayBackgroundView
......@@ -298,14 +278,6 @@ const char* TrayBackgroundView::GetClassName() const {
return kViewClassName;
}
void TrayBackgroundView::OnGestureEvent(ui::GestureEvent* event) {
if (drag_controller())
drag_controller_->ProcessGestureEvent(event, this);
if (!event->handled())
ActionableView::OnGestureEvent(event);
}
void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) {
Shelf* shelf = Shelf::ForWindow(GetWidget()->GetNativeWindow());
StatusAreaWidgetDelegate* delegate =
......@@ -373,11 +345,6 @@ TrayBackgroundView::CreateInkDropHighlight() const {
return highlight;
}
void TrayBackgroundView::ProcessGestureEventForBubble(ui::GestureEvent* event) {
if (drag_controller())
drag_controller_->ProcessGestureEvent(event, this);
}
void TrayBackgroundView::OnVirtualKeyboardVisibilityChanged() {
if (show_with_virtual_keyboard_) {
// The view always shows up when virtual keyboard is visible if
......@@ -414,11 +381,6 @@ void TrayBackgroundView::UpdateAfterRootWindowBoundsChange(
// Do nothing by default. Child class may do something.
}
void TrayBackgroundView::AnchorUpdated() {
if (GetBubbleView())
UpdateClippingWindowBounds();
}
void TrayBackgroundView::BubbleResized(const TrayBubbleView* bubble_view) {}
void TrayBackgroundView::OnImplicitAnimationsCompleted() {
......@@ -493,50 +455,10 @@ gfx::Insets TrayBackgroundView::GetBubbleAnchorInsets() const {
}
}
void TrayBackgroundView::UpdateClippingWindowBounds() {
if (clipping_window_.get())
clipping_window_->SetBounds(shelf_->GetUserWorkAreaBounds());
}
aura::Window* TrayBackgroundView::GetBubbleWindowContainer() {
aura::Window* container = Shell::GetContainer(
return Shell::GetContainer(
tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(),
kShellWindowId_SettingBubbleContainer);
// Place the bubble in |container|, or in a window clipped to the work area
// in maximize mode, to avoid tray bubble and shelf overlap when dragging the
// bubble from the tray.
if (Shell::Get()
->tablet_mode_controller()
->IsTabletModeWindowManagerEnabled() &&
drag_controller()) {
if (!clipping_window_.get()) {
clipping_window_ = window_factory::NewWindow();
clipping_window_->Init(ui::LAYER_NOT_DRAWN);
clipping_window_->layer()->SetMasksToBounds(true);
container->AddChild(clipping_window_.get());
clipping_window_->Show();
}
clipping_window_->SetBounds(shelf_->GetUserWorkAreaBounds());
return clipping_window_.get();
}
return container;
}
void TrayBackgroundView::AnimateToTargetBounds(const gfx::Rect& target_bounds,
bool close_bubble) {
const int kAnimationDurationMS = 200;
ui::ScopedLayerAnimationSettings settings(
GetBubbleView()->GetWidget()->GetNativeView()->layer()->GetAnimator());
settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(kAnimationDurationMS));
settings.SetTweenType(gfx::Tween::EASE_OUT);
settings.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
if (close_bubble)
settings.AddObserver(new CloseBubbleObserver(this));
GetBubbleView()->GetWidget()->SetBounds(target_bounds);
}
gfx::Rect TrayBackgroundView::GetBackgroundBounds() const {
......
......@@ -12,7 +12,6 @@
#include "ash/system/model/virtual_keyboard_model.h"
#include "ash/system/tray/actionable_view.h"
#include "ash/system/tray/tray_bubble_view.h"
#include "ash/system/tray_drag_controller.h"
#include "base/macros.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/gfx/geometry/insets.h"
......@@ -47,7 +46,6 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// views::View:
void SetVisible(bool visible) override;
const char* GetClassName() const override;
void OnGestureEvent(ui::GestureEvent* event) override;
void AboutToRequestFocusFromTabTraversal(bool reverse) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
void Layout() override;
......@@ -58,9 +56,6 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override;
// TrayBubbleView::Delegate:
void ProcessGestureEventForBubble(ui::GestureEvent* event) override;
// VirtualKeyboardModel::Observer:
void OnVirtualKeyboardVisibilityChanged() override;
......@@ -84,7 +79,7 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
const gfx::Rect& new_bounds);
// Called when the anchor (tray or bubble) may have moved or changed.
virtual void AnchorUpdated();
virtual void AnchorUpdated() {}
// Called from GetAccessibleNodeData, must return a valid accessible name.
virtual base::string16 GetAccessibleNameForTray() = 0;
......@@ -126,26 +121,13 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// tray_container().
gfx::Insets GetBubbleAnchorInsets() const;
// Updates the |clipping_window_| bounds if the anchor moved or changed.
void UpdateClippingWindowBounds();
// Returns the container window for the bubble (on the proper display).
aura::Window* GetBubbleWindowContainer();
// Update the bounds of the associated tray bubble. Close the bubble if
// |close_bubble| is set.
void AnimateToTargetBounds(const gfx::Rect& target_bounds, bool close_bubble);
// Helper function that calculates background bounds relative to local bounds
// based on background insets returned from GetBackgroundInsets().
gfx::Rect GetBackgroundBounds() const;
aura::Window* clipping_window_for_test() const {
return clipping_window_.get();
}
TrayDragController* drag_controller() { return drag_controller_.get(); }
protected:
// ActionableView:
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
......@@ -155,11 +137,6 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
const ui::Event& event) override;
views::PaintInfo::ScaleType GetPaintScaleType() const override;
void set_drag_controller(
std::unique_ptr<TrayDragController> drag_controller) {
drag_controller_ = std::move(drag_controller);
}
void set_show_with_virtual_keyboard(bool show_with_virtual_keyboard) {
show_with_virtual_keyboard_ = show_with_virtual_keyboard;
}
......@@ -204,13 +181,6 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// If true, the view always shows up when virtual keyboard is visible.
bool show_with_virtual_keyboard_;
// Handles touch drag gestures on the tray area and its associated bubble.
std::unique_ptr<TrayDragController> drag_controller_;
// Used in maximize mode to make sure the system tray bubble only be shown in
// work area.
std::unique_ptr<aura::Window> clipping_window_;
std::unique_ptr<TrayWidgetObserver> widget_observer_;
std::unique_ptr<TrayEventFilter> tray_event_filter_;
......
......@@ -134,9 +134,6 @@ bool TrayBubbleView::Delegate::ShouldEnableExtraKeyboardAccessibility() {
void TrayBubbleView::Delegate::HideBubble(const TrayBubbleView* bubble_view) {}
void TrayBubbleView::Delegate::ProcessGestureEventForBubble(
ui::GestureEvent* event) {}
TrayBubbleView::InitParams::InitParams() = default;
TrayBubbleView::InitParams::InitParams(const InitParams& other) = default;
......@@ -443,11 +440,6 @@ void TrayBubbleView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
}
}
void TrayBubbleView::OnGestureEvent(ui::GestureEvent* event) {
if (delegate_)
delegate_->ProcessGestureEventForBubble(event);
}
void TrayBubbleView::MouseMovedOutOfHost() {
// The user moved the mouse that was over the bubble when it was first shown.
if (delegate_)
......
......@@ -78,10 +78,6 @@ class ASH_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView,
// child view was closed).
virtual void HideBubble(const TrayBubbleView* bubble_view);
// Called to process the gesture events that happened on the TrayBubbleView.
// Swiping down on the opened TrayBubbleView to close the bubble.
virtual void ProcessGestureEventForBubble(ui::GestureEvent* event);
private:
DISALLOW_COPY_AND_ASSIGN(Delegate);
};
......@@ -181,7 +177,6 @@ class ASH_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView,
void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(const ui::MouseEvent& event) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
void OnGestureEvent(ui::GestureEvent* event) override;
// Overridden from MouseWatcherListener
void MouseMovedOutOfHost() override;
......
......@@ -5,6 +5,7 @@
#include "ash/system/tray/tray_event_filter.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/unified/unified_system_tray.h"
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/tray_drag_controller.h"
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/shell.h"
#include "ash/system/tray/tray_background_view.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
namespace ash {
TrayDragController::TrayDragController(Shelf* shelf) : shelf_(shelf) {}
void TrayDragController::ProcessGestureEvent(ui::GestureEvent* event,
TrayBackgroundView* tray_view) {
if (!Shell::Get()
->tablet_mode_controller()
->IsTabletModeWindowManagerEnabled() ||
!shelf_->IsHorizontalAlignment()) {
return;
}
// Disable the tray view swiping if the app list is opened.
if (Shell::Get()->app_list_controller()->IsVisible())
return;
tray_view_ = tray_view;
is_on_bubble_ = event->target() != tray_view;
if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
StartGestureDrag(*event);
// Should not handle the event if the scroll sequence begins to scroll
// upward on the tray view, let the shelf handle the event instead.
if (!is_on_bubble_ && event->details().scroll_y_hint() > 0)
return;
event->SetHandled();
return;
}
if (!tray_view_->GetBubbleView() || !is_in_drag_)
return;
if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
UpdateGestureDrag(*event);
event->SetHandled();
return;
}
if (event->type() == ui::ET_GESTURE_SCROLL_END ||
event->type() == ui::ET_SCROLL_FLING_START) {
CompleteGestureDrag(*event);
event->SetHandled();
return;
}
// Unexpected event. Reset the drag state and close the bubble.
is_in_drag_ = false;
tray_view_->CloseBubble();
}
void TrayDragController::StartGestureDrag(const ui::GestureEvent& gesture) {
if (!is_on_bubble_) {
// Dragging on the tray view when the tray bubble is opened should do
// nothing.
if (tray_view_->GetBubbleView())
return;
// Should not open the tray bubble if the scroll sequence begins to scroll
// downward. The event will instead handled by the shelf.
if (gesture.details().scroll_y_hint() > 0)
return;
tray_view_->ShowBubble(true /* show_by_click */);
}
if (!tray_view_->GetBubbleView())
return;
is_in_drag_ = true;
gesture_drag_amount_ = 0.f;
tray_bubble_bounds_ =
tray_view_->GetBubbleView()->GetWidget()->GetWindowBoundsInScreen();
UpdateBubbleBounds();
}
void TrayDragController::UpdateGestureDrag(const ui::GestureEvent& gesture) {
gesture_drag_amount_ += gesture.details().scroll_y();
UpdateBubbleBounds();
}
void TrayDragController::CompleteGestureDrag(const ui::GestureEvent& gesture) {
const bool hide_bubble = !ShouldShowBubbleAfterScrollSequence(gesture);
gfx::Rect target_bounds = tray_bubble_bounds_;
if (hide_bubble)
target_bounds.set_y(shelf_->GetIdealBounds().y());
tray_view_->AnimateToTargetBounds(target_bounds, hide_bubble);
is_in_drag_ = false;
UserMetricsRecorder* metrics = Shell::Get()->metrics();
if (is_on_bubble_) {
metrics->RecordUserMetricsAction(
hide_bubble ? UMA_TRAY_SWIPE_TO_CLOSE_SUCCESSFUL
: UMA_TRAY_SWIPE_TO_CLOSE_UNSUCCESSFUL);
} else {
metrics->RecordUserMetricsAction(hide_bubble
? UMA_TRAY_SWIPE_TO_OPEN_UNSUCCESSFUL
: UMA_TRAY_SWIPE_TO_OPEN_SUCCESSFUL);
}
}
void TrayDragController::UpdateBubbleBounds() {
DCHECK(tray_view_->GetBubbleView());
gfx::Rect current_tray_bubble_bounds = tray_bubble_bounds_;
const int bounds_y =
(is_on_bubble_ ? tray_bubble_bounds_.y() : shelf_->GetIdealBounds().y()) +
gesture_drag_amount_;
current_tray_bubble_bounds.set_y(std::max(bounds_y, tray_bubble_bounds_.y()));
tray_view_->GetBubbleView()->GetWidget()->SetBounds(
current_tray_bubble_bounds);
}
bool TrayDragController::ShouldShowBubbleAfterScrollSequence(
const ui::GestureEvent& sequence_end) {
// If the scroll sequence terminates with a fling, show the bubble if the
// fling was fast enough and in the correct direction.
if (sequence_end.type() == ui::ET_SCROLL_FLING_START &&
fabs(sequence_end.details().velocity_y()) > kFlingVelocity) {
return sequence_end.details().velocity_y() < 0;
}
DCHECK(sequence_end.type() == ui::ET_GESTURE_SCROLL_END ||
sequence_end.type() == ui::ET_SCROLL_FLING_START);
// Keep the bubble's original state if the |gesture_drag_amount_| doesn't
// exceed one-third of the bubble's height.
if (is_on_bubble_)
return gesture_drag_amount_ < tray_bubble_bounds_.height() / 3.0;
return -gesture_drag_amount_ >= tray_bubble_bounds_.height() / 3.0;
}
} // namespace ash
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_TRAY_DRAG_CONTROLLER_H_
#define ASH_SYSTEM_TRAY_DRAG_CONTROLLER_H_
#include "ash/ash_export.h"
#include "ash/shelf/shelf.h"
#include "ui/views/view.h"
namespace ash {
class TrayBackgroundView;
// The TrayDragController helps to process the swiping events that happened on
// TrayBackgroundView or TrayBubbleView. Not all the TrayBackgroundView can be
// dragged currently. Only ImeMenuTray, SystemTray, PaletteTray,
// NotificationTray and their associated tray bubbles can be dragged.
class ASH_EXPORT TrayDragController {
public:
// The threshold of the velocity of the fling event.
static constexpr float kFlingVelocity = 100.0f;
explicit TrayDragController(Shelf* shelf);
// Processes a gesture event and updates the dragging state of the bubble when
// appropriate.
void ProcessGestureEvent(ui::GestureEvent* event,
TrayBackgroundView* tray_view);
private:
// Gesture related functions:
void StartGestureDrag(const ui::GestureEvent& gesture);
void UpdateGestureDrag(const ui::GestureEvent& gesture);
void CompleteGestureDrag(const ui::GestureEvent& gesture);
// Update the bounds of the tray bubble according to
// |gesture_drag_amount_|.
void UpdateBubbleBounds();
// Return true if the bubble should be shown (i.e., animated upward to
// be made fully visible) after a sequence of scroll events terminated by
// |sequence_end|. Otherwise return false, indicating that the
// partially-visible bubble should be animated downward and made fully
// hidden.
bool ShouldShowBubbleAfterScrollSequence(
const ui::GestureEvent& sequence_end);
// The shelf containing the TrayBackgroundView.
Shelf* shelf_;
// The specific TrayBackgroundView that dragging happened on. e.g, SystemTray.
TrayBackgroundView* tray_view_ = nullptr;
// The original bounds of the tray bubble.
gfx::Rect tray_bubble_bounds_;
// Tracks the amount of the drag. Only valid if |is_in_drag_| is true.
float gesture_drag_amount_ = 0.f;
// True if the user is in the process of gesture-dragging on
// TrayBackgroundView to open the tray bubble, or on the already-opened
// TrayBubbleView to close it. Otherwise false.
bool is_in_drag_ = false;
// True if the dragging happened on the bubble view, false if it happened on
// the tray view. Note, only valid if |is_in_drag_| is true.
bool is_on_bubble_ = false;
DISALLOW_COPY_AND_ASSIGN(TrayDragController);
};
} // namespace ash
#endif // ASH_SYSTEM_TRAY_DRAG_CONTROLLER_H_
......@@ -7,6 +7,7 @@
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/system/brightness/unified_brightness_slider_controller.h"
#include "ash/system/keyboard_brightness/unified_keyboard_brightness_slider_controller.h"
......
......@@ -5,6 +5,7 @@
#include "ash/system/unified/unified_system_tray.h"
#include "ash/accessibility/accessibility_controller.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/date/date_view.h"
......
......@@ -5,6 +5,7 @@
#include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/tray_constants.h"
......
......@@ -19971,6 +19971,10 @@ should be able to be added at any place in this file.
</action>
<action name="Tray_SwipeToClose_Successful">
<obsolete>
No longer needed since swipe on the tray bubble to close it has been
disabled and unified system tray has been launched.
</obsolete>
<owner>omrilio@chromium.org</owner>
<owner>minch@chromium.org</owner>
<description>
......@@ -19981,6 +19985,10 @@ should be able to be added at any place in this file.
</action>
<action name="Tray_SwipeToClose_Unsuccessful">
<obsolete>
No longer needed since swipe on the tray bubble to close has been disabled
and unified system tray has been launched.
</obsolete>
<owner>omrilio@chromium.org</owner>
<owner>minch@chromium.org</owner>
<description>
......@@ -19991,6 +19999,10 @@ should be able to be added at any place in this file.
</action>
<action name="Tray_SwipeToOpen_Successful">
<obsolete>
No longer needed since swipe on the status area tray to open it has been
disabled and unified system tray has been launched.
</obsolete>
<owner>omrilio@chromium.org</owner>
<owner>minch@chromium.org</owner>
<description>
......@@ -20001,6 +20013,10 @@ should be able to be added at any place in this file.
</action>
<action name="Tray_SwipeToOpen_Unsuccessful">
<obsolete>
No longer needed since swipe on the status area tray to open it has been
disabled and unified system tray has been launched.
</obsolete>
<owner>omrilio@chromium.org</owner>
<owner>minch@chromium.org</owner>
<description>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment