Commit 13325025 authored by Avery Musbach's avatar Avery Musbach Committed by Commit Bot

split view: Modify CanSnapInSplitview to account for divider thickness

Test: SplitViewControllerTest.SnapWindowWithMinimumSizeTest
Bug: 1019965
Change-Id: Ia31c621d18fbdcf6016f095f78aceff1fa0dd600
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1891756Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Avery Musbach <amusbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711282}
parent 607ade07
......@@ -1489,24 +1489,26 @@ TEST_P(SplitViewControllerTest, ExitTabletModeEndSplitView) {
EXPECT_FALSE(split_view_controller()->InSplitViewMode());
}
// Tests that if a window's minimum size is larger than half of the display work
// area's size, it can't be snapped.
// Test that |CanSnapInSplitview| checks that the minimum size of the window
// fits into the left or top, with the default divider position. (If the work
// area length is odd, then the right or bottom will be one pixel larger.)
TEST_P(SplitViewControllerTest, SnapWindowWithMinimumSizeTest) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
EXPECT_TRUE(CanSnapInSplitview(window1.get()));
const gfx::Rect display_bounds =
screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
window1.get());
UpdateDisplay("800x600");
aura::test::TestWindowDelegate* delegate =
static_cast<aura::test::TestWindowDelegate*>(window1->delegate());
delegate->set_minimum_size(
gfx::Size(display_bounds.width() * 0.5f, display_bounds.height()));
delegate->set_minimum_size(gfx::Size(396, 0));
EXPECT_TRUE(CanSnapInSplitview(window1.get()));
delegate->set_minimum_size(gfx::Size(397, 0));
EXPECT_FALSE(CanSnapInSplitview(window1.get()));
delegate->set_minimum_size(
gfx::Size(display_bounds.width() * 0.67f, display_bounds.height()));
UpdateDisplay("799x600");
delegate->set_minimum_size(gfx::Size(395, 0));
EXPECT_TRUE(CanSnapInSplitview(window1.get()));
delegate->set_minimum_size(gfx::Size(396, 0));
EXPECT_FALSE(CanSnapInSplitview(window1.get()));
}
......
......@@ -331,8 +331,9 @@ bool CanSnapInSplitview(aura::Window* window) {
if (!WindowState::Get(window)->CanSnap())
return false;
// Return true if |window|'s minimum size, if any, fits into half the work
// area lengthwise.
// Return true if |window|'s minimum size, if any, fits into the left or top
// with the default divider position. (If the work area length is odd, then
// the right or bottom will be one pixel larger.)
if (!window->delegate())
return true;
const gfx::Size min_size = window->delegate()->GetMinimumSize();
......@@ -340,8 +341,10 @@ bool CanSnapInSplitview(aura::Window* window) {
screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
window);
return IsCurrentScreenOrientationLandscape()
? min_size.width() <= work_area.width() / 2
: min_size.height() <= work_area.height() / 2;
? min_size.width() <=
work_area.width() / 2 - kSplitviewDividerShortSideLength / 2
: min_size.height() <= work_area.height() / 2 -
kSplitviewDividerShortSideLength / 2;
}
void ShowAppCannotSnapToast() {
......
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