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 VIEWS_IME_INPUT_METHOD_H_ | |
6 #define VIEWS_IME_INPUT_METHOD_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/i18n/rtl.h" | |
13 | |
14 namespace views { | |
15 | |
16 namespace internal { | |
17 class InputMethodDelegate; | |
18 } // namespace internal | |
19 | |
20 class KeyEvent; | |
21 class View; | |
22 class Widget; | |
23 | |
24 // An interface implemented by an object that encapsulates a native input method | |
25 // service provided by the underlying operation system. | |
26 // Because on most systems, the system input method service is bound to | |
27 // individual native window. On Windows, its HWND, on Linux/Gtk, its GdkWindow. | |
28 // And in Views control system, only the top-level NativeWidget has a native | |
29 // window that can get keyboard focus. So this API is designed to be bound to | |
30 // the top-level NativeWidget. | |
31 class InputMethod { | |
32 public: | |
33 virtual ~InputMethod() {} | |
34 | |
35 // Sets the delegate used by this InputMethod instance. It should only be | |
36 // called by the internal NativeWidget or testing code. | |
37 virtual void set_delegate(internal::InputMethodDelegate* delegate) = 0; | |
38 | |
39 // Initialize the InputMethod object and attach it to the given |widget|. | |
40 // The |widget| must already be initialized. | |
41 virtual void Init(Widget* widget) = 0; | |
42 | |
43 // Called when the top-level NativeWidget gets keyboard focus. It should only | |
44 // be called by the top-level NativeWidget which owns this InputMethod | |
45 // instance. | |
46 virtual void OnFocusIn() = 0; | |
47 | |
48 // Called when the top-level NativeWidget loses keyboard focus. It should only | |
49 // be called by the top-level NativeWidget which owns this InputMethod | |
50 // instance. | |
51 virtual void OnFocusOut() = 0; | |
Peng
2011/03/29 19:12:19
It is better to add some API for browser to trace
James Su
2011/03/29 19:39:15
I think it may not be necessary to add such thing
Peng
2011/03/29 19:50:47
Your suggestion can work. But it is not idea solut
James Su
2011/03/29 22:32:38
Let's add it later when we figure out the actual w
Peng
2011/03/29 22:47:05
Do you mean we should let class InputMethodIBus co
James Su
2011/03/29 23:13:14
It depends on how it's implemented in InputMethodI
Peng
2011/03/30 21:32:37
I think it is better to have a reasonable idea to
James Su
2011/03/30 21:44:00
I didn't say to let InputMethodIBus to control vir
| |
52 | |
53 // Dispatch a key event to the input method. The key event will be dispatched | |
54 // back to the caller via InputMethodDelegate::DispatchKeyEventPostIME(), once | |
55 // it's processed by the input method. It should only be called by the | |
56 // top-level NativeWidget which owns this InputMethod instance, or other | |
57 // related platform dependent code, such as a message dispatcher. | |
58 virtual void DispatchKeyEvent(const KeyEvent& key) = 0; | |
59 | |
60 // Called by the focused |view| whenever its text input type is changed. | |
61 // Before calling this method, the focused |view| must confirm or clear | |
62 // existing composition text and call InputMethod::CancelComposition() when | |
63 // necessary. Otherwise unexpected behavior may happen. | |
64 virtual void OnTextInputTypeChanged(View* view) = 0; | |
65 | |
66 // Called by the focused |view| whenever its caret bounds is changed. | |
67 virtual void OnCaretBoundsChanged(View* view) = 0; | |
68 | |
69 // Called by the focused |view| to ask the input method cancel the ongoing | |
70 // composition session. | |
71 virtual void CancelComposition(View* view) = 0; | |
72 | |
73 // Returns the locale of current keyboard layout or input method, as a BCP-47 | |
74 // tag, or an empty string if the input method cannot provide it. | |
75 virtual std::string GetInputLocale() = 0; | |
76 | |
77 // Returns the text direction of current keyboard layout or input method, or | |
78 // base::i18n::UNKNOWN_DIRECTION if the input method cannot provide it. | |
79 virtual base::i18n::TextDirection GetInputTextDirection() = 0; | |
80 | |
81 // Checks if the input method is active, i.e. if it's ready for processing | |
82 // keyboard event and generate composition or text result. | |
83 // If the input method is inactive, then it's not necessary to inform it the | |
84 // changes of caret bounds and text input type. | |
85 // Note: character results may still be generated and sent to the text input | |
86 // client by calling TextInputClient::InsertChar(), even if the input method | |
87 // is not active. | |
88 virtual bool IsActive() = 0; | |
89 | |
90 // TODO(suzhe): Support mouse/touch event. | |
Peng
2011/03/29 19:12:19
It is better to have a static helper function like
James Su
2011/03/29 19:39:15
Good point. I'll add some helper methods.
| |
91 }; | |
92 | |
93 } // namespace views | |
94 | |
95 #endif // VIEWS_IME_INPUT_METHOD_H_ | |
OLD | NEW |