Commit 7b104ecc authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Add Show/HideKeyboard methods to keybaord_controller.mojom

This CL:
* Introduces ShowKeyboard, HideKeyboard, and IsKeyboardVisible
  to keyboard_controller.mojom.
* Includes HideReason for HideKeyboard (User or System).
* Introduces keyboard::mojom::KeyboardEnableFlag::kTemporarilyEnabled
  for temporarily enabling the keyboard and showing it.
* Renames keyboard::mojom::ReloadKeyboard() -> RebuildKeyboardIfEnabled().
* Introduces keyboard::mojom::ReloadKeyboardIfNeeded() which calls
  KeyboardUI::ReloadKeyboardIfNeeded() which updates the keyboard URL if
  it has changed and otherwise does nothing.
* Replaces direct calls to KeyboardController from most of src/chrome
  Notable exception: ChromeVirtualKeyboardDelegate which will be
  transitioned in a follow up CL.

Bug: 843332
Change-Id: I2faf000c8233ee0253b799a6e4780020ba3bbe1f
Reviewed-on: https://chromium-review.googlesource.com/c/1309215
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarShu Chen <shuchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606311}
parent 053d52a2
......@@ -113,7 +113,11 @@ void AshKeyboardController::ClearEnableFlag(KeyboardEnableFlag flag) {
UpdateEnableFlag(was_enabled);
}
void AshKeyboardController::ReloadKeyboard() {
void AshKeyboardController::ReloadKeyboardIfNeeded() {
keyboard_controller_->Reload();
}
void AshKeyboardController::RebuildKeyboardIfEnabled() {
// Test IsKeyboardEnableRequested in case of an unlikely edge case where this
// is called while after the enable state changed to disabled (in which case
// we do not want to override the requested state).
......@@ -121,6 +125,29 @@ void AshKeyboardController::ReloadKeyboard() {
EnableKeyboard();
}
void AshKeyboardController::IsKeyboardVisible(
IsKeyboardVisibleCallback callback) {
std::move(callback).Run(keyboard_controller_->IsKeyboardVisible());
}
void AshKeyboardController::ShowKeyboard() {
if (keyboard_controller_->IsEnabled())
keyboard_controller_->ShowKeyboard(false /* lock */);
}
void AshKeyboardController::HideKeyboard(mojom::HideReason reason) {
if (!keyboard_controller_->IsEnabled())
return;
switch (reason) {
case mojom::HideReason::kUser:
keyboard_controller_->HideKeyboardByUser();
break;
case mojom::HideReason::kSystem:
keyboard_controller_->HideKeyboardExplicitlyBySystem();
break;
}
}
void AshKeyboardController::OnSessionStateChanged(
session_manager::SessionState state) {
if (!keyboard_controller_->IsKeyboardEnableRequested())
......
......@@ -64,7 +64,11 @@ class ASH_EXPORT AshKeyboardController
void IsKeyboardEnabled(IsKeyboardEnabledCallback callback) override;
void SetEnableFlag(keyboard::mojom::KeyboardEnableFlag flag) override;
void ClearEnableFlag(keyboard::mojom::KeyboardEnableFlag flag) override;
void ReloadKeyboard() override;
void ReloadKeyboardIfNeeded() override;
void RebuildKeyboardIfEnabled() override;
void IsKeyboardVisible(IsKeyboardVisibleCallback callback) override;
void ShowKeyboard() override;
void HideKeyboard(mojom::HideReason reason) override;
void AddObserver(
mojom::KeyboardControllerObserverAssociatedPtrInfo observer) override;
......
......@@ -63,7 +63,7 @@ class TestClient {
~TestClient() = default;
bool GetIsEnabled() {
bool IsKeyboardEnabled() {
keyboard_controller_->IsKeyboardEnabled(base::BindOnce(
&TestClient::OnIsKeyboardEnabled, base::Unretained(this)));
keyboard_controller_.FlushForTesting();
......@@ -91,19 +91,38 @@ class TestClient {
keyboard_controller_.FlushForTesting();
}
void ReloadKeyboard() {
keyboard_controller_->ReloadKeyboard();
void RebuildKeyboardIfEnabled() {
keyboard_controller_->RebuildKeyboardIfEnabled();
keyboard_controller_.FlushForTesting();
}
bool IsKeyboardVisible() {
keyboard_controller_->IsKeyboardVisible(base::BindOnce(
&TestClient::OnIsKeyboardVisible, base::Unretained(this)));
keyboard_controller_.FlushForTesting();
return is_visible_;
}
void ShowKeyboard() {
keyboard_controller_->ShowKeyboard();
keyboard_controller_.FlushForTesting();
}
void HideKeyboard() {
keyboard_controller_->HideKeyboard(ash::mojom::HideReason::kUser);
keyboard_controller_.FlushForTesting();
}
TestObserver* test_observer() const { return test_observer_.get(); }
bool is_enabled_ = false;
bool is_visible_ = false;
int got_keyboard_config_count_ = 0;
KeyboardConfig keyboard_config_;
private:
void OnIsKeyboardEnabled(bool enabled) { is_enabled_ = enabled; }
void OnIsKeyboardVisible(bool visible) { is_visible_ = visible; }
void OnGetKeyboardConfig(KeyboardConfigPtr config) {
++got_keyboard_config_count_;
......@@ -196,21 +215,21 @@ TEST_F(AshKeyboardControllerTest, SetKeyboardConfig) {
}
TEST_F(AshKeyboardControllerTest, Enabled) {
EXPECT_FALSE(test_client()->GetIsEnabled());
EXPECT_FALSE(test_client()->IsKeyboardEnabled());
// Enable the keyboard.
test_client()->SetEnableFlag(KeyboardEnableFlag::kExtensionEnabled);
EXPECT_TRUE(test_client()->GetIsEnabled());
EXPECT_TRUE(test_client()->IsKeyboardEnabled());
// Set the enable override to disable the keyboard.
test_client()->SetEnableFlag(KeyboardEnableFlag::kPolicyDisabled);
EXPECT_FALSE(test_client()->GetIsEnabled());
EXPECT_FALSE(test_client()->IsKeyboardEnabled());
// Clear the enable override; should enable the keyboard.
test_client()->ClearEnableFlag(KeyboardEnableFlag::kPolicyDisabled);
EXPECT_TRUE(test_client()->GetIsEnabled());
EXPECT_TRUE(test_client()->IsKeyboardEnabled());
}
TEST_F(AshKeyboardControllerTest, ReloadKeyboard) {
TEST_F(AshKeyboardControllerTest, RebuildKeyboardIfEnabled) {
EXPECT_EQ(0, test_client()->test_observer()->destroyed_count_);
// Enable the keyboard.
......@@ -221,8 +240,8 @@ TEST_F(AshKeyboardControllerTest, ReloadKeyboard) {
test_client()->SetEnableFlag(KeyboardEnableFlag::kExtensionEnabled);
EXPECT_EQ(0, test_client()->test_observer()->destroyed_count_);
// Reload the keyboard. This should destroy the previous keyboard window.
test_client()->ReloadKeyboard();
// Rebuild the keyboard. This should destroy the previous keyboard window.
test_client()->RebuildKeyboardIfEnabled();
EXPECT_EQ(1, test_client()->test_observer()->destroyed_count_);
// Disable the keyboard. The keyboard window should be destroyed.
......@@ -230,4 +249,21 @@ TEST_F(AshKeyboardControllerTest, ReloadKeyboard) {
EXPECT_EQ(2, test_client()->test_observer()->destroyed_count_);
}
TEST_F(AshKeyboardControllerTest, ShowAndHideKeyboard) {
// Enable the keyboard. This will not trigger showing the keyboard.
test_client()->SetEnableFlag(KeyboardEnableFlag::kExtensionEnabled);
EXPECT_FALSE(keyboard_controller()->show_on_keyboard_window_load_for_test());
// Show the keyboard. TODO(stevenjb): Use TestObserver and IsKeyboardVisible
// to test visibility changes once ash::TestKeyboardUI properly fakes showing
// the keyboard. https://crbug.com/849995.
test_client()->ShowKeyboard();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(keyboard_controller()->show_on_keyboard_window_load_for_test());
// Hide the keyboard. See comment above.
test_client()->HideKeyboard();
EXPECT_FALSE(keyboard_controller()->show_on_keyboard_window_load_for_test());
}
} // namespace ash
......@@ -8,6 +8,15 @@ import "ui/gfx/geometry/mojo/geometry.mojom";
import "ui/keyboard/public/keyboard_config.mojom";
import "ui/keyboard/public/keyboard_enable_flag.mojom";
enum HideReason {
// Hide requested by an explicit user action.
kUser,
// Hide requested due to a system event (e.g. because it would interfere with
// a menu or other on screen UI).
kSystem,
};
interface KeyboardControllerObserver {
// Called when the keyboard is enabled or disabled. If ReloadKeyboard() is
// called or other code enables the keyboard while already enabled, this will
......@@ -44,8 +53,23 @@ interface KeyboardController {
// changes, enables or disables the keyboard to match the new state.
ClearEnableFlag(keyboard.mojom.KeyboardEnableFlag flag);
// Reloads the virtual keyboard if it is enabled.
ReloadKeyboard();
// Reloads the virtual keyboard if it is enabled and the URL has changed, e.g.
// the focus has switched from one type of field to another.
ReloadKeyboardIfNeeded();
// Rebuilds (disables and re-enables) the virtual keyboard if it is enabled.
// This is used to force a reload of the virtual keyboard when preferences or
// other configuration that affects loading the keyboard may have changed.
RebuildKeyboardIfEnabled();
// Returns whether the virtual keyboard is visible.
IsKeyboardVisible() => (bool visible);
// Shows the virtual keyboard on the current display if it is enabled.
ShowKeyboard();
// Hides the virtual keyboard if it is visible.
HideKeyboard(HideReason reason);
// Adds a KeyboardControllerObserver.
AddObserver(associated KeyboardControllerObserver observer);
......
......@@ -2433,6 +2433,7 @@ source_set("unit_tests") {
"//base",
"//chrome/browser/chromeos/android_sms:unit_tests",
"//chrome/browser/resources/chromeos/zip_archiver:char_coding",
"//chrome/browser/ui:ash_test_support",
"//chrome/browser/web_applications/components:test_support",
"//chrome/common",
"//chromeos:login_manager_proto",
......
......@@ -9,10 +9,7 @@
#include <utility>
#include <vector>
#include "ash/keyboard/ash_keyboard_controller.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
......@@ -21,7 +18,7 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ui/ash/chrome_keyboard_controller_client.h"
#include "chrome/browser/ui/ash/chrome_keyboard_controller_client_test_helper.h"
#include "chrome/browser/ui/ash/tablet_mode_client.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
......@@ -30,8 +27,6 @@
#include "components/arc/test/test_browser_context.h"
#include "components/crx_file/id_util.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_service_manager_context.h"
#include "services/service_manager/public/cpp/connector.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ime/chromeos/extension_ime_util.h"
#include "ui/base/ime/chromeos/mock_input_method_manager.h"
......@@ -258,21 +253,9 @@ class ArcInputMethodManagerServiceTest : public ash::AshTestBase {
profile_ = std::make_unique<TestingProfile>();
tablet_mode_client_ = std::make_unique<TabletModeClient>();
// Create a local service manager connector to handle requests to
// ash::mojom::CrosDisplayConfigController.
service_manager::mojom::ConnectorRequest request;
connector_ = service_manager::Connector::Create(&request);
service_manager::Connector::TestApi test_api(connector_.get());
test_api.OverrideBinderForTesting(
service_manager::Identity(ash::mojom::kServiceName),
ash::mojom::KeyboardController::Name_,
base::BindRepeating(
&ArcInputMethodManagerServiceTest::AddKeyboardControllerBinding,
base::Unretained(this)));
// Provide the local connector to ChromeKeyboardControllerClient.
chrome_keyboard_controller_client_ =
std::make_unique<ChromeKeyboardControllerClient>(connector_.get());
chrome_keyboard_controller_client_->set_profile_for_test(profile_.get());
chrome_keyboard_controller_client_test_helper_ =
ChromeKeyboardControllerClientTestHelper::InitializeForAsh();
chrome_keyboard_controller_client_test_helper_->SetProfile(profile_.get());
service_ = ArcInputMethodManagerService::GetForBrowserContextForTesting(
profile_.get());
......@@ -281,17 +264,11 @@ class ArcInputMethodManagerServiceTest : public ash::AshTestBase {
base::WrapUnique(test_bridge_));
}
void AddKeyboardControllerBinding(mojo::ScopedMessagePipeHandle handle) {
ash::Shell::Get()->ash_keyboard_controller()->BindRequest(
ash::mojom::KeyboardControllerRequest(std::move(handle)));
}
void TearDown() override {
test_bridge_ = nullptr;
service_->Shutdown();
profile_.reset(nullptr);
chrome_keyboard_controller_client_.reset();
connector_.reset();
chrome_keyboard_controller_client_test_helper_.reset();
profile_.reset();
tablet_mode_client_.reset(nullptr);
chromeos::input_method::InputMethodManager::Shutdown();
ui::IMEBridge::Shutdown();
......@@ -299,13 +276,11 @@ class ArcInputMethodManagerServiceTest : public ash::AshTestBase {
}
private:
content::TestServiceManagerContext service_manager_context_;
std::unique_ptr<service_manager::Connector> connector_;
std::unique_ptr<ArcServiceManager> arc_service_manager_;
std::unique_ptr<TestingProfile> profile_;
std::unique_ptr<TabletModeClient> tablet_mode_client_;
std::unique_ptr<ChromeKeyboardControllerClient>
chrome_keyboard_controller_client_;
std::unique_ptr<ChromeKeyboardControllerClientTestHelper>
chrome_keyboard_controller_client_test_helper_;
TestInputMethodManager* input_method_manager_ = nullptr;
TestInputMethodManagerBridge* test_bridge_ = nullptr; // Owned by |service_|
ArcInputMethodManagerService* service_ = nullptr;
......
......@@ -10,6 +10,8 @@
#include <string>
#include <utility>
#include "base/bind.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/values.h"
......@@ -22,6 +24,7 @@
#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "chrome/browser/spellchecker/spellcheck_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/ash/chrome_keyboard_controller_client.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/common/chrome_features.h"
......@@ -38,8 +41,6 @@
#include "ui/base/ime/chromeos/input_method_manager.h"
#include "ui/base/ime/chromeos/input_method_util.h"
#include "ui/base/ime/ime_bridge.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_util.h"
namespace AddWordToDictionary =
extensions::api::input_method_private::AddWordToDictionary;
......@@ -245,26 +246,28 @@ InputMethodPrivateShowInputViewFunction::Run() {
#if !defined(OS_CHROMEOS)
EXTENSION_FUNCTION_VALIDATE(false);
#else
auto* keyboard_controller = keyboard::KeyboardController::Get();
if (keyboard_controller->IsEnabled()) {
keyboard_controller->ShowKeyboard(false);
auto* keyboard_client = ChromeKeyboardControllerClient::Get();
if (!keyboard_client->is_keyboard_enabled()) {
keyboard_client->ShowKeyboard();
return RespondNow(NoArguments());
}
if (keyboard::IsKeyboardEnabled())
return RespondNow(Error(kErrorFailToShowInputView));
// Temporarily enable the onscreen keyboard if there is no keyboard enabled.
// This will be cleared when the keybaord is hidden.
keyboard_client->SetEnableFlag(
keyboard::mojom::KeyboardEnableFlag::kTemporarilyEnabled);
keyboard_client->GetKeyboardEnabled(base::BindOnce(
&InputMethodPrivateShowInputViewFunction::OnGetIsEnabled, this));
return RespondLater();
}
// Forcibly enables the a11y onscreen keyboard if there is on keyboard enabled
// for now. And re-disables it after showing once.
keyboard::SetAccessibilityKeyboardEnabled(true);
keyboard_controller = keyboard::KeyboardController::Get();
if (!keyboard_controller->IsEnabled()) {
keyboard::SetAccessibilityKeyboardEnabled(false);
return RespondNow(Error(kErrorFailToShowInputView));
void InputMethodPrivateShowInputViewFunction::OnGetIsEnabled(bool enabled) {
if (!enabled) {
Respond(Error(kErrorFailToShowInputView));
return;
}
keyboard_controller->ShowKeyboard(false);
keyboard::SetAccessibilityKeyboardEnabled(false);
return RespondNow(NoArguments());
ChromeKeyboardControllerClient::Get()->ShowKeyboard();
Respond(NoArguments());
#endif
}
......
......@@ -170,6 +170,8 @@ class InputMethodPrivateShowInputViewFunction
ResponseAction Run() override;
private:
void OnGetIsEnabled(bool enabled);
DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.showInputView",
INPUTMETHODPRIVATE_SHOWINPUTVIEW)
DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateShowInputViewFunction);
......
......@@ -14,6 +14,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/chrome_keyboard_controller_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ime/candidate_window.h"
......@@ -32,7 +33,6 @@
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/keyboard/keyboard_controller.h"
using input_method::InputMethodEngineBase;
......@@ -216,26 +216,18 @@ bool InputMethodEngine::IsActive() const {
}
void InputMethodEngine::HideInputView() {
// TODO(crbug.com/756059): Support virtual keyboard under MASH. There is no
// KeyboardController in the browser process under MASH.
if (!features::IsUsingWindowService()) {
auto* keyboard_controller = keyboard::KeyboardController::Get();
if (keyboard_controller->IsEnabled())
keyboard_controller->HideKeyboardByUser();
}
auto* keyboard_client = ChromeKeyboardControllerClient::Get();
if (keyboard_client->is_keyboard_enabled())
keyboard_client->HideKeyboard(ash::mojom::HideReason::kUser);
}
void InputMethodEngine::EnableInputView() {
input_method::InputMethodManager::Get()
->GetActiveIMEState()
->EnableInputView();
// TODO(crbug.com/756059): Support virtual keyboard under MASH. There is no
// KeyboardController in the browser process under MASH.
if (!features::IsUsingWindowService()) {
auto* keyboard_controller = keyboard::KeyboardController::Get();
if (keyboard_controller->IsEnabled())
keyboard_controller->Reload();
}
auto* keyboard_client = ChromeKeyboardControllerClient::Get();
if (keyboard_client->is_keyboard_enabled())
keyboard_client->ReloadKeyboardIfNeeded();
}
......
......@@ -12,10 +12,14 @@
#include "base/metrics/histogram_samples.h"
#include "base/metrics/statistics_recorder.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_task_environment.h"
#include "chrome/browser/chromeos/input_method/input_method_configuration.h"
#include "chrome/browser/chromeos/input_method/mock_input_method_manager_impl.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/chrome_keyboard_controller_client_test_helper.h"
#include "chrome/browser/ui/input_method/input_method_engine_base.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_service_manager_context.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ime/chromeos/extension_ime_util.h"
#include "ui/base/ime/chromeos/mock_component_extension_ime_manager_delegate.h"
......@@ -140,7 +144,7 @@ class TestObserver : public InputMethodEngineBase::Observer {
class InputMethodEngineTest : public testing::Test {
public:
InputMethodEngineTest() : observer_(NULL), input_view_("inputview.html") {
InputMethodEngineTest() : observer_(nullptr), input_view_("inputview.html") {
languages_.push_back("en-US");
layouts_.push_back("us");
InitInputMethod();
......@@ -148,10 +152,15 @@ class InputMethodEngineTest : public testing::Test {
mock_ime_input_context_handler_.reset(new ui::MockIMEInputContextHandler());
ui::IMEBridge::Get()->SetInputContextHandler(
mock_ime_input_context_handler_.get());
chrome_keyboard_controller_client_test_helper_ =
ChromeKeyboardControllerClientTestHelper::InitializeWithFake();
}
~InputMethodEngineTest() override {
ui::IMEBridge::Get()->SetInputContextHandler(NULL);
ui::IMEBridge::Get()->SetInputContextHandler(nullptr);
engine_.reset();
chrome_keyboard_controller_client_test_helper_.reset();
Shutdown();
}
......@@ -182,11 +191,12 @@ class InputMethodEngineTest : public testing::Test {
GURL options_page_;
GURL input_view_;
content::TestBrowserThreadBundle thread_bundle_;
content::TestServiceManagerContext service_manager_context_;
std::unique_ptr<ui::MockIMEInputContextHandler>
mock_ime_input_context_handler_;
// Used by InputMethodEngine::EnableInputView().
keyboard::KeyboardController keyboard_controller_;
std::unique_ptr<ChromeKeyboardControllerClientTestHelper>
chrome_keyboard_controller_client_test_helper_;
private:
DISALLOW_COPY_AND_ASSIGN(InputMethodEngineTest);
......@@ -301,13 +311,13 @@ TEST_F(InputMethodEngineTest, TestHistograms) {
int context = engine_->GetCotextIdForTesting();
std::string error;
base::HistogramTester histograms;
engine_->SetComposition(context, "test", 0, 0, 0, segments, NULL);
engine_->SetComposition(context, "test", 0, 0, 0, segments, nullptr);
engine_->CommitText(context, "input", &error);
engine_->SetComposition(context, "test", 0, 0, 0, segments, NULL);
engine_->SetComposition(context, "test", 0, 0, 0, segments, nullptr);
engine_->CommitText(context,
"\xE5\x85\xA5\xE5\x8A\x9B", // 2 UTF-8 characters
&error);
engine_->SetComposition(context, "test", 0, 0, 0, segments, NULL);
engine_->SetComposition(context, "test", 0, 0, 0, segments, nullptr);
engine_->CommitText(context, "input\xE5\x85\xA5\xE5\x8A\x9B", &error);
histograms.ExpectTotalCount("InputMethod.CommitLength", 3);
histograms.ExpectBucketCount("InputMethod.CommitLength", 5, 1);
......
......@@ -32,6 +32,7 @@
#include "chrome/browser/chromeos/login/session/user_session_manager.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/chrome_keyboard_controller_client.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "chromeos/system/devicemode.h"
......@@ -1123,14 +1124,7 @@ void InputMethodManagerImpl::ChangeInputMethodInternal(
// If no engine to enable, cancel the virtual keyboard url override so that
// it can use the fallback system virtual keyboard UI.
state_->DisableInputView();
// TODO(crbug.com/756059): Support virtual keyboard under MASH. There is no
// KeyboardController in the browser process under MASH.
if (!features::IsUsingWindowService()) {
auto* keyboard_controller = keyboard::KeyboardController::Get();
if (keyboard_controller->IsEnabled())
keyboard_controller->Reload();
}
ReloadKeyboard();
}
// Change the keyboard layout to a preferred layout for the input method.
......@@ -1342,9 +1336,7 @@ void InputMethodManagerImpl::OverrideKeyboardKeyset(mojom::ImeKeyset keyset) {
// Resets the url as the input method default url and notify the hash
// changed to VK.
state_->input_view_url = state_->current_input_method.input_view_url();
auto* keyboard_controller = keyboard::KeyboardController::Get();
if (keyboard_controller->IsEnabled())
keyboard_controller->Reload();
ReloadKeyboard();
return;
}
......@@ -1364,9 +1356,7 @@ void InputMethodManagerImpl::OverrideKeyboardKeyset(mojom::ImeKeyset keyset) {
replacements.SetRefStr(overridden_ref);
state_->input_view_url = url.ReplaceComponents(replacements);
auto* keyboard_controller = keyboard::KeyboardController::Get();
if (keyboard_controller->IsEnabled())
keyboard_controller->Reload();
ReloadKeyboard();
}
void InputMethodManagerImpl::SetImeMenuFeatureEnabled(ImeMenuFeature feature,
......@@ -1404,12 +1394,19 @@ void InputMethodManagerImpl::NotifyObserversImeExtraInputStateChange() {
ui::InputMethodKeyboardController*
InputMethodManagerImpl::GetInputMethodKeyboardController() {
// Callers expect a nullptr when the keyboard is disabled. See
// https://crbug.com/850020.
// https://crbug.com/850020. TODO(stevenjb/shuchen): Fix this for Mash.
// https://crbug.com/756059
return keyboard::KeyboardController::HasInstance() &&
keyboard::KeyboardController::Get()->IsEnabled()
? keyboard::KeyboardController::Get()
: nullptr;
}
void InputMethodManagerImpl::ReloadKeyboard() {
auto* keyboard_client = ChromeKeyboardControllerClient::Get();
if (keyboard_client->is_keyboard_enabled())
keyboard_client->ReloadKeyboardIfNeeded();
}
} // namespace input_method
} // namespace chromeos
......@@ -273,6 +273,9 @@ class InputMethodManagerImpl : public InputMethodManager,
// changed.
void NotifyImeMenuListChanged();
// Request that the virtual keyboard be reloaded.
void ReloadKeyboard();
std::unique_ptr<InputMethodDelegate> delegate_;
// The current UI session status.
......
......@@ -16,14 +16,17 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "chrome/browser/chromeos/input_method/mock_candidate_window_controller.h"
#include "chrome/browser/chromeos/input_method/mock_input_method_engine.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/chrome_keyboard_controller_client_test_helper.h"
#include "chrome/browser/ui/ash/ime_controller_client.h"
#include "chrome/browser/ui/ash/test_ime_controller.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "content/public/test/test_service_manager_context.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ime/chromeos/extension_ime_util.h"
......@@ -130,11 +133,16 @@ class TestCandidateWindowObserver
class InputMethodManagerImplTest : public BrowserWithTestWindowTest {
public:
InputMethodManagerImplTest()
: delegate_(NULL),
candidate_window_controller_(NULL),
keyboard_(NULL) {
: delegate_(nullptr),
candidate_window_controller_(nullptr),
keyboard_(nullptr) {
chrome_keyboard_controller_client_test_helper_ =
ChromeKeyboardControllerClientTestHelper::InitializeWithFake();
}
~InputMethodManagerImplTest() override {
chrome_keyboard_controller_client_test_helper_.reset();
}
~InputMethodManagerImplTest() override {}
void SetUp() override {
ui::InitializeInputMethodForTesting();
......@@ -164,9 +172,9 @@ class InputMethodManagerImplTest : public BrowserWithTestWindowTest {
ui::ShutdownInputMethodForTesting();
delegate_ = NULL;
candidate_window_controller_ = NULL;
keyboard_ = NULL;
delegate_ = nullptr;
candidate_window_controller_ = nullptr;
keyboard_ = nullptr;
manager_.reset();
}
......@@ -183,8 +191,8 @@ class InputMethodManagerImplTest : public BrowserWithTestWindowTest {
std::unique_ptr<ComponentExtensionIMEManagerDelegate> delegate(
mock_delegate_);
// CreateNewState(NULL) returns state with non-empty current_input_method.
// So SetState() triggers ChangeInputMethod().
// CreateNewState(nullptr) returns state with non-empty
// current_input_method. So SetState() triggers ChangeInputMethod().
manager_->SetState(
manager_->CreateNewState(ProfileManager::GetActiveUserProfile()));
......@@ -352,6 +360,9 @@ class InputMethodManagerImplTest : public BrowserWithTestWindowTest {
ime_list_.push_back(ext2);
}
content::TestServiceManagerContext service_manager_context_;
std::unique_ptr<ChromeKeyboardControllerClientTestHelper>
chrome_keyboard_controller_client_test_helper_;
std::unique_ptr<InputMethodManagerImpl> manager_;
FakeInputMethodDelegate* delegate_;
MockCandidateWindowController* candidate_window_controller_;
......
......@@ -320,7 +320,7 @@ void AppLaunchController::OnProfileLoaded(Profile* profile) {
profile_->InitChromeOSPreferences();
// Reset virtual keyboard to use IME engines in app profile early.
ChromeKeyboardControllerClient::Get()->ReloadKeyboard();
ChromeKeyboardControllerClient::Get()->RebuildKeyboardIfEnabled();
kiosk_profile_loader_.reset();
startup_app_launcher_.reset(
......
......@@ -27,7 +27,6 @@
#include "ui/base/ime/chromeos/input_method_manager.h"
#include "ui/base/ime/ime_engine_handler_interface.h"
#include "ui/base/ui_base_features.h"
#include "ui/keyboard/keyboard_controller.h"
namespace input_ime = extensions::api::input_ime;
namespace input_method_private = extensions::api::input_method_private;
......@@ -781,8 +780,8 @@ void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context,
// desktop shelf will disappear. see bugs: 775507,788247,786273,761714.
// But still need to unload keyboard container document. Since ime extension
// need to re-render the document when it's recovered.
auto* keyboard_controller = keyboard::KeyboardController::Get();
if (keyboard_controller->IsEnabled()) {
auto* keyboard_client = ChromeKeyboardControllerClient::Get();
if (keyboard_client->is_keyboard_enabled()) {
// Keyboard controller "Reload" method only reload current page when the
// url is changed. So we need unload the current page first. Then next
// engine->Enable() can refresh the inputview page correctly.
......@@ -790,7 +789,7 @@ void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context,
// current page.
// TODO(wuyingbing): Should add a new method to unload the document.
manager->GetActiveIMEState()->DisableInputView();
keyboard_controller->Reload();
keyboard_client->ReloadKeyboardIfNeeded();
}
event_router->SetUnloadedExtensionId(extension->id());
} else {
......
......@@ -131,7 +131,7 @@ void ChromeVirtualKeyboardDelegate::SetHotrodKeyboard(bool enable) {
// This reloads virtual keyboard even if it exists. This ensures virtual
// keyboard gets the correct state of the hotrod keyboard through
// chrome.virtualKeyboardPrivate.getKeyboardConfig.
ChromeKeyboardControllerClient::Get()->ReloadKeyboard();
ChromeKeyboardControllerClient::Get()->RebuildKeyboardIfEnabled();
}
bool ChromeVirtualKeyboardDelegate::LockKeyboard(bool state) {
......@@ -389,7 +389,7 @@ ChromeVirtualKeyboardDelegate::RestrictFeatures(
// keyboard gets the correct state through
// chrome.virtualKeyboardPrivate.getKeyboardConfig.
// TODO(oka): Extension should reload on it's own by receiving event
ChromeKeyboardControllerClient::Get()->ReloadKeyboard();
ChromeKeyboardControllerClient::Get()->RebuildKeyboardIfEnabled();
}
return update;
}
......
......@@ -3624,3 +3624,16 @@ static_library("test_support") {
deps += [ "//extensions/browser" ]
}
}
if (is_chromeos) {
source_set("ash_test_support") {
check_includes = false
sources = [
"ash/chrome_keyboard_controller_client_test_helper.cc",
"ash/chrome_keyboard_controller_client_test_helper.h",
]
deps = [
"//ash",
]
}
}
......@@ -7,6 +7,8 @@
#include <memory>
#include "ash/public/interfaces/constants.mojom.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
......@@ -56,10 +58,25 @@ ChromeKeyboardControllerClient::ChromeKeyboardControllerClient(
connector->BindInterface(ash::mojom::kServiceName, &keyboard_controller_ptr_);
// Request the configuration. This will be queued until the service is ready.
keyboard_controller_ptr_->GetKeyboardConfig(base::BindOnce(
&ChromeKeyboardControllerClient::OnGetInitialKeyboardConfig,
// Add this as a KeyboardController observer.
ash::mojom::KeyboardControllerObserverAssociatedPtrInfo ptr_info;
keyboard_controller_observer_binding_.Bind(mojo::MakeRequest(&ptr_info));
keyboard_controller_ptr_->AddObserver(std::move(ptr_info));
// Request the initial enabled state.
keyboard_controller_ptr_->IsKeyboardEnabled(
base::BindOnce(&ChromeKeyboardControllerClient::OnKeyboardEnabledChanged,
weak_ptr_factory_.GetWeakPtr()));
// Request the initial visible state.
keyboard_controller_ptr_->IsKeyboardVisible(base::BindOnce(
&ChromeKeyboardControllerClient::OnKeyboardVisibilityChanged,
weak_ptr_factory_.GetWeakPtr()));
// Request the configuration.
keyboard_controller_ptr_->GetKeyboardConfig(
base::BindOnce(&ChromeKeyboardControllerClient::OnKeyboardConfigChanged,
weak_ptr_factory_.GetWeakPtr()));
}
ChromeKeyboardControllerClient::~ChromeKeyboardControllerClient() {
......@@ -89,7 +106,12 @@ void ChromeKeyboardControllerClient::SetKeyboardConfig(
const keyboard::mojom::KeyboardConfig& config) {
// Update the cache immediately.
cached_keyboard_config_ = keyboard::mojom::KeyboardConfig::New(config);
keyboard_controller_ptr_->SetKeyboardConfig(cached_keyboard_config_.Clone());
keyboard_controller_ptr_->SetKeyboardConfig(config.Clone());
}
void ChromeKeyboardControllerClient::GetKeyboardEnabled(
base::OnceCallback<void(bool)> callback) {
keyboard_controller_ptr_->IsKeyboardEnabled(std::move(callback));
}
void ChromeKeyboardControllerClient::SetEnableFlag(
......@@ -102,8 +124,21 @@ void ChromeKeyboardControllerClient::ClearEnableFlag(
keyboard_controller_ptr_->ClearEnableFlag(flag);
}
void ChromeKeyboardControllerClient::ReloadKeyboard() {
keyboard_controller_ptr_->ReloadKeyboard();
void ChromeKeyboardControllerClient::ReloadKeyboardIfNeeded() {
keyboard_controller_ptr_->ReloadKeyboardIfNeeded();
}
void ChromeKeyboardControllerClient::RebuildKeyboardIfEnabled() {
keyboard_controller_ptr_->RebuildKeyboardIfEnabled();
}
void ChromeKeyboardControllerClient::ShowKeyboard() {
keyboard_controller_ptr_->ShowKeyboard();
}
void ChromeKeyboardControllerClient::HideKeyboard(
ash::mojom::HideReason reason) {
keyboard_controller_ptr_->HideKeyboard(reason);
}
bool ChromeKeyboardControllerClient::IsKeyboardOverscrollEnabled() {
......@@ -143,24 +178,6 @@ void ChromeKeyboardControllerClient::FlushForTesting() {
keyboard_controller_ptr_.FlushForTesting();
}
void ChromeKeyboardControllerClient::OnGetInitialKeyboardConfig(
keyboard::mojom::KeyboardConfigPtr config) {
// Only set the cached value if not already set by SetKeyboardConfig (the
// set value will override the initial value once processed).
if (!cached_keyboard_config_)
cached_keyboard_config_ = std::move(config);
// Add this as a KeyboardController observer now that the service is ready.
ash::mojom::KeyboardControllerObserverAssociatedPtrInfo ptr_info;
keyboard_controller_observer_binding_.Bind(mojo::MakeRequest(&ptr_info));
keyboard_controller_ptr_->AddObserver(std::move(ptr_info));
// Request the initial enabled state.
keyboard_controller_ptr_->IsKeyboardEnabled(
base::BindOnce(&ChromeKeyboardControllerClient::OnKeyboardEnabledChanged,
weak_ptr_factory_.GetWeakPtr()));
}
void ChromeKeyboardControllerClient::OnKeyboardEnabledChanged(bool enabled) {
bool was_enabled = is_keyboard_enabled_;
is_keyboard_enabled_ = enabled;
......@@ -186,7 +203,11 @@ void ChromeKeyboardControllerClient::OnKeyboardEnabledChanged(bool enabled) {
void ChromeKeyboardControllerClient::OnKeyboardConfigChanged(
keyboard::mojom::KeyboardConfigPtr config) {
// Only notify extensions after the initial config is received.
bool notify = !!cached_keyboard_config_;
cached_keyboard_config_ = std::move(config);
if (!notify)
return;
extensions::VirtualKeyboardAPI* api =
extensions::BrowserContextKeyedAPIFactory<
extensions::VirtualKeyboardAPI>::Get(GetProfile());
......@@ -194,6 +215,7 @@ void ChromeKeyboardControllerClient::OnKeyboardConfigChanged(
}
void ChromeKeyboardControllerClient::OnKeyboardVisibilityChanged(bool visible) {
is_keyboard_visible_ = visible;
for (auto& observer : observers_)
observer.OnKeyboardVisibilityChanged(visible);
}
......
......@@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_ASH_CHROME_KEYBOARD_CONTROLLER_CLIENT_H_
#include "ash/public/interfaces/keyboard_controller.mojom.h"
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
......@@ -55,12 +56,25 @@ class ChromeKeyboardControllerClient
// Sets the new keyboard configuration and updates the cached config.
void SetKeyboardConfig(const keyboard::mojom::KeyboardConfig& config);
// Invokes |callback| with the current enabled state. Call this after
// Set/ClearEnableFlag to get the updated enabled state.
void GetKeyboardEnabled(base::OnceCallback<void(bool)> callback);
// Sets/clears the privided keyboard enable state.
void SetEnableFlag(const keyboard::mojom::KeyboardEnableFlag& state);
void ClearEnableFlag(const keyboard::mojom::KeyboardEnableFlag& state);
// Reloads the virtual keyboard if enabled.
void ReloadKeyboard();
// Calls ash.mojom.ReloadKeyboardIfNeeded.
void ReloadKeyboardIfNeeded();
// Calls ash.mojom.RebuildKeyboard.
void RebuildKeyboardIfEnabled();
// Shows the virtual keyboard if enabled.
void ShowKeyboard();
// Hides the virtual keyboard if enabled.
void HideKeyboard(ash::mojom::HideReason reason);
// Returns true if overscroll is enabled by the config or command line.
bool IsKeyboardOverscrollEnabled();
......@@ -69,6 +83,7 @@ class ChromeKeyboardControllerClient
GURL GetVirtualKeyboardUrl();
bool is_keyboard_enabled() { return is_keyboard_enabled_; }
bool is_keyboard_visible() { return is_keyboard_visible_; }
void FlushForTesting();
......@@ -78,8 +93,6 @@ class ChromeKeyboardControllerClient
}
private:
void OnGetInitialKeyboardConfig(keyboard::mojom::KeyboardConfigPtr config);
// keyboard::mojom::KeyboardControllerObserver:
void OnKeyboardEnabledChanged(bool enabled) override;
void OnKeyboardConfigChanged(
......@@ -100,6 +113,9 @@ class ChromeKeyboardControllerClient
// Tracks the enabled state of the keyboard.
bool is_keyboard_enabled_ = false;
// Tracks the visible state of the keyboard.
bool is_keyboard_visible_ = false;
base::ObserverList<Observer> observers_;
Profile* profile_for_test_ = nullptr;
......
// 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 "chrome/browser/ui/ash/chrome_keyboard_controller_client_test_helper.h"
#include <set>
#include "ash/keyboard/ash_keyboard_controller.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "ash/public/interfaces/keyboard_controller.mojom.h"
#include "ash/shell.h"
#include "base/callback.h"
#include "chrome/browser/profiles/profile.h"
#include "services/service_manager/public/cpp/connector.h"
class ChromeKeyboardControllerClientTestHelper::FakeKeyboardController
: public ash::mojom::KeyboardController {
public:
FakeKeyboardController() = default;
~FakeKeyboardController() override = default;
void BindRequest(ash::mojom::KeyboardControllerRequest request) {
bindings_.AddBinding(this, std::move(request));
}
// ash::mojom::KeyboardController:
void GetKeyboardConfig(GetKeyboardConfigCallback callback) override {
std::move(callback).Run(
keyboard::mojom::KeyboardConfig::New(keyboard_config_));
}
void SetKeyboardConfig(
keyboard::mojom::KeyboardConfigPtr keyboard_config) override {
keyboard_config_ = *keyboard_config;
}
void IsKeyboardEnabled(IsKeyboardEnabledCallback callback) override {
std::move(callback).Run(enabled_);
}
void SetEnableFlag(keyboard::mojom::KeyboardEnableFlag flag) override {
keyboard_enable_flags_.insert(flag);
}
void ClearEnableFlag(keyboard::mojom::KeyboardEnableFlag flag) override {
keyboard_enable_flags_.erase(flag);
}
void ReloadKeyboardIfNeeded() override {}
void RebuildKeyboardIfEnabled() override {}
void IsKeyboardVisible(IsKeyboardVisibleCallback callback) override {
std::move(callback).Run(visible_);
}
void ShowKeyboard() override { visible_ = true; }
void HideKeyboard(ash::mojom::HideReason reason) override {
visible_ = false;
}
void AddObserver(ash::mojom::KeyboardControllerObserverAssociatedPtrInfo
observer) override {}
private:
mojo::BindingSet<ash::mojom::KeyboardController> bindings_;
keyboard::mojom::KeyboardConfig keyboard_config_;
std::set<keyboard::mojom::KeyboardEnableFlag> keyboard_enable_flags_;
bool enabled_ = false;
bool visible_ = false;
DISALLOW_COPY_AND_ASSIGN(FakeKeyboardController);
};
// static
std::unique_ptr<ChromeKeyboardControllerClientTestHelper>
ChromeKeyboardControllerClientTestHelper::InitializeForAsh() {
auto helper = std::make_unique<ChromeKeyboardControllerClientTestHelper>();
helper->Initialize(
base::BindRepeating(&ChromeKeyboardControllerClientTestHelper::
AddKeyboardControllerBindingForAsh,
base::Unretained(helper.get())));
return helper;
}
// static
std::unique_ptr<ChromeKeyboardControllerClientTestHelper>
ChromeKeyboardControllerClientTestHelper::InitializeWithFake() {
auto helper = std::make_unique<ChromeKeyboardControllerClientTestHelper>();
helper->Initialize(
base::BindRepeating(&ChromeKeyboardControllerClientTestHelper::
AddKeyboardControllerBindingForFake,
base::Unretained(helper.get())));
return helper;
}
void ChromeKeyboardControllerClientTestHelper::Initialize(
base::RepeatingCallback<void(mojo::ScopedMessagePipeHandle)>
bind_callback) {
// Create a local service manager connector to handle requests to
// ash::mojom::KeyboardController and bind to AshKeyboardController.
service_manager::mojom::ConnectorRequest request;
connector_ = service_manager::Connector::Create(&request);
service_manager::Connector::TestApi test_api(connector_.get());
test_api.OverrideBinderForTesting(
service_manager::Identity(ash::mojom::kServiceName),
ash::mojom::KeyboardController::Name_, bind_callback);
// Provide the local connector to ChromeKeyboardControllerClient.
chrome_keyboard_controller_client_ =
std::make_unique<ChromeKeyboardControllerClient>(connector_.get());
}
ChromeKeyboardControllerClientTestHelper::
ChromeKeyboardControllerClientTestHelper() = default;
ChromeKeyboardControllerClientTestHelper::
~ChromeKeyboardControllerClientTestHelper() {
chrome_keyboard_controller_client_.reset();
connector_.reset();
}
void ChromeKeyboardControllerClientTestHelper::SetProfile(Profile* profile) {
chrome_keyboard_controller_client_->set_profile_for_test(profile);
}
void ChromeKeyboardControllerClientTestHelper::
AddKeyboardControllerBindingForAsh(mojo::ScopedMessagePipeHandle handle) {
ash::Shell::Get()->ash_keyboard_controller()->BindRequest(
ash::mojom::KeyboardControllerRequest(std::move(handle)));
}
void ChromeKeyboardControllerClientTestHelper::
AddKeyboardControllerBindingForFake(mojo::ScopedMessagePipeHandle handle) {
fake_controller_ = std::make_unique<FakeKeyboardController>();
fake_controller_->BindRequest(
ash::mojom::KeyboardControllerRequest(std::move(handle)));
}
// 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.
#ifndef CHROME_BROWSER_UI_ASH_CHROME_KEYBOARD_CONTROLLER_CLIENT_TEST_HELPER_H_
#define CHROME_BROWSER_UI_ASH_CHROME_KEYBOARD_CONTROLLER_CLIENT_TEST_HELPER_H_
#include <memory>
#include "base/callback_forward.h"
#include "chrome/browser/ui/ash/chrome_keyboard_controller_client.h"
namespace service_manager {
class Connector;
}
class Profile;
// Helper for tests depending on ChromeKeyboardControllerClient.
// Tests must include a content::TestServiceManagerContext instance.
class ChromeKeyboardControllerClientTestHelper {
public:
// Use this for tests using AshTestBase. TODO(stevenjb): Update tests to
// rely on the fake behavior instead.
static std::unique_ptr<ChromeKeyboardControllerClientTestHelper>
InitializeForAsh();
// Use this for tests that trigger calls to ChromeKeyboardControllerClient.
// The interface will be connected to a fake implementation.
static std::unique_ptr<ChromeKeyboardControllerClientTestHelper>
InitializeWithFake();
ChromeKeyboardControllerClientTestHelper();
~ChromeKeyboardControllerClientTestHelper();
void SetProfile(Profile* profile);
private:
class FakeKeyboardController;
void Initialize(base::RepeatingCallback<void(mojo::ScopedMessagePipeHandle)>
bind_callback);
void AddKeyboardControllerBindingForAsh(mojo::ScopedMessagePipeHandle handle);
void AddKeyboardControllerBindingForFake(
mojo::ScopedMessagePipeHandle handle);
std::unique_ptr<service_manager::Connector> connector_;
std::unique_ptr<ChromeKeyboardControllerClient>
chrome_keyboard_controller_client_;
// Used when InitializeWithFake is called.
std::unique_ptr<FakeKeyboardController> fake_controller_;
DISALLOW_COPY_AND_ASSIGN(ChromeKeyboardControllerClientTestHelper);
};
#endif // CHROME_BROWSER_UI_ASH_CHROME_KEYBOARD_CONTROLLER_CLIENT_TEST_HELPER_H_
......@@ -38,7 +38,7 @@
#include "ui/views/metrics.h"
#if defined(OS_CHROMEOS)
#include "ui/keyboard/keyboard_controller.h"
#include "chrome/browser/ui/ash/chrome_keyboard_controller_client.h"
#endif // defined(OS_CHROMEOS)
// static
......@@ -86,13 +86,9 @@ void BrowserAppMenuButton::ShowMenu(bool for_drop) {
return;
#if defined(OS_CHROMEOS)
// On platforms other than ChromeOS or when running under MASH, there is no
// KeyboardController in the browser process.
if (!features::IsUsingWindowService()) {
auto* keyboard_controller = keyboard::KeyboardController::Get();
if (keyboard_controller->IsKeyboardVisible())
keyboard_controller->HideKeyboardExplicitlyBySystem();
}
auto* keyboard_client = ChromeKeyboardControllerClient::Get();
if (keyboard_client->is_keyboard_visible())
keyboard_client->HideKeyboard(ash::mojom::HideReason::kSystem);
#endif
Browser* browser = toolbar_view_->browser();
......
......@@ -32,6 +32,7 @@
#include "chrome/browser/chromeos/tpm_firmware_update.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/ui/ash/ash_util.h"
#include "chrome/browser/ui/ash/chrome_keyboard_controller_client.h"
#include "chrome/browser/ui/ash/tablet_mode_client.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
......@@ -56,7 +57,6 @@
#include "ui/display/screen.h"
#include "ui/events/event_sink.h"
#include "ui/gfx/geometry/size.h"
#include "ui/keyboard/keyboard_controller.h"
namespace chromeos {
......@@ -585,8 +585,8 @@ void CoreOobeHandler::UpdateKeyboardState() {
// TODO(crbug.com/646565): Support virtual keyboard under MASH. There is no
// KeyboardController in the browser process under MASH.
if (!features::IsUsingWindowService()) {
auto* keyboard_controller = keyboard::KeyboardController::Get();
const bool is_keyboard_shown = keyboard_controller->IsKeyboardVisible();
const bool is_keyboard_shown =
ChromeKeyboardControllerClient::Get()->is_keyboard_visible();
ShowControlBar(!is_keyboard_shown);
SetVirtualKeyboardShown(is_keyboard_shown);
}
......
......@@ -436,7 +436,8 @@ bool KeyboardController::IsKeyboardEnableRequested() const {
return false;
return IsEnableFlagSet(KeyboardEnableFlag::kExtensionEnabled) ||
IsEnableFlagSet(KeyboardEnableFlag::kTouchEnabled);
IsEnableFlagSet(KeyboardEnableFlag::kTouchEnabled) ||
IsEnableFlagSet(KeyboardEnableFlag::kTemporarilyEnabled);
}
bool KeyboardController::IsKeyboardOverscrollEnabled() const {
......@@ -528,6 +529,10 @@ void KeyboardController::HideKeyboard(HideReason reason) {
ui_->HideKeyboardWindow();
ChangeState(KeyboardControllerState::HIDDEN);
// Clear the temporary enabled flag when the keyboard is hidden.
// Note: This does not actually disable the keyboard.
ClearEnableFlag(mojom::KeyboardEnableFlag::kTemporarilyEnabled);
for (KeyboardControllerObserver& observer : observer_list_)
observer.OnKeyboardHidden(reason == HIDE_REASON_SYSTEM_TEMPORARY);
......
......@@ -253,6 +253,9 @@ class KEYBOARD_EXPORT KeyboardController
KeyboardControllerState GetStateForTest() const { return state_; }
ui::InputMethod* GetInputMethodForTest();
void EnsureCaretInWorkAreaForTest(const gfx::Rect& occluded_bounds);
bool show_on_keyboard_window_load_for_test() {
return show_on_keyboard_window_load_;
}
private:
// For access to Observer methods for simulation.
......
......@@ -43,8 +43,9 @@ void SendProcessKeyEvent(ui::EventType type, aura::WindowTreeHost* host) {
// https://crbug.com/84332.
bool GetFlag(mojom::KeyboardEnableFlag flag) {
auto* controller = KeyboardController::Get();
return controller ? controller->IsEnableFlagSet(flag) : false;
return KeyboardController::HasInstance()
? KeyboardController::Get()->IsEnableFlagSet(flag)
: false;
}
void SetOrClearEnableFlag(mojom::KeyboardEnableFlag flag, bool enabled) {
......
......@@ -32,4 +32,7 @@ enum KeyboardEnableFlag {
// Enabled by the touch controller.
kTouchEnabled,
// Temporarily enable the keyboard; cleared once the keyboard is shown.
kTemporarilyEnabled,
};
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