- add sources.
[platform/framework/web/crosswalk.git] / src / ui / base / ime / input_method_win.h
1 // Copyright (c) 2011 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_BASE_IME_INPUT_METHOD_WIN_H_
6 #define UI_BASE_IME_INPUT_METHOD_WIN_H_
7
8 #include <windows.h>
9
10 #include <string>
11
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "ui/base/ime/input_method_base.h"
15 #include "ui/base/ime/win/imm32_manager.h"
16
17 namespace ui {
18
19 // A common InputMethod implementation shared between IMM32 and TSF.
20 class UI_EXPORT InputMethodWin : public InputMethodBase {
21  public:
22   InputMethodWin(internal::InputMethodDelegate* delegate,
23                  HWND toplevel_window_handle);
24
25   // Overridden from InputMethod:
26   virtual void Init(bool focused) OVERRIDE;
27   virtual bool DispatchKeyEvent(
28       const base::NativeEvent& native_key_event) OVERRIDE;
29   virtual bool DispatchFabricatedKeyEvent(const ui::KeyEvent& event) OVERRIDE;
30   virtual void OnInputLocaleChanged() OVERRIDE;
31   virtual std::string GetInputLocale() OVERRIDE;
32   virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
33   virtual bool IsActive() OVERRIDE;
34
35  protected:
36   // Some IMEs rely on WM_IME_REQUEST message even when TSF is enabled. So
37   // OnImeRequest (and its actual implementations as OnDocumentFeed,
38   // OnReconvertString, and OnQueryCharPosition) are placed in this base class.
39   LRESULT OnImeRequest(UINT message,
40                        WPARAM wparam,
41                        LPARAM lparam,
42                        BOOL* handled);
43   // For both WM_CHAR and WM_SYSCHAR
44   LRESULT OnChar(HWND window_handle,
45                  UINT message,
46                  WPARAM wparam,
47                  LPARAM lparam,
48                  BOOL* handled);
49   // For both WM_DEADCHAR and WM_SYSDEADCHAR
50   // TODO(yukawa): Stop handling WM_DEADCHAR and WM_SYSDEADCHAR when non-Aura
51   // build is deprecated.
52   LRESULT OnDeadChar(UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled);
53
54   LRESULT OnDocumentFeed(RECONVERTSTRING* reconv);
55   LRESULT OnReconvertString(RECONVERTSTRING* reconv);
56   LRESULT OnQueryCharPosition(IMECHARPOSITION* char_positon);
57
58   // Returns the window handle to which |text_input_client| is bound.
59   // On Aura environment, |toplevel_window_handle_| is always returned.
60   HWND GetAttachedWindowHandle(const TextInputClient* text_input_client) const;
61
62   // Returns true if the Win32 native window bound to |client| is considered
63   // to be ready for receiving keyboard input.
64   bool IsWindowFocused(const TextInputClient* client) const;
65
66   // Indicates if the current input locale has an IME.
67   bool active_;
68
69   // Windows IMM32 wrapper.
70   // (See "ui/base/ime/win/ime_input.h" for its details.)
71   ui::IMM32Manager imm32_manager_;
72
73  private:
74   // The toplevel window handle.
75   // On non-Aura environment, this value is not used and always NULL.
76   const HWND toplevel_window_handle_;
77
78   // Name of the current input locale.
79   std::string locale_;
80
81   // The current input text direction.
82   base::i18n::TextDirection direction_;
83
84   // The new text direction and layout alignment requested by the user by
85   // pressing ctrl-shift. It'll be sent to the text input client when the key
86   // is released.
87   base::i18n::TextDirection pending_requested_direction_;
88
89   DISALLOW_COPY_AND_ASSIGN(InputMethodWin);
90 };
91
92 }  // namespace ui
93
94 #endif  // UI_BASE_IME_INPUT_METHOD_WIN_H_