1// Copyright (c) 2012 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#ifndef UI_VIEWS_COREWM_INPUT_METHOD_EVENT_FILTER_H_ 6#define UI_VIEWS_COREWM_INPUT_METHOD_EVENT_FILTER_H_ 7 8#include "base/basictypes.h" 9#include "base/compiler_specific.h" 10#include "base/memory/scoped_ptr.h" 11#include "ui/aura/window.h" 12#include "ui/base/ime/input_method_delegate.h" 13#include "ui/events/event_handler.h" 14#include "ui/gfx/native_widget_types.h" 15#include "ui/views/views_export.h" 16 17namespace ui { 18class InputMethod; 19} 20 21namespace views { 22namespace corewm { 23 24// An event filter that forwards a KeyEvent to a system IME, and dispatches a 25// TranslatedKeyEvent to the root window as needed. 26class VIEWS_EXPORT InputMethodEventFilter 27 : public ui::EventHandler, 28 public ui::internal::InputMethodDelegate { 29 public: 30 explicit InputMethodEventFilter(gfx::AcceleratedWidget widget); 31 virtual ~InputMethodEventFilter(); 32 33 void SetInputMethodPropertyInRootWindow(aura::Window* root_window); 34 35 ui::InputMethod* input_method() const { return input_method_.get(); } 36 37 private: 38 // Overridden from ui::EventHandler: 39 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; 40 41 // Overridden from ui::internal::InputMethodDelegate. 42 virtual bool DispatchKeyEventPostIME(const base::NativeEvent& event) OVERRIDE; 43 virtual bool DispatchFabricatedKeyEventPostIME(ui::EventType type, 44 ui::KeyboardCode key_code, 45 int flags) OVERRIDE; 46 47 scoped_ptr<ui::InputMethod> input_method_; 48 49 // The target dispatcher that will receive translated key events from the IME. 50 aura::WindowEventDispatcher* target_dispatcher_; 51 52 DISALLOW_COPY_AND_ASSIGN(InputMethodEventFilter); 53}; 54 55} // namespace corewm 56} // namespace views 57 58#endif // UI_VIEWS_COREWM_INPUT_METHOD_EVENT_FILTER_H_ 59