Index: components/exo/wayland/server.cc |
diff --git a/components/exo/wayland/server.cc b/components/exo/wayland/server.cc |
index 84c17c1bfb9acfb2ff99527cd600b6093f3763ac..a4b624f85a48443f0967e76324901a15c26269b6 100644 |
--- a/components/exo/wayland/server.cc |
+++ b/components/exo/wayland/server.cc |
@@ -85,6 +85,9 @@ |
#include <drm_fourcc.h> |
#include <linux-dmabuf-unstable-v1-server-protocol.h> |
#include <wayland-drm-server-protocol.h> |
+#include "ui/base/ime/chromeos/ime_keyboard.h" |
reveman
2017/06/09 16:50:13
think we need another ifdef for this file. ozone c
jclinton
2017/06/09 20:24:22
Done.
|
+#include "ui/base/ime/chromeos/input_method_manager.h" |
reveman
2017/06/09 16:50:13
ditto
jclinton
2017/06/09 20:24:22
Done.
|
+#include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" |
#endif |
#if BUILDFLAG(USE_XKBCOMMON) |
@@ -2737,13 +2740,16 @@ const struct wl_pointer_interface pointer_implementation = {pointer_set_cursor, |
// Keyboard delegate class that accepts events for surfaces owned by the same |
// client as a keyboard resource. |
-class WaylandKeyboardDelegate : public KeyboardDelegate { |
+class WaylandKeyboardDelegate |
+ : public KeyboardDelegate |
+#if defined(USE_OZONE) |
+ , public chromeos::input_method::ImeKeyboard::Observer |
reveman
2017/06/09 16:50:12
ozone can be used without chromeos
jclinton
2017/06/09 20:24:22
Done.
|
+#endif |
+ { |
public: |
explicit WaylandKeyboardDelegate(wl_resource* keyboard_resource) |
: keyboard_resource_(keyboard_resource), |
xkb_context_(xkb_context_new(XKB_CONTEXT_NO_FLAGS)), |
- // TODO(reveman): Keep keymap synchronized with the keymap used by |
- // chromium and the host OS. |
xkb_keymap_(xkb_keymap_new_from_names(xkb_context_.get(), |
nullptr, |
XKB_KEYMAP_COMPILE_NO_FLAGS)), |
@@ -2759,6 +2765,20 @@ class WaylandKeyboardDelegate : public KeyboardDelegate { |
wl_keyboard_send_keymap(keyboard_resource_, |
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
shared_keymap.handle().GetHandle(), keymap_size); |
+#if defined(USE_OZONE) |
+ chromeos::input_method::ImeKeyboard* keyboard = |
+ chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); |
+ if (keyboard) { |
+ keyboard->AddObserver(this); |
+ keyboard->ReapplyCurrentKeyboardLayout(); |
reveman
2017/06/09 16:50:13
See my SendLayout() comment below. Can we call tha
jclinton
2017/06/09 20:24:22
Done.
|
+ } |
+ } |
+ ~WaylandKeyboardDelegate() override { |
+ chromeos::input_method::ImeKeyboard* keyboard = |
+ chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); |
+ if (keyboard) |
+ keyboard->RemoveObserver(this); |
+#endif |
} |
// Overridden from KeyboardDelegate: |
@@ -2816,6 +2836,36 @@ class WaylandKeyboardDelegate : public KeyboardDelegate { |
wl_client_flush(client()); |
} |
+#if defined(USE_OZONE) |
+ // Overridden from input_method::ImeKeyboard::Observer: |
+ void OnCapsLockChanged(bool enabled) override {} |
+ void OnLayoutChanged(const std::string& layout_name) override { |
reveman
2017/06/09 16:50:13
This duplicates a lot of code in the ctor. Please
jclinton
2017/06/09 20:24:22
Done.
|
+ std::string layout_id; |
+ std::string layout_variant; |
+ ui::XkbKeyboardLayoutEngine::ParseLayoutName(layout_name, &layout_id, |
+ &layout_variant); |
+ xkb_rule_names names = {.rules = NULL, |
+ .model = "pc101", |
+ .layout = layout_id.c_str(), |
+ .variant = layout_variant.c_str(), |
+ .options = ""}; |
+ xkb_keymap_.reset(xkb_keymap_new_from_names(xkb_context_.get(), &names, |
+ XKB_KEYMAP_COMPILE_NO_FLAGS)); |
+ xkb_state_.reset(xkb_state_new(xkb_keymap_.get())); |
+ std::unique_ptr<char, base::FreeDeleter> keymap_string( |
+ xkb_keymap_get_as_string(xkb_keymap_.get(), XKB_KEYMAP_FORMAT_TEXT_V1)); |
+ DCHECK(keymap_string.get()); |
+ size_t keymap_size = strlen(keymap_string.get()) + 1; |
+ base::SharedMemory shared_keymap; |
+ bool rv = shared_keymap.CreateAndMapAnonymous(keymap_size); |
+ DCHECK(rv); |
+ memcpy(shared_keymap.memory(), keymap_string.get(), keymap_size); |
+ wl_keyboard_send_keymap(keyboard_resource_, |
+ WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
+ shared_keymap.handle().GetHandle(), keymap_size); |
+ }; |
reveman
2017/06/09 16:50:12
remove ";"
jclinton
2017/06/09 20:24:22
Done.
|
+#endif |
+ |
private: |
// Returns the corresponding key given a dom code. |
uint32_t DomCodeToKey(ui::DomCode code) const { |