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.
5 #ifndef UI_BASE_IME_INPUT_METHOD_WIN_H_
6 #define UI_BASE_IME_INPUT_METHOD_WIN_H_
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"
19 // A common InputMethod implementation based on IMM32.
20 class UI_BASE_IME_EXPORT InputMethodWin
: public InputMethodBase
{
22 InputMethodWin(internal::InputMethodDelegate
* delegate
,
23 HWND toplevel_window_handle
);
25 // Overridden from InputMethod:
26 void OnFocus() override
;
27 void OnBlur() override
;
28 bool OnUntranslatedIMEMessage(const base::NativeEvent
& event
,
29 NativeEventResult
* result
) override
;
30 void DispatchKeyEvent(ui::KeyEvent
* event
) override
;
31 void OnTextInputTypeChanged(const TextInputClient
* client
) override
;
32 void OnCaretBoundsChanged(const TextInputClient
* client
) override
;
33 void CancelComposition(const TextInputClient
* client
) override
;
34 void OnInputLocaleChanged() override
;
35 std::string
GetInputLocale() override
;
36 bool IsCandidatePopupOpen() const override
;
39 // Overridden from InputMethodBase:
40 // If a derived class overrides this method, it should call parent's
42 void OnWillChangeFocusedClient(TextInputClient
* focused_before
,
43 TextInputClient
* focused
) override
;
44 void OnDidChangeFocusedClient(TextInputClient
* focused_before
,
45 TextInputClient
* focused
) override
;
48 // For both WM_CHAR and WM_SYSCHAR
49 LRESULT
OnChar(HWND window_handle
,
55 LRESULT
OnImeSetContext(HWND window_handle
,
60 LRESULT
OnImeStartComposition(HWND window_handle
,
65 LRESULT
OnImeComposition(HWND window_handle
,
70 LRESULT
OnImeEndComposition(HWND window_handle
,
75 LRESULT
OnImeNotify(UINT message
,
80 // Some IMEs rely on WM_IME_REQUEST message even when TSF is enabled. So
81 // OnImeRequest (and its actual implementations as OnDocumentFeed,
82 // OnReconvertString, and OnQueryCharPosition) are placed in this base class.
83 LRESULT
OnImeRequest(UINT message
,
87 LRESULT
OnDocumentFeed(RECONVERTSTRING
* reconv
);
88 LRESULT
OnReconvertString(RECONVERTSTRING
* reconv
);
89 LRESULT
OnQueryCharPosition(IMECHARPOSITION
* char_positon
);
91 // Returns true if the Win32 native window bound to |client| is considered
92 // to be ready for receiving keyboard input.
93 bool IsWindowFocused(const TextInputClient
* client
) const;
95 void DispatchFabricatedKeyEvent(ui::KeyEvent
* event
);
97 // Asks the client to confirm current composition text.
98 void ConfirmCompositionText();
100 // Enables or disables the IME according to the current text input type.
101 void UpdateIMEState();
103 // Windows IMM32 wrapper.
104 // (See "ui/base/ime/win/ime_input.h" for its details.)
105 ui::IMM32Manager imm32_manager_
;
107 // The toplevel window handle.
108 // On non-Aura environment, this value is not used and always NULL.
109 const HWND toplevel_window_handle_
;
111 // The new text direction and layout alignment requested by the user by
112 // pressing ctrl-shift. It'll be sent to the text input client when the key
114 base::i18n::TextDirection pending_requested_direction_
;
116 // Represents if WM_CHAR[wparam=='\r'] should be dispatched to the focused
117 // text input client or ignored silently. This flag is introduced as a quick
118 // workaround against crbug.com/319100
119 // TODO(yukawa, IME): Figure out long-term solution.
120 bool accept_carriage_return_
;
122 // True when an IME should be allowed to process key events.
125 // True if we know for sure that a candidate window is open.
126 bool is_candidate_popup_open_
;
128 // Window handle where composition is on-going. NULL when there is no
130 HWND composing_window_handle_
;
132 // Set to true to suppress the next WM_CHAR, when the WM_KEYDOWN gets stopped
133 // propagation (e.g. triggered an accelerator).
134 bool suppress_next_char_
;
136 DISALLOW_COPY_AND_ASSIGN(InputMethodWin
);
141 #endif // UI_BASE_IME_INPUT_METHOD_WIN_H_