Commit ce4c62d3 authored by Yuki Awano's avatar Yuki Awano Committed by Commit Bot

Pass through search key accelerator to Android window

- TalkBack (screen reader on Android) uses search key as modifier key.
  We want to pass search key accelerator without rewrite if user is
  navigating with TalkBack.

Bug: 854917
Test: None
Change-Id: I304f2c2013c95f4efbd9a57bdd6b47dfa5017411
Reviewed-on: https://chromium-review.googlesource.com/1111480Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Yuki Awano <yawano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570981}
parent 63c3a442
......@@ -133,6 +133,7 @@ DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect,
DEFINE_UI_CLASS_PROPERTY_KEY(mojom::WindowStateType,
kRestoreWindowStateTypeOverrideKey,
mojom::WindowStateType::DEFAULT);
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSearchKeyAcceleratorReservedKey, false);
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(std::string, kShelfIDKey, nullptr);
DEFINE_UI_CLASS_PROPERTY_KEY(int32_t, kShelfItemTypeKey, TYPE_UNDEFINED);
DEFINE_UI_CLASS_PROPERTY_KEY(aura::Window*,
......
......@@ -127,6 +127,13 @@ ASH_PUBLIC_EXPORT extern const aura::WindowProperty<gfx::Rect*>* const
ASH_PUBLIC_EXPORT extern const aura::WindowProperty<
mojom::WindowStateType>* const kRestoreWindowStateTypeOverrideKey;
// A property key to store whether search key accelerator is reserved for a
// window. This is used to pass through search key accelerators to Android
// window if user is navigating with TalkBack (screen reader on Android).
// TalkBack uses search key as a modifier key.
ASH_PUBLIC_EXPORT extern const aura::WindowProperty<bool>* const
kSearchKeyAcceleratorReservedKey;
// A property key to store the id for a window's shelf item.
ASH_PUBLIC_EXPORT extern const aura::WindowProperty<std::string*>* const
kShelfIDKey;
......
......@@ -6,6 +6,7 @@
#include <utility>
#include "ash/public/cpp/window_properties.h"
#include "ash/system/message_center/arc/arc_notification_surface.h"
#include "base/command_line.h"
#include "base/memory/singleton.h"
......@@ -486,7 +487,7 @@ void ArcAccessibilityHelperBridge::OnAccessibilityStatusChanged(
}
UpdateFilterType();
UpdateTouchExplorationPassThrough(GetActiveWindow());
UpdateWindowProperties(GetActiveWindow());
}
void ArcAccessibilityHelperBridge::UpdateFilterType() {
......@@ -515,7 +516,7 @@ void ArcAccessibilityHelperBridge::UpdateFilterType() {
wm_helper->RemoveActivationObserver(this);
}
void ArcAccessibilityHelperBridge::UpdateTouchExplorationPassThrough(
void ArcAccessibilityHelperBridge::UpdateWindowProperties(
aura::Window* window) {
if (!window)
return;
......@@ -531,8 +532,11 @@ void ArcAccessibilityHelperBridge::UpdateTouchExplorationPassThrough(
// app isn't whitelisted Android side or no data has been received for the
// app.
auto it = task_id_to_tree_.find(task_id);
bool use_talkback = it == task_id_to_tree_.end();
window->SetProperty(aura::client::kAccessibilityTouchExplorationPassThrough,
it == task_id_to_tree_.end());
use_talkback);
window->SetProperty(ash::kSearchKeyAcceleratorReservedKey, use_talkback);
}
aura::Window* ArcAccessibilityHelperBridge::GetActiveWindow() {
......@@ -550,7 +554,7 @@ void ArcAccessibilityHelperBridge::OnWindowActivated(
if (gained_active == lost_active)
return;
UpdateTouchExplorationPassThrough(gained_active);
UpdateWindowProperties(gained_active);
}
void ArcAccessibilityHelperBridge::OnTaskDestroyed(int32_t task_id) {
......
......@@ -111,7 +111,7 @@ class ArcAccessibilityHelperBridge
void OnAccessibilityStatusChanged(
const chromeos::AccessibilityStatusEventDetails& event_details);
void UpdateFilterType();
void UpdateTouchExplorationPassThrough(aura::Window* window);
void UpdateWindowProperties(aura::Window* window);
void UpdateTreeIdOfNotificationSurface(const std::string& notification_key,
uint32_t tree_id);
......
......@@ -1011,7 +1011,8 @@ void ChromeBrowserMainPartsChromeos::PostBrowserStart() {
// TODO(mash): Support EventRewriterController; see crbug.com/647781
ash::EventRewriterController* event_rewriter_controller =
ash::Shell::Get()->event_rewriter_controller();
event_rewriter_delegate_ = std::make_unique<EventRewriterDelegateImpl>();
event_rewriter_delegate_ = std::make_unique<EventRewriterDelegateImpl>(
ash::Shell::Get()->activation_client());
event_rewriter_controller->AddEventRewriter(
std::make_unique<ui::EventRewriterChromeOS>(
event_rewriter_delegate_.get(),
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/chromeos/events/event_rewriter_delegate_impl.h"
#include "ash/public/cpp/window_properties.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/extensions/extension_commands_global_registry.h"
#include "chrome/browser/profiles/profile_manager.h"
......@@ -12,11 +13,14 @@
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/user_manager/user_manager.h"
#include "ui/aura/client/aura_constants.h"
namespace chromeos {
EventRewriterDelegateImpl::EventRewriterDelegateImpl()
: pref_service_for_testing_(nullptr) {}
EventRewriterDelegateImpl::EventRewriterDelegateImpl(
wm::ActivationClient* activation_client)
: pref_service_for_testing_(nullptr),
activation_client_(activation_client) {}
EventRewriterDelegateImpl::~EventRewriterDelegateImpl() {}
......@@ -92,6 +96,16 @@ bool EventRewriterDelegateImpl::IsExtensionCommandRegistered(
->IsRegistered(accelerator);
}
bool EventRewriterDelegateImpl::IsSearchKeyAcceleratorReserved() const {
// |activation_client_| can be null in test.
if (!activation_client_)
return false;
aura::Window* active_window = activation_client_->GetActiveWindow();
return active_window &&
active_window->GetProperty(ash::kSearchKeyAcceleratorReservedKey);
}
const PrefService* EventRewriterDelegateImpl::GetPrefService() const {
if (pref_service_for_testing_)
return pref_service_for_testing_;
......
......@@ -7,6 +7,7 @@
#include "base/macros.h"
#include "ui/chromeos/events/event_rewriter_chromeos.h"
#include "ui/wm/public/activation_client.h"
class PrefService;
......@@ -14,7 +15,7 @@ namespace chromeos {
class EventRewriterDelegateImpl : public ui::EventRewriterChromeOS::Delegate {
public:
EventRewriterDelegateImpl();
explicit EventRewriterDelegateImpl(wm::ActivationClient* activation_client);
~EventRewriterDelegateImpl() override;
void set_pref_service_for_testing(const PrefService* pref_service) {
......@@ -28,12 +29,15 @@ class EventRewriterDelegateImpl : public ui::EventRewriterChromeOS::Delegate {
bool TopRowKeysAreFunctionKeys() const override;
bool IsExtensionCommandRegistered(ui::KeyboardCode key_code,
int flags) const override;
bool IsSearchKeyAcceleratorReserved() const override;
private:
const PrefService* GetPrefService() const;
const PrefService* pref_service_for_testing_;
wm::ActivationClient* activation_client_;
DISALLOW_COPY_AND_ASSIGN(EventRewriterDelegateImpl);
};
......
......@@ -120,7 +120,7 @@ class EventRewriterTest : public ash::AshTestBase {
input_method_manager_mock_ = new input_method::MockInputMethodManagerImpl;
chromeos::input_method::InitializeForTesting(
input_method_manager_mock_); // pass ownership
delegate_ = std::make_unique<EventRewriterDelegateImpl>();
delegate_ = std::make_unique<EventRewriterDelegateImpl>(nullptr);
delegate_->set_pref_service_for_testing(prefs());
rewriter_ =
std::make_unique<ui::EventRewriterChromeOS>(delegate_.get(), nullptr);
......@@ -2177,7 +2177,7 @@ class EventRewriterAshTest : public ash::AshTestBase {
void SetUp() override {
AshTestBase::SetUp();
sticky_keys_controller_ = ash::Shell::Get()->sticky_keys_controller();
delegate_ = std::make_unique<EventRewriterDelegateImpl>();
delegate_ = std::make_unique<EventRewriterDelegateImpl>(nullptr);
delegate_->set_pref_service_for_testing(prefs());
rewriter_ = std::make_unique<ui::EventRewriterChromeOS>(
delegate_.get(), sticky_keys_controller_);
......
......@@ -932,7 +932,10 @@ void EventRewriterChromeOS::RewriteExtendedKeys(const ui::KeyEvent& key_event,
{ui::EF_COMMAND_DOWN, ui::VKEY_OEM_PERIOD},
{ui::EF_NONE, ui::DomCode::INSERT, ui::DomKey::INSERT,
ui::VKEY_INSERT}}};
if (RewriteWithKeyboardRemappings(
bool skip_search_key_remapping =
delegate_ && delegate_->IsSearchKeyAcceleratorReserved();
if (!skip_search_key_remapping &&
RewriteWithKeyboardRemappings(
kSearchRemappings, arraysize(kSearchRemappings), incoming, state)) {
return;
}
......
......@@ -91,6 +91,10 @@ class EventRewriterChromeOS : public ui::EventRewriter {
virtual bool IsExtensionCommandRegistered(ui::KeyboardCode key_code,
int flags) const = 0;
// Returns true if search key accelerator is reserved for current active
// window and EventRewriterChromeOS will not rewrite the event.
virtual bool IsSearchKeyAcceleratorReserved() const = 0;
private:
DISALLOW_COPY_AND_ASSIGN(Delegate);
};
......
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