Commit d3e3afec authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[VK] Keyboard tray icon should toggle the virtual keyboard.

We're changing the keyboard tray action to toggle the virtual keyboard
instead of always showing the virtual keyboard.

Previously, we made it so that the VK hides when you interact with
the shelf. So we also have to exclude the keyboard tray icon from this
behaviour.

Bug: 897672
Change-Id: I019f8acf2263a18a3f9248f232e51156c0b8a349
Reviewed-on: https://chromium-review.googlesource.com/c/1298513Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602909}
parent f2e1fa4d
...@@ -1942,6 +1942,7 @@ test("ash_unittests") { ...@@ -1942,6 +1942,7 @@ test("ash_unittests") {
"system/update/tray_update_unittest.cc", "system/update/tray_update_unittest.cc",
"system/update/update_notification_controller_unittest.cc", "system/update/update_notification_controller_unittest.cc",
"system/user/tray_user_unittest.cc", "system/user/tray_user_unittest.cc",
"system/virtual_keyboard/virtual_keyboard_tray_unittest.cc",
"test/ash_test_helper_unittest.cc", "test/ash_test_helper_unittest.cc",
"test/ash_unittests.cc", "test/ash_unittests.cc",
"tooltips/tooltip_controller_unittest.cc", "tooltips/tooltip_controller_unittest.cc",
......
...@@ -270,14 +270,26 @@ void StatusAreaWidget::UpdateShelfItemBackground(SkColor color) { ...@@ -270,14 +270,26 @@ void StatusAreaWidget::UpdateShelfItemBackground(SkColor color) {
} }
void StatusAreaWidget::OnMouseEvent(ui::MouseEvent* event) { void StatusAreaWidget::OnMouseEvent(ui::MouseEvent* event) {
if (event->type() == ui::ET_MOUSE_PRESSED) // Clicking anywhere except the virtual keyboard tray icon should hide the
// virtual keyboard.
gfx::Point location = event->location();
views::View::ConvertPointFromWidget(virtual_keyboard_tray_.get(), &location);
if (event->type() == ui::ET_MOUSE_PRESSED &&
!virtual_keyboard_tray_->HitTestPoint(location)) {
keyboard::KeyboardController::Get()->HideKeyboardImplicitlyByUser(); keyboard::KeyboardController::Get()->HideKeyboardImplicitlyByUser();
}
views::Widget::OnMouseEvent(event); views::Widget::OnMouseEvent(event);
} }
void StatusAreaWidget::OnGestureEvent(ui::GestureEvent* event) { void StatusAreaWidget::OnGestureEvent(ui::GestureEvent* event) {
if (event->type() == ui::ET_GESTURE_TAP_DOWN) // Tapping anywhere except the virtual keyboard tray icon should hide the
// virtual keyboard.
gfx::Point location = event->location();
views::View::ConvertPointFromWidget(virtual_keyboard_tray_.get(), &location);
if (event->type() == ui::ET_GESTURE_TAP_DOWN &&
!virtual_keyboard_tray_->HitTestPoint(location)) {
keyboard::KeyboardController::Get()->HideKeyboardImplicitlyByUser(); keyboard::KeyboardController::Get()->HideKeyboardImplicitlyByUser();
}
views::Widget::OnGestureEvent(event); views::Widget::OnGestureEvent(event);
} }
......
...@@ -340,6 +340,8 @@ class StatusAreaWidgetVirtualKeyboardTest : public AshTestBase { ...@@ -340,6 +340,8 @@ class StatusAreaWidgetVirtualKeyboardTest : public AshTestBase {
// only case where both the virtual keyboard and the shelf are visible. // only case where both the virtual keyboard and the shelf are visible.
keyboard_controller()->SetContainerType(keyboard::ContainerType::FLOATING, keyboard_controller()->SetContainerType(keyboard::ContainerType::FLOATING,
base::nullopt, base::DoNothing()); base::nullopt, base::DoNothing());
keyboard_controller()->GetKeyboardWindow()->SetBounds(
gfx::Rect(0, 0, 10, 10));
} }
keyboard::KeyboardController* keyboard_controller() { keyboard::KeyboardController* keyboard_controller() {
...@@ -347,6 +349,47 @@ class StatusAreaWidgetVirtualKeyboardTest : public AshTestBase { ...@@ -347,6 +349,47 @@ class StatusAreaWidgetVirtualKeyboardTest : public AshTestBase {
} }
}; };
// See https://crbug.com/897672.
TEST_F(StatusAreaWidgetVirtualKeyboardTest,
ClickingVirtualKeyboardTrayHidesShownKeyboard) {
// Set up the virtual keyboard tray icon along with some other tray icons.
StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget();
status->virtual_keyboard_tray_for_testing()->SetVisible(true);
status->ime_menu_tray()->SetVisible(true);
keyboard_controller()->ShowKeyboard(false /* locked */);
keyboard_controller()->NotifyKeyboardWindowLoaded();
ASSERT_TRUE(keyboard::WaitUntilShown());
// The keyboard should hide when clicked.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_location(status->virtual_keyboard_tray_for_testing()
->GetBoundsInScreen()
.CenterPoint());
generator->ClickLeftButton();
ASSERT_TRUE(keyboard::WaitUntilHidden());
}
// See https://crbug.com/897672.
TEST_F(StatusAreaWidgetVirtualKeyboardTest,
TappingVirtualKeyboardTrayHidesShownKeyboard) {
// Set up the virtual keyboard tray icon along with some other tray icons.
StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget();
status->virtual_keyboard_tray_for_testing()->SetVisible(true);
status->ime_menu_tray()->SetVisible(true);
keyboard_controller()->ShowKeyboard(false /* locked */);
keyboard_controller()->NotifyKeyboardWindowLoaded();
ASSERT_TRUE(keyboard::WaitUntilShown());
// The keyboard should hide when tapped.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->GestureTapAt(status->virtual_keyboard_tray_for_testing()
->GetBoundsInScreen()
.CenterPoint());
ASSERT_TRUE(keyboard::WaitUntilHidden());
}
TEST_F(StatusAreaWidgetVirtualKeyboardTest, ClickingHidesVirtualKeyboard) { TEST_F(StatusAreaWidgetVirtualKeyboardTest, ClickingHidesVirtualKeyboard) {
keyboard_controller()->ShowKeyboard(false /* locked */); keyboard_controller()->ShowKeyboard(false /* locked */);
keyboard_controller()->NotifyKeyboardWindowLoaded(); keyboard_controller()->NotifyKeyboardWindowLoaded();
......
...@@ -67,18 +67,26 @@ bool VirtualKeyboardTray::PerformAction(const ui::Event& event) { ...@@ -67,18 +67,26 @@ bool VirtualKeyboardTray::PerformAction(const ui::Event& event) {
LoginMetricsRecorder::TrayClickTarget::kVirtualKeyboardTray); LoginMetricsRecorder::TrayClickTarget::kVirtualKeyboardTray);
auto* keyboard_controller = keyboard::KeyboardController::Get(); auto* keyboard_controller = keyboard::KeyboardController::Get();
// Keyboard may not always be enabled. https://crbug.com/749989 // Keyboard may not always be enabled. https://crbug.com/749989
if (keyboard_controller->IsEnabled()) { if (!keyboard_controller->IsEnabled())
keyboard_controller->ShowKeyboardInDisplay( return true;
display::Screen::GetScreen()->GetDisplayNearestWindow(
shelf_->GetWindow()));
}
// Normally, active status is set when virtual keyboard is shown/hidden, // Normally, active status is set when virtual keyboard is shown/hidden,
// however, showing virtual keyboard happens asynchronously and, especially // however, showing virtual keyboard happens asynchronously and, especially
// the first time, takes some time. We need to set active status here to // the first time, takes some time. We need to set active status here to
// prevent bad things happening if user clicked the button before keyboard is // prevent bad things happening if user clicked the button before keyboard is
// shown. // shown.
SetIsActive(true); if (is_active()) {
keyboard_controller->HideKeyboardByUser();
SetIsActive(false);
} else {
keyboard_controller->ShowKeyboardInDisplay(
display::Screen::GetScreen()->GetDisplayNearestWindow(
shelf_->GetWindow()));
SetIsActive(true);
}
return true; return true;
} }
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/virtual_keyboard/virtual_keyboard_tray.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h"
#include "ash/test/ash_test_base.h"
#include "base/command_line.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_switches.h"
#include "ui/keyboard/keyboard_util.h"
#include "ui/keyboard/test/keyboard_test_util.h"
namespace ash {
class VirtualKeyboardTrayTest : public AshTestBase {
protected:
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
keyboard::switches::kEnableVirtualKeyboard);
AshTestBase::SetUp();
ASSERT_TRUE(keyboard::IsKeyboardEnabled());
// These tests only apply to the floating virtual keyboard, as it is the
// only case where both the virtual keyboard and the shelf are visible.
keyboard_controller()->LoadKeyboardWindowInBackground();
keyboard_controller()->NotifyKeyboardWindowLoaded();
keyboard_controller()->SetContainerType(keyboard::ContainerType::FLOATING,
base::nullopt, base::DoNothing());
}
keyboard::KeyboardController* keyboard_controller() {
return keyboard::KeyboardController::Get();
}
};
// Tests that the tray action toggles the virtual keyboard.
TEST_F(VirtualKeyboardTrayTest, PerformActionTogglesVirtualKeyboard) {
StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget();
VirtualKeyboardTray* tray = status->virtual_keyboard_tray_for_testing();
tray->SetVisible(true);
ASSERT_TRUE(tray->visible());
// First tap should show the virtual keyboard.
tray->PerformAction(ui::GestureEvent(
0, 0, 0, base::TimeTicks(), ui::GestureEventDetails(ui::ET_GESTURE_TAP)));
EXPECT_TRUE(tray->is_active());
ASSERT_TRUE(keyboard::WaitUntilShown());
// Second tap should hide the virtual keyboard.
tray->PerformAction(ui::GestureEvent(
0, 0, 0, base::TimeTicks(), ui::GestureEventDetails(ui::ET_GESTURE_TAP)));
EXPECT_FALSE(tray->is_active());
ASSERT_TRUE(keyboard::WaitUntilHidden());
}
} // namespace ash
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
-ShelfWidgetVirtualKeyboardTest.ClickingHidesVirtualKeyboard -ShelfWidgetVirtualKeyboardTest.ClickingHidesVirtualKeyboard
-ShelfWidgetVirtualKeyboardTest.TappingHidesVirtualKeyboard -ShelfWidgetVirtualKeyboardTest.TappingHidesVirtualKeyboard
-ShelfWidgetVirtualKeyboardTest.DoesNotHideLockedVirtualKeyboard -ShelfWidgetVirtualKeyboardTest.DoesNotHideLockedVirtualKeyboard
-StatusAreaWidgetVirtualKeyboardTest.ClickingVirtualKeyboardTrayHidesShownKeyboard
-StatusAreaWidgetVirtualKeyboardTest.TappingVirtualKeyboardTrayHidesShownKeyboard
-StatusAreaWidgetVirtualKeyboardTest.ClickingHidesVirtualKeyboard -StatusAreaWidgetVirtualKeyboardTest.ClickingHidesVirtualKeyboard
-StatusAreaWidgetVirtualKeyboardTest.TappingHidesVirtualKeyboard -StatusAreaWidgetVirtualKeyboardTest.TappingHidesVirtualKeyboard
-StatusAreaWidgetVirtualKeyboardTest.DoesNotHideLockedVirtualKeyboard -StatusAreaWidgetVirtualKeyboardTest.DoesNotHideLockedVirtualKeyboard
...@@ -55,6 +57,7 @@ ...@@ -55,6 +57,7 @@
-VirtualKeyboardRootWindowControllerTest.ZOrderTest -VirtualKeyboardRootWindowControllerTest.ZOrderTest
-VirtualKeyboardTest.EventsAreHandledBasedOnHitTestBounds -VirtualKeyboardTest.EventsAreHandledBasedOnHitTestBounds
-VirtualKeyboardTest.HitTestBoundsAreResetWhenContainerTypeChanges -VirtualKeyboardTest.HitTestBoundsAreResetWhenContainerTypeChanges
-VirtualKeyboardTrayTest.PerformActionTogglesVirtualKeyboard
-WindowSelectorControllerTest.ToggleOverviewModeHidesVirtualKeyboard -WindowSelectorControllerTest.ToggleOverviewModeHidesVirtualKeyboard
-WindowSelectorControllerTest.ToggleOverviewModeDoesNotHideLockedVirtualKeyboard -WindowSelectorControllerTest.ToggleOverviewModeDoesNotHideLockedVirtualKeyboard
-WorkspaceLayoutManagerKeyboardTest.IgnoreWorkAreaChangeinNonStickyMode -WorkspaceLayoutManagerKeyboardTest.IgnoreWorkAreaChangeinNonStickyMode
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