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 CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_ENGINE_CONTROLLER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_ENGINE_CONTROLLER_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 namespace chromeos { | |
14 namespace input_method { | |
15 | |
16 struct KeyEventHandle; | |
17 | |
18 // IBusEngineController is used to encapsulate an ibus engine. | |
19 class IBusEngineController { | |
20 public: | |
21 class Observer { | |
22 public: | |
23 // Called when a key is pressed or released. | |
24 virtual void OnKeyEvent(bool key_press, unsigned int keyval, | |
25 unsigned int keycode, bool alt_key, | |
26 bool ctrl_key, bool shift_key, | |
27 KeyEventHandle* key_data) = 0; | |
28 | |
29 // Called when the engine should reset its internal state. | |
30 virtual void OnReset() = 0; | |
31 | |
32 // Called when the engine become the current engine. | |
33 virtual void OnEnable() = 0; | |
34 | |
35 // Called when the engine is being disabled. | |
36 virtual void OnDisable() = 0; | |
37 | |
38 // Called when a text field is focused. | |
39 virtual void OnFocusIn() = 0; | |
40 | |
41 // Called when focus leaves a text field. | |
42 virtual void OnFocusOut() = 0; | |
43 | |
44 // Called when one of the engine's menus is interacted with. | |
45 virtual void OnPropertyActivate(const char *prop_name, | |
46 unsigned int prop_state) = 0; | |
47 | |
48 // Called when a candidate in the candidate window is clicked on. | |
49 virtual void OnCandidateClicked(unsigned int index, unsigned int button, | |
50 unsigned int state) = 0; | |
51 }; | |
52 | |
53 struct Candidate { | |
54 std::string value; | |
55 std::string label; | |
56 std::string annotation; | |
57 }; | |
58 | |
59 enum { | |
60 PROPERTY_MODIFIED_LABEL = 0x0001, | |
61 PROPERTY_MODIFIED_TOOLTIP = 0x0002, | |
62 PROPERTY_MODIFIED_SENSITIVE = 0x0004, | |
63 PROPERTY_MODIFIED_VISIBLE = 0x0008, | |
64 PROPERTY_MODIFIED_TYPE = 0x0010, | |
65 PROPERTY_MODIFIED_CHECKED = 0x0020, | |
66 }; | |
67 | |
68 struct EngineProperty { | |
69 EngineProperty(); | |
70 virtual ~EngineProperty(); | |
71 | |
72 std::string key; | |
73 std::string label; | |
74 std::string tooltip; | |
75 bool sensitive; | |
76 bool visible; | |
77 int type; | |
78 bool checked; | |
79 | |
80 unsigned int modified; | |
81 std::vector<EngineProperty*> children; | |
82 }; | |
83 | |
84 // Constants for the button parameter of OnCandidateClicked | |
85 enum { | |
86 MOUSE_BUTTON_1_MASK = 0x01, | |
87 MOUSE_BUTTON_2_MASK = 0x02, | |
88 MOUSE_BUTTON_3_MASK = 0x04, | |
89 }; | |
90 | |
91 // Constants for the type argument of SetPreeditUnderline | |
92 enum { | |
93 UNDERLINE_NONE, | |
94 UNDERLINE_SINGLE, | |
95 UNDERLINE_DOUBLE, | |
96 UNDERLINE_LOW, | |
97 UNDERLINE_ERROR | |
98 }; | |
99 | |
100 // Constants for RegisterProperties and UpdateProperties | |
101 enum { | |
102 PROPERTY_TYPE_NORMAL, | |
103 PROPERTY_TYPE_TOGGLE, | |
104 PROPERTY_TYPE_RADIO, | |
105 PROPERTY_TYPE_SEPARATOR, | |
106 PROPERTY_TYPE_MENU | |
107 }; | |
108 | |
109 static IBusEngineController* Create(Observer* observer, | |
110 const char* engine_id, | |
111 const char* engine_name, | |
112 const char* description, | |
113 const char* language, | |
114 const char* layout); | |
115 | |
116 virtual ~IBusEngineController(); | |
117 | |
118 // Set the preedit text. | |
119 virtual void SetPreeditText(const char* text, int cursor) = 0; | |
120 | |
121 // Adds an underline to the preedit text. Can be called multiple times. | |
122 virtual void SetPreeditUnderline(int start, int end, int type) = 0; | |
123 | |
124 // Commit the provided text to the current input box. | |
125 virtual void CommitText(const char* text) = 0; | |
126 | |
127 // Show or hide the candidate window. | |
128 virtual void SetTableVisible(bool visible) = 0; | |
129 | |
130 // Show or hide the cursor in the candidate window. | |
131 virtual void SetCursorVisible(bool visible) = 0; | |
132 | |
133 // Change the orientation of the candidate window. | |
134 virtual void SetOrientationVertical(bool vertical) = 0; | |
135 | |
136 // Set the number of candidates displayed in the candidate window. | |
137 virtual void SetPageSize(unsigned int size) = 0; | |
138 | |
139 // Remove all candidates. | |
140 virtual void ClearCandidates() = 0; | |
141 | |
142 // Set the list of candidates in the candidate window. | |
143 virtual void SetCandidates(std::vector<Candidate> candidates) = 0; | |
144 | |
145 // Set the text displayed at the bottom of the candidate window. | |
146 virtual void SetCandidateAuxText(const char* text) = 0; | |
147 | |
148 // Show or hide the text at the bottom of the candidate window. | |
149 virtual void SetCandidateAuxTextVisible(bool visible) = 0; | |
150 | |
151 // Set the posistion of the cursor in the candidate window. | |
152 virtual void SetCursorPosition(unsigned int position) = 0; | |
153 | |
154 // Set the properties that ibus will display in the language bar. | |
155 virtual bool RegisterProperties( | |
156 const std::vector<EngineProperty*>& properties) = 0; | |
157 | |
158 // Update the attributes of the listed properties. | |
159 virtual bool UpdateProperties( | |
160 const std::vector<EngineProperty*>& properties) = 0; | |
161 | |
162 // Inform the engine that a key event has been processed. | |
163 virtual void KeyEventDone(KeyEventHandle* key_data, bool handled) = 0; | |
164 }; | |
165 | |
166 } // namespace input_method | |
167 } // namespace chromeos | |
168 | |
169 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_ENGINE_CONTROLLER_H_ | |
OLD | NEW |