Commit fdfc9a0e authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

overview: Fix stacking issue with splitview for grid layout.

On entering overview, windows that are stacked above the snapped window
need to stacked underneath, otherwise when we scroll it will scroll
over it.

Also changed the aspect ratio maintaining codes to account for the
overview margin and overview header.

Test: manual, added test
Bug: 981188
Change-Id: I99c368d5ab50931a1eabe7bc70bf8a5b738c2bea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1747027
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686147}
parent f111676a
...@@ -1421,7 +1421,6 @@ std::vector<gfx::RectF> OverviewGrid::GetWindowRectsForTabletModeLayout( ...@@ -1421,7 +1421,6 @@ std::vector<gfx::RectF> OverviewGrid::GetWindowRectsForTabletModeLayout(
// Windows occupy vertically centered area with additional vertical insets. // Windows occupy vertically centered area with additional vertical insets.
total_bounds.Inset(GetGridInsets(total_bounds)); total_bounds.Inset(GetGridInsets(total_bounds));
// TODO(sammiequon): Check why scrolling during split view stacks windows.
// When the dragged item becomes an |ignored_item|, move the other windows // When the dragged item becomes an |ignored_item|, move the other windows
// accordingly. |window_position| matches the positions of the windows' // accordingly. |window_position| matches the positions of the windows'
// indexes from |window_list_|. However, if a window turns out to be an // indexes from |window_list_|. However, if a window turns out to be an
...@@ -1441,9 +1440,14 @@ std::vector<gfx::RectF> OverviewGrid::GetWindowRectsForTabletModeLayout( ...@@ -1441,9 +1440,14 @@ std::vector<gfx::RectF> OverviewGrid::GetWindowRectsForTabletModeLayout(
++i; ++i;
continue; continue;
} }
const float ratio = float{height} / window->GetWindow()->bounds().height();
const int width = window->GetWindow()->bounds().width() * ratio;
// Maintains the aspect ratio from the original window. The window's
// original height will be shrunk to fit into |height|, minus the margin and
// overview header.
const float ratio = float{height - kHeaderHeightDp - kOverviewMargin} /
window->GetWindow()->bounds().height();
const int width =
window->GetWindow()->bounds().width() * ratio + kOverviewMargin;
const int y = const int y =
height * (window_position % kTabletLayoutRow) + total_bounds.y(); height * (window_position % kTabletLayoutRow) + total_bounds.y();
......
...@@ -2975,6 +2975,37 @@ TEST_F(OverviewSessionNewLayoutTest, CheckOverviewItemScrollingBounds) { ...@@ -2975,6 +2975,37 @@ TEST_F(OverviewSessionNewLayoutTest, CheckOverviewItemScrollingBounds) {
EXPECT_EQ(right_bounds, rightmost_window->target_bounds()); EXPECT_EQ(right_bounds, rightmost_window->target_bounds());
} }
// Tests the windows are stacked correctly when entering or exiting splitview
// while the new overivew layout is enabled.
TEST_F(OverviewSessionNewLayoutTest, StackingOrderSplitviewWindow) {
std::unique_ptr<aura::Window> window1 = CreateTestWindow();
std::unique_ptr<aura::Window> window2 = CreateTestWindow();
ToggleOverview();
ASSERT_TRUE(InOverviewSession());
// Snap |window1| to the left and exit overview. |window2| should have higher
// z-order now, since it is the MRU window.
auto* split_view_controller = Shell::Get()->split_view_controller();
split_view_controller->SnapWindow(window1.get(), SplitViewController::LEFT);
ToggleOverview();
ASSERT_EQ(SplitViewState::kBothSnapped, split_view_controller->state());
ASSERT_GT(IndexOf(window2.get(), window2->parent()),
IndexOf(window1.get(), window1->parent()));
// Test that on entering overview, |window2| is of a lower z-order, so that
// when we scroll the grid, it will be seen under |window1|.
ToggleOverview();
EXPECT_LT(IndexOf(window2.get(), window2->parent()),
IndexOf(window1.get(), window1->parent()));
// Test that on exiting overview, |window2| becomes activated, so it returns
// to being higher on the z-order than |window1|.
ToggleOverview();
EXPECT_GT(IndexOf(window2.get(), window2->parent()),
IndexOf(window1.get(), window1->parent()));
}
// Test the split view and overview functionalities in tablet mode. // Test the split view and overview functionalities in tablet mode.
class SplitViewOverviewSessionTest : public OverviewSessionTest { class SplitViewOverviewSessionTest : public OverviewSessionTest {
public: public:
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "ash/wm/overview/overview_item.h" #include "ash/wm/overview/overview_item.h"
#include "ash/wm/overview/overview_utils.h" #include "ash/wm/overview/overview_utils.h"
#include "ash/wm/overview/scoped_overview_animation_settings.h" #include "ash/wm/overview/scoped_overview_animation_settings.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_preview_view.h" #include "ash/wm/window_preview_view.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
...@@ -126,6 +127,34 @@ ScopedOverviewTransformWindow::ScopedOverviewTransformWindow( ...@@ -126,6 +127,34 @@ ScopedOverviewTransformWindow::ScopedOverviewTransformWindow(
} }
aura::client::GetTransientWindowClient()->AddObserver(this); aura::client::GetTransientWindowClient()->AddObserver(this);
// Tablet mode grid layout has scrolling, so all windows must be stacked under
// the current split view window if they share the same parent so that during
// scrolls, they get scrolled underneath the split view window. The window
// will be returned to its proper z-order on exiting overview if it is
// activated.
// TODO(sammiequon): This does not handle the case if either the snapped
// window or this window is an always on top window.
auto* split_view_controller = Shell::Get()->split_view_controller();
if (ShouldUseTabletModeGridLayout() &&
split_view_controller->InSplitViewMode()) {
aura::Window* snapped_window =
split_view_controller->GetDefaultSnappedWindow();
if (window->parent() == snapped_window->parent()) {
// Helper to get the z order of a window in its parent.
auto get_z_order = [](aura::Window* window) -> size_t {
for (size_t i = 0u; i < window->parent()->children().size(); ++i) {
if (window == window->parent()->children()[i])
return i;
}
NOTREACHED();
return 0u;
};
if (get_z_order(window_) > get_z_order(snapped_window))
window_->parent()->StackChildBelow(window_, snapped_window);
}
}
} }
ScopedOverviewTransformWindow::~ScopedOverviewTransformWindow() { ScopedOverviewTransformWindow::~ScopedOverviewTransformWindow() {
......
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