OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_BASE_IME_INPUT_METHOD_WIN_H_ | 5 #ifndef UI_BASE_IME_INPUT_METHOD_WIN_H_ |
6 #define UI_BASE_IME_INPUT_METHOD_WIN_H_ | 6 #define UI_BASE_IME_INPUT_METHOD_WIN_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "ui/base/ime/input_method_base.h" | 14 #include "ui/base/ime/input_method_base.h" |
15 #include "ui/base/ime/win/imm32_manager.h" | 15 #include "ui/base/ime/win/imm32_manager.h" |
16 | 16 |
17 namespace ui { | 17 namespace ui { |
18 | 18 |
19 // A common InputMethod implementation shared between IMM32 and TSF. | 19 // A common InputMethod implementation based on IMM32. |
20 class UI_BASE_EXPORT InputMethodWin : public InputMethodBase { | 20 class UI_BASE_EXPORT InputMethodWin : public InputMethodBase { |
21 public: | 21 public: |
22 InputMethodWin(internal::InputMethodDelegate* delegate, | 22 InputMethodWin(internal::InputMethodDelegate* delegate, |
23 HWND toplevel_window_handle); | 23 HWND toplevel_window_handle); |
24 | 24 |
25 // Overridden from InputMethod: | 25 // Overridden from InputMethod: |
26 virtual void Init(bool focused) OVERRIDE; | 26 virtual void Init(bool focused) OVERRIDE; |
| 27 virtual void OnFocus() OVERRIDE; |
| 28 virtual void OnBlur() OVERRIDE; |
| 29 virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event, |
| 30 NativeEventResult* result) OVERRIDE; |
27 virtual bool DispatchKeyEvent(const ui::KeyEvent& event) OVERRIDE; | 31 virtual bool DispatchKeyEvent(const ui::KeyEvent& event) OVERRIDE; |
| 32 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE; |
| 33 virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE; |
| 34 virtual void CancelComposition(const TextInputClient* client) OVERRIDE; |
28 virtual void OnInputLocaleChanged() OVERRIDE; | 35 virtual void OnInputLocaleChanged() OVERRIDE; |
29 virtual std::string GetInputLocale() OVERRIDE; | 36 virtual std::string GetInputLocale() OVERRIDE; |
30 virtual bool IsActive() OVERRIDE; | 37 virtual bool IsActive() OVERRIDE; |
| 38 virtual bool IsCandidatePopupOpen() const OVERRIDE; |
31 | 39 |
32 protected: | 40 protected: |
33 // Overridden from InputMethodBase: | 41 // Overridden from InputMethodBase: |
34 // If a derived class overrides this method, it should call parent's | 42 // If a derived class overrides this method, it should call parent's |
35 // implementation. | 43 // implementation. |
| 44 virtual void OnWillChangeFocusedClient(TextInputClient* focused_before, |
| 45 TextInputClient* focused) OVERRIDE; |
36 virtual void OnDidChangeFocusedClient(TextInputClient* focused_before, | 46 virtual void OnDidChangeFocusedClient(TextInputClient* focused_before, |
37 TextInputClient* focused) OVERRIDE; | 47 TextInputClient* focused) OVERRIDE; |
38 | 48 |
39 // Some IMEs rely on WM_IME_REQUEST message even when TSF is enabled. So | 49 private: |
40 // OnImeRequest (and its actual implementations as OnDocumentFeed, | |
41 // OnReconvertString, and OnQueryCharPosition) are placed in this base class. | |
42 LRESULT OnImeRequest(UINT message, | |
43 WPARAM wparam, | |
44 LPARAM lparam, | |
45 BOOL* handled); | |
46 // For both WM_CHAR and WM_SYSCHAR | 50 // For both WM_CHAR and WM_SYSCHAR |
47 LRESULT OnChar(HWND window_handle, | 51 LRESULT OnChar(HWND window_handle, |
48 UINT message, | 52 UINT message, |
49 WPARAM wparam, | 53 WPARAM wparam, |
50 LPARAM lparam, | 54 LPARAM lparam, |
51 BOOL* handled); | 55 BOOL* handled); |
52 | 56 |
| 57 LRESULT OnImeSetContext(HWND window_handle, |
| 58 UINT message, |
| 59 WPARAM wparam, |
| 60 LPARAM lparam, |
| 61 BOOL* handled); |
| 62 LRESULT OnImeStartComposition(HWND window_handle, |
| 63 UINT message, |
| 64 WPARAM wparam, |
| 65 LPARAM lparam, |
| 66 BOOL* handled); |
| 67 LRESULT OnImeComposition(HWND window_handle, |
| 68 UINT message, |
| 69 WPARAM wparam, |
| 70 LPARAM lparam, |
| 71 BOOL* handled); |
| 72 LRESULT OnImeEndComposition(HWND window_handle, |
| 73 UINT message, |
| 74 WPARAM wparam, |
| 75 LPARAM lparam, |
| 76 BOOL* handled); |
| 77 LRESULT OnImeNotify(UINT message, |
| 78 WPARAM wparam, |
| 79 LPARAM lparam, |
| 80 BOOL* handled); |
| 81 |
| 82 // Some IMEs rely on WM_IME_REQUEST message even when TSF is enabled. So |
| 83 // OnImeRequest (and its actual implementations as OnDocumentFeed, |
| 84 // OnReconvertString, and OnQueryCharPosition) are placed in this base class. |
| 85 LRESULT OnImeRequest(UINT message, |
| 86 WPARAM wparam, |
| 87 LPARAM lparam, |
| 88 BOOL* handled); |
53 LRESULT OnDocumentFeed(RECONVERTSTRING* reconv); | 89 LRESULT OnDocumentFeed(RECONVERTSTRING* reconv); |
54 LRESULT OnReconvertString(RECONVERTSTRING* reconv); | 90 LRESULT OnReconvertString(RECONVERTSTRING* reconv); |
55 LRESULT OnQueryCharPosition(IMECHARPOSITION* char_positon); | 91 LRESULT OnQueryCharPosition(IMECHARPOSITION* char_positon); |
56 | 92 |
57 // Returns the window handle to which |text_input_client| is bound. | 93 // Returns the window handle to which |text_input_client| is bound. |
58 // On Aura environment, |toplevel_window_handle_| is always returned. | 94 // On Aura environment, |toplevel_window_handle_| is always returned. |
59 HWND GetAttachedWindowHandle(const TextInputClient* text_input_client) const; | 95 HWND GetAttachedWindowHandle(const TextInputClient* text_input_client) const; |
60 | 96 |
61 // Returns true if the Win32 native window bound to |client| is considered | 97 // Returns true if the Win32 native window bound to |client| is considered |
62 // to be ready for receiving keyboard input. | 98 // to be ready for receiving keyboard input. |
63 bool IsWindowFocused(const TextInputClient* client) const; | 99 bool IsWindowFocused(const TextInputClient* client) const; |
64 | 100 |
65 // Indicates if the current input locale has an IME. | 101 bool DispatchFabricatedKeyEvent(const ui::KeyEvent& event); |
66 bool active_; | 102 |
| 103 // Asks the client to confirm current composition text. |
| 104 void ConfirmCompositionText(); |
| 105 |
| 106 // Enables or disables the IME according to the current text input type. |
| 107 void UpdateIMEState(); |
67 | 108 |
68 // Windows IMM32 wrapper. | 109 // Windows IMM32 wrapper. |
69 // (See "ui/base/ime/win/ime_input.h" for its details.) | 110 // (See "ui/base/ime/win/ime_input.h" for its details.) |
70 ui::IMM32Manager imm32_manager_; | 111 ui::IMM32Manager imm32_manager_; |
71 | 112 |
72 private: | |
73 bool DispatchFabricatedKeyEvent(const ui::KeyEvent& event); | |
74 | |
75 // The toplevel window handle. | 113 // The toplevel window handle. |
76 // On non-Aura environment, this value is not used and always NULL. | 114 // On non-Aura environment, this value is not used and always NULL. |
77 const HWND toplevel_window_handle_; | 115 const HWND toplevel_window_handle_; |
78 | 116 |
79 // Name of the current input locale. | 117 // Name of the current input locale. |
80 std::string locale_; | 118 std::string locale_; |
81 | 119 |
82 // The new text direction and layout alignment requested by the user by | 120 // The new text direction and layout alignment requested by the user by |
83 // pressing ctrl-shift. It'll be sent to the text input client when the key | 121 // pressing ctrl-shift. It'll be sent to the text input client when the key |
84 // is released. | 122 // is released. |
85 base::i18n::TextDirection pending_requested_direction_; | 123 base::i18n::TextDirection pending_requested_direction_; |
86 | 124 |
87 // Represents if WM_CHAR[wparam=='\r'] should be dispatched to the focused | 125 // Represents if WM_CHAR[wparam=='\r'] should be dispatched to the focused |
88 // text input client or ignored silently. This flag is introduced as a quick | 126 // text input client or ignored silently. This flag is introduced as a quick |
89 // workaround against crbug.com/319100 | 127 // workaround against crbug.com/319100 |
90 // TODO(yukawa, IME): Figure out long-term solution. | 128 // TODO(yukawa, IME): Figure out long-term solution. |
91 bool accept_carriage_return_; | 129 bool accept_carriage_return_; |
92 | 130 |
| 131 // Indicates if the current input locale has an IME. |
| 132 bool active_; |
| 133 |
| 134 // True when an IME should be allowed to process key events. |
| 135 bool enabled_; |
| 136 |
| 137 // True if we know for sure that a candidate window is open. |
| 138 bool is_candidate_popup_open_; |
| 139 |
| 140 // Window handle where composition is on-going. NULL when there is no |
| 141 // composition. |
| 142 HWND composing_window_handle_; |
| 143 |
93 DISALLOW_COPY_AND_ASSIGN(InputMethodWin); | 144 DISALLOW_COPY_AND_ASSIGN(InputMethodWin); |
94 }; | 145 }; |
95 | 146 |
96 } // namespace ui | 147 } // namespace ui |
97 | 148 |
98 #endif // UI_BASE_IME_INPUT_METHOD_WIN_H_ | 149 #endif // UI_BASE_IME_INPUT_METHOD_WIN_H_ |
OLD | NEW |