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