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);
}; };
......
...@@ -35,9 +35,11 @@ class DragWindowFromShelfControllerTest : public AshTestBase { ...@@ -35,9 +35,11 @@ class DragWindowFromShelfControllerTest : public AshTestBase {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
void StartDrag(aura::Window* window) { void StartDrag(aura::Window* window,
window_drag_controller_ = const gfx::Point& location_in_screen,
std::make_unique<DragWindowFromShelfController>(window); HotseatState hotseat_state) {
window_drag_controller_ = std::make_unique<DragWindowFromShelfController>(
window, location_in_screen, hotseat_state);
} }
void Drag(const gfx::Point& location_in_screen, void Drag(const gfx::Point& location_in_screen,
float scroll_x, float scroll_x,
...@@ -77,7 +79,7 @@ TEST_F(DragWindowFromShelfControllerTest, HideWindowDuringWindowDragging) { ...@@ -77,7 +79,7 @@ TEST_F(DragWindowFromShelfControllerTest, HideWindowDuringWindowDragging) {
EXPECT_TRUE(window2->IsVisible()); EXPECT_TRUE(window2->IsVisible());
EXPECT_TRUE(window3->IsVisible()); EXPECT_TRUE(window3->IsVisible());
StartDrag(window1.get()); StartDrag(window1.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 1.f, 1.f); Drag(gfx::Point(200, 200), 1.f, 1.f);
EXPECT_TRUE(window1->IsVisible()); EXPECT_TRUE(window1->IsVisible());
EXPECT_FALSE(window2->IsVisible()); EXPECT_FALSE(window2->IsVisible());
...@@ -91,7 +93,7 @@ TEST_F(DragWindowFromShelfControllerTest, HideWindowDuringWindowDragging) { ...@@ -91,7 +93,7 @@ TEST_F(DragWindowFromShelfControllerTest, HideWindowDuringWindowDragging) {
split_view_controller()->SnapWindow(window1.get(), SplitViewController::LEFT); split_view_controller()->SnapWindow(window1.get(), SplitViewController::LEFT);
split_view_controller()->SnapWindow(window2.get(), split_view_controller()->SnapWindow(window2.get(),
SplitViewController::RIGHT); SplitViewController::RIGHT);
StartDrag(window1.get()); StartDrag(window1.get(), shelf_bounds.left_center(), HotseatState::kExtended);
Drag(gfx::Point(0, 200), 1.f, 1.f); Drag(gfx::Point(0, 200), 1.f, 1.f);
EXPECT_TRUE(window1->IsVisible()); EXPECT_TRUE(window1->IsVisible());
EXPECT_TRUE(window2->IsVisible()); EXPECT_TRUE(window2->IsVisible());
...@@ -101,7 +103,8 @@ TEST_F(DragWindowFromShelfControllerTest, HideWindowDuringWindowDragging) { ...@@ -101,7 +103,8 @@ TEST_F(DragWindowFromShelfControllerTest, HideWindowDuringWindowDragging) {
EXPECT_TRUE(window2->IsVisible()); EXPECT_TRUE(window2->IsVisible());
EXPECT_TRUE(window3->IsVisible()); EXPECT_TRUE(window3->IsVisible());
StartDrag(window2.get()); StartDrag(window2.get(), shelf_bounds.right_center(),
HotseatState::kExtended);
Drag(gfx::Point(400, 200), 1.f, 1.f); Drag(gfx::Point(400, 200), 1.f, 1.f);
EXPECT_TRUE(window1->IsVisible()); EXPECT_TRUE(window1->IsVisible());
EXPECT_TRUE(window2->IsVisible()); EXPECT_TRUE(window2->IsVisible());
...@@ -118,7 +121,7 @@ TEST_F(DragWindowFromShelfControllerTest, HideHomeLauncherDuringDraggingTest) { ...@@ -118,7 +121,7 @@ TEST_F(DragWindowFromShelfControllerTest, HideHomeLauncherDuringDraggingTest) {
const gfx::Rect shelf_bounds = const gfx::Rect shelf_bounds =
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds(); Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
auto window = CreateTestWindow(); auto window = CreateTestWindow();
StartDrag(window.get()); StartDrag(window.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(0, 200), 0.f, 1.f); Drag(gfx::Point(0, 200), 0.f, 1.f);
aura::Window* home_screen_window = aura::Window* home_screen_window =
Shell::Get()->home_screen_controller()->delegate()->GetHomeScreenWindow(); Shell::Get()->home_screen_controller()->delegate()->GetHomeScreenWindow();
...@@ -141,14 +144,14 @@ TEST_F(DragWindowFromShelfControllerTest, MayOrMayNotReShowHiddenWindows) { ...@@ -141,14 +144,14 @@ TEST_F(DragWindowFromShelfControllerTest, MayOrMayNotReShowHiddenWindows) {
// If the dragged window restores to its original position, reshow the hidden // If the dragged window restores to its original position, reshow the hidden
// windows. // windows.
StartDrag(window1.get()); StartDrag(window1.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 0.f, 1.f); Drag(gfx::Point(200, 200), 0.f, 1.f);
EXPECT_FALSE(window2->IsVisible()); EXPECT_FALSE(window2->IsVisible());
EndDrag(shelf_bounds.CenterPoint(), base::nullopt); EndDrag(shelf_bounds.CenterPoint(), base::nullopt);
EXPECT_TRUE(window2->IsVisible()); EXPECT_TRUE(window2->IsVisible());
// If fling to homescreen, do not reshow the hidden windows. // If fling to homescreen, do not reshow the hidden windows.
StartDrag(window1.get()); StartDrag(window1.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 0.f, 1.f); Drag(gfx::Point(200, 200), 0.f, 1.f);
EXPECT_FALSE(window2->IsVisible()); EXPECT_FALSE(window2->IsVisible());
EndDrag(gfx::Point(200, 200), EndDrag(gfx::Point(200, 200),
...@@ -160,7 +163,7 @@ TEST_F(DragWindowFromShelfControllerTest, MayOrMayNotReShowHiddenWindows) { ...@@ -160,7 +163,7 @@ TEST_F(DragWindowFromShelfControllerTest, MayOrMayNotReShowHiddenWindows) {
// windows. // windows.
window2->Show(); window2->Show();
window1->Show(); window1->Show();
StartDrag(window1.get()); StartDrag(window1.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 0.f, 1.f); Drag(gfx::Point(200, 200), 0.f, 1.f);
EXPECT_FALSE(window2->IsVisible()); EXPECT_FALSE(window2->IsVisible());
OverviewController* overview_controller = Shell::Get()->overview_controller(); OverviewController* overview_controller = Shell::Get()->overview_controller();
...@@ -176,7 +179,7 @@ TEST_F(DragWindowFromShelfControllerTest, MayOrMayNotReShowHiddenWindows) { ...@@ -176,7 +179,7 @@ TEST_F(DragWindowFromShelfControllerTest, MayOrMayNotReShowHiddenWindows) {
// showing in overview, do not reshow the hidden windows. // showing in overview, do not reshow the hidden windows.
window2->Show(); window2->Show();
window1->Show(); window1->Show();
StartDrag(window1.get()); StartDrag(window1.get(), shelf_bounds.left_center(), HotseatState::kExtended);
Drag(gfx::Point(0, 200), 0.f, 1.f); Drag(gfx::Point(0, 200), 0.f, 1.f);
EXPECT_FALSE(window2->IsVisible()); EXPECT_FALSE(window2->IsVisible());
EXPECT_TRUE(overview_controller->InOverviewSession()); EXPECT_TRUE(overview_controller->InOverviewSession());
...@@ -191,14 +194,13 @@ TEST_F(DragWindowFromShelfControllerTest, MayOrMayNotReShowHiddenWindows) { ...@@ -191,14 +194,13 @@ TEST_F(DragWindowFromShelfControllerTest, MayOrMayNotReShowHiddenWindows) {
// show correctly in overview. // show correctly in overview.
TEST_F(DragWindowFromShelfControllerTest, MinimizedWindowsShowInOverview) { TEST_F(DragWindowFromShelfControllerTest, MinimizedWindowsShowInOverview) {
UpdateDisplay("400x400"); UpdateDisplay("400x400");
const gfx::Rect shelf_bounds =
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
auto window3 = CreateTestWindow(); auto window3 = CreateTestWindow();
auto window2 = CreateTestWindow(); auto window2 = CreateTestWindow();
auto window1 = CreateTestWindow(); auto window1 = CreateTestWindow();
StartDrag(window1.get()); StartDrag(window1.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
EXPECT_TRUE(window1->IsVisible());
EXPECT_TRUE(window2->IsVisible());
EXPECT_TRUE(window3->IsVisible());
// Drag it far enough so overview should be open behind the dragged window. // Drag it far enough so overview should be open behind the dragged window.
Drag(gfx::Point(200, 200), 0.f, 1.f); Drag(gfx::Point(200, 200), 0.f, 1.f);
OverviewController* overview_controller = Shell::Get()->overview_controller(); OverviewController* overview_controller = Shell::Get()->overview_controller();
...@@ -224,9 +226,11 @@ TEST_F(DragWindowFromShelfControllerTest, MinimizedWindowsShowInOverview) { ...@@ -224,9 +226,11 @@ TEST_F(DragWindowFromShelfControllerTest, MinimizedWindowsShowInOverview) {
// delta (velocity) decrease to kOpenOverviewThreshold or less. // delta (velocity) decrease to kOpenOverviewThreshold or less.
TEST_F(DragWindowFromShelfControllerTest, OpenOverviewWhenHold) { TEST_F(DragWindowFromShelfControllerTest, OpenOverviewWhenHold) {
UpdateDisplay("400x400"); UpdateDisplay("400x400");
const gfx::Rect shelf_bounds =
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
auto window = CreateTestWindow(); auto window = CreateTestWindow();
StartDrag(window.get()); StartDrag(window.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 0.f, Drag(gfx::Point(200, 200), 0.f,
DragWindowFromShelfController::kOpenOverviewThreshold + 1); DragWindowFromShelfController::kOpenOverviewThreshold + 1);
OverviewController* overview_controller = Shell::Get()->overview_controller(); OverviewController* overview_controller = Shell::Get()->overview_controller();
...@@ -241,13 +245,15 @@ TEST_F(DragWindowFromShelfControllerTest, OpenOverviewWhenHold) { ...@@ -241,13 +245,15 @@ TEST_F(DragWindowFromShelfControllerTest, OpenOverviewWhenHold) {
// kReturnToMaximizedThreshold, it will restore back to its original position. // kReturnToMaximizedThreshold, it will restore back to its original position.
TEST_F(DragWindowFromShelfControllerTest, RestoreWindowToOriginalBounds) { TEST_F(DragWindowFromShelfControllerTest, RestoreWindowToOriginalBounds) {
UpdateDisplay("400x400"); UpdateDisplay("400x400");
const gfx::Rect shelf_bounds =
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
auto window = CreateTestWindow(); auto window = CreateTestWindow();
const gfx::Rect work_area = display::Screen::GetScreen() const gfx::Rect display_bounds = display::Screen::GetScreen()
->GetDisplayNearestWindow(window.get()) ->GetDisplayNearestWindow(window.get())
.work_area(); .bounds();
// Drag it for a small distance and then release. // Drag it for a small distance and then release.
StartDrag(window.get()); StartDrag(window.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 0.f, Drag(gfx::Point(200, 200), 0.f,
DragWindowFromShelfController::kShowOverviewThreshold + 1); DragWindowFromShelfController::kShowOverviewThreshold + 1);
EXPECT_FALSE(window->layer()->GetTargetTransform().IsIdentity()); EXPECT_FALSE(window->layer()->GetTargetTransform().IsIdentity());
...@@ -258,14 +264,15 @@ TEST_F(DragWindowFromShelfControllerTest, RestoreWindowToOriginalBounds) { ...@@ -258,14 +264,15 @@ TEST_F(DragWindowFromShelfControllerTest, RestoreWindowToOriginalBounds) {
EXPECT_TRUE(WindowState::Get(window.get())->IsMaximized()); EXPECT_TRUE(WindowState::Get(window.get())->IsMaximized());
// Drag it for a large distance and then drag back to release. // Drag it for a large distance and then drag back to release.
StartDrag(window.get()); StartDrag(window.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 0.f, 1.f); Drag(gfx::Point(200, 200), 0.f, 1.f);
EXPECT_FALSE(window->layer()->GetTargetTransform().IsIdentity()); EXPECT_FALSE(window->layer()->GetTargetTransform().IsIdentity());
EXPECT_TRUE(overview_controller->InOverviewSession()); EXPECT_TRUE(overview_controller->InOverviewSession());
EndDrag( EndDrag(
gfx::Point( gfx::Point(
200, work_area.bottom() - 200,
DragWindowFromShelfController::kReturnToMaximizedThreshold + display_bounds.bottom() -
DragWindowFromShelfController::GetReturnToMaximizedThreshold() +
1), 1),
base::nullopt); base::nullopt);
EXPECT_TRUE(window->layer()->GetTargetTransform().IsIdentity()); EXPECT_TRUE(window->layer()->GetTargetTransform().IsIdentity());
...@@ -277,7 +284,7 @@ TEST_F(DragWindowFromShelfControllerTest, RestoreWindowToOriginalBounds) { ...@@ -277,7 +284,7 @@ TEST_F(DragWindowFromShelfControllerTest, RestoreWindowToOriginalBounds) {
split_view_controller()->SnapWindow(window.get(), SplitViewController::LEFT); split_view_controller()->SnapWindow(window.get(), SplitViewController::LEFT);
split_view_controller()->SnapWindow(window2.get(), split_view_controller()->SnapWindow(window2.get(),
SplitViewController::RIGHT); SplitViewController::RIGHT);
StartDrag(window.get()); StartDrag(window.get(), shelf_bounds.left_center(), HotseatState::kExtended);
Drag(gfx::Point(0, 200), 0.f, 1.f); Drag(gfx::Point(0, 200), 0.f, 1.f);
EXPECT_FALSE(window->layer()->GetTargetTransform().IsIdentity()); EXPECT_FALSE(window->layer()->GetTargetTransform().IsIdentity());
EXPECT_TRUE(overview_controller->InOverviewSession()); EXPECT_TRUE(overview_controller->InOverviewSession());
...@@ -292,11 +299,13 @@ TEST_F(DragWindowFromShelfControllerTest, RestoreWindowToOriginalBounds) { ...@@ -292,11 +299,13 @@ TEST_F(DragWindowFromShelfControllerTest, RestoreWindowToOriginalBounds) {
// TODO(https://crbug.com/1019080) This test is flaky. // TODO(https://crbug.com/1019080) This test is flaky.
TEST_F(DragWindowFromShelfControllerTest, DISABLED_FlingInOverview) { TEST_F(DragWindowFromShelfControllerTest, DISABLED_FlingInOverview) {
UpdateDisplay("400x400"); UpdateDisplay("400x400");
const gfx::Rect shelf_bounds =
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
auto window = CreateTestWindow(); auto window = CreateTestWindow();
// If fling velocity is smaller than kVelocityToHomeScreenThreshold, decide // If fling velocity is smaller than kVelocityToHomeScreenThreshold, decide
// where the window should go based on the release position. // where the window should go based on the release position.
StartDrag(window.get()); StartDrag(window.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 0.f, 1.f); Drag(gfx::Point(200, 200), 0.f, 1.f);
OverviewController* overview_controller = Shell::Get()->overview_controller(); OverviewController* overview_controller = Shell::Get()->overview_controller();
EXPECT_TRUE(overview_controller->InOverviewSession()); EXPECT_TRUE(overview_controller->InOverviewSession());
...@@ -309,7 +318,7 @@ TEST_F(DragWindowFromShelfControllerTest, DISABLED_FlingInOverview) { ...@@ -309,7 +318,7 @@ TEST_F(DragWindowFromShelfControllerTest, DISABLED_FlingInOverview) {
EXPECT_TRUE(WindowState::Get(window.get())->IsMaximized()); EXPECT_TRUE(WindowState::Get(window.get())->IsMaximized());
// If fling velocity is equal or larger than kVelocityToHomeScreenThreshold // If fling velocity is equal or larger than kVelocityToHomeScreenThreshold
StartDrag(window.get()); StartDrag(window.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 0.f, 1.f); Drag(gfx::Point(200, 200), 0.f, 1.f);
EXPECT_TRUE(overview_controller->InOverviewSession()); EXPECT_TRUE(overview_controller->InOverviewSession());
EndDrag(gfx::Point(0, 350), EndDrag(gfx::Point(0, 350),
...@@ -323,6 +332,8 @@ TEST_F(DragWindowFromShelfControllerTest, DISABLED_FlingInOverview) { ...@@ -323,6 +332,8 @@ TEST_F(DragWindowFromShelfControllerTest, DISABLED_FlingInOverview) {
// overview. // overview.
TEST_F(DragWindowFromShelfControllerTest, DragOrFlingInSplitView) { TEST_F(DragWindowFromShelfControllerTest, DragOrFlingInSplitView) {
UpdateDisplay("400x400"); UpdateDisplay("400x400");
const gfx::Rect shelf_bounds =
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
auto window1 = CreateTestWindow(); auto window1 = CreateTestWindow();
auto window2 = CreateTestWindow(); auto window2 = CreateTestWindow();
...@@ -333,7 +344,7 @@ TEST_F(DragWindowFromShelfControllerTest, DragOrFlingInSplitView) { ...@@ -333,7 +344,7 @@ TEST_F(DragWindowFromShelfControllerTest, DragOrFlingInSplitView) {
EXPECT_TRUE(split_view_controller()->InSplitViewMode()); EXPECT_TRUE(split_view_controller()->InSplitViewMode());
// If the window is only dragged for a small distance: // If the window is only dragged for a small distance:
StartDrag(window1.get()); StartDrag(window1.get(), shelf_bounds.left_center(), HotseatState::kExtended);
Drag(gfx::Point(100, 200), 0.f, 1.f); Drag(gfx::Point(100, 200), 0.f, 1.f);
EXPECT_TRUE(split_view_controller()->InSplitViewMode()); EXPECT_TRUE(split_view_controller()->InSplitViewMode());
EXPECT_TRUE(overview_controller->InOverviewSession()); EXPECT_TRUE(overview_controller->InOverviewSession());
...@@ -344,7 +355,7 @@ TEST_F(DragWindowFromShelfControllerTest, DragOrFlingInSplitView) { ...@@ -344,7 +355,7 @@ TEST_F(DragWindowFromShelfControllerTest, DragOrFlingInSplitView) {
EXPECT_TRUE(split_view_controller()->IsWindowInSplitView(window2.get())); EXPECT_TRUE(split_view_controller()->IsWindowInSplitView(window2.get()));
// If the window is dragged for a long distance: // If the window is dragged for a long distance:
StartDrag(window1.get()); StartDrag(window1.get(), shelf_bounds.left_center(), HotseatState::kExtended);
Drag(gfx::Point(100, 200), 0.f, 1.f); Drag(gfx::Point(100, 200), 0.f, 1.f);
EXPECT_TRUE(split_view_controller()->InSplitViewMode()); EXPECT_TRUE(split_view_controller()->InSplitViewMode());
EXPECT_TRUE(overview_controller->InOverviewSession()); EXPECT_TRUE(overview_controller->InOverviewSession());
...@@ -358,7 +369,7 @@ TEST_F(DragWindowFromShelfControllerTest, DragOrFlingInSplitView) { ...@@ -358,7 +369,7 @@ TEST_F(DragWindowFromShelfControllerTest, DragOrFlingInSplitView) {
overview_controller->EndOverview(); overview_controller->EndOverview();
// If the window is flung with a small velocity: // If the window is flung with a small velocity:
StartDrag(window1.get()); StartDrag(window1.get(), shelf_bounds.left_center(), HotseatState::kExtended);
Drag(gfx::Point(100, 200), 0.f, 1.f); Drag(gfx::Point(100, 200), 0.f, 1.f);
EXPECT_TRUE(split_view_controller()->InSplitViewMode()); EXPECT_TRUE(split_view_controller()->InSplitViewMode());
EXPECT_TRUE(overview_controller->InOverviewSession()); EXPECT_TRUE(overview_controller->InOverviewSession());
...@@ -372,7 +383,7 @@ TEST_F(DragWindowFromShelfControllerTest, DragOrFlingInSplitView) { ...@@ -372,7 +383,7 @@ TEST_F(DragWindowFromShelfControllerTest, DragOrFlingInSplitView) {
EXPECT_TRUE(split_view_controller()->IsWindowInSplitView(window2.get())); EXPECT_TRUE(split_view_controller()->IsWindowInSplitView(window2.get()));
// If the window is flung with a large velocity: // If the window is flung with a large velocity:
StartDrag(window1.get()); StartDrag(window1.get(), shelf_bounds.left_center(), HotseatState::kExtended);
Drag(gfx::Point(100, 200), 0.f, 1.f); Drag(gfx::Point(100, 200), 0.f, 1.f);
EXPECT_TRUE(split_view_controller()->InSplitViewMode()); EXPECT_TRUE(split_view_controller()->InSplitViewMode());
EXPECT_TRUE(overview_controller->InOverviewSession()); EXPECT_TRUE(overview_controller->InOverviewSession());
...@@ -396,7 +407,7 @@ TEST_F(DragWindowFromShelfControllerTest, WallpaperBlurDuringDragging) { ...@@ -396,7 +407,7 @@ TEST_F(DragWindowFromShelfControllerTest, WallpaperBlurDuringDragging) {
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds(); Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
auto window = CreateTestWindow(); auto window = CreateTestWindow();
StartDrag(window.get()); StartDrag(window.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(0, 200), 0.f, Drag(gfx::Point(0, 200), 0.f,
DragWindowFromShelfController::kShowOverviewThreshold + 1); DragWindowFromShelfController::kShowOverviewThreshold + 1);
OverviewController* overview_controller = Shell::Get()->overview_controller(); OverviewController* overview_controller = Shell::Get()->overview_controller();
...@@ -416,10 +427,12 @@ TEST_F(DragWindowFromShelfControllerTest, WallpaperBlurDuringDragging) { ...@@ -416,10 +427,12 @@ TEST_F(DragWindowFromShelfControllerTest, WallpaperBlurDuringDragging) {
// stops. // stops.
TEST_F(DragWindowFromShelfControllerTest, HideOverviewDuringDragging) { TEST_F(DragWindowFromShelfControllerTest, HideOverviewDuringDragging) {
UpdateDisplay("400x400"); UpdateDisplay("400x400");
const gfx::Rect shelf_bounds =
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
auto window2 = CreateTestWindow(); auto window2 = CreateTestWindow();
auto window1 = CreateTestWindow(); auto window1 = CreateTestWindow();
StartDrag(window1.get()); StartDrag(window1.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 0.5f, 0.5f); Drag(gfx::Point(200, 200), 0.5f, 0.5f);
OverviewController* overview_controller = Shell::Get()->overview_controller(); OverviewController* overview_controller = Shell::Get()->overview_controller();
EXPECT_TRUE(overview_controller->InOverviewSession()); EXPECT_TRUE(overview_controller->InOverviewSession());
...@@ -456,7 +469,7 @@ TEST_F(DragWindowFromShelfControllerTest, ...@@ -456,7 +469,7 @@ TEST_F(DragWindowFromShelfControllerTest,
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds(); Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
auto window = CreateTestWindow(); auto window = CreateTestWindow();
StartDrag(window.get()); StartDrag(window.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 0.5f, 0.5f); Drag(gfx::Point(200, 200), 0.5f, 0.5f);
OverviewController* overview_controller = Shell::Get()->overview_controller(); OverviewController* overview_controller = Shell::Get()->overview_controller();
EXPECT_TRUE(overview_controller->InOverviewSession()); EXPECT_TRUE(overview_controller->InOverviewSession());
...@@ -506,7 +519,7 @@ TEST_F(DragWindowFromShelfControllerTest, NoBackdropDuringWindowScaleDown) { ...@@ -506,7 +519,7 @@ TEST_F(DragWindowFromShelfControllerTest, NoBackdropDuringWindowScaleDown) {
EXPECT_NE(window->GetProperty(kBackdropWindowMode), EXPECT_NE(window->GetProperty(kBackdropWindowMode),
BackdropWindowMode::kDisabled); BackdropWindowMode::kDisabled);
StartDrag(window.get()); StartDrag(window.get(), shelf_bounds.left_center(), HotseatState::kExtended);
Drag(gfx::Point(0, 200), 0.f, 10.f); Drag(gfx::Point(0, 200), 0.f, 10.f);
EndDrag(shelf_bounds.CenterPoint(), EndDrag(shelf_bounds.CenterPoint(),
base::make_optional( base::make_optional(
...@@ -520,6 +533,8 @@ TEST_F(DragWindowFromShelfControllerTest, NoBackdropDuringWindowScaleDown) { ...@@ -520,6 +533,8 @@ TEST_F(DragWindowFromShelfControllerTest, NoBackdropDuringWindowScaleDown) {
// hidden windows should restore to its previous visibility state. // hidden windows should restore to its previous visibility state.
// TODO(crbug.com/1022319): flaky. // TODO(crbug.com/1022319): flaky.
TEST_F(DragWindowFromShelfControllerTest, DISABLED_CancelDragDismissOverview) { TEST_F(DragWindowFromShelfControllerTest, DISABLED_CancelDragDismissOverview) {
const gfx::Rect shelf_bounds =
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
auto window3 = CreateTestWindow(); auto window3 = CreateTestWindow();
auto window2 = CreateTestWindow(); auto window2 = CreateTestWindow();
auto window1 = CreateTestWindow(); auto window1 = CreateTestWindow();
...@@ -527,7 +542,7 @@ TEST_F(DragWindowFromShelfControllerTest, DISABLED_CancelDragDismissOverview) { ...@@ -527,7 +542,7 @@ TEST_F(DragWindowFromShelfControllerTest, DISABLED_CancelDragDismissOverview) {
EXPECT_TRUE(window2->IsVisible()); EXPECT_TRUE(window2->IsVisible());
EXPECT_TRUE(window3->IsVisible()); EXPECT_TRUE(window3->IsVisible());
StartDrag(window1.get()); StartDrag(window1.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 0.5f, 0.5f); Drag(gfx::Point(200, 200), 0.5f, 0.5f);
OverviewController* overview_controller = Shell::Get()->overview_controller(); OverviewController* overview_controller = Shell::Get()->overview_controller();
EXPECT_TRUE(overview_controller->InOverviewSession()); EXPECT_TRUE(overview_controller->InOverviewSession());
...@@ -545,8 +560,10 @@ TEST_F(DragWindowFromShelfControllerTest, DISABLED_CancelDragDismissOverview) { ...@@ -545,8 +560,10 @@ TEST_F(DragWindowFromShelfControllerTest, DISABLED_CancelDragDismissOverview) {
// TODO(https://crbug.com/1018498) This test is flaky. // TODO(https://crbug.com/1018498) This test is flaky.
TEST_F(DragWindowFromShelfControllerTest, TEST_F(DragWindowFromShelfControllerTest,
DISABLED_CancelDragIfWindowDestroyed) { DISABLED_CancelDragIfWindowDestroyed) {
const gfx::Rect shelf_bounds =
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
auto window = CreateTestWindow(); auto window = CreateTestWindow();
StartDrag(window.get()); StartDrag(window.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 0.5f, 0.5f); Drag(gfx::Point(200, 200), 0.5f, 0.5f);
EXPECT_EQ(window_drag_controller()->dragged_window(), window.get()); EXPECT_EQ(window_drag_controller()->dragged_window(), window.get());
EXPECT_TRUE(window_drag_controller()->drag_started()); EXPECT_TRUE(window_drag_controller()->drag_started());
...@@ -558,4 +575,28 @@ TEST_F(DragWindowFromShelfControllerTest, ...@@ -558,4 +575,28 @@ TEST_F(DragWindowFromShelfControllerTest,
CancelDrag(); CancelDrag();
} }
TEST_F(DragWindowFromShelfControllerTest, FlingWithHiddenHotseat) {
const gfx::Rect shelf_bounds =
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
auto window = CreateTestWindow();
gfx::Point start = shelf_bounds.CenterPoint();
StartDrag(window.get(), start, HotseatState::kHidden);
// Only drag for a small distance and then fling.
Drag(gfx::Point(start.x(), start.y() - 10), 0.5f, 0.5f);
EndDrag(gfx::Point(start.x(), start.y() - 10),
base::make_optional(
-DragWindowFromShelfController::kVelocityToHomeScreenThreshold));
// The window should restore back to its original position.
EXPECT_TRUE(WindowState::Get(window.get())->IsMaximized());
// Now a bigger distance to fling.
StartDrag(window.get(), start, HotseatState::kHidden);
Drag(gfx::Point(start.x(), start.y() - 200), 0.5f, 0.5f);
EndDrag(gfx::Point(start.x(), start.y() - 200),
base::make_optional(
-DragWindowFromShelfController::kVelocityToHomeScreenThreshold));
// The window should be minimized.
EXPECT_TRUE(WindowState::Get(window.get())->IsMinimized());
}
} // namespace ash } // namespace ash
...@@ -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