Commit ee43abcb authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

ozone/wayland: Simplify WaylandKeyboard::Delegate::OnKeyEvent

Modifies WaylandKeyboard::Delegate::OnKeyboardKeyEvent such that both
wl_keyboard and zwp_text_input (IME) decode key codes the same way (by
using Ozone's KeyboardLayoutEngine, xkbcommon, etc). Furthermore, this
simplifies its function signature, making it easier to use to inject key
events, such as in follow-up CL https://crrev.com/c/2417065.

No functional changes are expected.

R=msisov@igalia.com

Bug: None
Change-Id: Ia3610c5fbf9bb326c7f7ce4f1e4486083a348464
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422429
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Reviewed-by: default avatarMaksim Sisov (GMT+3) <msisov@igalia.com>
Auto-Submit: Nick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#809292}
parent c9ccbe4e
......@@ -104,17 +104,15 @@ void WaylandEventSource::OnKeyboardModifiersChanged(int modifiers) {
uint32_t WaylandEventSource::OnKeyboardKeyEvent(EventType type,
DomCode dom_code,
DomKey dom_key,
KeyboardCode key_code,
bool repeat,
base::TimeTicks timestamp) {
DCHECK(type == ET_KEY_PRESSED || type == ET_KEY_RELEASED);
if (!keyboard_)
return POST_DISPATCH_NONE;
// try to decode key, if not yet.
if (dom_key == DomKey::NONE &&
!keyboard_->Decode(dom_code, keyboard_modifiers_, &dom_key, &key_code)) {
DomKey dom_key;
KeyboardCode key_code;
if (!keyboard_->Decode(dom_code, keyboard_modifiers_, &dom_key, &key_code)) {
LOG(ERROR) << "Failed to decode key event.";
return POST_DISPATCH_NONE;
}
......
......@@ -13,8 +13,6 @@
#include "base/time/time.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/dom_key.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/events/pointer_details.h"
#include "ui/events/types/event_type.h"
......@@ -85,8 +83,6 @@ class WaylandEventSource : public PlatformEventSource,
void OnKeyboardModifiersChanged(int modifiers) override;
uint32_t OnKeyboardKeyEvent(EventType type,
DomCode dom_code,
DomKey dom_key,
KeyboardCode key_code,
bool repeat,
base::TimeTicks timestamp) override;
......
......@@ -15,10 +15,7 @@
#include "ui/events/event.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/events/keycodes/keyboard_code_conversion.h"
#include "ui/events/keycodes/keyboard_code_conversion_xkb.h"
#include "ui/events/ozone/layout/keyboard_layout_engine.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/ozone/evdev/keyboard_util_evdev.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/range/range.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
......@@ -27,12 +24,6 @@
namespace ui {
namespace {
constexpr int kXkbKeycodeOffset = 8;
} // namespace
WaylandInputMethodContext::WaylandInputMethodContext(
WaylandConnection* connection,
WaylandKeyboard::Delegate* key_delegate,
......@@ -160,18 +151,16 @@ void WaylandInputMethodContext::OnDeleteSurroundingText(int32_t index,
void WaylandInputMethodContext::OnKeysym(uint32_t key,
uint32_t state,
uint32_t modifiers) {
DomKey dom_key = NonPrintableXKeySymToDomKey(key);
KeyboardCode key_code = NonPrintableDomKeyToKeyboardCode(dom_key);
DomCode dom_code =
KeycodeConverter::NativeKeycodeToDomCode(key_code + kXkbKeycodeOffset);
KeycodeConverter::NativeKeycodeToDomCode(EvdevCodeToNativeCode(key));
if (dom_code == ui::DomCode::NONE)
return;
// TODO(crbug.com/1079353): Handle modifiers.
EventType type =
state == WL_KEYBOARD_KEY_STATE_PRESSED ? ET_KEY_PRESSED : ET_KEY_RELEASED;
key_delegate_->OnKeyboardKeyEvent(type, dom_code, dom_key, key_code,
/*repeat=*/false, EventTimeForNow());
key_delegate_->OnKeyboardKeyEvent(type, dom_code, /*repeat=*/false,
EventTimeForNow());
}
} // namespace ui
......@@ -201,8 +201,7 @@ void WaylandKeyboard::DispatchKey(uint32_t key,
// Pass empty DomKey and KeyboardCode here so the delegate can pre-process
// and decode it when needed.
uint32_t result = delegate_->OnKeyboardKeyEvent(
down ? ET_KEY_PRESSED : ET_KEY_RELEASED, dom_code, DomKey::NONE,
KeyboardCode::VKEY_UNKNOWN, repeat, timestamp);
down ? ET_KEY_PRESSED : ET_KEY_RELEASED, dom_code, repeat, timestamp);
if (extended_keyboard_v1_) {
bool handled = result & POST_DISPATCH_STOP_PROPAGATION;
......
......@@ -116,8 +116,6 @@ class WaylandKeyboard::Delegate {
// dispatched.
virtual uint32_t OnKeyboardKeyEvent(EventType type,
DomCode dom_code,
DomKey dom_key,
KeyboardCode key_code,
bool repeat,
base::TimeTicks timestamp) = 0;
......
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