Commit 9b660319 authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Commit Bot

back gesture: close VK first if VK is visible when performing back.

Bug: 1056939
Change-Id: I70acfadf7ad2468e8055f8150759861b892812b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2083756Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746156}
parent 7f6eed59
......@@ -9,6 +9,7 @@
#include "ash/home_screen/home_screen_controller.h"
#include "ash/public/cpp/app_types.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/keyboard/keyboard_controller.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/contextual_tooltip.h"
#include "ash/shell.h"
......@@ -258,47 +259,52 @@ bool BackGestureEventHandler::MaybeHandleBackGesture(ui::GestureEvent* event,
if (back_gesture_affordance_->IsActivated() ||
(event->type() == ui::ET_SCROLL_FLING_START &&
event->details().velocity_x() >= kFlingVelocityForGoingBack)) {
ActivateUnderneathWindowInSplitViewMode(
back_start_location_, dragged_from_splitview_divider_);
auto* top_window_state =
WindowState::Get(TabletModeWindowManager::GetTopWindow());
if (top_window_state && top_window_state->IsFullscreen() &&
!Shell::Get()->overview_controller()->InOverviewSession()) {
// For fullscreen ARC apps, show the hotseat and shelf on the first
// back swipe, and send a back event on the second back swipe. For
// other fullscreen apps, exit fullscreen.
const bool arc_app =
top_window_state->window()->GetProperty(aura::client::kAppType) ==
static_cast<int>(AppType::ARC_APP);
if (arc_app) {
// Go back to the previous page if the shelf was already shown,
// otherwise record as showing shelf.
if (Shelf::ForWindow(top_window_state->window())->IsVisible()) {
SendBackEvent(screen_location);
if (KeyboardController::Get()->IsKeyboardVisible()) {
KeyboardController::Get()->HideKeyboard(HideReason::kUser);
} else {
ActivateUnderneathWindowInSplitViewMode(
back_start_location_, dragged_from_splitview_divider_);
auto* top_window_state =
WindowState::Get(TabletModeWindowManager::GetTopWindow());
if (top_window_state && top_window_state->IsFullscreen() &&
!Shell::Get()->overview_controller()->InOverviewSession()) {
// For fullscreen ARC apps, show the hotseat and shelf on the first
// back swipe, and send a back event on the second back swipe. For
// other fullscreen apps, exit fullscreen.
const bool arc_app = top_window_state->window()->GetProperty(
aura::client::kAppType) ==
static_cast<int>(AppType::ARC_APP);
if (arc_app) {
// Go back to the previous page if the shelf was already shown,
// otherwise record as showing shelf.
if (Shelf::ForWindow(top_window_state->window())->IsVisible()) {
SendBackEvent(screen_location);
} else {
Shelf::ForWindow(top_window_state->window())
->shelf_layout_manager()
->UpdateVisibilityStateForBackGesture();
RecordEndScenarioType(
BackGestureEndScenarioType::kShowShelfAndHotseat);
}
} else {
Shelf::ForWindow(top_window_state->window())
->shelf_layout_manager()
->UpdateVisibilityStateForBackGesture();
// Complete as exiting the fullscreen mode of the underneath
// window.
const WMEvent event(WM_EVENT_TOGGLE_FULLSCREEN);
top_window_state->OnWMEvent(&event);
RecordEndScenarioType(
BackGestureEndScenarioType::kShowShelfAndHotseat);
BackGestureEndScenarioType::kExitFullscreen);
}
} else if (TabletModeWindowManager::ShouldMinimizeTopWindowOnBack()) {
// Complete as minimizing the underneath window.
top_window_state->Minimize();
RecordEndScenarioType(
GetEndScenarioType(back_gesture_start_scenario_type_,
BackGestureEndType::kMinimize));
} else {
// Complete as exiting the fullscreen mode of the underneath
// Complete as going back to the previous page of the underneath
// window.
const WMEvent event(WM_EVENT_TOGGLE_FULLSCREEN);
top_window_state->OnWMEvent(&event);
RecordEndScenarioType(BackGestureEndScenarioType::kExitFullscreen);
SendBackEvent(screen_location);
}
} else if (TabletModeWindowManager::ShouldMinimizeTopWindowOnBack()) {
// Complete as minimizing the underneath window.
top_window_state->Minimize();
RecordEndScenarioType(
GetEndScenarioType(back_gesture_start_scenario_type_,
BackGestureEndType::kMinimize));
} else {
// Complete as going back to the previous page of the underneath
// window.
SendBackEvent(screen_location);
}
back_gesture_affordance_->Complete();
if (features::AreContextualNudgesEnabled()) {
......
......@@ -11,7 +11,9 @@
#include "ash/display/screen_orientation_controller.h"
#include "ash/display/screen_orientation_controller_test_api.h"
#include "ash/home_screen/home_screen_controller.h"
#include "ash/keyboard/ui/test/keyboard_test_util.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/keyboard/keyboard_controller.h"
#include "ash/screen_util.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/hotseat_widget.h"
......@@ -539,4 +541,29 @@ TEST_F(BackGestureEventHandlerTest, ARCFullscreenedWindow) {
EXPECT_EQ(1, target_back_release.accelerator_count());
}
// Tests the back gesture behavior when a virtual keyboard is visible.
TEST_F(BackGestureEventHandlerTest, BackGestureWithVKTest) {
ui::TestAcceleratorTarget target_back_press, target_back_release;
RegisterBackPressAndRelease(&target_back_press, &target_back_release);
KeyboardController* keyboard_controller = KeyboardController::Get();
keyboard_controller->SetEnableFlag(
keyboard::KeyboardEnableFlag::kExtensionEnabled);
// The keyboard needs to be in a loaded state before being shown.
ASSERT_TRUE(keyboard::test::WaitUntilLoaded());
keyboard_controller->ShowKeyboard();
EXPECT_TRUE(keyboard_controller->IsKeyboardVisible());
GenerateBackSequence();
// First back gesture should hide the virtual keyboard.
EXPECT_FALSE(keyboard_controller->IsKeyboardVisible());
EXPECT_EQ(0, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
GenerateBackSequence();
// Second back gesture should trigger go back.
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
}
} // namespace ash
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