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

split view: Simplify code that uses screen orientation

Change-Id: I52750f7838d3d7f043ca83de02c274168bdb4a72
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1874716Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Avery Musbach <amusbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708601}
parent 6f2e8141
......@@ -832,43 +832,13 @@ void SplitViewController::OnResizeLoopStarted(aura::Window* window) {
return;
}
const int resize_component =
WindowState::Get(window)->drag_details()->window_component;
const OrientationLockType orientation_type = GetCurrentScreenOrientation();
// In clamshell mode, if splitview is active (which means overview is active
// at the same time), only the resize that happens on the window edge that's
// next to the overview grid will resize the window and overview grid at the
// same time. For the resize that happens on the other part of the window,
// we'll just end splitview and overview mode.
bool should_end_splitview = true;
switch (orientation_type) {
case OrientationLockType::kLandscapePrimary:
should_end_splitview =
!(window == left_window_ && resize_component == HTRIGHT) &&
!(window == right_window_ && resize_component == HTLEFT);
break;
case OrientationLockType::kLandscapeSecondary:
should_end_splitview =
!(window == left_window_ && resize_component == HTLEFT) &&
!(window == right_window_ && resize_component == HTRIGHT);
break;
case OrientationLockType::kPortraitPrimary:
should_end_splitview =
!(window == left_window_ && resize_component == HTBOTTOM) &&
!(window == right_window_ && resize_component == HTTOP);
break;
case OrientationLockType::kPortraitSecondary:
should_end_splitview =
!(window == left_window_ && resize_component == HTTOP) &&
!(window == right_window_ && resize_component == HTBOTTOM);
break;
default:
break;
}
if (should_end_splitview) {
EndSplitView();
if (WindowState::Get(window)->drag_details()->window_component !=
GetWindowComponentForResize(window)) {
Shell::Get()->overview_controller()->EndOverview();
}
}
......@@ -1633,21 +1603,10 @@ void SplitViewController::GetDividerOptionalPositionRatios(
}
int SplitViewController::GetWindowComponentForResize(aura::Window* window) {
if (IsWindowInSplitView(window)) {
switch (GetCurrentScreenOrientation()) {
case OrientationLockType::kLandscapePrimary:
return (window == left_window_) ? HTRIGHT : HTLEFT;
case OrientationLockType::kLandscapeSecondary:
return (window == left_window_) ? HTLEFT : HTRIGHT;
case OrientationLockType::kPortraitSecondary:
return (window == left_window_) ? HTTOP : HTBOTTOM;
case OrientationLockType::kPortraitPrimary:
return (window == left_window_) ? HTBOTTOM : HTTOP;
default:
return HTNOWHERE;
}
}
return HTNOWHERE;
DCHECK(IsWindowInSplitView(window));
return window == GetPhysicalLeftOrTopWindow()
? (IsCurrentScreenOrientationLandscape() ? HTRIGHT : HTBOTTOM)
: (IsCurrentScreenOrientationLandscape() ? HTLEFT : HTTOP);
}
gfx::Point SplitViewController::GetEndDragLocationInScreen(
......@@ -1660,22 +1619,12 @@ gfx::Point SplitViewController::GetEndDragLocationInScreen(
const gfx::Rect bounds = (window == left_window_)
? GetSnappedWindowBoundsInScreen(LEFT)
: GetSnappedWindowBoundsInScreen(RIGHT);
switch (GetCurrentScreenOrientation()) {
case OrientationLockType::kLandscapePrimary:
end_location.set_x(window == left_window_ ? bounds.right() : bounds.x());
break;
case OrientationLockType::kLandscapeSecondary:
end_location.set_x(window == left_window_ ? bounds.x() : bounds.right());
break;
case OrientationLockType::kPortraitSecondary:
end_location.set_y(window == left_window_ ? bounds.y() : bounds.bottom());
break;
case OrientationLockType::kPortraitPrimary:
end_location.set_y(window == left_window_ ? bounds.bottom() : bounds.y());
break;
default:
NOTREACHED();
break;
if (IsCurrentScreenOrientationLandscape()) {
end_location.set_x(window == GetPhysicalLeftOrTopWindow() ? bounds.right()
: bounds.x());
} else {
end_location.set_y(window == GetPhysicalLeftOrTopWindow() ? bounds.bottom()
: bounds.y());
}
return end_location;
}
......@@ -1720,10 +1669,8 @@ void SplitViewController::UpdateWindowStackingAfterSnap(
void SplitViewController::SetWindowsTransformDuringResizing() {
DCHECK(InSplitViewMode());
const bool is_landscape = IsCurrentScreenOrientationLandscape();
aura::Window* left_or_top_window =
IsCurrentScreenOrientationPrimary() ? left_window_ : right_window_;
aura::Window* right_or_bottom_window =
IsCurrentScreenOrientationPrimary() ? right_window_ : left_window_;
aura::Window* left_or_top_window = GetPhysicalLeftOrTopWindow();
aura::Window* right_or_bottom_window = GetPhysicalRightOrBottomWindow();
gfx::Rect left_or_top_rect, right_or_bottom_rect;
GetSnappedWindowBoundsInScreenInternal(&left_or_top_rect,
......
......@@ -331,21 +331,17 @@ bool CanSnapInSplitview(aura::Window* window) {
if (!WindowState::Get(window)->CanSnap())
return false;
if (window->delegate()) {
// If the window's minimum size is larger than half of the display's work
// area size, the window can't be snapped in this case.
const gfx::Size min_size = window->delegate()->GetMinimumSize();
const gfx::Rect display_area =
screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
window);
const bool is_landscape = (display_area.width() > display_area.height());
if ((is_landscape && min_size.width() > display_area.width() / 2) ||
(!is_landscape && min_size.height() > display_area.height() / 2)) {
return false;
}
}
return true;
// Return true if |window|'s minimum size, if any, fits into half the work
// area lengthwise.
if (!window->delegate())
return true;
const gfx::Size min_size = window->delegate()->GetMinimumSize();
const gfx::Rect work_area =
screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
window);
return IsCurrentScreenOrientationLandscape()
? min_size.width() <= work_area.width() / 2
: min_size.height() <= work_area.height() / 2;
}
void ShowAppCannotSnapToast() {
......
......@@ -96,8 +96,7 @@ ASH_EXPORT bool AreMultiDisplayOverviewAndSplitViewEnabled();
// Returns true if split view mode is supported.
ASH_EXPORT bool ShouldAllowSplitView();
// Returns true if |window| can be activated and snapped in split screen in
// tablet mode.
// Returns true if |window| can be activated and snapped in split view.
ASH_EXPORT bool CanSnapInSplitview(aura::Window* window);
// Displays a toast notifying users the application selected for split view is
......
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