0

float: Improvements to drag from shelf animation

1. If the other (not dragged) window is the floated window, set the
   parent to the active desk container. This is because when we enter
   overview, the float container is stacked below the desks containers.
2. If the other window is floated, skip the scale animation while
   dragging. The scale animation is for maximized windows, which would
   otherwise block overview. The float window is much smaller, and
   scaling it would shift it offscreen since it is not centered.

Test: manual
Change-Id: Id8b7964ebcb05a82bbdbbf3e80142e89e32183bf
Fixed: b/274499102
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4370449
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1122679}
This commit is contained in:
Sammie Quon
2023-03-27 22:02:07 +00:00
committed by Chromium LUCI CQ
parent bd746cfdf1
commit 2d0bda78b1
2 changed files with 30 additions and 12 deletions

@ -20,6 +20,7 @@
#include "ash/wallpaper/wallpaper_constants.h"
#include "ash/wallpaper/wallpaper_view.h"
#include "ash/wallpaper/wallpaper_widget_controller.h"
#include "ash/wm/desks/desks_util.h"
#include "ash/wm/float/float_controller.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/overview/overview_constants.h"
@ -242,8 +243,20 @@ DragWindowFromShelfController::DragWindowFromShelfController(
other_window_copy_ = wm::RecreateLayers(other_window_);
other_window_copy_->root()->SetVisible(true);
other_window_copy_->root()->SetOpacity(1.f);
other_window_->layer()->parent()->StackAbove(other_window_copy_->root(),
other_window_->layer());
// If `other_window_` is the floated window, we need to move the copy to
// the active desk container. The float container will be moved under the
// desk containers (see `ScopedFloatContainerStacker `), so that the
// overview item does not appear above the dragged window during the drag.
if (other_window_ == floated_window) {
ui::Layer* new_parent = desks_util::GetActiveDeskContainerForRoot(
Shell::GetPrimaryRootWindow())
->layer();
new_parent->Add(other_window_copy_->root());
} else {
other_window_->layer()->parent()->StackAbove(other_window_copy_->root(),
other_window_->layer());
}
}
}
@ -628,12 +641,16 @@ void DragWindowFromShelfController::UpdateDraggedWindow(
copy_scale = 1.f - base::clamp(copy_scale, 0.f, 1.f);
other_window_copy_->root()->SetOpacity(copy_scale);
const float copy_transform_scale =
base::clamp(copy_scale, kOtherWindowMaxScale, 1.f);
const gfx::Transform copy_transform = gfx::GetScaleTransform(
other_window_copy_->root()->bounds().CenterPoint(),
copy_transform_scale);
other_window_copy_->root()->SetTransform(copy_transform);
CHECK(other_window_);
if (!WindowState::Get(other_window_)->IsFloated()) {
const float copy_transform_scale =
base::clamp(copy_scale, kOtherWindowMaxScale, 1.f);
const gfx::Transform copy_transform = gfx::GetScaleTransform(
other_window_copy_->root()->bounds().CenterPoint(),
copy_transform_scale);
other_window_copy_->root()->SetTransform(copy_transform);
}
}
}

@ -1488,12 +1488,13 @@ TEST_F(FloatDragWindowFromShelfControllerTest, DragMaximizedWindow) {
ui::Layer* other_window_copy_layer = GetOtherWindowCopyLayer();
ASSERT_TRUE(other_window_copy_layer);
// To check if the copy is of the floated window, we check the parent and
// bounds.
EXPECT_EQ(floated_window->layer()->parent(),
other_window_copy_layer->parent());
// To check if the copy is of the floated window, we check the bounds. The
// float container gets stacked under the desk containers during overview, so
// the copy should be on a different parent.
EXPECT_EQ(floated_window->layer()->bounds(),
other_window_copy_layer->bounds());
EXPECT_NE(floated_window->layer()->parent(),
other_window_copy_layer->parent());
Drag(gfx::Point(0, 200), 1.f, 1.f);
EndDrag(shelf_bounds.CenterPoint(), /*velocity_y=*/absl::nullopt);