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. 4 5#include "mojo/views/input_method_mojo_linux.h" 6 7#include "ui/base/ime/text_input_client.h" 8#include "ui/events/event.h" 9 10namespace mojo { 11 12InputMethodMojoLinux::InputMethodMojoLinux( 13 ui::internal::InputMethodDelegate* delegate) 14 : ui::InputMethodAuraLinux(delegate) { 15} 16 17InputMethodMojoLinux::~InputMethodMojoLinux() {} 18 19bool 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()); 23 24 // If no text input client, do nothing. 25 if (!GetTextInputClient()) 26 return DispatchKeyEventPostIME(event); 27 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()); 36 37 return false; 38 } 39 40 return DispatchKeyEventPostIME(event); 41} 42 43} // namespace mojo 44