Skip to content

Commit

Permalink
[ozone/wayland] Split WaylandKeyboard::Key in two smaller methods
Browse files Browse the repository at this point in the history
This CL is a driven-by CL that splits the existing WaylandKeyboard::Key
method into two smaller ones.

In practice, it brings no functionality change, but makes it
easier to understand follow up changes like https://crrev.com/c/874670.

BUG=578890

Change-Id: If62cd7158cec4af338af2eb17a9399624d84d5f5
Reviewed-on: https://chromium-review.googlesource.com/878481
Reviewed-by: Michael Spang <spang@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#530914}
  • Loading branch information
tonikitoo authored and Commit Bot committed Jan 22, 2018
1 parent 77fbb3e commit 7cc5ad4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
58 changes: 36 additions & 22 deletions ui/ozone/platform/wayland/wayland_keyboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,32 +95,17 @@ void WaylandKeyboard::Key(void* data,
uint32_t key,
uint32_t state) {
WaylandKeyboard* keyboard = static_cast<WaylandKeyboard*>(data);
keyboard->connection_->set_serial(serial);
DCHECK(keyboard);

DomCode dom_code =
KeycodeConverter::NativeKeycodeToDomCode(key + kXkbKeycodeOffset);
if (dom_code == ui::DomCode::NONE)
return;

uint8_t flags = keyboard->event_modifiers_.GetModifierFlags();
DomKey dom_key;
KeyboardCode key_code;
if (!KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()->Lookup(
dom_code, flags, &dom_key, &key_code))
return;
keyboard->connection_->set_serial(serial);

bool down = state == WL_KEYBOARD_KEY_STATE_PRESSED;

// TODO(tonikitoo,msisov): only the two lines below if not handling repeat.
int flag = ModifierDomKeyToEventFlag(dom_key);
keyboard->UpdateModifier(flag, down);

ui::KeyEvent event(
down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code,
keyboard->event_modifiers_.GetModifierFlags(), dom_key,
base::TimeTicks() + base::TimeDelta::FromMilliseconds(time));
event.set_source_device_id(keyboard->obj_.id());
keyboard->callback_.Run(&event);
// TODO(tonikitoo,msisov): Handler 'repeat' parameter below.
keyboard->DispatchKey(
key, down, false /*repeat*/,
base::TimeTicks() + base::TimeDelta::FromMilliseconds(time),
keyboard->obj_.id());
}

void WaylandKeyboard::Modifiers(void* data,
Expand All @@ -145,6 +130,35 @@ void WaylandKeyboard::RepeatInfo(void* data,
NOTIMPLEMENTED();
}

void WaylandKeyboard::DispatchKey(uint32_t key,
bool down,
bool repeat,
base::TimeTicks timestamp,
int device_id) {
DomCode dom_code =
KeycodeConverter::NativeKeycodeToDomCode(key + kXkbKeycodeOffset);
if (dom_code == ui::DomCode::NONE)
return;

uint8_t flags = event_modifiers_.GetModifierFlags();
DomKey dom_key;
KeyboardCode key_code;
if (!KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()->Lookup(
dom_code, flags, &dom_key, &key_code))
return;

if (!repeat) {
int flag = ModifierDomKeyToEventFlag(dom_key);
UpdateModifier(flag, down);
}

ui::KeyEvent event(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code,
dom_code, event_modifiers_.GetModifierFlags(), dom_key,
timestamp);
event.set_source_device_id(device_id);
callback_.Run(&event);
}

void WaylandKeyboard::UpdateModifier(int modifier_flag, bool down) {
if (modifier_flag == EF_NONE)
return;
Expand Down
6 changes: 6 additions & 0 deletions ui/ozone/platform/wayland/wayland_keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class WaylandKeyboard {

void UpdateModifier(int modifier_flag, bool down);

void DispatchKey(unsigned int key,
bool down,
bool repeat,
base::TimeTicks timestamp,
int device_id);

WaylandConnection* connection_ = nullptr;
wl::Object<wl_keyboard> obj_;
EventDispatchCallback callback_;
Expand Down

0 comments on commit 7cc5ad4

Please sign in to comment.