Commit 7a2732fd authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Commit Bot

Move window finalization handling logic to the same function.

Currently when swiping up from bottom to drag a window, the window can
be ended in 4 different places: restore to its old position, go to home
screen, drop in overview, or snap in splitview. These operations are
handled in different places, with the first 2 handled in
FinalizedDraggedWindow() function and the latter 2 handled in
EndDrag() function. The reason for it to avoid window state change to
interfere with shelf state change, see https://crrev.com/c/2004052.

This CL moves the logic of window finalization operations together while
keeping the existing logic unchanged.

This CL doesn't have any functional change.

Bug: None
Change-Id: Ib2c4e866893c51ee952725a3b80c701f8b02120a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2320770Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792108}
parent 291e2a30
...@@ -240,6 +240,7 @@ base::Optional<ShelfWindowDragResult> DragWindowFromShelfController::EndDrag( ...@@ -240,6 +240,7 @@ base::Optional<ShelfWindowDragResult> DragWindowFromShelfController::EndDrag(
return base::nullopt; return base::nullopt;
drag_started_ = false; drag_started_ = false;
previous_location_in_screen_ = location_in_screen;
presentation_time_recorder_.reset(); presentation_time_recorder_.reset();
OverviewController* overview_controller = Shell::Get()->overview_controller(); OverviewController* overview_controller = Shell::Get()->overview_controller();
SplitViewController* split_view_controller = SplitViewController* split_view_controller =
...@@ -248,8 +249,7 @@ base::Optional<ShelfWindowDragResult> DragWindowFromShelfController::EndDrag( ...@@ -248,8 +249,7 @@ base::Optional<ShelfWindowDragResult> DragWindowFromShelfController::EndDrag(
const bool in_splitview = split_view_controller->InSplitViewMode(); const bool in_splitview = split_view_controller->InSplitViewMode();
const bool drop_window_in_overview = const bool drop_window_in_overview =
ShouldDropWindowInOverview(location_in_screen, velocity_y); ShouldDropWindowInOverview(location_in_screen, velocity_y);
SplitViewController::SnapPosition snap_position = end_snap_position_ = GetSnapPositionOnDragEnd(location_in_screen, velocity_y);
GetSnapPositionOnDragEnd(location_in_screen, velocity_y);
window_drag_result_ = base::nullopt; window_drag_result_ = base::nullopt;
if (ShouldGoToHomeScreen(location_in_screen, velocity_y)) { if (ShouldGoToHomeScreen(location_in_screen, velocity_y)) {
...@@ -266,19 +266,18 @@ base::Optional<ShelfWindowDragResult> DragWindowFromShelfController::EndDrag( ...@@ -266,19 +266,18 @@ base::Optional<ShelfWindowDragResult> DragWindowFromShelfController::EndDrag(
} else { } else {
if (drop_window_in_overview) if (drop_window_in_overview)
window_drag_result_ = ShelfWindowDragResult::kGoToOverviewMode; window_drag_result_ = ShelfWindowDragResult::kGoToOverviewMode;
else if (snap_position != SplitViewController::NONE) else if (end_snap_position_ != SplitViewController::NONE)
window_drag_result_ = ShelfWindowDragResult::kGoToSplitviewMode; window_drag_result_ = ShelfWindowDragResult::kGoToSplitviewMode;
// For window that may drop in overview or snap in split screen, restore its // For window that may drop in overview or snap in split screen, restore its
// original backdrop mode. // original backdrop mode.
WindowBackdrop::Get(window_)->RestoreBackdrop(); WindowBackdrop::Get(window_)->RestoreBackdrop();
} }
WindowState::Get(window_)->DeleteDragDetails();
if (window_drag_result_.has_value()) { if (window_drag_result_.has_value()) {
UMA_HISTOGRAM_ENUMERATION(kHandleDragWindowFromShelfHistogramName, UMA_HISTOGRAM_ENUMERATION(kHandleDragWindowFromShelfHistogramName,
*window_drag_result_); *window_drag_result_);
} }
OnDragEnded(location_in_screen, drop_window_in_overview, snap_position);
return window_drag_result_; return window_drag_result_;
} }
...@@ -301,9 +300,11 @@ void DragWindowFromShelfController::CancelDrag() { ...@@ -301,9 +300,11 @@ void DragWindowFromShelfController::CancelDrag() {
overview_controller->EndOverview(OverviewEnterExitType::kImmediateExit); overview_controller->EndOverview(OverviewEnterExitType::kImmediateExit);
ReshowHiddenWindowsOnDragEnd(); ReshowHiddenWindowsOnDragEnd();
window_drag_result_ = ShelfWindowDragResult::kDragCanceled;
OnDragEnded(previous_location_in_screen_, OnDragEnded(previous_location_in_screen_,
/*should_drop_window_in_overview=*/false, /*should_drop_window_in_overview=*/false,
/*snap_position=*/SplitViewController::NONE); /*snap_position=*/SplitViewController::NONE);
WindowState::Get(window_)->DeleteDragDetails();
} }
bool DragWindowFromShelfController::IsDraggedWindowAnimating() const { bool DragWindowFromShelfController::IsDraggedWindowAnimating() const {
...@@ -319,22 +320,9 @@ void DragWindowFromShelfController::FinalizeDraggedWindow() { ...@@ -319,22 +320,9 @@ void DragWindowFromShelfController::FinalizeDraggedWindow() {
DCHECK(!drag_started_); DCHECK(!drag_started_);
DCHECK(window_); DCHECK(window_);
switch (*window_drag_result_) { OnDragEnded(previous_location_in_screen_,
case ShelfWindowDragResult::kGoToHomeScreen: *window_drag_result_ == ShelfWindowDragResult::kGoToOverviewMode,
ScaleDownWindowAfterDrag(); end_snap_position_);
break;
case ShelfWindowDragResult::kRestoreToOriginalBounds:
ScaleUpToRestoreWindowAfterDrag();
break;
case ShelfWindowDragResult::kGoToOverviewMode:
case ShelfWindowDragResult::kGoToSplitviewMode:
case ShelfWindowDragResult::kDragCanceled:
// No action is needed.
break;
}
window_drag_result_.reset();
started_in_overview_ = false;
} }
void DragWindowFromShelfController::OnWindowDestroying(aura::Window* window) { void DragWindowFromShelfController::OnWindowDestroying(aura::Window* window) {
...@@ -425,7 +413,22 @@ void DragWindowFromShelfController::OnDragEnded( ...@@ -425,7 +413,22 @@ void DragWindowFromShelfController::OnDragEnded(
->SetWallpaperProperty(wallpaper_constants::kClear); ->SetWallpaperProperty(wallpaper_constants::kClear);
} }
WindowState::Get(window_)->DeleteDragDetails(); DCHECK(window_drag_result_.has_value());
switch (*window_drag_result_) {
case ShelfWindowDragResult::kGoToHomeScreen:
ScaleDownWindowAfterDrag();
break;
case ShelfWindowDragResult::kRestoreToOriginalBounds:
ScaleUpToRestoreWindowAfterDrag();
break;
case ShelfWindowDragResult::kGoToOverviewMode:
case ShelfWindowDragResult::kGoToSplitviewMode:
case ShelfWindowDragResult::kDragCanceled:
// No action is needed.
break;
}
window_drag_result_.reset();
started_in_overview_ = false;
} }
void DragWindowFromShelfController::UpdateDraggedWindow( void DragWindowFromShelfController::UpdateDraggedWindow(
......
...@@ -205,6 +205,9 @@ class ASH_EXPORT DragWindowFromShelfController : public aura::WindowObserver { ...@@ -205,6 +205,9 @@ class ASH_EXPORT DragWindowFromShelfController : public aura::WindowObserver {
bool during_window_restoration_callback_ = false; bool during_window_restoration_callback_ = false;
SplitViewController::SnapPosition end_snap_position_ =
SplitViewController::NONE;
std::unique_ptr<PresentationTimeRecorder> presentation_time_recorder_; std::unique_ptr<PresentationTimeRecorder> presentation_time_recorder_;
base::WeakPtrFactory<DragWindowFromShelfController> weak_ptr_factory_{this}; base::WeakPtrFactory<DragWindowFromShelfController> weak_ptr_factory_{this};
......
...@@ -2399,11 +2399,6 @@ void ShelfLayoutManager::CompleteDrag(const ui::LocatedEvent& event_in_screen) { ...@@ -2399,11 +2399,6 @@ void ShelfLayoutManager::CompleteDrag(const ui::LocatedEvent& event_in_screen) {
else else
CancelDrag(window_drag_result); CancelDrag(window_drag_result);
// Dragged window is finalized after drag handling is completed so drag state
// does not interfere with updates on shelf state during window state changes.
if (window_drag_controller_.get())
window_drag_controller_->FinalizeDraggedWindow();
// Hotseat gestures are meaningful only in tablet mode with hotseat enabled. // Hotseat gestures are meaningful only in tablet mode with hotseat enabled.
if (chromeos::switches::ShouldShowShelfHotseat() && if (chromeos::switches::ShouldShowShelfHotseat() &&
Shell::Get()->IsInTabletMode()) { Shell::Get()->IsInTabletMode()) {
...@@ -2464,12 +2459,21 @@ void ShelfLayoutManager::CancelDrag( ...@@ -2464,12 +2459,21 @@ void ShelfLayoutManager::CancelDrag(
else else
Shell::Get()->app_list_controller()->DismissAppList(); Shell::Get()->app_list_controller()->DismissAppList();
} else { } else {
MaybeCancelWindowDrag();
// Set |drag_status_| to kDragCancelInProgress to set the // Set |drag_status_| to kDragCancelInProgress to set the
// auto hide state to |drag_auto_hide_state_|, which is the // auto hide state to |drag_auto_hide_state_|, which is the
// visibility state before starting drag. // visibility state before starting drag.
drag_status_ = kDragCancelInProgress; drag_status_ = kDragCancelInProgress;
UpdateVisibilityState(); UpdateVisibilityState();
// Dragged window is finalized after drag handling is completed so drag
// state does not interfere with updates on shelf state during window state
// changes.
if (window_drag_controller_.get()) {
if (window_drag_result.has_value())
window_drag_controller_->FinalizeDraggedWindow();
else
MaybeCancelWindowDrag();
}
} }
if (hotseat_is_in_drag_) { if (hotseat_is_in_drag_) {
// If the gesture started the overview session, the hotseat will be // If the gesture started the overview session, the hotseat will be
...@@ -2509,6 +2513,12 @@ void ShelfLayoutManager::CompleteDragWithChangedVisibility() { ...@@ -2509,6 +2513,12 @@ void ShelfLayoutManager::CompleteDragWithChangedVisibility() {
drag_status_ = kDragCompleteInProgress; drag_status_ = kDragCompleteInProgress;
UpdateVisibilityState(); UpdateVisibilityState();
// Dragged window is finalized after drag handling is completed so drag state
// does not interfere with updates on shelf state during window state changes.
if (window_drag_controller_.get())
window_drag_controller_->FinalizeDraggedWindow();
drag_status_ = kDragNone; drag_status_ = kDragNone;
if (hotseat_is_in_drag_) if (hotseat_is_in_drag_)
hotseat_presentation_time_recorder_.reset(); hotseat_presentation_time_recorder_.reset();
......
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