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) { ...@@ -832,43 +832,13 @@ void SplitViewController::OnResizeLoopStarted(aura::Window* window) {
return; 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 // 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 // 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 // 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, // same time. For the resize that happens on the other part of the window,
// we'll just end splitview and overview mode. // we'll just end splitview and overview mode.
bool should_end_splitview = true; if (WindowState::Get(window)->drag_details()->window_component !=
switch (orientation_type) { GetWindowComponentForResize(window)) {
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();
Shell::Get()->overview_controller()->EndOverview(); Shell::Get()->overview_controller()->EndOverview();
} }
} }
...@@ -1633,21 +1603,10 @@ void SplitViewController::GetDividerOptionalPositionRatios( ...@@ -1633,21 +1603,10 @@ void SplitViewController::GetDividerOptionalPositionRatios(
} }
int SplitViewController::GetWindowComponentForResize(aura::Window* window) { int SplitViewController::GetWindowComponentForResize(aura::Window* window) {
if (IsWindowInSplitView(window)) { DCHECK(IsWindowInSplitView(window));
switch (GetCurrentScreenOrientation()) { return window == GetPhysicalLeftOrTopWindow()
case OrientationLockType::kLandscapePrimary: ? (IsCurrentScreenOrientationLandscape() ? HTRIGHT : HTBOTTOM)
return (window == left_window_) ? HTRIGHT : HTLEFT; : (IsCurrentScreenOrientationLandscape() ? HTLEFT : HTTOP);
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;
} }
gfx::Point SplitViewController::GetEndDragLocationInScreen( gfx::Point SplitViewController::GetEndDragLocationInScreen(
...@@ -1660,22 +1619,12 @@ gfx::Point SplitViewController::GetEndDragLocationInScreen( ...@@ -1660,22 +1619,12 @@ gfx::Point SplitViewController::GetEndDragLocationInScreen(
const gfx::Rect bounds = (window == left_window_) const gfx::Rect bounds = (window == left_window_)
? GetSnappedWindowBoundsInScreen(LEFT) ? GetSnappedWindowBoundsInScreen(LEFT)
: GetSnappedWindowBoundsInScreen(RIGHT); : GetSnappedWindowBoundsInScreen(RIGHT);
switch (GetCurrentScreenOrientation()) { if (IsCurrentScreenOrientationLandscape()) {
case OrientationLockType::kLandscapePrimary: end_location.set_x(window == GetPhysicalLeftOrTopWindow() ? bounds.right()
end_location.set_x(window == left_window_ ? bounds.right() : bounds.x()); : bounds.x());
break; } else {
case OrientationLockType::kLandscapeSecondary: end_location.set_y(window == GetPhysicalLeftOrTopWindow() ? bounds.bottom()
end_location.set_x(window == left_window_ ? bounds.x() : bounds.right()); : bounds.y());
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;
} }
return end_location; return end_location;
} }
...@@ -1720,10 +1669,8 @@ void SplitViewController::UpdateWindowStackingAfterSnap( ...@@ -1720,10 +1669,8 @@ void SplitViewController::UpdateWindowStackingAfterSnap(
void SplitViewController::SetWindowsTransformDuringResizing() { void SplitViewController::SetWindowsTransformDuringResizing() {
DCHECK(InSplitViewMode()); DCHECK(InSplitViewMode());
const bool is_landscape = IsCurrentScreenOrientationLandscape(); const bool is_landscape = IsCurrentScreenOrientationLandscape();
aura::Window* left_or_top_window = aura::Window* left_or_top_window = GetPhysicalLeftOrTopWindow();
IsCurrentScreenOrientationPrimary() ? left_window_ : right_window_; aura::Window* right_or_bottom_window = GetPhysicalRightOrBottomWindow();
aura::Window* right_or_bottom_window =
IsCurrentScreenOrientationPrimary() ? right_window_ : left_window_;
gfx::Rect left_or_top_rect, right_or_bottom_rect; gfx::Rect left_or_top_rect, right_or_bottom_rect;
GetSnappedWindowBoundsInScreenInternal(&left_or_top_rect, GetSnappedWindowBoundsInScreenInternal(&left_or_top_rect,
......
...@@ -331,21 +331,17 @@ bool CanSnapInSplitview(aura::Window* window) { ...@@ -331,21 +331,17 @@ bool CanSnapInSplitview(aura::Window* window) {
if (!WindowState::Get(window)->CanSnap()) if (!WindowState::Get(window)->CanSnap())
return false; return false;
if (window->delegate()) { // Return true if |window|'s minimum size, if any, fits into half the work
// If the window's minimum size is larger than half of the display's work // area lengthwise.
// area size, the window can't be snapped in this case. if (!window->delegate())
const gfx::Size min_size = window->delegate()->GetMinimumSize(); return true;
const gfx::Rect display_area = const gfx::Size min_size = window->delegate()->GetMinimumSize();
screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer( const gfx::Rect work_area =
window); screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
const bool is_landscape = (display_area.width() > display_area.height()); window);
if ((is_landscape && min_size.width() > display_area.width() / 2) || return IsCurrentScreenOrientationLandscape()
(!is_landscape && min_size.height() > display_area.height() / 2)) { ? min_size.width() <= work_area.width() / 2
return false; : min_size.height() <= work_area.height() / 2;
}
}
return true;
} }
void ShowAppCannotSnapToast() { void ShowAppCannotSnapToast() {
......
...@@ -96,8 +96,7 @@ ASH_EXPORT bool AreMultiDisplayOverviewAndSplitViewEnabled(); ...@@ -96,8 +96,7 @@ ASH_EXPORT bool AreMultiDisplayOverviewAndSplitViewEnabled();
// Returns true if split view mode is supported. // Returns true if split view mode is supported.
ASH_EXPORT bool ShouldAllowSplitView(); ASH_EXPORT bool ShouldAllowSplitView();
// Returns true if |window| can be activated and snapped in split screen in // Returns true if |window| can be activated and snapped in split view.
// tablet mode.
ASH_EXPORT bool CanSnapInSplitview(aura::Window* window); ASH_EXPORT bool CanSnapInSplitview(aura::Window* window);
// Displays a toast notifying users the application selected for split view is // 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