Commit 745a9ac2 authored by Avery Musbach's avatar Avery Musbach Committed by Commit Bot

home screen: Fix snap preview animations when dragging window from shelf

The present CL is a new way to serve the same purpose as [1]. As
SplitViewDragIndicators::WindowDraggingState has values called
kFromOverview and kFromTop, I think it is most intuitive to add one
called kFromShelf, with the caveat that the difference between kNoDrag
and kFromShelf is all about animations. Compared to [1], I think it is
nice to avoid adding a whole extra member variable.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/1894754

Test: ash_unittests DragWindowFromShelfControllerTest.SplitViewDragIndicatorsWindowDraggingStates
Test: ash_unittests SplitViewDragIndicatorsTest.SplitViewDragIndicatorsVisibility
Fixed: 1020349
Change-Id: I69aefae3a68579d2f0d0c61a8d8f5588689d0b13
Bug: 1020349
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1898771
Commit-Queue: Avery Musbach <amusbach@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713270}
parent 75389fd0
......@@ -160,13 +160,10 @@ void DragWindowFromShelfController::Drag(const gfx::Point& location_in_screen,
if (overview_controller->InOverviewSession()) {
const SplitViewController::SnapPosition snap_position =
GetSnapPosition(location_in_screen);
// Pass non_snap_state=kNoDrag so that only snap previews show up.
// TODO(crbug.com/1020349): Achieve that effect another way, because this
// way causes incorrect animations.
SplitViewDragIndicators::WindowDraggingState window_dragging_state =
SplitViewDragIndicators::ComputeWindowDraggingState(
drag_started_,
SplitViewDragIndicators::WindowDraggingState::kNoDrag,
SplitViewDragIndicators::WindowDraggingState::kFromShelf,
snap_position);
OverviewSession* overview_session = overview_controller->overview_session();
overview_session->SetSplitViewDragIndicatorsWindowDraggingState(
......
......@@ -447,8 +447,9 @@ TEST_F(DragWindowFromShelfControllerTest, HideOverviewDuringDragging) {
EXPECT_EQ(window1->layer()->GetTargetOpacity(), 1.f);
}
// Test there is no drag-to-snap or cannot-snap drag indicators during dragging.
TEST_F(DragWindowFromShelfControllerTest, NoDragToSnapIndicator) {
// Check the split view drag indicators window dragging states.
TEST_F(DragWindowFromShelfControllerTest,
SplitViewDragIndicatorsWindowDraggingStates) {
UpdateDisplay("400x400");
const gfx::Rect shelf_bounds =
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
......@@ -462,14 +463,30 @@ TEST_F(DragWindowFromShelfControllerTest, NoDragToSnapIndicator) {
SplitViewDragIndicators::WindowDraggingState window_dragging_state =
overview_session->split_view_drag_indicators()
->current_window_dragging_state();
EXPECT_EQ(SplitViewDragIndicators::WindowDraggingState::kNoDrag,
EXPECT_EQ(SplitViewDragIndicators::WindowDraggingState::kFromShelf,
window_dragging_state);
Drag(gfx::Point(0, 200), 0.5f, 0.5f);
window_dragging_state = overview_session->split_view_drag_indicators()
->current_window_dragging_state();
EXPECT_EQ(SplitViewDragIndicators::WindowDraggingState::kToSnapLeft,
window_dragging_state);
Drag(gfx::Point(0, 300), 0.5f, 0.5f);
window_dragging_state = overview_session->split_view_drag_indicators()
->current_window_dragging_state();
EXPECT_EQ(SplitViewDragIndicators::WindowDraggingState::kFromShelf,
window_dragging_state);
Drag(gfx::Point(0, 200), 0.5f, 0.5f);
window_dragging_state = overview_session->split_view_drag_indicators()
->current_window_dragging_state();
EXPECT_EQ(SplitViewDragIndicators::WindowDraggingState::kToSnapLeft,
window_dragging_state);
Drag(gfx::Point(200, 200), 0.5f, 0.5f);
window_dragging_state = overview_session->split_view_drag_indicators()
->current_window_dragging_state();
EXPECT_EQ(SplitViewDragIndicators::WindowDraggingState::kFromShelf,
window_dragging_state);
EndDrag(shelf_bounds.CenterPoint(),
/*velocity_y=*/base::nullopt);
......
......@@ -160,12 +160,6 @@ class SplitViewDragIndicators::RotatedImageLabelView : public views::View {
WindowDraggingState window_dragging_state,
WindowDraggingState previous_window_dragging_state,
bool can_dragged_window_be_snapped) {
// In split view, the labels never show, and they do not need to be updated.
if (SplitViewController::Get(GetWidget()->GetNativeWindow())
->InSplitViewMode()) {
return;
}
// No top label for dragging from the top in portrait orientation.
if (window_dragging_state == WindowDraggingState::kFromTop &&
!IsCurrentScreenOrientationLandscape() && !is_right_or_bottom_) {
......@@ -274,19 +268,25 @@ class SplitViewDragIndicators::SplitViewDragIndicatorsView
previous_window_dragging_state_ = window_dragging_state_;
window_dragging_state_ = window_dragging_state;
const bool previews_only =
window_dragging_state == WindowDraggingState::kFromShelf ||
SplitViewController::Get(GetWidget()->GetNativeWindow())
->InSplitViewMode();
const bool can_dragged_window_be_snapped =
dragged_window_ && CanSnapInSplitview(dragged_window_);
if (!previews_only) {
left_rotated_view_->OnWindowDraggingStateChanged(
window_dragging_state, previous_window_dragging_state_,
can_dragged_window_be_snapped);
right_rotated_view_->OnWindowDraggingStateChanged(
window_dragging_state, previous_window_dragging_state_,
can_dragged_window_be_snapped);
}
left_highlight_view_->OnWindowDraggingStateChanged(
window_dragging_state, previous_window_dragging_state_,
window_dragging_state, previous_window_dragging_state_, previews_only,
can_dragged_window_be_snapped);
right_highlight_view_->OnWindowDraggingStateChanged(
window_dragging_state, previous_window_dragging_state_,
window_dragging_state, previous_window_dragging_state_, previews_only,
can_dragged_window_be_snapped);
if (window_dragging_state != WindowDraggingState::kNoDrag ||
......
......@@ -55,6 +55,11 @@ class ASH_EXPORT SplitViewDragIndicators {
// snapped in split view.
kFromTop,
// Started dragging from the shelf. Split view is supported. Not currently
// dragging in a snap area, or the dragged window is not eligible to be
// snapped in split view.
kFromShelf,
// Currently dragging in the |SplitViewController::LEFT| snap area, and the
// dragged window is eligible to be snapped in split view.
kToSnapLeft,
......
......@@ -415,6 +415,25 @@ TEST_F(SplitViewDragIndicatorsTest, SplitViewDragIndicatorsVisibility) {
SplitViewDragIndicators::WindowDraggingState::kToSnapRight, gfx::Point());
check_helper(indicator.get(), to_int(IndicatorType::kRightHighlight));
// Verify that only snap previews are shown for window dragging from shelf.
indicator->SetWindowDraggingState(
SplitViewDragIndicators::WindowDraggingState::kNoDrag, gfx::Point());
indicator->SetWindowDraggingState(
SplitViewDragIndicators::WindowDraggingState::kFromShelf, gfx::Point());
check_helper(indicator.get(), 0);
indicator->SetWindowDraggingState(
SplitViewDragIndicators::WindowDraggingState::kToSnapLeft, gfx::Point());
check_helper(indicator.get(), to_int(IndicatorType::kLeftHighlight));
indicator->SetWindowDraggingState(
SplitViewDragIndicators::WindowDraggingState::kFromShelf, gfx::Point());
check_helper(indicator.get(), 0);
indicator->SetWindowDraggingState(
SplitViewDragIndicators::WindowDraggingState::kToSnapRight, gfx::Point());
check_helper(indicator.get(), to_int(IndicatorType::kRightHighlight));
indicator->SetWindowDraggingState(
SplitViewDragIndicators::WindowDraggingState::kFromShelf, gfx::Point());
check_helper(indicator.get(), 0);
ScreenOrientationControllerTestApi orientation_api(
Shell::Get()->screen_orientation_controller());
// Verify that everything is visible in state
......
......@@ -177,6 +177,7 @@ void SplitViewHighlightView::SetColor(SkColor color) {
void SplitViewHighlightView::OnWindowDraggingStateChanged(
SplitViewDragIndicators::WindowDraggingState window_dragging_state,
SplitViewDragIndicators::WindowDraggingState previous_window_dragging_state,
bool previews_only,
bool can_dragged_window_be_snapped) {
// No top indicator for dragging from the top in portrait orientation.
if (window_dragging_state ==
......@@ -212,10 +213,6 @@ void SplitViewHighlightView::OnWindowDraggingStateChanged(
return;
}
const bool previews_only =
SplitViewController::Get(GetWidget()->GetNativeWindow())
->InSplitViewMode();
if (previous_preview_position != SplitViewController::NONE) {
// There was a snap preview showing, but now the user has dragged away from
// the edge of the screen, so that the preview should go away.
......
......@@ -45,11 +45,15 @@ class ASH_EXPORT SplitViewHighlightView : public views::View {
void SetColor(SkColor color);
// Called to update the opacity of the highlights view on transition from
// |previous_window_dragging_state| to |window_dragging_state|.
// |previous_window_dragging_state| to |window_dragging_state|. If
// |previews_only|, then there shall be no visible drag indicators except for
// snap previews. The highlights are white if |can_dragged_window_be_snapped|,
// black otherwise.
void OnWindowDraggingStateChanged(
SplitViewDragIndicators::WindowDraggingState window_dragging_state,
SplitViewDragIndicators::WindowDraggingState
previous_window_dragging_state,
bool previews_only,
bool can_dragged_window_be_snapped);
private:
......
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