Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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_H_ | |
| 6 #define UI_BASE_IME_INPUT_METHOD_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/event_types.h" | |
| 13 #include "base/i18n/rtl.h" | |
| 14 #include "ui/base/ime/text_input_type.h" | |
| 15 #include "ui/base/keycodes/keyboard_codes.h" | |
| 16 #include "ui/gfx/native_widget_types.h" | |
| 17 #include "ui/base/ui_export.h" | |
| 18 | |
| 19 namespace ui { | |
| 20 | |
| 21 namespace internal { | |
| 22 class InputMethodDelegate; | |
| 23 } // namespace internal | |
| 24 | |
| 25 class TextInputClient; | |
| 26 | |
| 27 // An interface implemented by an object that encapsulates a native input method | |
| 28 // service provided by the underlying operating system, and acts as a "system | |
| 29 // wide" input method for all Chrome windows. A class that implements this | |
| 30 // interface should behave as follows: | |
| 31 // - Receives a keyboard event directly from a message dispatcher for the | |
| 32 // system through the InputMethod::DispatchKeyEvent API, and forwards it to | |
| 33 // an underlying input method for the OS. | |
| 34 // - The input method should handle the key event either of the following ways: | |
| 35 // 1) Send the original key down event to the focused window, which is e.g. | |
| 36 // a NativeWidgetAura (NWA) or a RenderWidgetHostViewAura (RWHVA), using | |
| 37 // internal::InputMethodDelegate::DispatchKeyEventPostIME API, then send | |
| 38 // a Char event using TextInputClient::InsertChar API to a text input | |
| 39 // client, which is, again, e.g. NWA or RWHVA, and then send the original | |
| 40 // key up event to the same window. | |
| 41 // 2) Send VKEY_PROCESSKEY event to the window using the DispatchKeyEvent API, | |
| 42 // then update IME status (e.g. composition text) using TextInputClient, | |
| 43 // and then send the original key up event to the window. | |
| 44 // - Keeps track of the active top-level gfx::NativeWindow to see which window | |
| 45 // can call APIs, OnTextInputTypeChanged, OnCaretBoundsChanged, and | |
| 46 // CancelComposition, that change the state of the input method. | |
| 47 // In Aura environment, aura::DesktopHost creates an instance of ui::InputMethod | |
| 48 // and owns it. | |
| 49 class UI_EXPORT InputMethod { | |
| 50 public: | |
| 51 virtual ~InputMethod(); | |
| 52 | |
| 53 // Sets the delegate used by this InputMethod instance. It should only be | |
| 54 // called by an object which manages the whole UI (e.g. aura::DesktopHost). | |
| 55 virtual void set_delegate(internal::InputMethodDelegate* delegate) = 0; | |
| 56 | |
| 57 // Sets the text input client which receives text input events such as | |
| 58 // SetCompositionText(). |client| can be NULL. A gfx::NativeWindow which | |
| 59 // implementes TextInputClient interface, e.g. NWA and RWHVA, should register | |
| 60 // itself by calling the method when it is focused, and unregister itself by | |
| 61 // calling the metho with NULL when it is unfocused. | |
| 62 virtual void set_text_input_client(TextInputClient* client) = 0; | |
|
James Su
2011/11/21 08:23:36
How about rename it to SetFocusedTextInputClient()
Yusuke Sato
2011/11/22 11:09:30
Done.
| |
| 63 | |
| 64 // Gets the current text input client. Returns NULL when no client is set. | |
| 65 virtual TextInputClient* text_input_client() const = 0; | |
|
James Su
2011/11/21 08:23:36
We may rename it to GetTextInputClient() as well.
Yusuke Sato
2011/11/22 11:09:30
Done.
| |
| 66 | |
| 67 // Initializes the InputMethod object. | |
| 68 virtual void Init() = 0; | |
|
James Su
2011/11/21 08:23:36
This method should have a parameter to tell this u
Yusuke Sato
2011/11/22 11:09:30
Done.
| |
| 69 | |
| 70 // Dispatches a key event to the input method. The key event will be | |
| 71 // dispatched back to the caller via | |
| 72 // ui::InputMethodDelegate::DispatchKeyEventPostIME(), once it's processed by | |
| 73 // the input method. It should only be called by a message dispatcher. | |
| 74 virtual void DispatchKeyEvent(gfx::NativeEvent native_key_event) = 0; | |
|
James Su
2011/11/21 08:23:36
It's better to use the real system event type (bas
Yusuke Sato
2011/11/22 11:09:30
Done.
| |
| 75 | |
| 76 // Called by the focused |window| whenever its text input type is changed. | |
| 77 // Before calling this method, the focused |window| must confirm or clear | |
| 78 // existing composition text and call InputMethod::CancelComposition() when | |
| 79 // necessary. Otherwise unexpected behavior may happen. This method has no | |
| 80 // effect if the |window| is not inside the active window. | |
| 81 virtual void OnTextInputTypeChanged(gfx::NativeWindow window) = 0; | |
|
James Su
2011/11/21 08:23:36
Using |window| as parameter makes no sense here. W
Yusuke Sato
2011/11/22 11:09:30
Done.
| |
| 82 | |
| 83 // Called by the focused |window| whenever its caret bounds is changed. | |
| 84 // This method has no effect if the |window| is not inside the active window. | |
| 85 virtual void OnCaretBoundsChanged(gfx::NativeWindow window) = 0; | |
|
James Su
2011/11/21 08:23:36
Same as above method.
The only problem is how to t
Yusuke Sato
2011/11/22 11:09:30
Done.
| |
| 86 | |
| 87 // Called by the focused |window| to ask the input method cancel the ongoing | |
| 88 // composition session. This method has no effect if the |window| is not | |
| 89 // inside the active window. | |
| 90 virtual void CancelComposition(gfx::NativeWindow window) = 0; | |
|
James Su
2011/11/21 08:23:36
ditto.
Yusuke Sato
2011/11/22 11:09:30
Done.
| |
| 91 | |
| 92 // Returns the locale of current keyboard layout or input method, as a BCP-47 | |
| 93 // tag, or an empty string if the input method cannot provide it. | |
| 94 virtual std::string GetInputLocale() = 0; | |
| 95 | |
| 96 // Returns the text direction of current keyboard layout or input method, or | |
| 97 // base::i18n::UNKNOWN_DIRECTION if the input method cannot provide it. | |
| 98 virtual base::i18n::TextDirection GetInputTextDirection() = 0; | |
| 99 | |
| 100 // Checks if the input method is active, i.e. if it's ready for processing | |
| 101 // keyboard event and generate composition or text result. | |
| 102 // If the input method is inactive, then it's not necessary to inform it the | |
| 103 // changes of caret bounds and text input type. | |
| 104 // Note: character results may still be generated and sent to the text input | |
| 105 // client by calling TextInputClient::InsertChar(), even if the input method | |
| 106 // is not active. | |
| 107 virtual bool IsActive() = 0; | |
| 108 | |
| 109 // Gets the text input type of the focused text input client. Returns | |
| 110 // ui::TEXT_INPUT_TYPE_NONE if there is no focused client. | |
| 111 virtual TextInputType GetTextInputType() const = 0; | |
| 112 | |
| 113 // We emulate Windows' WM_KEYDOWN and WM_CHAR messages. WM_CHAR events are | |
| 114 // only generated for certain keys; see | |
| 115 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms646268.aspx. | |
| 116 static bool ShouldSendCharEventForKeyboardCode(KeyboardCode keycode); | |
|
James Su
2011/11/21 08:23:36
I'm wondering why we need this method. On Linux, i
Yusuke Sato
2011/11/22 11:09:30
Removed.
| |
| 117 }; | |
| 118 | |
| 119 } // namespace ui | |
| 120 | |
| 121 #endif // UI_BASE_IME_INPUT_METHOD_H_ | |
| OLD | NEW |