Commit cb3b5524 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

Reland "splitview: Grab app for splitscreen only happen on long press."

This is a reland of b9d68c49
Left the previously disabled test disabled in the reland. Will fix in a
seperate cl.

TBR=oshima@chromium.org

Original change's description:
> splitview: Grab app for splitscreen only happen on long press.
>
> The indicators and the item enlarging only happen after long press, or
> if the item has been dragged.
>
> This is preparation for fling to dismiss. It also removes a flicker of
> the indidcators when you tap to open a item.
>
> Also renables a previous flaky test. Tested locally and it is not flaky
> no more.
>
> Test: ash_unittests SplitViewWindowSelectorTest.*
> Bug: 817863
> Change-Id: I9c20f2fa9a3c0a9218b3072c5b3d25711ad9c655
> Reviewed-on: https://chromium-review.googlesource.com/996528
> Commit-Queue: Sammie Quon <sammiequon@chromium.org>
> Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
> Reviewed-by: Xiaoqian Dai <xdai@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#550884}

Bug: 817863
Change-Id: I0d6b255a89e69443af2e6509a0769622c8f64fb3
Reviewed-on: https://chromium-review.googlesource.com/1012735Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551036}
parent 18a5665b
......@@ -14,12 +14,19 @@
#include "ash/wm/splitview/split_view_constants.h"
#include "ash/wm/splitview/split_view_drag_indicators.h"
#include "ash/wm/window_positioning_utils.h"
#include "ash/wm/wm_event.h"
#include "ui/aura/window.h"
#include "ui/wm/core/coordinate_conversion.h"
namespace ash {
namespace {
// Before dragging an overview window, the window will scale up |kPreDragScale|
// to indicate its selection.
constexpr float kDragWindowScale = 0.04f;
} // namespace
OverviewWindowDragController::OverviewWindowDragController(
WindowSelector* window_selector)
: window_selector_(window_selector),
......@@ -39,12 +46,6 @@ void OverviewWindowDragController::InitiateDrag(
GetSnapPosition(location_in_screen) == SplitViewController::NONE
? base::nullopt
: base::make_optional(location_in_screen);
window_selector_->SetSplitViewDragIndicatorsIndicatorState(
split_view_controller_->CanSnap(item->GetWindow())
? IndicatorState::kDragArea
: IndicatorState::kCannotSnap,
location_in_screen);
}
void OverviewWindowDragController::Drag(const gfx::Point& location_in_screen) {
......@@ -56,8 +57,8 @@ void OverviewWindowDragController::Drag(const gfx::Point& location_in_screen) {
std::abs(distance.y()) < kMinimumDragOffset) {
return;
}
StartSplitViewDragMode(location_in_screen);
}
did_move_ = true;
// Update the dragged |item_|'s bounds accordingly.
gfx::Rect bounds(item_->target_bounds());
......@@ -94,6 +95,23 @@ void OverviewWindowDragController::CompleteDrag(
item_ = nullptr;
}
void OverviewWindowDragController::StartSplitViewDragMode(
const gfx::Point& location_in_screen) {
// Increase the bounds of the dragged item.
gfx::Rect scaled_bounds(item_->target_bounds());
scaled_bounds.Inset(-scaled_bounds.width() * kDragWindowScale,
-scaled_bounds.height() * kDragWindowScale);
item_->SetBounds(scaled_bounds,
OverviewAnimationType::OVERVIEW_ANIMATION_NONE);
did_move_ = true;
window_selector_->SetSplitViewDragIndicatorsIndicatorState(
split_view_controller_->CanSnap(item_->GetWindow())
? IndicatorState::kDragArea
: IndicatorState::kCannotSnap,
location_in_screen);
}
void OverviewWindowDragController::ActivateDraggedWindow() {
// If no drag was initiated (e.g., a click/tap on the overview window),
// activate the window. If the split view is active and has a left window,
......
......@@ -38,6 +38,7 @@ class ASH_EXPORT OverviewWindowDragController {
const gfx::Point& location_in_screen);
void Drag(const gfx::Point& location_in_screen);
void CompleteDrag(const gfx::Point& location_in_screen);
void StartSplitViewDragMode(const gfx::Point& location_in_screen);
void ActivateDraggedWindow();
void ResetGesture();
......
......@@ -617,14 +617,14 @@ void WindowSelector::InitiateDrag(WindowSelectorItem* item,
void WindowSelector::Drag(WindowSelectorItem* item,
const gfx::Point& location_in_screen) {
DCHECK(window_drag_controller_.get());
DCHECK(window_drag_controller_);
DCHECK_EQ(item, window_drag_controller_->item());
window_drag_controller_->Drag(location_in_screen);
}
void WindowSelector::CompleteDrag(WindowSelectorItem* item,
const gfx::Point& location_in_screen) {
DCHECK(window_drag_controller_.get());
DCHECK(window_drag_controller_);
DCHECK_EQ(item, window_drag_controller_->item());
window_drag_controller_->CompleteDrag(location_in_screen);
......@@ -632,13 +632,16 @@ void WindowSelector::CompleteDrag(WindowSelectorItem* item,
grid->OnSelectorItemDragEnded();
}
void WindowSelector::StartSplitViewDragMode(
const gfx::Point& location_in_screen) {
window_drag_controller_->StartSplitViewDragMode(location_in_screen);
}
void WindowSelector::ActivateDraggedWindow() {
DCHECK(window_drag_controller_.get());
window_drag_controller_->ActivateDraggedWindow();
}
void WindowSelector::ResetDraggedWindowGesture() {
DCHECK(window_drag_controller_.get());
window_drag_controller_->ResetGesture();
}
......
......@@ -120,6 +120,7 @@ class ASH_EXPORT WindowSelector : public display::DisplayObserver,
void Drag(WindowSelectorItem* item, const gfx::Point& location_in_screen);
void CompleteDrag(WindowSelectorItem* item,
const gfx::Point& location_in_screen);
void StartSplitViewDragMode(const gfx::Point& location_in_screen);
void ActivateDraggedWindow();
void ResetDraggedWindowGesture();
......
......@@ -118,10 +118,6 @@ constexpr int kDragAnimationMs = 167;
// this fraction of size.
constexpr float kPreCloseScale = 0.02f;
// Before dragging an overview window, the window will scale up |kPreDragScale|
// to indicate its selection.
constexpr float kDragWindowScale = 0.04f;
// The size in dp of the window icon shown on the overview window next to the
// title.
constexpr gfx::Size kIconSize = gfx::Size(24, 24);
......@@ -255,6 +251,9 @@ class ShieldButton : public views::Button {
case ui::ET_GESTURE_SCROLL_END:
listener()->HandleReleaseEvent(location);
break;
case ui::ET_GESTURE_LONG_PRESS:
listener()->HandleLongPressEvent(location);
break;
case ui::ET_GESTURE_TAP:
listener()->ActivateDraggedWindow();
break;
......@@ -997,6 +996,11 @@ void WindowSelectorItem::HandleDragEvent(const gfx::Point& location_in_screen) {
window_selector_->Drag(this, location_in_screen);
}
void WindowSelectorItem::HandleLongPressEvent(
const gfx::Point& location_in_screen) {
window_selector_->StartSplitViewDragMode(location_in_screen);
}
void WindowSelectorItem::ActivateDraggedWindow() {
if (!IsDragItem())
return;
......@@ -1393,13 +1397,6 @@ void WindowSelectorItem::StartDrag() {
// window is pressed while still animating.
transform_window_.CancelAnimationsListener();
gfx::Rect scaled_bounds(target_bounds_);
scaled_bounds.Inset(-target_bounds_.width() * kDragWindowScale,
-target_bounds_.height() * kDragWindowScale);
OverviewAnimationType animation_type =
OverviewAnimationType::OVERVIEW_ANIMATION_NONE;
SetBounds(scaled_bounds, animation_type);
aura::Window* widget_window = item_widget_->GetNativeWindow();
aura::Window* window = GetWindowForStacking();
if (widget_window && widget_window->parent() == window->parent()) {
......
......@@ -182,6 +182,7 @@ class ASH_EXPORT WindowSelectorItem : public views::ButtonListener,
void HandlePressEvent(const gfx::Point& location_in_screen);
void HandleReleaseEvent(const gfx::Point& location_in_screen);
void HandleDragEvent(const gfx::Point& location_in_screen);
void HandleLongPressEvent(const gfx::Point& location_in_screen);
void ActivateDraggedWindow();
void ResetDraggedWindowGesture();
......
......@@ -2960,6 +2960,7 @@ TEST_F(WindowSelectorTest, DISABLED_DraggingWithTwoFingers) {
// Dragging is only allowed in tablet mode.
RunAllPendingInMessageLoop();
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
RunAllPendingInMessageLoop();
ToggleOverview();
RunAllPendingInMessageLoop();
......@@ -2972,11 +2973,21 @@ TEST_F(WindowSelectorTest, DISABLED_DraggingWithTwoFingers) {
constexpr int kTouchId1 = 1;
constexpr int kTouchId2 = 2;
// Dispatches a long press event at the event generators current location.
// Long press is one way to start dragging in splitview.
auto dispatch_long_press = [this]() {
ui::TouchEvent long_press(
ui::ET_GESTURE_LONG_PRESS, GetEventGenerator().current_location(),
base::TimeTicks::Now(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH));
GetEventGenerator().Dispatch(&long_press);
};
// Verify that the bounds of the tapped window expand when touched.
ui::test::EventGenerator& generator = GetEventGenerator();
generator.set_current_location(original_bounds1.CenterPoint());
generator.PressTouchId(kTouchId1);
RunAllPendingInMessageLoop();
dispatch_long_press();
EXPECT_GT(item1->target_bounds().width(), original_bounds1.width());
EXPECT_GT(item1->target_bounds().height(), original_bounds1.height());
......@@ -2985,7 +2996,7 @@ TEST_F(WindowSelectorTest, DISABLED_DraggingWithTwoFingers) {
// dragged.
generator.set_current_location(original_bounds2.CenterPoint());
generator.PressTouchId(kTouchId2);
RunAllPendingInMessageLoop();
dispatch_long_press();
EXPECT_GT(item1->target_bounds().width(), original_bounds1.width());
EXPECT_GT(item1->target_bounds().height(), original_bounds1.height());
EXPECT_EQ(item2->target_bounds(), original_bounds2);
......@@ -3002,8 +3013,8 @@ TEST_F(WindowSelectorTest, DISABLED_DraggingWithTwoFingers) {
last_center_point = item1->target_bounds().CenterPoint();
generator.ReleaseTouchId(kTouchId2);
generator.PressTouchId(kTouchId2);
dispatch_long_press();
generator.MoveTouchIdBy(kTouchId2, 40, 40);
RunAllPendingInMessageLoop();
EXPECT_NE(last_center_point, item1->target_bounds().CenterPoint());
EXPECT_EQ(original_bounds2.CenterPoint(),
item2->target_bounds().CenterPoint());
......@@ -3546,15 +3557,24 @@ TEST_F(SplitViewWindowSelectorTest, SplitViewDragIndicatorsState) {
screen_util::GetDisplayWorkAreaBoundsInParent(window1.get()).width();
const int edge_inset = GetEdgeInset(screen_width);
// Verify that when are no snapped windows, the indicator is visible when a
// drag is initiated and the left preview area appears when the drag reaches
// |edge_inset| from the edge of the screen.
// Verify that when are no snapped windows, the indicator is visible once
// there is a long press or after the drag has started.
const int grid_index = 0;
WindowSelectorItem* selector_item =
GetWindowItemForWindow(grid_index, window1.get());
gfx::Point start_location(selector_item->target_bounds().CenterPoint());
window_selector()->InitiateDrag(selector_item, start_location);
EXPECT_EQ(IndicatorState::kNone, indicator_state());
window_selector()->StartSplitViewDragMode(start_location);
EXPECT_EQ(IndicatorState::kDragArea, indicator_state());
// Reset the gesture so we stay in overview mode.
window_selector()->ResetDraggedWindowGesture();
// Verify the indicator is visible once the item starts moving, and becomes a
// preview area once we reach the left edge of the screen.
window_selector()->InitiateDrag(selector_item, start_location);
EXPECT_EQ(IndicatorState::kNone, indicator_state());
window_selector()->Drag(selector_item, gfx::Point(edge_inset + 1, 0));
EXPECT_EQ(IndicatorState::kDragArea, indicator_state());
window_selector()->Drag(selector_item, gfx::Point(edge_inset, 0));
......@@ -3571,7 +3591,7 @@ TEST_F(SplitViewWindowSelectorTest, SplitViewDragIndicatorsState) {
selector_item = GetWindowItemForWindow(grid_index, window2.get());
start_location = selector_item->target_bounds().CenterPoint();
window_selector()->InitiateDrag(selector_item, start_location);
EXPECT_EQ(IndicatorState::kDragArea, indicator_state());
EXPECT_EQ(IndicatorState::kNone, indicator_state());
window_selector()->Drag(selector_item, gfx::Point(screen_width - 1, 0));
EXPECT_EQ(IndicatorState::kPreviewAreaRight, indicator_state());
window_selector()->CompleteDrag(selector_item, start_location);
......@@ -3591,6 +3611,7 @@ TEST_F(SplitViewWindowSelectorTest,
GetWindowItemForWindow(grid_index, unsnappable_window.get());
gfx::Point start_location(selector_item->target_bounds().CenterPoint());
window_selector()->InitiateDrag(selector_item, start_location);
window_selector()->StartSplitViewDragMode(start_location);
EXPECT_EQ(IndicatorState::kCannotSnap, indicator_state());
const gfx::Point end_location1(0, 0);
window_selector()->Drag(selector_item, end_location1);
......@@ -3672,6 +3693,7 @@ TEST_F(SplitViewWindowSelectorTest, SplitViewDragIndicatorsWidgetReparenting) {
GetWindowItemForWindow(0, primary_screen_window.get());
gfx::Point start_location(selector_item->target_bounds().CenterPoint());
window_selector()->InitiateDrag(selector_item, start_location);
window_selector()->Drag(selector_item, gfx::Point(100, 100));
EXPECT_EQ(IndicatorState::kDragArea, indicator_state());
EXPECT_EQ(root_windows[0], window_selector()
->split_view_drag_indicators()
......@@ -3690,6 +3712,7 @@ TEST_F(SplitViewWindowSelectorTest, SplitViewDragIndicatorsWidgetReparenting) {
selector_item = GetWindowItemForWindow(1, secondary_screen_window.get());
start_location = gfx::Point(selector_item->target_bounds().CenterPoint());
window_selector()->InitiateDrag(selector_item, start_location);
window_selector()->Drag(selector_item, gfx::Point(800, 200));
EXPECT_EQ(IndicatorState::kDragArea, indicator_state());
EXPECT_EQ(root_windows[1], window_selector()
->split_view_drag_indicators()
......
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