Chromium Code Reviews| Index: components/exo/wayland/server.cc |
| diff --git a/components/exo/wayland/server.cc b/components/exo/wayland/server.cc |
| index 84c17c1bfb9acfb2ff99527cd600b6093f3763ac..2f12dcd93adaba77a5227d7e3cfd4f4ccdcfbdc6 100644 |
| --- a/components/exo/wayland/server.cc |
| +++ b/components/exo/wayland/server.cc |
| @@ -85,6 +85,11 @@ |
| #include <drm_fourcc.h> |
| #include <linux-dmabuf-unstable-v1-server-protocol.h> |
| #include <wayland-drm-server-protocol.h> |
| +#if defined(OS_CHROMEOS) |
| +#include "ui/base/ime/chromeos/ime_keyboard.h" |
| +#include "ui/base/ime/chromeos/input_method_manager.h" |
| +#include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" |
| +#endif |
| #endif |
| #if BUILDFLAG(USE_XKBCOMMON) |
| @@ -2737,28 +2742,40 @@ 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(OS_CHROMEOS) |
|
reveman
2017/06/09 21:15:18
#if defined(USE_OZONE) && defined(OS_CHROMEOS)
as
jclinton
2017/06/09 22:17:59
Done.
|
| + , public chromeos::input_method::ImeKeyboard::Observer |
| +#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)), |
| - xkb_state_(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); |
| + xkb_context_(xkb_context_new(XKB_CONTEXT_NO_FLAGS)) { |
| +#if defined(OS_CHROMEOS) |
|
reveman
2017/06/09 21:15:18
#if defined(USE_OZONE) && defined(OS_CHROMEOS)
jclinton
2017/06/09 22:17:58
Done.
|
| + chromeos::input_method::ImeKeyboard* keyboard = |
| + chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); |
| + if (keyboard) |
| + keyboard->AddObserver(this); |
| + std::string layout_id, layout_variant; |
| + std::string layout_name = keyboard->GetCurrentKeyboardLayoutName(); |
| + 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 = ""}; |
|
reveman
2017/06/09 21:15:18
Please avoid duplication of above code. Maybe add
jclinton
2017/06/09 22:17:58
Done.
|
| + SendLayout(names); |
| + } |
| + ~WaylandKeyboardDelegate() override { |
| + chromeos::input_method::ImeKeyboard* keyboard = |
| + chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); |
| + if (keyboard) |
| + keyboard->RemoveObserver(this); |
| +#else |
|
reveman
2017/06/09 21:15:18
ifdef that spans multiple functions like this is c
jclinton
2017/06/09 22:17:58
Done.
|
| + SendLayout(nullptr); |
| +#endif |
| } |
| // Overridden from KeyboardDelegate: |
| @@ -2816,6 +2833,22 @@ class WaylandKeyboardDelegate : public KeyboardDelegate { |
| wl_client_flush(client()); |
| } |
| +#if defined(OS_CHROMEOS) |
|
reveman
2017/06/09 21:15:18
#if defined(USE_OZONE) && defined(OS_CHROMEOS)
jclinton
2017/06/09 22:17:58
Done.
|
| + // Overridden from input_method::ImeKeyboard::Observer: |
| + void OnCapsLockChanged(bool enabled) override {} |
| + void OnLayoutChanged(const std::string& layout_name) override { |
| + std::string layout_id, 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 = ""}; |
| + SendLayout(names); |
| + } |
| +#endif |
| + |
| private: |
| // Returns the corresponding key given a dom code. |
| uint32_t DomCodeToKey(ui::DomCode code) const { |
| @@ -2853,6 +2886,24 @@ class WaylandKeyboardDelegate : public KeyboardDelegate { |
| return xkb_modifiers; |
| } |
| + // Send the current keyboard layout to the Wayland client |
|
reveman
2017/06/09 21:15:18
End sentence with "." and remove Wayland, "to the
jclinton
2017/06/09 22:17:58
Done.
|
| + void SendLayout(const struct xkb_rule_names& names) { |
|
reveman
2017/06/09 21:15:18
"struct" is not needed in c++ code. and "const xkb
jclinton
2017/06/09 22:17:58
Done.
|
| + 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); |
| + } |
| + |
| // The client who own this keyboard instance. |
| wl_client* client() const { |
| return wl_resource_get_client(keyboard_resource_); |