Commit b835d9c0 authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Commit Bot

Activate an unsnappable window should end both splitview and overview.

Bug: 880959
Change-Id: I87d4d222ea3b748171624846bfade66cca994a1b
Reviewed-on: https://chromium-review.googlesource.com/1208145Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589181}
parent e2a125c4
......@@ -929,14 +929,21 @@ bool WindowSelector::HandleKeyEvent(views::Textfield* sender,
void WindowSelector::OnSplitViewStateChanged(
SplitViewController::State previous_state,
SplitViewController::State state) {
if (state != SplitViewController::NO_SNAP) {
// Do not restore focus if a window was just snapped and activated.
const bool unsnappable_window_activated =
state == SplitViewController::NO_SNAP &&
Shell::Get()->split_view_controller()->end_reason() ==
SplitViewController::EndReason::kUnsnappableWindowActivated;
if (state != SplitViewController::NO_SNAP || unsnappable_window_activated) {
// Do not restore focus if a window was just snapped and activated or
// splitview mode is ended by activating an unsnappable window.
ResetFocusRestoreWindow(false);
}
if (state == SplitViewController::BOTH_SNAPPED) {
// If two windows were snapped to both sides of the screen, end overview
// mode.
if (state == SplitViewController::BOTH_SNAPPED ||
unsnappable_window_activated) {
// If two windows were snapped to both sides of the screen or an unsnappable
// window was just activated, end overview mode.
CancelSelection();
} else {
// Otherwise adjust the overview window grid bounds if overview mode is
......
......@@ -695,7 +695,7 @@ void SplitViewController::OnWindowActivated(ActivationReason reason,
// mode and show the cannot snap toast.
if (!CanSnap(gained_active)) {
if (wm::GetWindowState(gained_active)->IsUserPositionable()) {
EndSplitView();
EndSplitView(EndReason::kUnsnappableWindowActivated);
ShowAppCannotSnapToast();
}
return;
......
......@@ -58,10 +58,12 @@ class ASH_EXPORT SplitViewController : public mojom::SplitViewController,
enum SnapPosition { NONE, LEFT, RIGHT };
// Why splitview was ended. For now, all reasons will be kNormal except when
// the home launcher button is pressed.
// the home launcher button is pressed or an unsnappable window just got
// activated.
enum class EndReason {
kNormal = 0,
kHomeLauncherPressed,
kUnsnappableWindowActivated,
};
class Observer {
......
......@@ -1596,6 +1596,24 @@ TEST_F(SplitViewControllerTest, WindowStateOnExit) {
EXPECT_FALSE(wm::GetWindowState(window2.get())->IsMaximized());
}
// Test that if overview and splitview are both active at the same time,
// activiate an unsnappable window should end both overview and splitview mode.
TEST_F(SplitViewControllerTest, ActivateNonSnappableWindow) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
std::unique_ptr<aura::Window> window3(CreateNonSnappableWindow(bounds));
split_view_controller()->SnapWindow(window1.get(), SplitViewController::LEFT);
ToggleOverview();
EXPECT_TRUE(split_view_controller()->IsSplitViewModeActive());
EXPECT_TRUE(Shell::Get()->window_selector_controller()->IsSelecting());
wm::ActivateWindow(window3.get());
EXPECT_FALSE(split_view_controller()->IsSplitViewModeActive());
EXPECT_FALSE(Shell::Get()->window_selector_controller()->IsSelecting());
}
// Test the tab-dragging related functionalities in tablet mode. Tab(s) can be
// dragged out of a window and then put in split view mode or merge into another
// window.
......
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