Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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_VIEWS_IME_INPUT_METHOD_WIN_H_ |
| 6 | #define UI_VIEWS_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" |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 14 | #include "ui/base/ime/win/imm32_manager.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 15 | #include "ui/views/ime/input_method_base.h" |
| 16 | #include "ui/views/view.h" |
| 17 | #include "ui/views/widget/widget.h" |
| 18 | |
| 19 | namespace ui { |
| 20 | class InputMethod; |
| 21 | } // namespace ui |
| 22 | |
| 23 | namespace views { |
| 24 | |
| 25 | // An InputMethod implementation based on Windows IMM32 API. |
| 26 | class InputMethodWin : public InputMethodBase { |
| 27 | public: |
| 28 | InputMethodWin(internal::InputMethodDelegate* delegate, |
| 29 | HWND hwnd, |
| 30 | ui::InputMethod* host); |
| 31 | virtual ~InputMethodWin(); |
| 32 | |
| 33 | // Overridden from InputMethod: |
| 34 | virtual void Init(Widget* widget) OVERRIDE; |
| 35 | virtual void OnFocus() OVERRIDE; |
| 36 | virtual void OnBlur() OVERRIDE; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 37 | virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event, |
| 38 | NativeEventResult* result) OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 39 | virtual void DispatchKeyEvent(const ui::KeyEvent& key) OVERRIDE; |
| 40 | virtual void OnTextInputTypeChanged(View* view) OVERRIDE; |
| 41 | virtual void OnCaretBoundsChanged(View* view) OVERRIDE; |
| 42 | virtual void CancelComposition(View* view) OVERRIDE; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 43 | virtual void OnInputLocaleChanged() OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 44 | virtual std::string GetInputLocale() OVERRIDE; |
| 45 | virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE; |
| 46 | virtual bool IsActive() OVERRIDE; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 47 | virtual bool IsCandidatePopupOpen() const OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 48 | |
| 49 | // Overridden from InputMethodBase. |
| 50 | virtual ui::TextInputClient* GetTextInputClient() const OVERRIDE; |
| 51 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 52 | private: |
| 53 | LRESULT OnImeSetContext( |
| 54 | UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
| 55 | LRESULT OnImeStartComposition( |
| 56 | UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
| 57 | LRESULT OnImeComposition( |
| 58 | UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
| 59 | LRESULT OnImeEndComposition( |
| 60 | UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
| 61 | LRESULT OnImeRequest( |
| 62 | UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 63 | LRESULT OnImeNotify( |
| 64 | UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 65 | // For both WM_CHAR and WM_SYSCHAR |
| 66 | LRESULT OnChar( |
| 67 | UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
| 68 | // For both WM_DEADCHAR and WM_SYSDEADCHAR |
| 69 | LRESULT OnDeadChar( |
| 70 | UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
| 71 | |
| 72 | LRESULT OnDocumentFeed(RECONVERTSTRING *reconv); |
| 73 | LRESULT OnReconvertString(RECONVERTSTRING *reconv); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 74 | LRESULT OnQueryCharPosition(IMECHARPOSITION *char_positon); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 75 | |
| 76 | // Overridden from InputMethodBase. |
| 77 | virtual void OnWillChangeFocus(View* focused_before, View* focused) OVERRIDE; |
| 78 | virtual void OnDidChangeFocus(View* focused_before, View* focused) OVERRIDE; |
| 79 | |
| 80 | // Asks the client to confirm current composition text. |
| 81 | void ConfirmCompositionText(); |
| 82 | |
| 83 | // Enables or disables the IME according to the current text input type. |
| 84 | void UpdateIMEState(); |
| 85 | |
| 86 | // The HWND this InputMethod is bound to. |
| 87 | HWND hwnd_; |
| 88 | |
| 89 | // Indicates if the current input locale has an IME. |
| 90 | bool active_; |
| 91 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 92 | // True if we know for sure that a candidate window is open. |
| 93 | bool is_candidate_popup_open_; |
| 94 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 95 | // Name of the current input locale. |
| 96 | std::string locale_; |
| 97 | |
| 98 | // The current input text direction. |
| 99 | base::i18n::TextDirection direction_; |
| 100 | |
| 101 | // The new text direction and layout alignment requested by the user by |
| 102 | // pressing ctrl-shift. It'll be sent to the text input client when the key |
| 103 | // is released. |
| 104 | base::i18n::TextDirection pending_requested_direction_; |
| 105 | |
| 106 | // Windows IMM32 wrapper. |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 107 | // (See "ui/base/ime/win/ime_input.h" for its details.) |
| 108 | ui::IMM32Manager imm32_manager_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 109 | |
| 110 | ui::InputMethod* const host_; |
| 111 | |
| 112 | DISALLOW_COPY_AND_ASSIGN(InputMethodWin); |
| 113 | }; |
| 114 | |
| 115 | } // namespace views |
| 116 | |
| 117 | #endif // UI_VIEWS_IME_INPUT_METHOD_WIN_H_ |