| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_VIEWS_IME_INPUT_METHOD_H_ | 5 #ifndef UI_VIEWS_IME_INPUT_METHOD_H_ |
| 6 #define UI_VIEWS_IME_INPUT_METHOD_H_ | 6 #define UI_VIEWS_IME_INPUT_METHOD_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 12 #include "ui/base/ime/text_input_type.h" | 12 #include "ui/base/ime/text_input_type.h" |
| 13 #include "ui/views/views_export.h" | 13 #include "ui/views/views_export.h" |
| 14 | 14 |
| 15 namespace ui { | 15 namespace ui { |
| 16 class KeyEvent; | 16 class KeyEvent; |
| 17 class TextInputClient; | 17 class TextInputClient; |
| 18 } // namespace ui | 18 } // namespace ui |
| 19 | 19 |
| 20 namespace views { | 20 namespace views { |
| 21 | 21 |
| 22 namespace internal { | 22 namespace internal { |
| 23 class InputMethodDelegate; | 23 class InputMethodDelegate; |
| 24 } // namespace internal | 24 } // namespace internal |
| 25 | 25 |
| 26 class View; | 26 class View; |
| 27 class Widget; | 27 class Widget; |
| 28 | 28 |
| 29 // An interface implemented by an object that encapsulates a native input method | 29 // An interface implemented by an object that encapsulates a native input method |
| 30 // service provided by the underlying operation system. | 30 // service provided by the underlying operation system. Input method services |
| 31 // Because on most systems, the system input method service is bound to | 31 // are typically bound to individual native windows (HWND, aura::Window, etc.). |
| 32 // individual native window. On Windows, its HWND, on Aura, its | 32 // In Views, only the top-level Widgets get keyboard focus, so this API is |
| 33 // ui::aura::Window. And in Views control system, only the top-level | 33 // designed to be bound to top-level Widgets. |
| 34 // NativeWidget has a native window that can get keyboard focus. So this API is | |
| 35 // designed to be bound to the top-level NativeWidget. | |
| 36 class VIEWS_EXPORT InputMethod { | 34 class VIEWS_EXPORT InputMethod { |
| 37 public: | 35 public: |
| 38 virtual ~InputMethod() {} | 36 virtual ~InputMethod() {} |
| 39 | 37 |
| 40 // Sets the delegate used by this InputMethod instance. It should only be | 38 // Sets the delegate used by this InputMethod instance. |
| 41 // called by the internal NativeWidget or testing code. | 39 // This should only be called by the owner Widget or testing code. |
| 42 virtual void set_delegate(internal::InputMethodDelegate* delegate) = 0; | 40 virtual void SetDelegate(internal::InputMethodDelegate* delegate) = 0; |
| 43 | 41 |
| 44 // Initialize the InputMethod object and attach it to the given |widget|. | 42 // Initialize the InputMethod object and attach it to the given |widget|. |
| 45 // The |widget| must already be initialized. | 43 // The |widget| must already be initialized. |
| 46 virtual void Init(Widget* widget) = 0; | 44 virtual void Init(Widget* widget) = 0; |
| 47 | 45 |
| 48 // Called when the top-level NativeWidget gets keyboard focus. It should only | 46 // Called when the top-level Widget gains or loses keyboard focus. |
| 49 // be called by the top-level NativeWidget which owns this InputMethod | 47 // These should only be called by the Widget that owns this InputMethod. |
| 50 // instance. | |
| 51 virtual void OnFocus() = 0; | 48 virtual void OnFocus() = 0; |
| 52 | |
| 53 // Called when the top-level NativeWidget loses keyboard focus. It should only | |
| 54 // be called by the top-level NativeWidget which owns this InputMethod | |
| 55 // instance. | |
| 56 virtual void OnBlur() = 0; | 49 virtual void OnBlur() = 0; |
| 57 | 50 |
| 58 // Dispatch a key event to the input method. The key event will be dispatched | 51 // Dispatch a key event to the input method. The key event will be dispatched |
| 59 // back to the caller via InputMethodDelegate::DispatchKeyEventPostIME(), once | 52 // back to the caller via InputMethodDelegate::DispatchKeyEventPostIME(), once |
| 60 // it's processed by the input method. It should only be called by the | 53 // it has been processed by the input method. It should only be called by the |
| 61 // top-level NativeWidget which owns this InputMethod instance, or other | 54 // top-level Widget that owns this InputMethod instance, or other related |
| 62 // related platform dependent code, such as a message dispatcher. | 55 // platform-specific code, such as a message dispatcher. |
| 63 virtual void DispatchKeyEvent(const ui::KeyEvent& key) = 0; | 56 virtual void DispatchKeyEvent(const ui::KeyEvent& key) = 0; |
| 64 | 57 |
| 65 // Called by the focused |view| whenever its text input type is changed. | 58 // Called by the focused |view| whenever its text input type has changed. |
| 66 // Before calling this method, the focused |view| must confirm or clear | 59 // Before calling this method, the focused |view| must confirm or clear any |
| 67 // existing composition text and call InputMethod::CancelComposition() when | 60 // existing composition text and call InputMethod::CancelComposition() when |
| 68 // necessary. Otherwise unexpected behavior may happen. This method has no | 61 // necessary. This method has no effect if |view| is not focused. |
| 69 // effect if the |view| is not focused. | |
| 70 virtual void OnTextInputTypeChanged(View* view) = 0; | 62 virtual void OnTextInputTypeChanged(View* view) = 0; |
| 71 | 63 |
| 72 // Called by the focused |view| whenever its caret bounds is changed. | 64 // Called by the focused |view| whenever its caret bounds have changed. |
| 73 // This method has no effect if the |view| is not focused. | 65 // This method has no effect if |view| is not focused. |
| 74 virtual void OnCaretBoundsChanged(View* view) = 0; | 66 virtual void OnCaretBoundsChanged(View* view) = 0; |
| 75 | 67 |
| 76 // Called by the focused |view| to ask the input method cancel the ongoing | 68 // Called by the focused |view| to cancel the ongoing composition session. |
| 77 // composition session. This method has no effect if the |view| is not | 69 // This method has no effect if |view| is not focused. |
| 78 // focused. | |
| 79 virtual void CancelComposition(View* view) = 0; | 70 virtual void CancelComposition(View* view) = 0; |
| 80 | 71 |
| 81 // Returns the locale of current keyboard layout or input method, as a BCP-47 | 72 // Returns the locale of current keyboard layout or input method, as a BCP-47 |
| 82 // tag, or an empty string if the input method cannot provide it. | 73 // tag, or an empty string if the input method cannot provide it. |
| 83 virtual std::string GetInputLocale() = 0; | 74 virtual std::string GetInputLocale() = 0; |
| 84 | 75 |
| 85 // Returns the text direction of current keyboard layout or input method, or | 76 // Returns the text direction of current keyboard layout or input method, or |
| 86 // base::i18n::UNKNOWN_DIRECTION if the input method cannot provide it. | 77 // base::i18n::UNKNOWN_DIRECTION if the input method cannot provide it. |
| 87 virtual base::i18n::TextDirection GetInputTextDirection() = 0; | 78 virtual base::i18n::TextDirection GetInputTextDirection() = 0; |
| 88 | 79 |
| 89 // Checks if the input method is active, i.e. if it's ready for processing | 80 // Returns true if the input method is ready to process keyboard events and |
| 90 // keyboard event and generate composition or text result. | 81 // generate composition or text results. It is not necessary to notify |
| 91 // If the input method is inactive, then it's not necessary to inform it the | 82 // inactive input methods of caret bounds or text input type changes. |
| 92 // changes of caret bounds and text input type. | 83 // Note: TextInputClient::InsertChar() may be called to send input to the text |
| 93 // Note: character results may still be generated and sent to the text input | 84 // input client even if the input method is not active. |
| 94 // client by calling TextInputClient::InsertChar(), even if the input method | |
| 95 // is not active. | |
| 96 virtual bool IsActive() = 0; | 85 virtual bool IsActive() = 0; |
| 97 | 86 |
| 98 // Gets the focused text input client. Returns NULL if the Widget is not | 87 // Returns the focused text input client, or NULL if the Widget is not active, |
| 99 // focused, or there is no focused View or the focused View doesn't support | 88 // has no focused View, or if the focused View does not support text input. |
| 100 // text input. | |
| 101 virtual ui::TextInputClient* GetTextInputClient() const = 0; | 89 virtual ui::TextInputClient* GetTextInputClient() const = 0; |
| 102 | 90 |
| 103 // Gets the text input type of the focused text input client. Returns | 91 // Gets the text input type of the focused text input client. Returns |
| 104 // ui::TEXT_INPUT_TYPE_NONE if there is no focused text input client. | 92 // ui::TEXT_INPUT_TYPE_NONE if there is no focused text input client. |
| 105 virtual ui::TextInputType GetTextInputType() const = 0; | 93 virtual ui::TextInputType GetTextInputType() const = 0; |
| 106 | 94 |
| 107 // Returns true if the input method is a mock and not real. | 95 // Returns true if the input method is a mock instance used for testing. |
| 108 virtual bool IsMock() const = 0; | 96 virtual bool IsMock() const = 0; |
| 109 | 97 |
| 110 // TODO(suzhe): Support mouse/touch event. | 98 // TODO(suzhe): Support mouse/touch event. |
| 111 }; | 99 }; |
| 112 | 100 |
| 113 } // namespace views | 101 } // namespace views |
| 114 | 102 |
| 115 #endif // UI_VIEWS_IME_INPUT_METHOD_H_ | 103 #endif // UI_VIEWS_IME_INPUT_METHOD_H_ |
| OLD | NEW |