Commit 9642dadd authored by Avery Musbach's avatar Avery Musbach Committed by Commit Bot

overview: Suppress cannot snap warning on dragged item in "normal" drag

During "normal" dragging from overview (not drag-to-close), the cannot
snap warning shall be suppressed on the dragged overview item.

Test: ash_unittests SplitViewOverviewSessionTest.OverviewUnsnappableIndicatorVisibilityWhileDragging/?
Bug: 1012413
Change-Id: I9036d6160231f3074e5e6f4472efe43c80571f32
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1849414
Commit-Queue: Avery Musbach <amusbach@chromium.org>
Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704338}
parent 88f33156
......@@ -586,6 +586,13 @@ void OverviewItem::UpdateCannotSnapWarningVisibility() {
cannot_snap_widget_->SetBoundsCenteredIn(bounds, /*animate=*/false);
}
void OverviewItem::HideCannotSnapWarning() {
if (!cannot_snap_widget_)
return;
DoSplitviewOpacityAnimation(cannot_snap_widget_->GetNativeWindow()->layer(),
SPLITVIEW_ANIMATION_OVERVIEW_ITEM_FADE_OUT);
}
void OverviewItem::OnSelectorItemDragStarted(OverviewItem* item) {
is_being_dragged_ = (item == this);
caption_container_view_->SetHeaderVisibility(
......
......@@ -108,6 +108,10 @@ class ASH_EXPORT OverviewItem : public CaptionContainerView::EventDelegate,
// window cannot be snapped.
void UpdateCannotSnapWarningVisibility();
// Hides the cannot snap warning (if it was showing) until the next call to
// |UpdateCannotSnapWarningVisibility|.
void HideCannotSnapWarning();
// Called when a OverviewItem on any grid is dragged. Hides the close button
// when a drag is started, and reshows it when a drag is finished.
// Additionally hides the title and window icon if |item| is this.
......
......@@ -78,6 +78,7 @@
#include "ui/display/manager/display_manager.h"
#include "ui/display/test/display_manager_test_api.h"
#include "ui/events/event_utils.h"
#include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/transform.h"
......@@ -4086,6 +4087,108 @@ TEST_P(SplitViewOverviewSessionTest, OverviewUnsnappableIndicatorVisibility) {
EXPECT_EQ(0.f, unsnappable_layer->opacity());
}
// Verify that during "normal" dragging from overview (not drag-to-close), the
// dragged item's unsnappable indicator is temporarily suppressed.
TEST_P(SplitViewOverviewSessionTest,
OverviewUnsnappableIndicatorVisibilityWhileDragging) {
ui::GestureConfiguration* gesture_config =
ui::GestureConfiguration::GetInstance();
gesture_config->set_long_press_time_in_ms(1);
gesture_config->set_show_press_delay_in_ms(1);
std::unique_ptr<aura::Window> snapped_window = CreateTestWindow();
std::unique_ptr<aura::Window> unsnappable_window = CreateUnsnappableWindow();
ToggleOverview();
ASSERT_TRUE(overview_controller()->InOverviewSession());
split_view_controller()->SnapWindow(snapped_window.get(),
SplitViewController::LEFT);
ASSERT_TRUE(split_view_controller()->InSplitViewMode());
OverviewItem* unsnappable_overview_item =
GetOverviewItemForWindow(unsnappable_window.get());
ASSERT_TRUE(unsnappable_overview_item->cannot_snap_widget_for_testing());
ui::Layer* unsnappable_layer =
unsnappable_overview_item->cannot_snap_widget_for_testing()
->GetNativeWindow()
->layer();
ASSERT_EQ(1.f, unsnappable_layer->opacity());
// Test that the unsnappable label is temporarily suppressed during mouse
// dragging.
ui::test::EventGenerator* generator = GetEventGenerator();
const gfx::Point drag_starting_point = gfx::ToRoundedPoint(
unsnappable_overview_item->target_bounds().CenterPoint());
generator->set_current_screen_location(drag_starting_point);
generator->PressLeftButton();
using DragBehavior = OverviewWindowDragController::DragBehavior;
EXPECT_EQ(
DragBehavior::kUndefined,
overview_session()->window_drag_controller()->current_drag_behavior());
EXPECT_EQ(1.f, unsnappable_layer->opacity());
generator->MoveMouseBy(0, 20);
EXPECT_EQ(
DragBehavior::kNormalDrag,
overview_session()->window_drag_controller()->current_drag_behavior());
EXPECT_EQ(0.f, unsnappable_layer->opacity());
generator->ReleaseLeftButton();
EXPECT_EQ(1.f, unsnappable_layer->opacity());
// Test that the unsnappable label is temporarily suppressed during "normal"
// touch dragging (not drag-to-close).
generator->set_current_screen_location(drag_starting_point);
generator->PressTouch();
{
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromMilliseconds(2));
run_loop.Run();
}
EXPECT_EQ(
DragBehavior::kNormalDrag,
overview_session()->window_drag_controller()->current_drag_behavior());
EXPECT_EQ(0.f, unsnappable_layer->opacity());
generator->MoveTouchBy(20, 0);
generator->ReleaseTouch();
EXPECT_EQ(1.f, unsnappable_layer->opacity());
// Test that the unsnappable label reappears if "normal" touch dragging (not
// drag-to-close) ends when the item has not been actually dragged anywhere.
// This case improves test coverage because it is handled in
// |OverviewWindowDragController::ResetGesture| instead of
// |OverviewWindowDragController::CompleteNormalDrag|.
generator->set_current_screen_location(drag_starting_point);
generator->PressTouch();
{
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromMilliseconds(2));
run_loop.Run();
}
EXPECT_EQ(
DragBehavior::kNormalDrag,
overview_session()->window_drag_controller()->current_drag_behavior());
EXPECT_EQ(0.f, unsnappable_layer->opacity());
generator->ReleaseTouch();
EXPECT_EQ(1.f, unsnappable_layer->opacity());
// Test that the unsnappable label persists in drag-to-close mode.
generator->set_current_screen_location(drag_starting_point);
generator->PressTouch();
// Use small increments otherwise a fling event will be fired.
for (int j = 0; j < 20; ++j)
generator->MoveTouchBy(0, 1);
EXPECT_EQ(
DragBehavior::kDragToClose,
overview_session()->window_drag_controller()->current_drag_behavior());
// Drag-to-close mode affects the opacity of the whole overview item,
// including the unsnappable label.
EXPECT_EQ(unsnappable_overview_item->GetWindow()->layer()->opacity(),
unsnappable_layer->opacity());
generator->ReleaseTouch();
EXPECT_EQ(1.f, unsnappable_layer->opacity());
}
// Test that when splitview mode and overview mode are both active at the same
// time, dragging divider behaviors are correct.
TEST_P(SplitViewOverviewSessionTest, DragDividerToExitTest) {
......
......@@ -239,6 +239,7 @@ void OverviewWindowDragController::StartNormalDragMode(
CanSnapInSplitview(item_->GetWindow()) ? IndicatorState::kDragArea
: IndicatorState::kCannotSnap,
gfx::ToRoundedPoint(location_in_screen));
item_->HideCannotSnapWarning();
// Update the split view divider bar status if necessary. If splitview is
// active when dragging the overview window, the split divider bar should be
......@@ -329,6 +330,7 @@ void OverviewWindowDragController::ResetGesture() {
if (should_allow_split_view_) {
overview_session_->SetSplitViewDragIndicatorsIndicatorState(
IndicatorState::kNone, gfx::Point());
item_->UpdateCannotSnapWarningVisibility();
}
}
overview_session_->PositionWindows(/*animate=*/true);
......@@ -514,6 +516,7 @@ OverviewWindowDragController::CompleteNormalDrag(
UpdateDragIndicatorsAndOverviewGrid(location_in_screen);
overview_session_->SetSplitViewDragIndicatorsIndicatorState(
IndicatorState::kNone, rounded_screen_point);
item_->UpdateCannotSnapWarningVisibility();
}
// This function has multiple exit positions, at each we must update the desks
......
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