Commit 9b9584f9 authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

ozone/x11: Fix regression in text input handling

After crrev.com/c/2028408, keyboard input handling has been broken in
Ozone/X11 desktop builds (CrOS on Linux is not affected), when IBus IME
is setup, among other cases which depend on KeyEvents::Properties being
properly set. This fixes it as well as adds a unit test to prevent
future similar regressions.

Bug: 1047999
Change-Id: If67b78eb795b8d5efabf987a25ebf68de733948e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2034810
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738473}
parent 97131558
......@@ -56,7 +56,7 @@ std::unique_ptr<KeyEvent> CreateKeyEvent(EventType event_type,
// in KeyEvent::ApplyLayout() which makes it possible for CrOS/Linux, for
// example, to support host system keyboard layouts.
#if defined(USE_OZONE)
return std::make_unique<KeyEvent>(event_type, key_code, event_flags);
auto event = std::make_unique<KeyEvent>(event_type, key_code, event_flags);
#else
DomCode dom_code = CodeFromXEvent(&xev);
DomKey dom_key = GetDomKeyFromXEvent(&xev);
......@@ -64,12 +64,12 @@ std::unique_ptr<KeyEvent> CreateKeyEvent(EventType event_type,
ValidateEventTimeClock(&timestamp);
auto event = std::make_unique<KeyEvent>(event_type, key_code, dom_code,
event_flags, dom_key, timestamp);
#endif
DCHECK(event);
event->SetProperties(GetEventPropertiesFromXEvent(event_type, xev));
event->InitializeNative();
return event;
#endif
}
void SetEventSourceDeviceId(MouseEvent* event, const XEvent& xev) {
......
......@@ -7,6 +7,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/dom/dom_key.h"
#include "ui/events/test/events_test_utils.h"
#include "ui/events/test/events_test_utils_x11.h"
......@@ -38,4 +39,43 @@ TEST(XEventTranslationTest, KeyEventDomKeyExtraction) {
EXPECT_EQ("Enter", keyev->GetCodeString());
}
// Ensure KeyEvent::Properties is properly set regardless X11 build config is
// in place. This prevents regressions such as crbug.com/1047999.
TEST(XEventTranslationTest, KeyEventXEventPropertiesSet) {
ui::ScopedKeyboardLayout keyboard_layout(ui::KEYBOARD_LAYOUT_ENGLISH_US);
ScopedXI2Event scoped_xev;
scoped_xev.InitKeyEvent(ET_KEY_PRESSED, VKEY_A, EF_NONE);
XEvent* xev = scoped_xev;
XDisplay* xdisplay = xev->xkey.display;
// Set keyboard group in XKeyEvent
xev->xkey.state = XkbBuildCoreState(xev->xkey.state, 2u);
// Set IBus-specific flags
xev->xkey.state |= 0x3 << ui::kPropertyKeyboardIBusFlagOffset;
auto keyev = ui::BuildKeyEventFromXEvent(*xev);
EXPECT_TRUE(keyev);
auto* properties = keyev->properties();
EXPECT_TRUE(properties);
EXPECT_EQ(3u, properties->size());
// Ensure hardware keycode, keyboard group and ibus flag properties are
// properly set.
auto hw_keycode_it = properties->find(ui::kPropertyKeyboardHwKeyCode);
EXPECT_NE(hw_keycode_it, properties->end());
EXPECT_EQ(1u, hw_keycode_it->second.size());
EXPECT_EQ(XKeysymToKeycode(xdisplay, XK_a), hw_keycode_it->second[0]);
auto kbd_group_it = properties->find(ui::kPropertyKeyboardGroup);
EXPECT_NE(kbd_group_it, properties->end());
EXPECT_EQ(1u, kbd_group_it->second.size());
EXPECT_EQ(2u, kbd_group_it->second[0]);
auto ibus_flag_it = properties->find(ui::kPropertyKeyboardIBusFlag);
EXPECT_NE(ibus_flag_it, properties->end());
EXPECT_EQ(1u, ibus_flag_it->second.size());
EXPECT_EQ(0x3, ibus_flag_it->second[0]);
}
} // 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