1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
Index: engine_interface.h
===================================================================
--- unix/ibus/engine_interface.h (revision 177)
+++ unix/ibus/engine_interface.h (working copy)
@@ -106,6 +106,11 @@
gint y,
gint w,
gint h) = 0;
+
+ // The interface function for the "set-content-type" signal
+ virtual void SetContentType(IBusEngine *engine,
+ guint purpose,
+ guint hints) = 0;
};
} // namespace ibus
Index: engine_registrar.cc
===================================================================
--- unix/ibus/engine_registrar.cc (revision 177)
+++ unix/ibus/engine_registrar.cc (working copy)
@@ -63,7 +63,9 @@
engine_class->reset = Reset;
engine_class->set_capabilities = SetCapabilities;
engine_class->set_cursor_location = SetCursorLocation;
-
+#if defined(MOZC_ENABLE_IBUS_INPUT_PURPOSE)
+ engine_class->set_content_type = SetContentType;
+#endif // MOZC_ENABLE_IBUS_INPUT_PURPOSE
return true;
}
@@ -87,6 +89,9 @@
engine_class->reset = NULL;
engine_class->set_capabilities = NULL;
engine_class->set_cursor_location = NULL;
+#if defined(MOZC_ENABLE_IBUS_INPUT_PURPOSE)
+ engine_class->set_content_type = NULL;
+#endif // MOZC_ENABLE_IBUS_INPUT_PURPOSE
mozc::ibus::EngineInterface *previous = g_engine;
g_engine = NULL;
@@ -179,5 +184,12 @@
g_engine->SetCursorLocation(engine, x, y, w, h);
}
+void EngineRegistrar::SetContentType(
+ IBusEngine *engine,
+ guint purpose,
+ guint hints) {
+ g_engine->SetContentType(engine, purpose, hints);
+}
+
} // namespace ibus
} // namespace mozc
Index: engine_registrar.h
===================================================================
--- unix/ibus/engine_registrar.h (revision 177)
+++ unix/ibus/engine_registrar.h (working copy)
@@ -84,6 +84,9 @@
gint y,
gint w,
gint h);
+ static void SetContentType(IBusEngine *engine,
+ guint purpose,
+ guint hints);
};
} // namespace ibus
Index: ibus_header.h
===================================================================
--- unix/ibus/ibus_header.h (revision 177)
+++ unix/ibus/ibus_header.h (working copy)
@@ -36,5 +36,10 @@
#error "ibus-mozc now requires IBus>=1.4.1"
#endif // libibus (<1.4.1)
+#if IBUS_CHECK_VERSION(1, 5, 4)
+#if !defined(MOZC_ENABLE_IBUS_INPUT_PURPOSE)
+#define MOZC_ENABLE_IBUS_INPUT_PURPOSE
+#endif // !MOZC_ENABLE_IBUS_INPUT_PURPOSE
+#endif // libibus(>=1.5.4)
#endif // MOZC_UNIX_IBUS_IBUS_HEADER_H_
Index: mozc_engine.cc
===================================================================
--- unix/ibus/mozc_engine.cc (revision 177)
+++ unix/ibus/mozc_engine.cc (working copy)
@@ -372,6 +372,7 @@
void MozcEngine::FocusOut(IBusEngine *engine) {
GetCandidateWindowHandler(engine)->Hide(engine);
+ property_handler_->ResetContentType(engine);
// Do not call SubmitSession or RevertSession. Preedit string will commit on
// Focus Out event automatically by ibus_engine_update_preedit_text_with_mode
@@ -397,6 +398,11 @@
VLOG(2) << "keyval: " << keyval
<< ", keycode: " << keycode
<< ", modifiers: " << modifiers;
+ if (property_handler_->IsDisabled()) {
+ // It is each enginze's responsibility for ignoreing keyevents on
+ // the password field on the locked screen since IBus 1.5.4.
+ return FALSE;
+ }
// Send current caret location to mozc_server to manage suggest window
// position.
@@ -501,6 +507,18 @@
// Do nothing
}
+void MozcEngine::SetContentType(IBusEngine *engine,
+ guint purpose,
+ guint hints) {
+ const bool prev_disabled =
+ property_handler_->IsDisabled();
+ property_handler_->UpdateContentType(engine);
+ if (!prev_disabled && property_handler_->IsDisabled()) {
+ // Make sure on-going composition is reverted.
+ RevertSession(engine);
+ }
+}
+
GType MozcEngine::GetType() {
static GType type = 0;
Index: mozc_engine.h
===================================================================
--- unix/ibus/mozc_engine.h (revision 177)
+++ unix/ibus/mozc_engine.h (working copy)
@@ -99,6 +99,9 @@
gint y,
gint w,
gint h);
+ void SetContentType(IBusEngine *engine,
+ guint purpose,
+ guint hints);
// Returns the GType which this class represents.
static GType GetType();
Index: property_handler.cc
===================================================================
--- unix/ibus/property_handler.cc (revision 177)
+++ unix/ibus/property_handler.cc (working copy)
@@ -61,6 +61,19 @@
bool IsMozcToolAvailable() {
return FileUtil::FileExists(SystemUtil::GetToolPath());
}
+
+bool GetDisabled(IBusEngine *engine) {
+ bool disabled = false;
+#if defined(MOZC_ENABLE_IBUS_INPUT_PURPOSE)
+ guint purpose = IBUS_INPUT_PURPOSE_FREE_FORM;
+ guint hints = IBUS_INPUT_HINT_NONE;
+ ibus_engine_get_content_type(engine, &purpose, &hints);
+ disabled = (purpose == IBUS_INPUT_PURPOSE_PASSWORD ||
+ purpose == IBUS_INPUT_PURPOSE_PIN);
+#endif // MOZC_ENABLE_IBUS_INPUT_PURPOSE
+ return disabled;
+}
+
} // namespace
PropertyHandler::PropertyHandler(MessageTranslatorInterface *translator,
@@ -71,7 +84,8 @@
client_(client),
translator_(translator),
original_composition_mode_(kMozcEngineInitialCompositionMode),
- is_activated_(true) {
+ is_activated_(true),
+ is_disabled_(false) {
AppendCompositionPropertyToPanel();
#ifndef OS_CHROMEOS
@@ -105,6 +119,7 @@
void PropertyHandler::Register(IBusEngine *engine) {
ibus_engine_register_properties(engine, prop_root_);
+ UpdateContentType(engine);
}
// TODO(nona): do not use kMozcEngine*** directory.
@@ -228,8 +243,34 @@
ibus_prop_list_append(prop_root_, prop_mozc_tool_);
}
+void PropertyHandler::UpdateContentTypeImpl(IBusEngine *engine,
+ bool disabled) {
+ const bool prev_is_disabled = is_disabled_;
+ is_disabled_ = disabled;
+ if (prev_is_disabled == is_disabled_) {
+ return;
+ }
+ const commands::CompositionMode visible_mode =
+ (prev_is_disabled && !is_disabled_ && IsActivated())
+ ? original_composition_mode_ :
+ kMozcEnginePropertyIMEOffState->composition_mode;
+ UpdateCompositionModeIcon(engine, visible_mode);
+}
+
+void PropertyHandler::ResetContentType(IBusEngine *engine) {
+ UpdateContentTypeImpl(engine, false);
+}
+
+void PropertyHandler::UpdateContentType(IBusEngine *engine) {
+ UpdateContentTypeImpl(engine, GetDisabled(engine));
+}
+
void PropertyHandler::Update(IBusEngine *engine,
const commands::Output &output) {
+ if (IsDisabled()) {
+ return;
+ }
+
if (output.has_status() &&
(output.status().activated() != is_activated_ ||
output.status().mode() != original_composition_mode_)) {
@@ -325,6 +366,10 @@
const gchar *property_name,
guint property_state) {
#ifndef OS_CHROMEOS
+ if (IsDisabled()) {
+ return;
+ }
+
if (prop_mozc_tool_) {
for (guint prop_index = 0; ; ++prop_index) {
IBusProperty *prop = ibus_prop_list_get(
@@ -371,9 +416,13 @@
}
bool PropertyHandler::IsActivated() const {
- return is_activated_;
+ return is_activated_ && !IsDisabled();
}
+bool PropertyHandler::IsDisabled() const {
+ return is_disabled_;
+}
+
commands::CompositionMode PropertyHandler::GetOriginalCompositionMode() const {
return original_composition_mode_;
}
Index: property_handler.h
===================================================================
--- unix/ibus/property_handler.h (revision 177)
+++ unix/ibus/property_handler.h (working copy)
@@ -54,14 +54,19 @@
virtual ~PropertyHandler();
virtual void Register(IBusEngine *engine);
+ virtual void ResetContentType(IBusEngine *engine);
+ virtual void UpdateContentType(IBusEngine *engine);
virtual void Update(IBusEngine *engine, const commands::Output &output);
virtual void ProcessPropertyActivate(IBusEngine *engine,
const gchar *property_name,
guint property_state);
virtual bool IsActivated() const;
+ virtual bool IsDisabled() const;
virtual commands::CompositionMode GetOriginalCompositionMode() const;
private:
+ void UpdateContentTypeImpl(IBusEngine *engine, bool disabled);
+
// Appends composition properties into panel
void AppendCompositionPropertyToPanel();
// Appends tool properties into panel
@@ -79,6 +84,7 @@
scoped_ptr<MessageTranslatorInterface> translator_;
commands::CompositionMode original_composition_mode_;
bool is_activated_;
+ bool is_disabled_;
};
} // namespace ibus
Index: property_handler_interface.h
===================================================================
--- unix/ibus/property_handler_interface.h (revision 177)
+++ unix/ibus/property_handler_interface.h (working copy)
@@ -45,6 +45,9 @@
// Registers current properties into engine.
virtual void Register(IBusEngine *engine) ABSTRACT;
+ virtual void ResetContentType(IBusEngine *engine) ABSTRACT;
+ virtual void UpdateContentType(IBusEngine *engine) ABSTRACT;
+
// Update properties.
virtual void Update(IBusEngine *engine,
const commands::Output &output) ABSTRACT;
@@ -55,6 +58,9 @@
// Returns if IME is activated or not.
virtual bool IsActivated() const ABSTRACT;
+ // Returns if IME is forcesully disabled, e.g. on a password field.
+ virtual bool IsDisabled() const ABSTRACT;
+
// Returns original composition mode before.
virtual commands::CompositionMode GetOriginalCompositionMode() const ABSTRACT;
};
|