Index: views/ime/input_method_win.h |
diff --git a/views/ime/input_method_win.h b/views/ime/input_method_win.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..15f63a98323f2043e9404604d1f3dde66372f5b7 |
--- /dev/null |
+++ b/views/ime/input_method_win.h |
@@ -0,0 +1,120 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef VIEWS_IME_INPUT_METHOD_WIN_H_ |
+#define VIEWS_IME_INPUT_METHOD_WIN_H_ |
+#pragma once |
+ |
+#include <windows.h> |
+ |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/compiler_specific.h" |
+#include "ui/base/win/ime_input.h" |
+#include "views/focus/focus_manager.h" |
+#include "views/ime/input_method.h" |
+#include "views/ime/input_method_delegate.h" |
+#include "views/ime/text_input_client.h" |
+#include "views/view.h" |
+#include "views/widget/widget.h" |
+ |
+namespace views { |
+ |
+// An InputMethod implementation based on Windows IMM32 API. |
+class InputMethodWin : public InputMethod, |
+ public FocusChangeListener { |
+ public: |
+ explicit InputMethodWin(internal::InputMethodDelegate* delegate); |
+ virtual ~InputMethodWin(); |
+ |
+ // Overridden from InputMethod: |
+ virtual void set_delegate(internal::InputMethodDelegate* delegate) OVERRIDE; |
+ virtual void Init(Widget* widget) OVERRIDE; |
+ virtual void DispatchKeyEvent(const KeyEvent& key) OVERRIDE; |
+ virtual void OnTextInputTypeChanged(View* view) OVERRIDE; |
+ virtual void OnCaretBoundsChanged(View* view) OVERRIDE; |
+ virtual void CancelComposition(View* view) OVERRIDE; |
+ virtual std::string GetInputLocale() OVERRIDE; |
+ virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE; |
+ virtual bool IsActive() OVERRIDE; |
+ |
+ // Overridden from FocusChangeListener: |
+ virtual void FocusWillChange(View* focused_before, View* focused) OVERRIDE; |
+ |
+ // Message handlers. The native widget is responsible for forwarding following |
+ // messages to the input method. |
+ void OnSetFocus(); |
+ void OnKillFocus(); |
+ void OnInputLangChange(DWORD character_set, HKL input_language_id); |
+ LRESULT OnImeSetContext( |
+ UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
+ LRESULT OnImeStartComposition( |
+ UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
+ LRESULT OnImeComposition( |
+ UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
+ LRESULT OnImeEndComposition( |
+ UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
+ // For both WM_CHAR and WM_SYSCHAR |
+ LRESULT OnChar( |
+ UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
+ // For both WM_DEADCHAR and WM_SYSDEADCHAR |
+ LRESULT OnDeadChar( |
+ UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); |
+ |
+ private: |
+ HWND hwnd() const { return widget_->GetNativeView(); } |
+ |
+ // Asks the client to confirm current composition text. |
+ void ConfirmComposition(); |
+ |
+ // Enables or disables the IME according to the current text input type. |
+ void UpdateIMEState(); |
+ |
+ // Gets the focused text input client. Returns NULL if there is no focused |
+ // View or the focused View doesn't support text input. |
+ TextInputClient* GetTextInputClient() const; |
+ |
+ // Gets the text input type of the focused text input client. |
+ ui::TextInputType GetTextInputType() const; |
+ |
+ // Checks if the given view is focused. Returns true only if the view and |
+ // toplevel widget are both focused. |
+ bool IsViewFocused(View* view) const; |
+ |
+ // Convenience method to call delegate_->DispatchKeyEventPostIME(). |
+ void DispatchKeyEventPostIME(const KeyEvent& key) const; |
+ |
+ // Convenience method to call text input client's OnInputMethodChanged(). |
+ void OnInputMethodChanged() const; |
+ |
+ internal::InputMethodDelegate* delegate_; |
+ Widget* widget_; |
+ View* focused_view_; |
+ |
+ // Indicates if the toplevel widget is focused or not. |
+ bool widget_focused_; |
+ |
+ // Indicates if the current input locale has an IME. |
+ bool active_; |
+ |
+ // Name of the current input locale. |
+ std::string locale_; |
+ |
+ // The current input text direction. |
+ base::i18n::TextDirection direction_; |
+ |
+ // The new text direction and layout alignment requested by the user by |
+ // pressing ctrl-shift. It'll be sent to the text input client when the key |
+ // is released. |
+ base::i18n::TextDirection pending_requested_direction_; |
+ |
+ // Windows IMM32 wrapper. |
+ // (See "ui/base/win/ime_input.h" for its details.) |
+ ui::ImeInput ime_input_; |
+}; |
+ |
+} // namespace views |
+ |
+#endif // VIEWS_IME_INPUT_METHOD_WIN_H_ |