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 @@ ...@@ -9,6 +9,7 @@
#include "ash/home_screen/home_screen_controller.h" #include "ash/home_screen/home_screen_controller.h"
#include "ash/public/cpp/app_types.h" #include "ash/public/cpp/app_types.h"
#include "ash/public/cpp/ash_features.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/session/session_controller_impl.h"
#include "ash/shelf/contextual_tooltip.h" #include "ash/shelf/contextual_tooltip.h"
#include "ash/shell.h" #include "ash/shell.h"
...@@ -258,47 +259,52 @@ bool BackGestureEventHandler::MaybeHandleBackGesture(ui::GestureEvent* event, ...@@ -258,47 +259,52 @@ bool BackGestureEventHandler::MaybeHandleBackGesture(ui::GestureEvent* event,
if (back_gesture_affordance_->IsActivated() || if (back_gesture_affordance_->IsActivated() ||
(event->type() == ui::ET_SCROLL_FLING_START && (event->type() == ui::ET_SCROLL_FLING_START &&
event->details().velocity_x() >= kFlingVelocityForGoingBack)) { event->details().velocity_x() >= kFlingVelocityForGoingBack)) {
ActivateUnderneathWindowInSplitViewMode( if (KeyboardController::Get()->IsKeyboardVisible()) {
back_start_location_, dragged_from_splitview_divider_); KeyboardController::Get()->HideKeyboard(HideReason::kUser);
auto* top_window_state = } else {
WindowState::Get(TabletModeWindowManager::GetTopWindow()); ActivateUnderneathWindowInSplitViewMode(
if (top_window_state && top_window_state->IsFullscreen() && back_start_location_, dragged_from_splitview_divider_);
!Shell::Get()->overview_controller()->InOverviewSession()) { auto* top_window_state =
// For fullscreen ARC apps, show the hotseat and shelf on the first WindowState::Get(TabletModeWindowManager::GetTopWindow());
// back swipe, and send a back event on the second back swipe. For if (top_window_state && top_window_state->IsFullscreen() &&
// other fullscreen apps, exit fullscreen. !Shell::Get()->overview_controller()->InOverviewSession()) {
const bool arc_app = // For fullscreen ARC apps, show the hotseat and shelf on the first
top_window_state->window()->GetProperty(aura::client::kAppType) == // back swipe, and send a back event on the second back swipe. For
static_cast<int>(AppType::ARC_APP); // other fullscreen apps, exit fullscreen.
if (arc_app) { const bool arc_app = top_window_state->window()->GetProperty(
// Go back to the previous page if the shelf was already shown, aura::client::kAppType) ==
// otherwise record as showing shelf. static_cast<int>(AppType::ARC_APP);
if (Shelf::ForWindow(top_window_state->window())->IsVisible()) { if (arc_app) {
SendBackEvent(screen_location); // 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 { } else {
Shelf::ForWindow(top_window_state->window()) // Complete as exiting the fullscreen mode of the underneath
->shelf_layout_manager() // window.
->UpdateVisibilityStateForBackGesture(); const WMEvent event(WM_EVENT_TOGGLE_FULLSCREEN);
top_window_state->OnWMEvent(&event);
RecordEndScenarioType( 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 { } else {
// Complete as exiting the fullscreen mode of the underneath // Complete as going back to the previous page of the underneath
// window. // window.
const WMEvent event(WM_EVENT_TOGGLE_FULLSCREEN); SendBackEvent(screen_location);
top_window_state->OnWMEvent(&event);
RecordEndScenarioType(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 going back to the previous page of the underneath
// window.
SendBackEvent(screen_location);
} }
back_gesture_affordance_->Complete(); back_gesture_affordance_->Complete();
if (features::AreContextualNudgesEnabled()) { if (features::AreContextualNudgesEnabled()) {
......
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
#include "ash/display/screen_orientation_controller.h" #include "ash/display/screen_orientation_controller.h"
#include "ash/display/screen_orientation_controller_test_api.h" #include "ash/display/screen_orientation_controller_test_api.h"
#include "ash/home_screen/home_screen_controller.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/ash_features.h"
#include "ash/public/cpp/keyboard/keyboard_controller.h"
#include "ash/screen_util.h" #include "ash/screen_util.h"
#include "ash/session/session_controller_impl.h" #include "ash/session/session_controller_impl.h"
#include "ash/shelf/hotseat_widget.h" #include "ash/shelf/hotseat_widget.h"
...@@ -539,4 +541,29 @@ TEST_F(BackGestureEventHandlerTest, ARCFullscreenedWindow) { ...@@ -539,4 +541,29 @@ TEST_F(BackGestureEventHandlerTest, ARCFullscreenedWindow) {
EXPECT_EQ(1, target_back_release.accelerator_count()); 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 } // 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