Commit 5ff2e973 authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Commit Bot

overview gesture: adjust the fling event.

For a fling event, if the hotseat was hidden when the drag started,
only if the fling event position exceeds the restore-to-maximized
threshold, the window will be taken back to home screen.

Also, remove the logic to decide if drag can be allowed from
DragWindowFromShelfController as ShelfLayoutManager already handled it.

Bug: 997885
Change-Id: I35b9c35df1477b92b5c01db49c9302b6f3bace60
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1902176
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713677}
parent 8ba9e7e0
...@@ -46,6 +46,12 @@ constexpr float kMinimumWindowScaleDuringDragging = 0.2f; ...@@ -46,6 +46,12 @@ constexpr float kMinimumWindowScaleDuringDragging = 0.2f;
constexpr base::TimeDelta kShowOverviewTimeWhenDragSuspend = constexpr base::TimeDelta kShowOverviewTimeWhenDragSuspend =
base::TimeDelta::FromMilliseconds(40); base::TimeDelta::FromMilliseconds(40);
// The distance for the dragged window to pass over the bottom of the display
// so that it can be dragged into home launcher or overview. If not pass this
// value, the window will snap back to its original position.
constexpr float kReturnToMaximizedDenseThreshold = 152.f;
constexpr float kReturnToMaximizedStandardThreshold = 164.f;
} // namespace } // namespace
// Hide all visible windows expect the dragged windows or the window showing in // Hide all visible windows expect the dragged windows or the window showing in
...@@ -105,10 +111,20 @@ class DragWindowFromShelfController::WindowsHider ...@@ -105,10 +111,20 @@ class DragWindowFromShelfController::WindowsHider
DISALLOW_COPY_AND_ASSIGN(WindowsHider); DISALLOW_COPY_AND_ASSIGN(WindowsHider);
}; };
// static
float DragWindowFromShelfController::GetReturnToMaximizedThreshold() {
return ShelfConfig::Get()->is_dense() ? kReturnToMaximizedDenseThreshold
: kReturnToMaximizedStandardThreshold;
}
DragWindowFromShelfController::DragWindowFromShelfController( DragWindowFromShelfController::DragWindowFromShelfController(
aura::Window* window) aura::Window* window,
: window_(window) { const gfx::Point& location_in_screen,
HotseatState hotseat_state)
: window_(window), hotseat_state_(hotseat_state) {
DCHECK_NE(hotseat_state, HotseatState::kShown);
window_->AddObserver(this); window_->AddObserver(this);
OnDragStarted(location_in_screen);
} }
DragWindowFromShelfController::~DragWindowFromShelfController() { DragWindowFromShelfController::~DragWindowFromShelfController() {
...@@ -124,17 +140,9 @@ void DragWindowFromShelfController::Drag(const gfx::Point& location_in_screen, ...@@ -124,17 +140,9 @@ void DragWindowFromShelfController::Drag(const gfx::Point& location_in_screen,
if (!window_) if (!window_)
return; return;
if (!drag_started_) { // TODO(xdai): clean up |drag_started_| variable.
// Do not start drag until the drag goes above the hotseat. if (!drag_started_)
const gfx::Rect work_area =
screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
window_);
if (location_in_screen.y() >
work_area.bottom() - ShelfConfig::Get()->hotseat_size()) {
return; return;
}
OnDragStarted(location_in_screen);
}
UpdateDraggedWindow(location_in_screen); UpdateDraggedWindow(location_in_screen);
...@@ -206,7 +214,7 @@ void DragWindowFromShelfController::EndDrag( ...@@ -206,7 +214,7 @@ void DragWindowFromShelfController::EndDrag(
const bool in_overview = overview_controller->InOverviewSession(); const bool in_overview = overview_controller->InOverviewSession();
const bool in_splitview = split_view_controller->InSplitViewMode(); const bool in_splitview = split_view_controller->InSplitViewMode();
if (ShouldGoToHomeScreen(velocity_y)) { if (ShouldGoToHomeScreen(location_in_screen, velocity_y)) {
DCHECK(!in_splitview); DCHECK(!in_splitview);
if (in_overview) { if (in_overview) {
overview_controller->EndOverview( overview_controller->EndOverview(
...@@ -397,7 +405,7 @@ SplitViewController::SnapPosition ...@@ -397,7 +405,7 @@ SplitViewController::SnapPosition
DragWindowFromShelfController::GetSnapPosition( DragWindowFromShelfController::GetSnapPosition(
const gfx::Point& location_in_screen) const { const gfx::Point& location_in_screen) const {
// if |location_in_screen| is close to the bottom of the screen and is // if |location_in_screen| is close to the bottom of the screen and is
// inside of kReturnToMaximizedThreshold threshold, we should not try to // inside of GetReturnToMaximizedThreshold() threshold, we should not try to
// snap the window. // snap the window.
if (ShouldRestoreToOriginalBounds(location_in_screen)) if (ShouldRestoreToOriginalBounds(location_in_screen))
return SplitViewController::NONE; return SplitViewController::NONE;
...@@ -423,15 +431,25 @@ DragWindowFromShelfController::GetSnapPosition( ...@@ -423,15 +431,25 @@ DragWindowFromShelfController::GetSnapPosition(
bool DragWindowFromShelfController::ShouldRestoreToOriginalBounds( bool DragWindowFromShelfController::ShouldRestoreToOriginalBounds(
const gfx::Point& location_in_screen) const { const gfx::Point& location_in_screen) const {
const gfx::Rect work_area = display::Screen::GetScreen() const gfx::Rect display_bounds =
display::Screen::GetScreen()
->GetDisplayNearestPoint(location_in_screen) ->GetDisplayNearestPoint(location_in_screen)
.work_area(); .bounds();
return location_in_screen.y() > return location_in_screen.y() >
work_area.bottom() - kReturnToMaximizedThreshold; display_bounds.bottom() - GetReturnToMaximizedThreshold();
} }
bool DragWindowFromShelfController::ShouldGoToHomeScreen( bool DragWindowFromShelfController::ShouldGoToHomeScreen(
const gfx::Point& location_in_screen,
base::Optional<float> velocity_y) const { base::Optional<float> velocity_y) const {
// For a hidden hotseat, if the event end position does not exceed
// GetReturnToMaximizedThreshold(), it should restore back to the maximized
// bounds even though the velocity might be large.
if (hotseat_state_ == HotseatState::kHidden &&
ShouldRestoreToOriginalBounds(location_in_screen)) {
return false;
}
return velocity_y.has_value() && *velocity_y < 0 && return velocity_y.has_value() && *velocity_y < 0 &&
std::abs(*velocity_y) >= kVelocityToHomeScreenThreshold && std::abs(*velocity_y) >= kVelocityToHomeScreenThreshold &&
!SplitViewController::Get(Shell::GetPrimaryRootWindow()) !SplitViewController::Get(Shell::GetPrimaryRootWindow())
...@@ -443,7 +461,7 @@ DragWindowFromShelfController::GetSnapPositionOnDragEnd( ...@@ -443,7 +461,7 @@ DragWindowFromShelfController::GetSnapPositionOnDragEnd(
const gfx::Point& location_in_screen, const gfx::Point& location_in_screen,
base::Optional<float> velocity_y) const { base::Optional<float> velocity_y) const {
if (ShouldRestoreToOriginalBounds(location_in_screen) || if (ShouldRestoreToOriginalBounds(location_in_screen) ||
ShouldGoToHomeScreen(velocity_y)) { ShouldGoToHomeScreen(location_in_screen, velocity_y)) {
return SplitViewController::NONE; return SplitViewController::NONE;
} }
...@@ -456,7 +474,7 @@ bool DragWindowFromShelfController::ShouldDropWindowInOverview( ...@@ -456,7 +474,7 @@ bool DragWindowFromShelfController::ShouldDropWindowInOverview(
if (!Shell::Get()->overview_controller()->InOverviewSession()) if (!Shell::Get()->overview_controller()->InOverviewSession())
return false; return false;
if (ShouldGoToHomeScreen(velocity_y)) if (ShouldGoToHomeScreen(location_in_screen, velocity_y))
return false; return false;
const bool in_splitview = const bool in_splitview =
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <vector> #include <vector>
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/public/cpp/shelf_types.h"
#include "ash/public/cpp/window_properties.h" #include "ash/public/cpp/window_properties.h"
#include "ash/wm/splitview/split_view_controller.h" #include "ash/wm/splitview/split_view_controller.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -26,11 +27,6 @@ namespace ash { ...@@ -26,11 +27,6 @@ namespace ash {
// swiping up from the shelf to homescreen, overview or splitview. // swiping up from the shelf to homescreen, overview or splitview.
class ASH_EXPORT DragWindowFromShelfController : public aura::WindowObserver { class ASH_EXPORT DragWindowFromShelfController : public aura::WindowObserver {
public: public:
// The distance for the dragged window to pass over shelf so that it can be
// dragged into home launcher or overview. If not pass this value, the window
// will snap back to its original position.
static constexpr float kReturnToMaximizedThreshold = 116;
// The deceleration threshold to open overview behind the dragged window // The deceleration threshold to open overview behind the dragged window
// when swiping up from the shelf to drag the active window. // when swiping up from the shelf to drag the active window.
static constexpr float kOpenOverviewThreshold = 10.f; static constexpr float kOpenOverviewThreshold = 10.f;
...@@ -47,7 +43,15 @@ class ASH_EXPORT DragWindowFromShelfController : public aura::WindowObserver { ...@@ -47,7 +43,15 @@ class ASH_EXPORT DragWindowFromShelfController : public aura::WindowObserver {
// view is active during dragging. // view is active during dragging.
static constexpr float kVelocityToOverviewThreshold = 1000.f; static constexpr float kVelocityToOverviewThreshold = 1000.f;
explicit DragWindowFromShelfController(aura::Window* window); // The distance for the dragged window to pass over the bottom of the display
// so that it can be dragged into home launcher or overview. If not pass this
// value, the window will snap back to its original position. The value is
// different for standard or dense shelf.
static float GetReturnToMaximizedThreshold();
DragWindowFromShelfController(aura::Window* window,
const gfx::Point& location_in_screen,
HotseatState hotseat_state);
~DragWindowFromShelfController() override; ~DragWindowFromShelfController() override;
// Called during swiping up on the shelf. // Called during swiping up on the shelf.
...@@ -81,7 +85,7 @@ class ASH_EXPORT DragWindowFromShelfController : public aura::WindowObserver { ...@@ -81,7 +85,7 @@ class ASH_EXPORT DragWindowFromShelfController : public aura::WindowObserver {
// Returns true if the dragged window should restore to its original bounds // Returns true if the dragged window should restore to its original bounds
// after drag ends. Happens when |location_in_screen| is within // after drag ends. Happens when |location_in_screen| is within
// kReturnToMaximizedThreshold threshold. // GetReturnToMaximizedThreshold() threshold.
bool ShouldRestoreToOriginalBounds( bool ShouldRestoreToOriginalBounds(
const gfx::Point& location_in_screen) const; const gfx::Point& location_in_screen) const;
...@@ -89,7 +93,8 @@ class ASH_EXPORT DragWindowFromShelfController : public aura::WindowObserver { ...@@ -89,7 +93,8 @@ class ASH_EXPORT DragWindowFromShelfController : public aura::WindowObserver {
// the upward vertical velocity is larger than kVelocityToHomeScreenThreshold // the upward vertical velocity is larger than kVelocityToHomeScreenThreshold
// and splitview is not active. Note when splitview is active, we do not allow // and splitview is not active. Note when splitview is active, we do not allow
// to go to home screen by fling. // to go to home screen by fling.
bool ShouldGoToHomeScreen(base::Optional<float> velocity_y) const; bool ShouldGoToHomeScreen(const gfx::Point& location_in_screen,
base::Optional<float> velocity_y) const;
// Returns the desired snap position on |location_in_screen| when drag ends. // Returns the desired snap position on |location_in_screen| when drag ends.
SplitViewController::SnapPosition GetSnapPositionOnDragEnd( SplitViewController::SnapPosition GetSnapPositionOnDragEnd(
...@@ -125,6 +130,9 @@ class ASH_EXPORT DragWindowFromShelfController : public aura::WindowObserver { ...@@ -125,6 +130,9 @@ class ASH_EXPORT DragWindowFromShelfController : public aura::WindowObserver {
// Timer to show and update overview. // Timer to show and update overview.
base::OneShotTimer show_overview_timer_; base::OneShotTimer show_overview_timer_;
// The hotseat state when drag starts.
const HotseatState hotseat_state_;
DISALLOW_COPY_AND_ASSIGN(DragWindowFromShelfController); DISALLOW_COPY_AND_ASSIGN(DragWindowFromShelfController);
}; };
......
...@@ -141,6 +141,8 @@ class ASH_EXPORT ShelfConfig : public TabletModeObserver, ...@@ -141,6 +141,8 @@ class ASH_EXPORT ShelfConfig : public TabletModeObserver,
return mousewheel_scroll_offset_threshold_; return mousewheel_scroll_offset_threshold_;
} }
bool is_dense() const { return is_dense_; }
// Gets the current color for the shelf control buttons. // Gets the current color for the shelf control buttons.
SkColor GetShelfControlButtonColor() const; SkColor GetShelfControlButtonColor() const;
......
...@@ -2456,8 +2456,8 @@ bool ShelfLayoutManager::MaybeStartDragWindowFromShelf( ...@@ -2456,8 +2456,8 @@ bool ShelfLayoutManager::MaybeStartDragWindowFromShelf(
if (!window) if (!window)
return false; return false;
window_drag_controller_ = window_drag_controller_ = std::make_unique<DragWindowFromShelfController>(
std::make_unique<DragWindowFromShelfController>(window); window, event_in_screen.location(), hotseat_state());
return true; return true;
} }
......
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