blob: 5668e8f30abdb1b244fd8607057b7b4e6742c3bd [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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 Murdoch9ab55632013-07-18 11:57:30 +010014#include "ui/base/ime/win/imm32_manager.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000015#include "ui/views/ime/input_method_base.h"
16#include "ui/views/view.h"
17#include "ui/views/widget/widget.h"
18
19namespace ui {
20class InputMethod;
21} // namespace ui
22
23namespace views {
24
25// An InputMethod implementation based on Windows IMM32 API.
26class 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)7d4cd472013-06-19 11:58:07 +010037 virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event,
38 NativeEventResult* result) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000039 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)7d4cd472013-06-19 11:58:07 +010043 virtual void OnInputLocaleChanged() OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000044 virtual std::string GetInputLocale() OVERRIDE;
45 virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
46 virtual bool IsActive() OVERRIDE;
Ben Murdocheb525c52013-07-10 11:40:50 +010047 virtual bool IsCandidatePopupOpen() const OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000048
49 // Overridden from InputMethodBase.
50 virtual ui::TextInputClient* GetTextInputClient() const OVERRIDE;
51
Torne (Richard Coles)58218062012-11-14 11:43:16 +000052 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 Murdocheb525c52013-07-10 11:40:50 +010063 LRESULT OnImeNotify(
64 UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000065 // 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)c2e0dbd2013-05-09 18:35:53 +010074 LRESULT OnQueryCharPosition(IMECHARPOSITION *char_positon);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000075
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 Murdocheb525c52013-07-10 11:40:50 +010092 // True if we know for sure that a candidate window is open.
93 bool is_candidate_popup_open_;
94
Torne (Richard Coles)58218062012-11-14 11:43:16 +000095 // 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 Murdoch9ab55632013-07-18 11:57:30 +0100107 // (See "ui/base/ime/win/ime_input.h" for its details.)
108 ui::IMM32Manager imm32_manager_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000109
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_