Commit 52899371 authored by Kazuki Takise's avatar Kazuki Takise Committed by Commit Bot

Use flinged bounds for snap fraction calculation

We currently save snap fraction in CompleteDrag, but if the PIP
window is flinged, the bounds of the PIP window is not the flinged
bounds at this point as it just creates a bounds event and sends
the client a bounds change request. So we need to pass the flinged
bounds to SaveSnapFraction.

Before introducing snap fraction, we used restore bounds and saved
the flinged bounds properly, so this CL basically does the same
thing with snap fraction.

BUG=b:149875362
TEST=Manually confirmed flinging PIP and rotating the screen works.

Change-Id: I7b109eaf7786aee5d3c70da167c27ff5c1a69e90
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2065510
Commit-Queue: Kazuki Takise <takise@chromium.org>
Auto-Submit: Kazuki Takise <takise@chromium.org>
Reviewed-by: default avatarStefan Kuhne <skuhne@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743799}
parent 7cb91122
......@@ -239,7 +239,8 @@ void ClientControlledState::HandleBoundsEvents(WindowState* window_state,
// position, we need to set it here.
if (window_state->IsPip() &&
!PipPositioner::HasSnapFraction(window_state)) {
PipPositioner::SaveSnapFraction(window_state);
PipPositioner::SaveSnapFraction(
window_state, window_state->window()->GetBoundsInScreen());
}
} else if (!window_state->IsPinned()) {
......
......@@ -125,26 +125,26 @@ bool PipPositioner::HasSnapFraction(WindowState* window_state) {
nullptr;
}
void PipPositioner::SaveSnapFraction(WindowState* window_state) {
void PipPositioner::SaveSnapFraction(WindowState* window_state,
const gfx::Rect& bounds) {
// Ensure that |bounds| is along one of the edges of the movement area.
// If the PIP window is drag-moved onto some system UI, it's possible that
// the PIP window is detached from any of them.
gfx::Rect bounds =
gfx::Rect snapped_bounds =
ash::CollisionDetectionUtils::AdjustToFitMovementAreaByGravity(
window_state->GetDisplay(),
window_state->window()->GetBoundsInScreen());
window_state->GetDisplay(), bounds);
gfx::Rect movement_area =
CollisionDetectionUtils::GetMovementArea(window_state->GetDisplay());
float width_fraction = (float)(bounds.x() - movement_area.x()) /
(movement_area.width() - bounds.width());
float height_fraction = (float)(bounds.y() - movement_area.y()) /
(movement_area.height() - bounds.height());
float width_fraction = (float)(snapped_bounds.x() - movement_area.x()) /
(movement_area.width() - snapped_bounds.width());
float height_fraction = (float)(snapped_bounds.y() - movement_area.y()) /
(movement_area.height() - snapped_bounds.height());
float snap_fraction;
if (bounds.y() == movement_area.y()) {
if (snapped_bounds.y() == movement_area.y()) {
snap_fraction = width_fraction;
} else if (bounds.right() == movement_area.right()) {
} else if (snapped_bounds.right() == movement_area.right()) {
snap_fraction = 1. + height_fraction;
} else if (bounds.bottom() == movement_area.bottom()) {
} else if (snapped_bounds.bottom() == movement_area.bottom()) {
snap_fraction = 2. + (1. - width_fraction);
} else {
snap_fraction = 3. + (1. - height_fraction);
......
......@@ -64,7 +64,8 @@ class ASH_EXPORT PipPositioner {
static bool HasSnapFraction(WindowState* window_state);
// Saves the current PIP snap fraction.
static void SaveSnapFraction(WindowState* window_state);
static void SaveSnapFraction(WindowState* window_state,
const gfx::Rect& bounds);
private:
friend class PipPositionerDisplayTest;
......
......@@ -203,7 +203,7 @@ TEST_F(PipTest, PipRestoresToPreviousBoundsOnMovementAreaChangeIfTheyExist) {
const gfx::Rect bounds = gfx::Rect(292, 200, 100, 100);
// Set restore position to where the window currently is.
window->SetBounds(bounds);
PipPositioner::SaveSnapFraction(window_state);
PipPositioner::SaveSnapFraction(window_state, window->GetBoundsInScreen());
EXPECT_TRUE(PipPositioner::HasSnapFraction(window_state));
// Update the work area so that the PIP window should be pushed upward.
......@@ -241,7 +241,7 @@ TEST_F(
window->SetBounds(gfx::Rect(8, 292, 100, 100));
// Set restore position to where the window currently is.
PipPositioner::SaveSnapFraction(window_state);
PipPositioner::SaveSnapFraction(window_state, window->GetBoundsInScreen());
EXPECT_TRUE(PipPositioner::HasSnapFraction(window_state));
// Update the work area so that the PIP window should be pushed upward.
......@@ -309,7 +309,7 @@ TEST_F(PipTest, PipSnappedToEdgeWhenSavingSnapFraction) {
window->SetBounds(gfx::Rect(100, 192, 100, 100));
// Set restore position to where the window currently is.
PipPositioner::SaveSnapFraction(window_state);
PipPositioner::SaveSnapFraction(window_state, window->GetBoundsInScreen());
EXPECT_TRUE(PipPositioner::HasSnapFraction(window_state));
// Ensure that the correct value is saved as snap fraction even when the PIP
......
......@@ -314,7 +314,7 @@ void PipWindowResizer::CompleteDrag() {
// TODO(edcourtney): This may not be the best place for this. Consider
// doing this a different way or saving these bounds at a later point when
// the work area changes.
PipPositioner::SaveSnapFraction(window_state());
PipPositioner::SaveSnapFraction(window_state(), bounds);
}
}
......
......@@ -789,7 +789,8 @@ TEST_F(WindowStateTest, SetBoundsSnapsPipBoundsToScreenEdge) {
EXPECT_EQ(gfx::Rect(541, 50, 51, 51),
window_state->window()->GetBoundsInScreen());
PipPositioner::SaveSnapFraction(window_state);
PipPositioner::SaveSnapFraction(window_state,
window_state->window()->GetBoundsInScreen());
EXPECT_TRUE(PipPositioner::HasSnapFraction(window_state));
EXPECT_EQ(gfx::Rect(541, 50, 51, 51),
PipPositioner::GetPositionAfterMovementAreaChange(window_state));
......
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