1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/views/input_method_mojo_linux.h"
7 #include "ui/base/ime/text_input_client.h"
8 #include "ui/events/event.h"
12 InputMethodMojoLinux::InputMethodMojoLinux(
13 ui::internal::InputMethodDelegate
* delegate
)
14 : ui::InputMethodAuraLinux(delegate
) {
17 InputMethodMojoLinux::~InputMethodMojoLinux() {}
19 bool InputMethodMojoLinux::DispatchKeyEvent(const ui::KeyEvent
& event
) {
20 DCHECK(event
.type() == ui::ET_KEY_PRESSED
||
21 event
.type() == ui::ET_KEY_RELEASED
);
22 DCHECK(system_toplevel_window_focused());
24 // If no text input client, do nothing.
25 if (!GetTextInputClient())
26 return DispatchKeyEventPostIME(event
);
28 // Here is where we change the differ from our base class's logic. Instead of
29 // always dispatching a key down event, and then sending a synthesized
30 // character event, we instead check to see if this is a character event and
31 // send out the key if it is. (We fallback to normal dispatch if it isn't.)
32 if (event
.is_char()) {
33 const uint16 ch
= event
.GetCharacter();
34 if (GetTextInputClient())
35 GetTextInputClient()->InsertChar(ch
, event
.flags());
40 return DispatchKeyEventPostIME(event
);