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 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
;
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
;
35 virtual void OnInputLocaleChanged() override
;
36 virtual std::string
GetInputLocale() override
;
37 virtual bool IsActive() override
;
38 virtual bool IsCandidatePopupOpen() const override
;
41 // Overridden from InputMethodBase:
42 // If a derived class overrides this method, it should call parent's
44 virtual void OnWillChangeFocusedClient(TextInputClient
* focused_before
,
45 TextInputClient
* focused
) override
;
46 virtual void OnDidChangeFocusedClient(TextInputClient
* focused_before
,
47 TextInputClient
* focused
) override
;
50 // For both WM_CHAR and WM_SYSCHAR
51 LRESULT
OnChar(HWND window_handle
,
57 LRESULT
OnImeSetContext(HWND window_handle
,
62 LRESULT
OnImeStartComposition(HWND window_handle
,
67 LRESULT
OnImeComposition(HWND window_handle
,
72 LRESULT
OnImeEndComposition(HWND window_handle
,
77 LRESULT
OnImeNotify(UINT message
,
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
,
89 LRESULT
OnDocumentFeed(RECONVERTSTRING
* reconv
);
90 LRESULT
OnReconvertString(RECONVERTSTRING
* reconv
);
91 LRESULT
OnQueryCharPosition(IMECHARPOSITION
* char_positon
);
93 // Returns the window handle to which |text_input_client| is bound.
94 // On Aura environment, |toplevel_window_handle_| is always returned.
95 HWND
GetAttachedWindowHandle(const TextInputClient
* text_input_client
) const;
97 // Returns true if the Win32 native window bound to |client| is considered
98 // to be ready for receiving keyboard input.
99 bool IsWindowFocused(const TextInputClient
* client
) const;
101 bool DispatchFabricatedKeyEvent(const ui::KeyEvent
& event
);
103 // Asks the client to confirm current composition text.
104 void ConfirmCompositionText();
106 // Enables or disables the IME according to the current text input type.
107 void UpdateIMEState();
109 // Windows IMM32 wrapper.
110 // (See "ui/base/ime/win/ime_input.h" for its details.)
111 ui::IMM32Manager imm32_manager_
;
113 // The toplevel window handle.
114 // On non-Aura environment, this value is not used and always NULL.
115 const HWND toplevel_window_handle_
;
117 // Name of the current input locale.
120 // The new text direction and layout alignment requested by the user by
121 // pressing ctrl-shift. It'll be sent to the text input client when the key
123 base::i18n::TextDirection pending_requested_direction_
;
125 // Represents if WM_CHAR[wparam=='\r'] should be dispatched to the focused
126 // text input client or ignored silently. This flag is introduced as a quick
127 // workaround against crbug.com/319100
128 // TODO(yukawa, IME): Figure out long-term solution.
129 bool accept_carriage_return_
;
131 // Indicates if the current input locale has an IME.
134 // True when an IME should be allowed to process key events.
137 // True if we know for sure that a candidate window is open.
138 bool is_candidate_popup_open_
;
140 // Window handle where composition is on-going. NULL when there is no
142 HWND composing_window_handle_
;
144 // Set to false initially. Tracks whether the IME has been initialized with
145 // the current input language.
146 bool default_input_language_initialized_
;
148 DISALLOW_COPY_AND_ASSIGN(InputMethodWin
);
153 #endif // UI_BASE_IME_INPUT_METHOD_WIN_H_