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_BASE_IME_INPUT_METHOD_WIN_H_
6#define UI_BASE_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"
14#include "ui/base/ime/input_method_base.h"
15#include "ui/base/ime/win/imm32_manager.h"
16
17namespace ui {
18
19// A common InputMethod implementation shared between IMM32 and TSF.
20class UI_EXPORT InputMethodWin : public InputMethodBase {
21 public:
22  InputMethodWin(internal::InputMethodDelegate* delegate,
23                 HWND toplevel_window_handle);
24
25  // Overridden from InputMethod:
26  virtual void Init(bool focused) OVERRIDE;
27  virtual bool DispatchKeyEvent(const ui::KeyEvent& event) OVERRIDE;
28  virtual void OnInputLocaleChanged() OVERRIDE;
29  virtual std::string GetInputLocale() OVERRIDE;
30  virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
31  virtual bool IsActive() OVERRIDE;
32
33 protected:
34  // Overridden from InputMethodBase:
35  // If a derived class overrides this method, it should call parent's
36  // implementation.
37  virtual void OnDidChangeFocusedClient(TextInputClient* focused_before,
38                                        TextInputClient* focused) OVERRIDE;
39
40  // Some IMEs rely on WM_IME_REQUEST message even when TSF is enabled. So
41  // OnImeRequest (and its actual implementations as OnDocumentFeed,
42  // OnReconvertString, and OnQueryCharPosition) are placed in this base class.
43  LRESULT OnImeRequest(UINT message,
44                       WPARAM wparam,
45                       LPARAM lparam,
46                       BOOL* handled);
47  // For both WM_CHAR and WM_SYSCHAR
48  LRESULT OnChar(HWND window_handle,
49                 UINT message,
50                 WPARAM wparam,
51                 LPARAM lparam,
52                 BOOL* handled);
53  // For both WM_DEADCHAR and WM_SYSDEADCHAR
54  // TODO(yukawa): Stop handling WM_DEADCHAR and WM_SYSDEADCHAR when non-Aura
55  // build is deprecated.
56  LRESULT OnDeadChar(UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled);
57
58  LRESULT OnDocumentFeed(RECONVERTSTRING* reconv);
59  LRESULT OnReconvertString(RECONVERTSTRING* reconv);
60  LRESULT OnQueryCharPosition(IMECHARPOSITION* char_positon);
61
62  // Returns the window handle to which |text_input_client| is bound.
63  // On Aura environment, |toplevel_window_handle_| is always returned.
64  HWND GetAttachedWindowHandle(const TextInputClient* text_input_client) const;
65
66  // Returns true if the Win32 native window bound to |client| is considered
67  // to be ready for receiving keyboard input.
68  bool IsWindowFocused(const TextInputClient* client) const;
69
70  // Indicates if the current input locale has an IME.
71  bool active_;
72
73  // Windows IMM32 wrapper.
74  // (See "ui/base/ime/win/ime_input.h" for its details.)
75  ui::IMM32Manager imm32_manager_;
76
77 private:
78  bool DispatchFabricatedKeyEvent(const ui::KeyEvent& event);
79
80  // The toplevel window handle.
81  // On non-Aura environment, this value is not used and always NULL.
82  const HWND toplevel_window_handle_;
83
84  // Name of the current input locale.
85  std::string locale_;
86
87  // The current input text direction.
88  base::i18n::TextDirection direction_;
89
90  // The new text direction and layout alignment requested by the user by
91  // pressing ctrl-shift. It'll be sent to the text input client when the key
92  // is released.
93  base::i18n::TextDirection pending_requested_direction_;
94
95  // Represents if WM_CHAR[wparam=='\r'] should be dispatched to the focused
96  // text input client or ignored silently. This flag is introduced as a quick
97  // workaround against crbug.com/319100
98  // TODO(yukawa, IME): Figure out long-term solution.
99  bool accept_carriage_return_;
100
101  DISALLOW_COPY_AND_ASSIGN(InputMethodWin);
102};
103
104}  // namespace ui
105
106#endif  // UI_BASE_IME_INPUT_METHOD_WIN_H_
107