Commit 7052392d authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

overview: Fix aspect ratio clipping on windows with top insets.

Bug was caused by us correctly adding the aspect ratio clipping, but
after a reposition of the windows, the clipping required for windows
with top insets would be set and override the aspect ratio clipping.

This patch adds a boolean so the overriding does not happen. A follow
up fix will be sent out later to address the specific workflow in the
bug, but this fixes a lot of other issues for now.

Test: added
Change-Id: I142c2f5530d06a47839ee36a65bf77684d3940b1
Bug: 1035186
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1972298Reviewed-by: default avatarAvery Musbach <amusbach@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726082}
parent 6707e4b1
...@@ -4115,8 +4115,10 @@ TEST_P(SplitViewOverviewSessionTest, Clipping) { ...@@ -4115,8 +4115,10 @@ TEST_P(SplitViewOverviewSessionTest, Clipping) {
std::unique_ptr<aura::Window> window1 = CreateTestWindow(); std::unique_ptr<aura::Window> window1 = CreateTestWindow();
std::unique_ptr<aura::Window> window2 = CreateTestWindow(); std::unique_ptr<aura::Window> window2 = CreateTestWindow();
std::unique_ptr<aura::Window> window3 = CreateTestWindow(); std::unique_ptr<aura::Window> window3 = CreateTestWindow(); // Minimized.
std::unique_ptr<aura::Window> window4 = CreateTestWindow(); // Has top inset.
WindowState::Get(window3.get())->Minimize(); WindowState::Get(window3.get())->Minimize();
window4->SetProperty(aura::client::kTopViewInset, 32);
for (bool portrait : {false, true}) { for (bool portrait : {false, true}) {
SCOPED_TRACE(portrait ? "Portrait" : "Landscape"); SCOPED_TRACE(portrait ? "Portrait" : "Landscape");
...@@ -4130,6 +4132,7 @@ TEST_P(SplitViewOverviewSessionTest, Clipping) { ...@@ -4130,6 +4132,7 @@ TEST_P(SplitViewOverviewSessionTest, Clipping) {
const gfx::Rect clipping1 = window1->layer()->clip_rect(); const gfx::Rect clipping1 = window1->layer()->clip_rect();
const gfx::Rect clipping2 = window2->layer()->clip_rect(); const gfx::Rect clipping2 = window2->layer()->clip_rect();
const gfx::Rect clipping3 = window3->layer()->clip_rect(); const gfx::Rect clipping3 = window3->layer()->clip_rect();
const gfx::Rect clipping4 = window4->layer()->clip_rect();
const gfx::Rect maximized_bounds = const gfx::Rect maximized_bounds =
screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer( screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
window1.get()); window1.get());
...@@ -4139,15 +4142,22 @@ TEST_P(SplitViewOverviewSessionTest, Clipping) { ...@@ -4139,15 +4142,22 @@ TEST_P(SplitViewOverviewSessionTest, Clipping) {
/*window_for_minimum_size=*/nullptr); /*window_for_minimum_size=*/nullptr);
ToggleOverview(); ToggleOverview();
// Clipping like rounded corners and shadows gets updated via a delayed post
// task.
base::RunLoop().RunUntilIdle();
// Tests that in regular overview, the clipping is unchanged. // Tests that in regular overview, the clipping is unchanged.
ASSERT_TRUE(overview_controller()->InOverviewSession()); ASSERT_TRUE(overview_controller()->InOverviewSession());
EXPECT_EQ(clipping1, window1->layer()->clip_rect()); EXPECT_EQ(clipping1, window1->layer()->clip_rect());
EXPECT_EQ(clipping2, window2->layer()->clip_rect()); EXPECT_EQ(clipping2, window2->layer()->clip_rect());
EXPECT_EQ(clipping3, window3->layer()->clip_rect()); EXPECT_EQ(clipping3, window3->layer()->clip_rect());
EXPECT_NE(clipping4, window4->layer()->clip_rect());
const gfx::Rect overview_clipping4 = window4->layer()->clip_rect();
OverviewItem* item1 = GetOverviewItemForWindow(window1.get()); OverviewItem* item1 = GetOverviewItemForWindow(window1.get());
OverviewItem* item2 = GetOverviewItemForWindow(window2.get()); OverviewItem* item2 = GetOverviewItemForWindow(window2.get());
OverviewItem* item3 = GetOverviewItemForWindow(window3.get()); OverviewItem* item3 = GetOverviewItemForWindow(window3.get());
OverviewItem* item4 = GetOverviewItemForWindow(window4.get());
overview_session()->InitiateDrag(item1, overview_session()->InitiateDrag(item1,
item1->target_bounds().CenterPoint(), item1->target_bounds().CenterPoint(),
/*is_touch_dragging=*/false); /*is_touch_dragging=*/false);
...@@ -4190,6 +4200,18 @@ TEST_P(SplitViewOverviewSessionTest, Clipping) { ...@@ -4190,6 +4200,18 @@ TEST_P(SplitViewOverviewSessionTest, Clipping) {
EXPECT_TRUE( EXPECT_TRUE(
aspect_ratio_near(window3->GetBoundsInScreen(), maximized_bounds)); aspect_ratio_near(window3->GetBoundsInScreen(), maximized_bounds));
// A window with top view inset should be clipped, but with a new clipping
// than the original overview clipping.
EXPECT_FALSE(window4->layer()->clip_rect().IsEmpty());
EXPECT_NE(overview_clipping4, window4->layer()->clip_rect());
EXPECT_TRUE(aspect_ratio_near(window4->layer()->clip_rect(),
split_view_bounds_right));
EXPECT_TRUE(aspect_ratio_near(
gfx::ToEnclosedRect(item4->GetWindowTargetBoundsWithInsets()),
split_view_bounds_right));
EXPECT_TRUE(
aspect_ratio_near(window4->GetBoundsInScreen(), maximized_bounds));
// Tests that after snapping, the aspect ratios should be the same as being // Tests that after snapping, the aspect ratios should be the same as being
// in the preview area. // in the preview area.
overview_session()->CompleteDrag(item1, gfx::PointF()); overview_session()->CompleteDrag(item1, gfx::PointF());
...@@ -4212,12 +4234,23 @@ TEST_P(SplitViewOverviewSessionTest, Clipping) { ...@@ -4212,12 +4234,23 @@ TEST_P(SplitViewOverviewSessionTest, Clipping) {
EXPECT_TRUE( EXPECT_TRUE(
aspect_ratio_near(window3->GetBoundsInScreen(), maximized_bounds)); aspect_ratio_near(window3->GetBoundsInScreen(), maximized_bounds));
EXPECT_FALSE(window4->layer()->clip_rect().IsEmpty());
EXPECT_NE(overview_clipping4, window4->layer()->clip_rect());
EXPECT_TRUE(aspect_ratio_near(window4->layer()->clip_rect(),
split_view_bounds_right));
EXPECT_TRUE(aspect_ratio_near(
gfx::ToEnclosedRect(item4->GetWindowTargetBoundsWithInsets()),
split_view_bounds_right));
EXPECT_TRUE(
aspect_ratio_near(window4->GetBoundsInScreen(), maximized_bounds));
// Tests that the clipping is reset after exiting overview. // Tests that the clipping is reset after exiting overview.
EndSplitView(); EndSplitView();
ToggleOverview(); ToggleOverview();
EXPECT_EQ(clipping1, window1->layer()->clip_rect()); EXPECT_EQ(clipping1, window1->layer()->clip_rect());
EXPECT_EQ(clipping2, window2->layer()->clip_rect()); EXPECT_EQ(clipping2, window2->layer()->clip_rect());
EXPECT_EQ(clipping3, window3->layer()->clip_rect()); EXPECT_EQ(clipping3, window3->layer()->clip_rect());
EXPECT_EQ(clipping4, window4->layer()->clip_rect());
} }
} }
......
...@@ -286,6 +286,8 @@ void ScopedOverviewTransformWindow::SetOpacity(float opacity) { ...@@ -286,6 +286,8 @@ void ScopedOverviewTransformWindow::SetOpacity(float opacity) {
} }
void ScopedOverviewTransformWindow::SetClipping(const gfx::SizeF& size) { void ScopedOverviewTransformWindow::SetClipping(const gfx::SizeF& size) {
has_aspect_ratio_clipping_ = !size.IsEmpty();
// If width or height are 0, restore the overview clipping. // If width or height are 0, restore the overview clipping.
if (size.IsEmpty()) { if (size.IsEmpty()) {
window_->layer()->SetClipRect(overview_clip_rect_); window_->layer()->SetClipRect(overview_clip_rect_);
...@@ -296,6 +298,7 @@ void ScopedOverviewTransformWindow::SetClipping(const gfx::SizeF& size) { ...@@ -296,6 +298,7 @@ void ScopedOverviewTransformWindow::SetClipping(const gfx::SizeF& size) {
// account. // account.
gfx::Rect clip_rect; gfx::Rect clip_rect;
const gfx::Vector2dF scale = window_->layer()->GetTargetTransform().Scale2d(); const gfx::Vector2dF scale = window_->layer()->GetTargetTransform().Scale2d();
clip_rect.set_y(GetTopInset());
clip_rect.set_width(size.width() / scale.x()); clip_rect.set_width(size.width() / scale.x());
clip_rect.set_height(size.height() / scale.y()); clip_rect.set_height(size.height() / scale.y());
window_->layer()->SetClipRect(clip_rect); window_->layer()->SetClipRect(clip_rect);
...@@ -417,7 +420,7 @@ void ScopedOverviewTransformWindow::UpdateRoundedCorners(bool show, ...@@ -417,7 +420,7 @@ void ScopedOverviewTransformWindow::UpdateRoundedCorners(bool show,
return; return;
const int top_inset = GetTopInset(); const int top_inset = GetTopInset();
if (top_inset > 0) { if (!has_aspect_ratio_clipping_ && top_inset > 0) {
gfx::Rect clip_rect(window_->bounds().size()); gfx::Rect clip_rect(window_->bounds().size());
// We add 1 to the top_inset, because in some cases, the header is not // We add 1 to the top_inset, because in some cases, the header is not
// clipped fully due to what seems to be a rounding error. // clipped fully due to what seems to be a rounding error.
......
...@@ -211,6 +211,10 @@ class ASH_EXPORT ScopedOverviewTransformWindow ...@@ -211,6 +211,10 @@ class ASH_EXPORT ScopedOverviewTransformWindow
// removed, we should go back to this clipping. // removed, we should go back to this clipping.
gfx::Rect overview_clip_rect_; gfx::Rect overview_clip_rect_;
// True if a window is clipped to match splitview bounds. If true, the
// splitview clipping overrides any top view inset clipping there may be.
bool has_aspect_ratio_clipping_ = false;
std::unique_ptr<ScopedOverviewHideWindows> hidden_transient_children_; std::unique_ptr<ScopedOverviewHideWindows> hidden_transient_children_;
base::WeakPtrFactory<ScopedOverviewTransformWindow> weak_ptr_factory_{this}; base::WeakPtrFactory<ScopedOverviewTransformWindow> weak_ptr_factory_{this};
......
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