Commit 5d5b8cb5 authored by yhanada's avatar yhanada Committed by Commit bot

exo: Implement support for zcr_keyboard_configuration_v1 protocol.

This CL allows us to notify keyboard type changes to a client
through zcr_keyboard_device_configuration_v1 interface.

BUG=670247

Review-Url: https://codereview.chromium.org/2506263002
Cr-Commit-Position: refs/heads/master@{#437750}
parent 421e8088
......@@ -20,6 +20,7 @@ source_set("exo") {
"keyboard.cc",
"keyboard.h",
"keyboard_delegate.h",
"keyboard_device_configuration_delegate.h",
"notification_surface.cc",
"notification_surface.h",
"notification_surface_manager.h",
......@@ -62,6 +63,7 @@ source_set("exo") {
"//ui/aura",
"//ui/compositor",
"//ui/display/manager",
"//ui/events/devices:devices",
"//ui/gfx",
"//ui/gfx/geometry",
"//ui/gl",
......
......@@ -5,16 +5,20 @@
#include "components/exo/keyboard.h"
#include "components/exo/keyboard_delegate.h"
#include "components/exo/keyboard_device_configuration_delegate.h"
#include "components/exo/shell_surface.h"
#include "components/exo/surface.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/window.h"
#include "ui/base/ime/input_method.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/devices/input_device.h"
#include "ui/events/devices/input_device_manager.h"
#include "ui/events/event.h"
#include "ui/views/widget/widget.h"
namespace exo {
namespace {
bool ConsumedByIme(Surface* focus, const ui::KeyEvent* event) {
// Check if IME consumed the event, to avoid it to be doubly processed.
......@@ -70,6 +74,21 @@ bool ConsumedByIme(Surface* focus, const ui::KeyEvent* event) {
return false;
}
bool IsPhysicalKeyboardEnabled() {
// The internal keyboard is enabled if maximize mode is not enabled.
if (WMHelper::GetInstance()->IsMaximizeModeWindowManagerEnabled())
return true;
for (auto& keyboard :
ui::InputDeviceManager::GetInstance()->GetKeyboardDevices()) {
if (keyboard.type != ui::InputDeviceType::INPUT_DEVICE_INTERNAL)
return true;
}
return false;
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
// Keyboard, public:
......@@ -77,16 +96,28 @@ Keyboard::Keyboard(KeyboardDelegate* delegate) : delegate_(delegate) {
auto* helper = WMHelper::GetInstance();
helper->AddPostTargetHandler(this);
helper->AddFocusObserver(this);
helper->AddMaximizeModeObserver(this);
helper->AddInputDeviceEventObserver(this);
OnWindowFocused(helper->GetFocusedWindow(), nullptr);
}
Keyboard::~Keyboard() {
delegate_->OnKeyboardDestroying(this);
if (device_configuration_delegate_)
device_configuration_delegate_->OnKeyboardDestroying(this);
if (focus_)
focus_->RemoveSurfaceObserver(this);
auto* helper = WMHelper::GetInstance();
helper->RemoveFocusObserver(this);
helper->RemovePostTargetHandler(this);
helper->RemoveMaximizeModeObserver(this);
helper->RemoveInputDeviceEventObserver(this);
}
void Keyboard::SetDeviceConfigurationDelegate(
KeyboardDeviceConfigurationDelegate* delegate) {
device_configuration_delegate_ = delegate;
OnKeyboardDeviceConfigurationChanged();
}
////////////////////////////////////////////////////////////////////////////////
......@@ -169,6 +200,27 @@ void Keyboard::OnSurfaceDestroying(Surface* surface) {
surface->RemoveSurfaceObserver(this);
}
////////////////////////////////////////////////////////////////////////////////
// ui::InputDeviceEventObserver overrides:
void Keyboard::OnKeyboardDeviceConfigurationChanged() {
if (device_configuration_delegate_) {
device_configuration_delegate_->OnKeyboardTypeChanged(
IsPhysicalKeyboardEnabled());
}
}
////////////////////////////////////////////////////////////////////////////////
// WMHelper::MaximizeModeObserver overrides:
void Keyboard::OnMaximizeModeStarted() {
OnKeyboardDeviceConfigurationChanged();
}
void Keyboard::OnMaximizeModeEnded() {
OnKeyboardDeviceConfigurationChanged();
}
////////////////////////////////////////////////////////////////////////////////
// Keyboard, private:
......
......@@ -10,7 +10,6 @@
#include "base/macros.h"
#include "components/exo/surface_observer.h"
#include "components/exo/wm_helper.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/events/event_handler.h"
namespace ui {
......@@ -20,17 +19,23 @@ class KeyEvent;
namespace exo {
class KeyboardDelegate;
class KeyboardDeviceConfigurationDelegate;
class Surface;
// This class implements a client keyboard that represents one or more keyboard
// devices.
class Keyboard : public ui::EventHandler,
public WMHelper::FocusObserver,
public WMHelper::InputDeviceEventObserver,
public WMHelper::MaximizeModeObserver,
public SurfaceObserver {
public:
explicit Keyboard(KeyboardDelegate* delegate);
~Keyboard() override;
void SetDeviceConfigurationDelegate(
KeyboardDeviceConfigurationDelegate* delegate);
// Overridden from ui::EventHandler:
void OnKeyEvent(ui::KeyEvent* event) override;
......@@ -41,13 +46,25 @@ class Keyboard : public ui::EventHandler,
// Overridden from SurfaceObserver:
void OnSurfaceDestroying(Surface* surface) override;
// Overridden from ui::InputDeviceEventObserver:
void OnKeyboardDeviceConfigurationChanged() override;
// Overridden from WMHelper::MaximizeModeObserver:
void OnMaximizeModeStarted() override;
void OnMaximizeModeEnded() override;
private:
// Returns the effective focus for |window|.
Surface* GetEffectiveFocus(aura::Window* window) const;
// The delegate instance that all events are dispatched to.
// The delegate instance that all events except for events about device
// configuration are dispatched to.
KeyboardDelegate* const delegate_;
// The delegate instance that events about device configuration are dispatched
// to.
KeyboardDeviceConfigurationDelegate* device_configuration_delegate_ = nullptr;
// The current focus surface for the keyboard.
Surface* focus_ = nullptr;
......
......@@ -36,7 +36,7 @@ class KeyboardDelegate {
// Called when keyboard focus leaves a valid target surface.
virtual void OnKeyboardLeave(Surface* surface) = 0;
// Called when pkeyboard key state changed. |pressed| is true when |key|
// Called when keyboard key state changed. |pressed| is true when |key|
// was pressed and false if it was released.
virtual void OnKeyboardKey(base::TimeTicks time_stamp,
ui::DomCode key,
......
// Copyright 2016 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 COMPONENTS_EXO_KEYBOARD_DEVICE_CONFIGURATION_H_
#define COMPONENTS_EXO_KEYBOARD_DEVICE_CONFIGURATION_H_
namespace exo {
class Keyboard;
// Used as an extension to the KeyboardDelegate.
class KeyboardDeviceConfigurationDelegate {
public:
// Called at the top of the keyboard's destructor, to give observers a chance
// to remove themselves.
virtual void OnKeyboardDestroying(Keyboard* keyboard) = 0;
// Called when used keyboard type changed.
virtual void OnKeyboardTypeChanged(bool is_physical) = 0;
protected:
virtual ~KeyboardDeviceConfigurationDelegate() {}
};
} // namespace exo
#endif // COMPONENTS_EXO_KEYBOARD_DEVICE_CONFIGURATION_H_
......@@ -39,6 +39,7 @@ source_set("wayland") {
"//third_party/wayland:wayland_server",
"//third_party/wayland-protocols:alpha_compositing_protocol",
"//third_party/wayland-protocols:gaming_input_protocol",
"//third_party/wayland-protocols:keyboard_configuration_protocol",
"//third_party/wayland-protocols:remote_shell_protocol",
"//third_party/wayland-protocols:secure_output_protocol",
"//third_party/wayland-protocols:stylus_protocol",
......
......@@ -14,6 +14,7 @@
// Note: core wayland headers need to be included before protocol headers.
#include <alpha-compositing-unstable-v1-server-protocol.h> // NOLINT
#include <keyboard-configuration-unstable-v1-server-protocol.h> // NOLINT
#include <gaming-input-unstable-v1-server-protocol.h> // NOLINT
#include <remote-shell-unstable-v1-server-protocol.h> // NOLINT
#include <secure-output-unstable-v1-server-protocol.h> // NOLINT
......@@ -47,6 +48,7 @@
#include "components/exo/gamepad_delegate.h"
#include "components/exo/keyboard.h"
#include "components/exo/keyboard_delegate.h"
#include "components/exo/keyboard_device_configuration_delegate.h"
#include "components/exo/notification_surface.h"
#include "components/exo/notification_surface_manager.h"
#include "components/exo/pointer.h"
......@@ -2984,6 +2986,7 @@ void stylus_get_pointer_stylus(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* pointer_resource) {
// TODO(yhanada): Produce an erorr if a delegate already exists.
Pointer* pointer = GetUserDataAs<Pointer>(pointer_resource);
wl_resource* stylus_resource =
......@@ -3004,6 +3007,83 @@ void bind_stylus(wl_client* client, void* data, uint32_t version, uint32_t id) {
nullptr);
}
////////////////////////////////////////////////////////////////////////////////
// keyboard_device_configuration interface:
class WaylandKeyboardDeviceConfigurationDelegate
: public KeyboardDeviceConfigurationDelegate {
public:
WaylandKeyboardDeviceConfigurationDelegate(wl_resource* resource,
Keyboard* keyboard)
: resource_(resource), keyboard_(keyboard) {
keyboard_->SetDeviceConfigurationDelegate(this);
}
~WaylandKeyboardDeviceConfigurationDelegate() override {
if (keyboard_)
keyboard_->SetDeviceConfigurationDelegate(nullptr);
}
void OnKeyboardDestroying(Keyboard* keyboard) override {
keyboard_ = nullptr;
}
void OnKeyboardTypeChanged(bool is_physical) override {
zcr_keyboard_device_configuration_v1_send_type_change(
resource_,
is_physical
? ZCR_KEYBOARD_DEVICE_CONFIGURATION_V1_KEYBOARD_TYPE_PHYSICAL
: ZCR_KEYBOARD_DEVICE_CONFIGURATION_V1_KEYBOARD_TYPE_VIRTUAL);
}
private:
wl_resource* resource_;
Keyboard* keyboard_;
DISALLOW_COPY_AND_ASSIGN(WaylandKeyboardDeviceConfigurationDelegate);
};
void keyboard_device_configuration_destroy(wl_client* client,
wl_resource* resource) {
wl_resource_destroy(resource);
}
const struct zcr_keyboard_device_configuration_v1_interface
keyboard_device_configuration_implementation = {
keyboard_device_configuration_destroy};
////////////////////////////////////////////////////////////////////////////////
// keyboard_configuration interface:
void keyboard_configuration_get_keyboard_device_configuration(
wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* keyboard_resource) {
// TODO(yhanada): Produce an error if a delegate already exists.
wl_resource* keyboard_device_configuration_resource = wl_resource_create(
client, &zcr_keyboard_device_configuration_v1_interface, 1, id);
SetImplementation(
keyboard_device_configuration_resource,
&keyboard_device_configuration_implementation,
base::MakeUnique<WaylandKeyboardDeviceConfigurationDelegate>(
keyboard_device_configuration_resource,
GetUserDataAs<Keyboard>(keyboard_resource)));
}
const struct zcr_keyboard_configuration_v1_interface
keyboard_configuration_implementation = {
keyboard_configuration_get_keyboard_device_configuration};
void bind_keyboard_configuration(wl_client* client,
void* data,
uint32_t version,
uint32_t id) {
wl_resource* resource = wl_resource_create(
client, &zcr_keyboard_configuration_v1_interface, version, id);
wl_resource_set_implementation(
resource, &keyboard_configuration_implementation, data, nullptr);
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
......@@ -3046,6 +3126,8 @@ Server::Server(Display* display)
display_, bind_gaming_input);
wl_global_create(wl_display_.get(), &zcr_stylus_v1_interface, 1, display_,
bind_stylus);
wl_global_create(wl_display_.get(), &zcr_keyboard_configuration_v1_interface,
1, display_, bind_keyboard_configuration);
}
Server::~Server() {}
......
......@@ -70,6 +70,15 @@ void WMHelper::RemoveAccessibilityObserver(AccessibilityObserver* observer) {
accessibility_observers_.RemoveObserver(observer);
}
void WMHelper::AddInputDeviceEventObserver(InputDeviceEventObserver* observer) {
input_device_event_observers_.AddObserver(observer);
}
void WMHelper::RemoveInputDeviceEventObserver(
InputDeviceEventObserver* observer) {
input_device_event_observers_.RemoveObserver(observer);
}
void WMHelper::NotifyWindowActivated(aura::Window* gained_active,
aura::Window* lost_active) {
for (ActivationObserver& observer : activation_observers_)
......@@ -107,4 +116,9 @@ void WMHelper::NotifyAccessibilityModeChanged() {
observer.OnAccessibilityModeChanged();
}
void WMHelper::NotifyKeyboardDeviceConfigurationChanged() {
for (InputDeviceEventObserver& observer : input_device_event_observers_)
observer.OnKeyboardDeviceConfigurationChanged();
}
} // namespace exo
......@@ -70,6 +70,14 @@ class WMHelper {
virtual ~AccessibilityObserver() {}
};
class InputDeviceEventObserver {
public:
virtual void OnKeyboardDeviceConfigurationChanged() = 0;
protected:
virtual ~InputDeviceEventObserver() {}
};
virtual ~WMHelper();
static void SetInstance(WMHelper* helper);
......@@ -85,6 +93,8 @@ class WMHelper {
void RemoveMaximizeModeObserver(MaximizeModeObserver* observer);
void AddAccessibilityObserver(AccessibilityObserver* observer);
void RemoveAccessibilityObserver(AccessibilityObserver* observer);
void AddInputDeviceEventObserver(InputDeviceEventObserver* observer);
void RemoveInputDeviceEventObserver(InputDeviceEventObserver* observer);
virtual const display::ManagedDisplayInfo GetDisplayInfo(
int64_t display_id) const = 0;
......@@ -113,6 +123,7 @@ class WMHelper {
void NotifyMaximizeModeStarted();
void NotifyMaximizeModeEnded();
void NotifyAccessibilityModeChanged();
void NotifyKeyboardDeviceConfigurationChanged();
private:
base::ObserverList<ActivationObserver> activation_observers_;
......@@ -120,6 +131,7 @@ class WMHelper {
base::ObserverList<CursorObserver> cursor_observers_;
base::ObserverList<MaximizeModeObserver> maximize_mode_observers_;
base::ObserverList<AccessibilityObserver> accessibility_observers_;
base::ObserverList<InputDeviceEventObserver> input_device_event_observers_;
DISALLOW_COPY_AND_ASSIGN(WMHelper);
};
......
......@@ -11,6 +11,7 @@
#include "base/memory/singleton.h"
#include "ui/aura/client/focus_client.h"
#include "ui/display/manager/display_manager.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/wm/public/activation_client.h"
namespace exo {
......@@ -24,6 +25,7 @@ WMHelperAsh::WMHelperAsh() {
aura::client::FocusClient* focus_client =
aura::client::GetFocusClient(ash::Shell::GetPrimaryRootWindow());
focus_client->AddObserver(this);
ui::DeviceDataManager::GetInstance()->AddObserver(this);
}
WMHelperAsh::~WMHelperAsh() {
......@@ -34,6 +36,7 @@ WMHelperAsh::~WMHelperAsh() {
focus_client->RemoveObserver(this);
ash::Shell::GetInstance()->activation_client()->RemoveObserver(this);
ash::WmShell::Get()->RemoveShellObserver(this);
ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -133,4 +136,8 @@ void WMHelperAsh::OnMaximizeModeEnded() {
NotifyMaximizeModeEnded();
}
void WMHelperAsh::OnKeyboardDeviceConfigurationChanged() {
NotifyKeyboardDeviceConfigurationChanged();
}
} // namespace exo
......@@ -11,6 +11,7 @@
#include "components/exo/wm_helper.h"
#include "ui/aura/client/cursor_client_observer.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/events/devices/input_device_event_observer.h"
#include "ui/wm/public/activation_change_observer.h"
namespace exo {
......@@ -21,7 +22,8 @@ class WMHelperAsh : public WMHelper,
public aura::client::FocusChangeObserver,
public aura::client::CursorClientObserver,
public ash::AccessibilityObserver,
public ash::ShellObserver {
public ash::ShellObserver,
public ui::InputDeviceEventObserver {
public:
WMHelperAsh();
~WMHelperAsh() override;
......@@ -64,6 +66,9 @@ class WMHelperAsh : public WMHelper,
void OnMaximizeModeStarted() override;
void OnMaximizeModeEnded() override;
// Overriden from ui::InputDeviceEventObserver:
void OnKeyboardDeviceConfigurationChanged() override;
private:
DISALLOW_COPY_AND_ASSIGN(WMHelperAsh);
};
......
......@@ -148,4 +148,8 @@ void WMHelperMus::OnWindowFocused(aura::Window* gained_focus,
}
}
void WMHelperMus::OnKeyboardDeviceConfigurationChanged() {
NotifyKeyboardDeviceConfigurationChanged();
}
} // namespace exo
......@@ -9,11 +9,13 @@
#include "components/exo/wm_helper.h"
#include "services/ui/public/cpp/window_tree_client_observer.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/events/devices/input_device_event_observer.h"
namespace exo {
// A helper class for accessing WindowManager related features.
class WMHelperMus : public WMHelper,
public ui::InputDeviceEventObserver,
public ui::WindowTreeClientObserver,
public aura::client::FocusChangeObserver {
public:
......@@ -44,6 +46,9 @@ class WMHelperMus : public WMHelper,
void OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) override;
// Overriden from ui::InputDeviceEventObserver:
void OnKeyboardDeviceConfigurationChanged() override;
private:
aura::Window* active_window_;
aura::Window* focused_window_;
......
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