OLD | NEW |
1 // Copyright (c) 2010 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 CHROME_BROWSER_IME_INPUT_H_ | 5 #ifndef UI_BASE_WIN_IME_INPUT_H_ |
6 #define CHROME_BROWSER_IME_INPUT_H_ | 6 #define UI_BASE_WIN_IME_INPUT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <windows.h> | 9 #include <windows.h> |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" | 15 #include "base/i18n/rtl.h" |
| 16 #include "base/string16.h" |
16 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
17 | 18 |
| 19 namespace ui { |
| 20 |
| 21 struct CompositionText; |
| 22 |
18 // This header file defines a struct and a class used for encapsulating IMM32 | 23 // This header file defines a struct and a class used for encapsulating IMM32 |
19 // APIs, controls IMEs attached to a window, and enables the 'on-the-spot' | 24 // APIs, controls IMEs attached to a window, and enables the 'on-the-spot' |
20 // input without deep knowledge about the APIs, i.e. knowledge about the | 25 // input without deep knowledge about the APIs, i.e. knowledge about the |
21 // language-specific and IME-specific behaviors. | 26 // language-specific and IME-specific behaviors. |
22 // The following items enumerates the simplest steps for an (window) | 27 // The following items enumerates the simplest steps for an (window) |
23 // application to control its IMEs with the struct and the class defined | 28 // application to control its IMEs with the struct and the class defined |
24 // this file. | 29 // this file. |
25 // 1. Add an instance of the ImeInput class to its window class. | 30 // 1. Add an instance of the ImeInput class to its window class. |
26 // (The ImeInput class needs a window handle.) | 31 // (The ImeInput class needs a window handle.) |
27 // 2. Add messages handlers listed in the following subsections, follow the | 32 // 2. Add messages handlers listed in the following subsections, follow the |
(...skipping 19 matching lines...) Expand all Loading... |
47 // 2.4. WM_IME_ENDCOMPOSITION (0x010E) | 52 // 2.4. WM_IME_ENDCOMPOSITION (0x010E) |
48 // Call the functions listed below: | 53 // Call the functions listed below: |
49 // - ImeInput::ResetComposition(), and; | 54 // - ImeInput::ResetComposition(), and; |
50 // - ImeInput::DestroyImeWindow(). | 55 // - ImeInput::DestroyImeWindow(). |
51 // An application CAN call ::DefWindowProc(). | 56 // An application CAN call ::DefWindowProc(). |
52 // 2.5. WM_INPUTLANGCHANGE (0x0051) | 57 // 2.5. WM_INPUTLANGCHANGE (0x0051) |
53 // Call the functions listed below: | 58 // Call the functions listed below: |
54 // - ImeInput::SetInputLanguage(). | 59 // - ImeInput::SetInputLanguage(). |
55 // An application CAN call ::DefWindowProc(). | 60 // An application CAN call ::DefWindowProc(). |
56 | 61 |
57 // This struct represents the status of an ongoing composition. | |
58 struct ImeComposition { | |
59 // Represents the start position of the selection range in the IME | |
60 // composition. | |
61 int selection_start; | |
62 | |
63 // Represents the end position of the selection range in the IME composition. | |
64 // If |selection_start| and |selection_end| are equal, then it represents the | |
65 // cursor position. | |
66 int selection_end; | |
67 | |
68 // Represents the type of the string in the 'ime_string' parameter. | |
69 // Its possible values and description are listed bwlow: | |
70 // Value Description | |
71 // 0 The parameter is not used. | |
72 // GCS_RESULTSTR The parameter represents a result string. | |
73 // GCS_COMPSTR The parameter represents a composition string. | |
74 int string_type; | |
75 | |
76 // Represents the string retrieved from IME (Input Method Editor) | |
77 std::wstring ime_string; | |
78 | |
79 // Contains the underline information of the composition string. | |
80 std::vector<WebKit::WebCompositionUnderline> underlines; | |
81 }; | |
82 | |
83 // This class controls the IMM (Input Method Manager) through IMM32 APIs and | 62 // This class controls the IMM (Input Method Manager) through IMM32 APIs and |
84 // enables it to retrieve the string being controled by the IMM. (I wrote | 63 // enables it to retrieve the string being controled by the IMM. (I wrote |
85 // a note to describe the reason why I do not use 'IME' but 'IMM' below.) | 64 // a note to describe the reason why I do not use 'IME' but 'IMM' below.) |
86 // NOTE(hbono): | 65 // NOTE(hbono): |
87 // Fortunately or unfortunately, TSF (Text Service Framework) and | 66 // Fortunately or unfortunately, TSF (Text Service Framework) and |
88 // CUAS (Cicero Unaware Application Support) allows IMM32 APIs for | 67 // CUAS (Cicero Unaware Application Support) allows IMM32 APIs for |
89 // retrieving not only the inputs from IMEs (Input Method Editors), used | 68 // retrieving not only the inputs from IMEs (Input Method Editors), used |
90 // only for inputting East-Asian language texts, but also the ones from | 69 // only for inputting East-Asian language texts, but also the ones from |
91 // tablets (on Windows XP Tablet PC Edition and Windows Vista), voice | 70 // tablets (on Windows XP Tablet PC Edition and Windows Vista), voice |
92 // recognizers (e.g. ViaVoice and Microsoft Office), etc. | 71 // recognizers (e.g. ViaVoice and Microsoft Office), etc. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // These parameters are used for verifying if this function is called | 106 // These parameters are used for verifying if this function is called |
128 // in a handler function for WM_IME_SETCONTEXT messages because this | 107 // in a handler function for WM_IME_SETCONTEXT messages because this |
129 // function uses ::DefWindowProc() to update the style. | 108 // function uses ::DefWindowProc() to update the style. |
130 // A caller just has to pass the input parameters for the handler | 109 // A caller just has to pass the input parameters for the handler |
131 // function without modifications. | 110 // function without modifications. |
132 // * handled [out] (BOOL*) | 111 // * handled [out] (BOOL*) |
133 // Returns ::DefWindowProc() is really called in this function. | 112 // Returns ::DefWindowProc() is really called in this function. |
134 // PLEASE DO NOT CALL ::DefWindowProc() IF THIS VALUE IS TRUE! | 113 // PLEASE DO NOT CALL ::DefWindowProc() IF THIS VALUE IS TRUE! |
135 // All the window styles set in this function are over-written when | 114 // All the window styles set in this function are over-written when |
136 // calling ::DefWindowProc() after returning this function. | 115 // calling ::DefWindowProc() after returning this function. |
137 void SetImeWindowStyle(HWND window_handle, UINT message, | 116 // Returns the value returned by DefWindowProc. |
138 WPARAM wparam, LPARAM lparam, BOOL* handled); | 117 LRESULT SetImeWindowStyle(HWND window_handle, UINT message, |
| 118 WPARAM wparam, LPARAM lparam, BOOL* handled); |
139 | 119 |
140 // Destroys the IME windows and all the resources attached to them. | 120 // Destroys the IME windows and all the resources attached to them. |
141 // Parameters | 121 // Parameters |
142 // * window_handle [in] (HWND) | 122 // * window_handle [in] (HWND) |
143 // Represents the window handle of the caller. | 123 // Represents the window handle of the caller. |
144 void DestroyImeWindow(HWND window_handle); | 124 void DestroyImeWindow(HWND window_handle); |
145 | 125 |
146 // Updates the position of the IME windows. | 126 // Updates the position of the IME windows. |
147 // Parameters | 127 // Parameters |
148 // * window_handle [in] (HWND) | 128 // * window_handle [in] (HWND) |
(...skipping 17 matching lines...) Expand all Loading... |
166 | 146 |
167 // Retrieves a composition result of the ongoing composition if it exists. | 147 // Retrieves a composition result of the ongoing composition if it exists. |
168 // Parameters | 148 // Parameters |
169 // * window_handle [in] (HWND) | 149 // * window_handle [in] (HWND) |
170 // Represents the window handle of the caller. | 150 // Represents the window handle of the caller. |
171 // * lparam [in] (LPARAM) | 151 // * lparam [in] (LPARAM) |
172 // Specifies the updated members of the ongoing composition, and must be | 152 // Specifies the updated members of the ongoing composition, and must be |
173 // the same parameter of a WM_IME_COMPOSITION message handler. | 153 // the same parameter of a WM_IME_COMPOSITION message handler. |
174 // This parameter is used for checking if the ongoing composition has | 154 // This parameter is used for checking if the ongoing composition has |
175 // its result string, | 155 // its result string, |
176 // * composition [out] (ImeComposition) | 156 // * result [out] (string16) |
177 // Represents the struct contains the composition result. | 157 // Represents the object contains the composition result. |
178 // Return values | 158 // Return values |
179 // * true | 159 // * true |
180 // The ongoing composition has a composition result. | 160 // The ongoing composition has a composition result. |
181 // * false | 161 // * false |
182 // The ongoing composition does not have composition results. | 162 // The ongoing composition does not have composition results. |
183 // Remarks | 163 // Remarks |
184 // This function is designed for being called from WM_IME_COMPOSITION | 164 // This function is designed for being called from WM_IME_COMPOSITION |
185 // message handlers. | 165 // message handlers. |
186 bool GetResult(HWND window_handle, LPARAM lparam, | 166 bool GetResult(HWND window_handle, LPARAM lparam, string16* result); |
187 ImeComposition* composition); | |
188 | 167 |
189 // Retrieves the current composition status of the ongoing composition. | 168 // Retrieves the current composition status of the ongoing composition. |
190 // Parameters | 169 // Parameters |
191 // * window_handle [in] (HWND) | 170 // * window_handle [in] (HWND) |
192 // Represents the window handle of the caller. | 171 // Represents the window handle of the caller. |
193 // * lparam [in] (LPARAM) | 172 // * lparam [in] (LPARAM) |
194 // Specifies the updated members of the ongoing composition, and must be | 173 // Specifies the updated members of the ongoing composition, and must be |
195 // the same parameter of a WM_IME_COMPOSITION message handler. | 174 // the same parameter of a WM_IME_COMPOSITION message handler. |
196 // This parameter is used for checking if the ongoing composition has | 175 // This parameter is used for checking if the ongoing composition has |
197 // its result string, | 176 // its result string, |
198 // * composition [out] (ImeComposition) | 177 // * composition [out] (Composition) |
199 // Represents the struct contains the composition status. | 178 // Represents the struct contains the composition status. |
200 // Return values | 179 // Return values |
201 // * true | 180 // * true |
202 // The status of the ongoing composition is updated. | 181 // The status of the ongoing composition is updated. |
203 // * false | 182 // * false |
204 // The status of the ongoing composition is not updated. | 183 // The status of the ongoing composition is not updated. |
205 // Remarks | 184 // Remarks |
206 // This function is designed for being called from WM_IME_COMPOSITION | 185 // This function is designed for being called from WM_IME_COMPOSITION |
207 // message handlers. | 186 // message handlers. |
208 bool GetComposition(HWND window_handle, LPARAM lparam, | 187 bool GetComposition(HWND window_handle, LPARAM lparam, |
209 ImeComposition* composition); | 188 CompositionText* composition); |
210 | 189 |
211 // Enables the IME attached to the given window, i.e. allows user-input | 190 // Enables the IME attached to the given window, i.e. allows user-input |
212 // events to be dispatched to the IME. | 191 // events to be dispatched to the IME. |
213 // Parameters | 192 // Parameters |
214 // * window_handle [in] (HWND) | 193 // * window_handle [in] (HWND) |
215 // Represents the window handle of the caller. | 194 // Represents the window handle of the caller. |
216 // * complete [in] (bool) | 195 // * complete [in] (bool) |
217 // Represents whether or not to complete the ongoing composition. | 196 // Represents whether or not to complete the ongoing composition. |
218 // + true | 197 // + true |
219 // After finishing the ongoing composition and close its IME windows, | 198 // After finishing the ongoing composition and close its IME windows, |
(...skipping 21 matching lines...) Expand all Loading... |
241 | 220 |
242 // Updates the caret position of the given window. | 221 // Updates the caret position of the given window. |
243 // Parameters | 222 // Parameters |
244 // * window_handle [in] (HWND) | 223 // * window_handle [in] (HWND) |
245 // Represents the window handle of the caller. | 224 // Represents the window handle of the caller. |
246 // * caret_rect [in] (const gfx::Rect&) | 225 // * caret_rect [in] (const gfx::Rect&) |
247 // Represent the rectangle of the input caret. | 226 // Represent the rectangle of the input caret. |
248 // This rectangle is used for controlling the positions of IME windows. | 227 // This rectangle is used for controlling the positions of IME windows. |
249 void UpdateCaretRect(HWND window_handle, const gfx::Rect& caret_rect); | 228 void UpdateCaretRect(HWND window_handle, const gfx::Rect& caret_rect); |
250 | 229 |
| 230 // Returns the current input language id. |
| 231 LANGID input_language_id() const { return input_language_id_; } |
| 232 |
| 233 // Returns BCP-47 tag name of the current input language. |
| 234 std::string GetInputLanguageName() const; |
| 235 |
| 236 // Returns the text direction of the current input language. |
| 237 base::i18n::TextDirection GetTextDirection() const; |
| 238 |
| 239 |
| 240 // Helper functions ---------------------------------------------------------- |
| 241 |
| 242 // Checks if there is any RTL keyboard layout installed in the system. |
| 243 static bool IsRTLKeyboardLayoutInstalled(); |
| 244 |
| 245 // Checks if the user pressed both Ctrl and right or left Shift keys to |
| 246 // requrest to change the text direction and layout alignment explicitly. |
| 247 // Returns true if only a Ctrl key and a Shift key are down. The desired text |
| 248 // direction will be stored in |*direction|. |
| 249 static bool IsCtrlShiftPressed(base::i18n::TextDirection* direction); |
| 250 |
251 protected: | 251 protected: |
252 // Retrieves the composition information. | 252 // Retrieves the composition information. |
253 void GetCompositionInfo(HIMC imm_context, LPARAM lparam, | 253 void GetCompositionInfo(HIMC imm_context, LPARAM lparam, |
254 ImeComposition* composition); | 254 CompositionText* composition); |
255 | 255 |
256 // Updates the position of the IME windows. | 256 // Updates the position of the IME windows. |
257 void MoveImeWindow(HWND window_handle, HIMC imm_context); | 257 void MoveImeWindow(HWND window_handle, HIMC imm_context); |
258 | 258 |
259 // Completes the ongoing composition if it exists. | 259 // Completes the ongoing composition if it exists. |
260 void CompleteComposition(HWND window_handle, HIMC imm_context); | 260 void CompleteComposition(HWND window_handle, HIMC imm_context); |
261 | 261 |
262 // Retrieves a string from the IMM. | 262 // Retrieves a string from the IMM. |
263 bool GetString(HIMC imm_context, WPARAM lparam, int type, | 263 bool GetString(HIMC imm_context, WPARAM lparam, int type, string16* result); |
264 ImeComposition* composition); | |
265 | 264 |
266 private: | 265 private: |
267 // Represents whether or not there is an ongoing composition in a browser | 266 // Represents whether or not there is an ongoing composition in a browser |
268 // process, i.e. whether or not a browser process is composing a text. | 267 // process, i.e. whether or not a browser process is composing a text. |
269 bool is_composing_; | 268 bool is_composing_; |
270 | 269 |
271 // This value represents whether or not the current input context has IMEs. | 270 // This value represents whether or not the current input context has IMEs. |
272 // The following table shows the list of IME status: | 271 // The following table shows the list of IME status: |
273 // Value Description | 272 // Value Description |
274 // false The current input language does not have IMEs. | 273 // false The current input language does not have IMEs. |
(...skipping 27 matching lines...) Expand all Loading... |
302 // * true: it creates a system caret. | 301 // * true: it creates a system caret. |
303 // * false: it does not create a system caret. | 302 // * false: it does not create a system caret. |
304 bool system_caret_; | 303 bool system_caret_; |
305 | 304 |
306 // The rectangle of the input caret retrieved from a renderer process. | 305 // The rectangle of the input caret retrieved from a renderer process. |
307 gfx::Rect caret_rect_; | 306 gfx::Rect caret_rect_; |
308 | 307 |
309 DISALLOW_COPY_AND_ASSIGN(ImeInput); | 308 DISALLOW_COPY_AND_ASSIGN(ImeInput); |
310 }; | 309 }; |
311 | 310 |
312 #endif // CHROME_BROWSER_IME_INPUT_H_ | 311 } // namespace ui |
| 312 |
| 313 #endif // UI_BASE_WIN_IME_INPUT_H_ |
OLD | NEW |