Commit 0a445800 authored by Joe Downing's avatar Joe Downing Committed by Commit Bot

[KeyboardLock] Enabling browser-level keyboard lock for X11

This CL adds a minimal KeyboardHook impl for X11 which enables
browser-level keyboard lock functionality.

I split up the original X11 KeyboardHook impl into two pieces as
the browser level keyboard lock functionality is well understood
and can be tested now whereas the system level keyboard lock for
X11 has a few questions that need to be resolved before checking
it in.

Therefore I want to get the the browser-level lock functionality
working so it can be tested in Canary while I sort out the
system shortcut aspect of the impl.

BUG=680809

Change-Id: I47ea23f50d6c61364343574ab4cdc73bd17f0c3f
Reviewed-on: https://chromium-review.googlesource.com/1034272Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Joe Downing <joedow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554822}
parent 1d649dd8
...@@ -149,6 +149,7 @@ component("events") { ...@@ -149,6 +149,7 @@ component("events") {
"keyboard_hook_base.h", "keyboard_hook_base.h",
"keycodes/platform_key_map_win.cc", "keycodes/platform_key_map_win.cc",
"keycodes/platform_key_map_win.h", "keycodes/platform_key_map_win.h",
"mac/keyboard_hook_mac.mm",
"null_event_targeter.cc", "null_event_targeter.cc",
"null_event_targeter.h", "null_event_targeter.h",
"scoped_target_handler.cc", "scoped_target_handler.cc",
...@@ -180,7 +181,7 @@ component("events") { ...@@ -180,7 +181,7 @@ component("events") {
if (use_x11) { if (use_x11) {
sources += [ sources += [
"x/events_x.cc", "x/events_x.cc",
"x/keyboard_hook_posix.cc", "x/keyboard_hook_x11.cc",
] ]
configs += [ "//build/config/linux:x11" ] configs += [ "//build/config/linux:x11" ]
deps += [ deps += [
......
// 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 "ui/events/keyboard_hook.h"
namespace ui {
// static
std::unique_ptr<KeyboardHook> KeyboardHook::Create(
base::Optional<base::flat_set<int>> key_codes,
KeyEventCallback callback) {
return nullptr;
}
} // namespace ui
...@@ -2,34 +2,40 @@ ...@@ -2,34 +2,40 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/events/keyboard_hook_base.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/containers/flat_set.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "ui/events/event.h" #include "ui/events/keyboard_hook_base.h"
namespace ui { namespace ui {
namespace { namespace {
// A default implementation for POSIX platforms. // A default implementation for the X11 platform.
class KeyboardHookPosix : public KeyboardHookBase { class KeyboardHookX11 : public KeyboardHookBase {
public: public:
KeyboardHookPosix(base::Optional<base::flat_set<int>> native_key_codes, KeyboardHookX11(base::Optional<base::flat_set<int>> native_key_codes,
KeyEventCallback callback); KeyEventCallback callback);
~KeyboardHookPosix() override; ~KeyboardHookX11() override;
bool Register();
private: private:
DISALLOW_COPY_AND_ASSIGN(KeyboardHookPosix); DISALLOW_COPY_AND_ASSIGN(KeyboardHookX11);
}; };
KeyboardHookPosix::KeyboardHookPosix( KeyboardHookX11::KeyboardHookX11(base::Optional<base::flat_set<int>> key_codes,
base::Optional<base::flat_set<int>> key_codes, KeyEventCallback callback)
KeyEventCallback callback)
: KeyboardHookBase(std::move(key_codes), std::move(callback)) {} : KeyboardHookBase(std::move(key_codes), std::move(callback)) {}
KeyboardHookPosix::~KeyboardHookPosix() = default; KeyboardHookX11::~KeyboardHookX11() = default;
bool KeyboardHookX11::Register() {
// TODO(680809): Implement system-level keyboard lock feature for X11.
// Return true to enable browser-level keyboard lock for the X11 platform.
return true;
}
} // namespace } // namespace
...@@ -37,7 +43,14 @@ KeyboardHookPosix::~KeyboardHookPosix() = default; ...@@ -37,7 +43,14 @@ KeyboardHookPosix::~KeyboardHookPosix() = default;
std::unique_ptr<KeyboardHook> KeyboardHook::Create( std::unique_ptr<KeyboardHook> KeyboardHook::Create(
base::Optional<base::flat_set<int>> native_key_codes, base::Optional<base::flat_set<int>> native_key_codes,
KeyboardHook::KeyEventCallback callback) { KeyboardHook::KeyEventCallback callback) {
return nullptr; std::unique_ptr<KeyboardHookX11> keyboard_hook =
std::make_unique<KeyboardHookX11>(std::move(native_key_codes),
std::move(callback));
if (!keyboard_hook->Register())
return nullptr;
return keyboard_hook;
} }
} // namespace ui } // namespace ui
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