/
input_method_private.clj
457 lines (346 loc) · 20 KB
/
input_method_private.clj
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
(ns chromex.app.input-method-private
" * available since Chrome 30"
(:refer-clojure :only [defmacro defn apply declare meta let partial])
(:require [chromex.wrapgen :refer [gen-wrap-helper]]
[chromex.callgen :refer [gen-call-helper gen-tap-all-events-call]]))
(declare api-table)
(declare gen-call)
; -- functions --------------------------------------------------------------------------------------------------------------
(defmacro get-input-method-config
"Gets configurations for input methods.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [config] where:
|config| - The input method config object.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([] (gen-call :function ::get-input-method-config &form)))
(defmacro get-input-methods
"Gets all whitelisted input methods.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [input-methods] where:
|input-methods| - Whitelisted input method objects.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([] (gen-call :function ::get-input-methods &form)))
(defmacro get-current-input-method
"Gets the current input method.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [input-method-id] where:
|input-method-id| - Current input method.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([] (gen-call :function ::get-current-input-method &form)))
(defmacro set-current-input-method
"Sets the current input method.
|input-method-id| - The input method ID to be set as current input method.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([input-method-id] (gen-call :function ::set-current-input-method &form input-method-id)))
(defmacro fetch-all-dictionary-words
"Fetches a list of all the words currently in the dictionary.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [words] where:
|words| - List of dictionary words.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([] (gen-call :function ::fetch-all-dictionary-words &form)))
(defmacro add-word-to-dictionary
"Adds a single word to be stored in the dictionary.
|word| - A new word to add to the dictionary.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([word] (gen-call :function ::add-word-to-dictionary &form word)))
(defmacro get-encrypt-sync-enabled
"Gets whether the encrypt sync is enabled.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [enabled] where:
|enabled| - The result of whether enabled.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([] (gen-call :function ::get-encrypt-sync-enabled &form)))
(defmacro set-xkb-layout
"Sets the XKB layout for the given input method.
|xkb-name| - The XKB layout name.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([xkb-name] (gen-call :function ::set-xkb-layout &form xkb-name)))
(defmacro notify-ime-menu-item-activated
"Fires the input.ime.onMenuItemActivated event.
|engine-id| - ID of the engine to use.
|name| - Name of the MenuItem which was activated"
([engine-id name] (gen-call :function ::notify-ime-menu-item-activated &form engine-id name)))
(defmacro show-input-view
"Shows the input view window. If the input view window is already shown, this function will do nothing.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([] (gen-call :function ::show-input-view &form)))
(defmacro open-options-page
"Opens the options page for the input method extension. If the input method does not have options, this function will do
nothing.
|input-method-id| - ID of the input method to open options for."
([input-method-id] (gen-call :function ::open-options-page &form input-method-id)))
(defmacro get-composition-bounds
"Gets the composition bounds
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [bounds-list] where:
|bounds-list| - List of bounds information.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([] (gen-call :function ::get-composition-bounds &form)))
(defmacro get-surrounding-text
"Gets the surrounding text of the current selection
|before-length| - The number of characters before the current selection.
|after-length| - The number of characters after the current selection.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [surrounding-info] where:
|surrounding-info| - The surrouding text info.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([before-length after-length] (gen-call :function ::get-surrounding-text &form before-length after-length)))
(defmacro get-setting
"Gets the current value of a setting for a particular input method
|engine-id| - The ID of the engine (e.g. 'zh-t-i0-pinyin', 'xkb:us::eng')
|key| - The setting to get
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [setting] where:
|setting| - The value for the requested setting, or null if there's no value
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([engine-id key] (gen-call :function ::get-setting &form engine-id key)))
(defmacro set-setting
"Sets the value of a setting for a particular input method
|engine-id| - The ID of the engine (e.g. 'zh-t-i0-pinyin', 'xkb:us::eng')
|key| - The setting to set
|value| - The new value of the setting
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([engine-id key value] (gen-call :function ::set-setting &form engine-id key value)))
(defmacro set-composition-range
"Set the composition range. If this extension does not own the active IME, this fails.
|parameters| - ?
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [success] where:
|success| - ?
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([parameters] (gen-call :function ::set-composition-range &form parameters)))
; -- events -----------------------------------------------------------------------------------------------------------------
;
; docs: https://github.com/binaryage/chromex/#tapping-events
(defmacro tap-on-changed-events
"Fired when the input method is changed.
Events will be put on the |channel| with signature [::on-changed [new-input-method-id]] where:
|new-input-method-id| - New input method which is being used.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-changed &form channel args)))
(defmacro tap-on-composition-bounds-changed-events
"Fired when the composition bounds or cursor bounds are changed.
Events will be put on the |channel| with signature [::on-composition-bounds-changed [first-bounds bounds-list]] where:
|first-bounds| - The bounds information for the first character in composition.
|bounds-list| - List of bounds information.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-composition-bounds-changed &form channel args)))
(defmacro tap-on-dictionary-loaded-events
"Fired when the custom spelling dictionary is loaded.
Events will be put on the |channel| with signature [::on-dictionary-loaded []].
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-dictionary-loaded &form channel args)))
(defmacro tap-on-dictionary-changed-events
"Fired when words are added or removed from the custom spelling dictionary.
Events will be put on the |channel| with signature [::on-dictionary-changed [added removed]] where:
|added| - List of added words.
|removed| - List of removed words.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-dictionary-changed &form channel args)))
(defmacro tap-on-ime-menu-activation-changed-events
"Fired when the IME menu is activated or deactivated.
Events will be put on the |channel| with signature [::on-ime-menu-activation-changed [activation]] where:
|activation| - Whether the IME menu is currently active.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-ime-menu-activation-changed &form channel args)))
(defmacro tap-on-ime-menu-list-changed-events
"Fired when the input method or the list of active input method IDs is changed.
Events will be put on the |channel| with signature [::on-ime-menu-list-changed []].
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-ime-menu-list-changed &form channel args)))
(defmacro tap-on-ime-menu-items-changed-events
"Fired when the input.ime.setMenuItems or input.ime.updateMenuItems API is called.
Events will be put on the |channel| with signature [::on-ime-menu-items-changed [engine-id items]] where:
|engine-id| - ID of the engine to use
|items| - MenuItems to add or update.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-ime-menu-items-changed &form channel args)))
(defmacro tap-on-focus-events
"This event is sent when focus enters a text box. It is sent to all extensions that are listening to this event, and enabled
by the user.
Events will be put on the |channel| with signature [::on-focus [context]] where:
|context| - Describes the text field that has acquired focus.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-focus &form channel args)))
(defmacro tap-on-settings-changed-events
"This event is sent when the settings for any input method changed. It is sent to all extensions that are listening to this
event, and enabled by the user.
Events will be put on the |channel| with signature [::on-settings-changed [engine-id key value]] where:
|engine-id| - ID of the engine that changed
|key| - The setting that changed
|value| - The new value of the setting
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-settings-changed &form channel args)))
(defmacro tap-on-screen-projection-changed-events
"This event is sent when the screen is being mirrored or the desktop is being cast.
Events will be put on the |channel| with signature [::on-screen-projection-changed [is-projected]] where:
|is-projected| - Whether the screen is projected.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-screen-projection-changed &form channel args)))
; -- convenience ------------------------------------------------------------------------------------------------------------
(defmacro tap-all-events
"Taps all valid non-deprecated events in chromex.app.input-method-private namespace."
[chan]
(gen-tap-all-events-call api-table (meta &form) chan))
; ---------------------------------------------------------------------------------------------------------------------------
; -- API TABLE --------------------------------------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------------------------------------------------
(def api-table
{:namespace "chrome.inputMethodPrivate",
:since "30",
:functions
[{:id ::get-input-method-config,
:name "getInputMethodConfig",
:since "40",
:callback? true,
:params [{:name "callback", :type :callback, :callback {:params [{:name "config", :type "object"}]}}]}
{:id ::get-input-methods,
:name "getInputMethods",
:since "37",
:callback? true,
:params
[{:name "callback", :type :callback, :callback {:params [{:name "input-methods", :type "[array-of-objects]"}]}}]}
{:id ::get-current-input-method,
:name "getCurrentInputMethod",
:since "37",
:callback? true,
:params [{:name "callback", :type :callback, :callback {:params [{:name "input-method-id", :type "string"}]}}]}
{:id ::set-current-input-method,
:name "setCurrentInputMethod",
:since "37",
:callback? true,
:params [{:name "input-method-id", :type "string"} {:name "callback", :optional? true, :type :callback}]}
{:id ::fetch-all-dictionary-words,
:name "fetchAllDictionaryWords",
:since "43",
:callback? true,
:params [{:name "callback", :type :callback, :callback {:params [{:name "words", :type "[array-of-strings]"}]}}]}
{:id ::add-word-to-dictionary,
:name "addWordToDictionary",
:since "43",
:callback? true,
:params [{:name "word", :type "string"} {:name "callback", :optional? true, :type :callback}]}
{:id ::get-encrypt-sync-enabled,
:name "getEncryptSyncEnabled",
:since "45",
:callback? true,
:params
[{:name "callback", :optional? true, :type :callback, :callback {:params [{:name "enabled", :type "boolean"}]}}]}
{:id ::set-xkb-layout,
:name "setXkbLayout",
:since "49",
:callback? true,
:params [{:name "xkb-name", :type "string"} {:name "callback", :optional? true, :type :callback}]}
{:id ::notify-ime-menu-item-activated,
:name "notifyImeMenuItemActivated",
:since "51",
:params [{:name "engine-id", :type "string"} {:name "name", :type "string"}]}
{:id ::show-input-view,
:name "showInputView",
:since "51",
:callback? true,
:params [{:name "callback", :optional? true, :type :callback}]}
{:id ::open-options-page, :name "openOptionsPage", :since "52", :params [{:name "input-method-id", :type "string"}]}
{:id ::get-composition-bounds,
:name "getCompositionBounds",
:since "68",
:callback? true,
:params
[{:name "callback", :type :callback, :callback {:params [{:name "bounds-list", :type "[array-of-objects]"}]}}]}
{:id ::get-surrounding-text,
:name "getSurroundingText",
:since "69",
:callback? true,
:params
[{:name "before-length", :type "integer"}
{:name "after-length", :type "integer"}
{:name "callback", :type :callback, :callback {:params [{:name "surrounding-info", :type "object"}]}}]}
{:id ::get-setting,
:name "getSetting",
:since "72",
:callback? true,
:params
[{:name "engine-id", :type "string"}
{:name "key", :type "string"}
{:name "callback", :type :callback, :callback {:params [{:name "setting", :optional? true, :type "any"}]}}]}
{:id ::set-setting,
:name "setSetting",
:since "72",
:callback? true,
:params
[{:name "engine-id", :type "string"}
{:name "key", :type "string"}
{:name "value", :type "any"}
{:name "callback", :optional? true, :type :callback}]}
{:id ::set-composition-range,
:name "setCompositionRange",
:since "future",
:callback? true,
:params
[{:name "parameters", :type "object"}
{:name "callback",
:optional? true,
:type :callback,
:callback {:params [{:name "success", :type "boolean"}]}}]}],
:events
[{:id ::on-changed, :name "onChanged", :params [{:name "new-input-method-id", :type "string"}]}
{:id ::on-composition-bounds-changed,
:name "onCompositionBoundsChanged",
:since "40",
:params
[{:name "first-bounds", :since "45", :type "object"}
{:name "bounds-list", :since "45", :type "[array-of-objects]"}]}
{:id ::on-dictionary-loaded, :name "onDictionaryLoaded", :since "43"}
{:id ::on-dictionary-changed,
:name "onDictionaryChanged",
:since "43",
:params [{:name "added", :type "[array-of-strings]"} {:name "removed", :type "[array-of-strings]"}]}
{:id ::on-ime-menu-activation-changed,
:name "onImeMenuActivationChanged",
:since "50",
:params [{:name "activation", :type "boolean"}]}
{:id ::on-ime-menu-list-changed, :name "onImeMenuListChanged", :since "50"}
{:id ::on-ime-menu-items-changed,
:name "onImeMenuItemsChanged",
:since "51",
:params [{:name "engine-id", :type "string"} {:name "items", :type "[array-of-inputMethodPrivate.MenuItems]"}]}
{:id ::on-focus, :name "onFocus", :since "68", :params [{:name "context", :type "inputMethodPrivate.InputContext"}]}
{:id ::on-settings-changed,
:name "onSettingsChanged",
:since "73",
:params [{:name "engine-id", :type "string"} {:name "key", :type "string"} {:name "value", :type "any"}]}
{:id ::on-screen-projection-changed,
:name "onScreenProjectionChanged",
:since "73",
:params [{:name "is-projected", :type "boolean"}]}]})
; -- helpers ----------------------------------------------------------------------------------------------------------------
; code generation for native API wrapper
(defmacro gen-wrap [kind item-id config & args]
(apply gen-wrap-helper api-table kind item-id config args))
; code generation for API call-site
(def gen-call (partial gen-call-helper api-table))