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 #include "ui/base/ime/text_input_type.h" | |
14 | |
15 namespace views { | |
16 | |
17 namespace internal { | |
18 class InputMethodDelegate; | |
19 } // namespace internal | |
20 | |
21 class KeyEvent; | |
22 class TextInputClient; | |
23 class View; | |
24 class Widget; | |
25 | |
26 // An interface implemented by an object that encapsulates a native input method | |
27 // service provided by the underlying operation system. | |
28 // Because on most systems, the system input method service is bound to | |
29 // individual native window. On Windows, its HWND, on Linux/Gtk, its GdkWindow. | |
30 // And in Views control system, only the top-level NativeWidget has a native | |
31 // window that can get keyboard focus. So this API is designed to be bound to | |
32 // the top-level NativeWidget. | |
33 class InputMethod { | |
34 public: | |
35 virtual ~InputMethod() {} | |
36 | |
37 // Sets the delegate used by this InputMethod instance. It should only be | |
38 // called by the internal NativeWidget or testing code. | |
39 virtual void set_delegate(internal::InputMethodDelegate* delegate) = 0; | |
40 | |
41 // Initialize the InputMethod object and attach it to the given |widget|. | |
42 // The |widget| must already be initialized. | |
43 virtual void Init(Widget* widget) = 0; | |
44 | |
45 // Called when the top-level NativeWidget gets keyboard focus. It should only | |
46 // be called by the top-level NativeWidget which owns this InputMethod | |
47 // instance. | |
48 virtual void OnFocusIn() = 0; | |
Peng
2011/03/30 18:41:35
Maybe rename to OnFocus() and OnBlur(). I changed
James Su
2011/03/30 19:44:22
Done.
| |
49 | |
50 // Called when the top-level NativeWidget loses keyboard focus. It should only | |
51 // be called by the top-level NativeWidget which owns this InputMethod | |
52 // instance. | |
53 virtual void OnFocusOut() = 0; | |
Peng
2011/03/30 18:41:35
I think it leaks some functions for tracing focus
James Su
2011/03/30 19:44:22
TextInputClient and View are 1:1 mapping, so they
Peng
2011/03/30 21:32:37
IC. The functions is for tracing view too. I did n
James Su
2011/03/30 21:44:00
That's the purpose of FocusChangeListener provided
Peng
2011/03/30 23:56:33
I think that is not convenient. I don't think it i
James Su
2011/03/31 00:08:08
No. Otherwise why we need FocusChangeListener at a
| |
54 | |
55 // Dispatch a key event to the input method. The key event will be dispatched | |
56 // back to the caller via InputMethodDelegate::DispatchKeyEventPostIME(), once | |
57 // it's processed by the input method. It should only be called by the | |
58 // top-level NativeWidget which owns this InputMethod instance, or other | |
59 // related platform dependent code, such as a message dispatcher. | |
60 virtual void DispatchKeyEvent(const KeyEvent& key) = 0; | |
61 | |
62 // Called by the focused |view| whenever its text input type is changed. | |
63 // Before calling this method, the focused |view| must confirm or clear | |
64 // existing composition text and call InputMethod::CancelComposition() when | |
65 // necessary. Otherwise unexpected behavior may happen. | |
66 virtual void OnTextInputTypeChanged(View* view) = 0; | |
Peng
2011/03/30 18:41:35
You defined TextInputClient in the design. It shou
James Su
2011/03/30 19:44:22
View* is used here intentionally, because we allow
Peng
2011/03/30 21:32:37
It is OK. But this design is weird.
On 2011/03/30
James Su
2011/03/30 21:44:00
It's pretty normal. Think in this way: the InputMe
| |
67 | |
68 // Called by the focused |view| whenever its caret bounds is changed. | |
69 virtual void OnCaretBoundsChanged(View* view) = 0; | |
70 | |
71 // Called by the focused |view| to ask the input method cancel the ongoing | |
72 // composition session. | |
73 virtual void CancelComposition(View* view) = 0; | |
74 | |
75 // Returns the locale of current keyboard layout or input method, as a BCP-47 | |
76 // tag, or an empty string if the input method cannot provide it. | |
77 virtual std::string GetInputLocale() = 0; | |
78 | |
79 // Returns the text direction of current keyboard layout or input method, or | |
80 // base::i18n::UNKNOWN_DIRECTION if the input method cannot provide it. | |
81 virtual base::i18n::TextDirection GetInputTextDirection() = 0; | |
82 | |
83 // Checks if the input method is active, i.e. if it's ready for processing | |
84 // keyboard event and generate composition or text result. | |
85 // If the input method is inactive, then it's not necessary to inform it the | |
86 // changes of caret bounds and text input type. | |
87 // Note: character results may still be generated and sent to the text input | |
88 // client by calling TextInputClient::InsertChar(), even if the input method | |
89 // is not active. | |
90 virtual bool IsActive() = 0; | |
91 | |
92 // Gets the focused text input client. Returns NULL if the Widget is not | |
93 // focused, or there is no focused View or the focused View doesn't support | |
94 // text input. | |
95 virtual TextInputClient* GetTextInputClient() const = 0; | |
96 | |
97 // Gets the text input type of the focused text input client. Returns | |
98 // ui::TEXT_INPUT_TYPE_NONE if there is no focused text input client. | |
99 virtual ui::TextInputType GetTextInputType() const = 0; | |
100 | |
101 // TODO(suzhe): Support mouse/touch event. | |
102 }; | |
103 | |
104 } // namespace views | |
105 | |
106 #endif // VIEWS_IME_INPUT_METHOD_H_ | |
OLD | NEW |