summaryrefslogtreecommitdiffstats
path: root/third_party/google_input_tools/src/chrome/os/message/type.js
blob: 6e279401b3083b4a208742bd1a25eee704cba9da (plain)
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
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.message');
goog.provide('i18n.input.chrome.message.Type');

goog.require('i18n.input.chrome.message.Source');


goog.scope(function() {
var Source = i18n.input.chrome.message.Source;


/**
 * The message type. "Background->Inputview" don't allow to share the same
 * message type with "Inputview->Background".
 *
 * @enum {string}
 */
i18n.input.chrome.message.Type = {
  // Background -> Inputview
  CANDIDATES_BACK: 'candidates_back',
  CONTEXT_BLUR: 'context_blur',
  CONTEXT_FOCUS: 'context_focus',
  FRONT_TOGGLE_LANGUAGE_STATE: 'front_toggle_language_state',
  HWT_NETWORK_ERROR: 'hwt_network_error',
  SURROUNDING_TEXT_CHANGED: 'surrounding_text_changed',
  UPDATE_SETTINGS: 'update_settings',
  VOICE_STATE_CHANGE: 'voice_state_change',

  // Inputview -> Background
  COMMIT_TEXT: 'commit_text',
  COMPLETION: 'completion',
  CONNECT: 'connect',
  DATASOURCE_READY: 'datasource_ready',
  DISCONNECT: 'disconnect',
  DOUBLE_CLICK_ON_SPACE_KEY: 'double_click_on_space_key',
  EXEC_ALL: 'exec_all',
  HWT_REQUEST: 'hwt_request',
  KEY_CLICK: 'key_click',
  KEY_EVENT: 'key_event',
  OPTION_CHANGE: 'option_change',
  PREDICTION: 'prediction',
  SELECT_CANDIDATE: 'select_candidate',
  SEND_KEY_EVENT: 'send_key_event',
  SET_COMPOSITION: 'set_composition',
  SET_LANGUAGE: 'set_language',
  SWITCH_KEYSET: 'switch_keyset',
  TOGGLE_LANGUAGE_STATE: 'toggle_language_state',
  VISIBILITY_CHANGE: 'visibility_change',
  SET_CONTROLLER: 'set_controller',
  UNSET_CONTROLLER: 'unset_controller',
  VOICE_VIEW_STATE_CHANGE: 'voice_view_state_change',


  // Inputview -> Elements
  HWT_PRIVACY_GOT_IT: 'hwt_privacy_got_it',
  VOICE_PRIVACY_GOT_IT: 'voice_privacy_got_it',

  // Options -> Background
  USER_DICT_ADD_ENTRY: 'user_dict_add_entry',
  USER_DICT_CLEAR: 'user_dict_clear',
  USER_DICT_LIST: 'user_dict_list',
  USER_DICT_SET_THRESHOLD: 'user_dict_set_threshold',
  USER_DICT_START: 'user_dict_start',
  USER_DICT_STOP: 'user_dict_stop',
  USER_DICT_REMOVE_ENTRY: 'user_dict_remove_entry',

  // Background -> Options
  USER_DICT_ENTRIES: 'user_dict_entries',

  // Background->Background
  HEARTBEAT: 'heart_beat'
};
var Type = i18n.input.chrome.message.Type;


/**
 * Returns whether the message type belong to "Background->Inputview" group;
 *
 * @param {string} type The message type.
 * @return {boolean} .
 */
i18n.input.chrome.message.isFromBackground = function(type) {
  var source = i18n.input.chrome.message.getMessageSource(type);
  return source == Source.BG_BG || source == Source.BG_OP ||
      source == Source.BG_VK;
};


/**
 * Returns whether the message type belong to "Background->Inputview" group;
 *
 * @param {string} type The message type.
 * @return {i18n.input.chrome.message.Source} The source.
 */
i18n.input.chrome.message.getMessageSource = function(type) {
  switch (type) {
    // Background -> Inputview
    case Type.CANDIDATES_BACK:
    case Type.CONTEXT_BLUR:
    case Type.CONTEXT_FOCUS:
    case Type.FRONT_TOGGLE_LANGUAGE_STATE:
    case Type.HWT_NETWORK_ERROR:
    case Type.SURROUNDING_TEXT_CHANGED:
    case Type.UPDATE_SETTINGS:
    case Type.VOICE_STATE_CHANGE:
      return Source.BG_VK;

    // Inputview -> Background
    case Type.COMMIT_TEXT:
    case Type.COMPLETION:
    case Type.CONNECT:
    case Type.DATASOURCE_READY:
    case Type.DISCONNECT:
    case Type.DOUBLE_CLICK_ON_SPACE_KEY:
    case Type.EXEC_ALL:
    case Type.HWT_REQUEST:
    case Type.KEY_CLICK:
    case Type.KEY_EVENT:
    case Type.OPTION_CHANGE:
    case Type.PREDICTION:
    case Type.SELECT_CANDIDATE:
    case Type.SEND_KEY_EVENT:
    case Type.SET_COMPOSITION:
    case Type.SET_LANGUAGE:
    case Type.SWITCH_KEYSET:
    case Type.TOGGLE_LANGUAGE_STATE:
    case Type.VISIBILITY_CHANGE:
    case Type.SET_CONTROLLER:
    case Type.UNSET_CONTROLLER:
    case Type.VOICE_VIEW_STATE_CHANGE:
      return Source.VK_BG;

    // Inputview -> Elements
    case Type.HWT_PRIVACY_GOT_IT:
    case Type.VOICE_PRIVACY_GOT_IT:
      return Source.VK_VK;

    // Options -> Background
    case Type.USER_DICT_ADD_ENTRY:
    case Type.USER_DICT_CLEAR:
    case Type.USER_DICT_LIST:
    case Type.USER_DICT_SET_THRESHOLD:
    case Type.USER_DICT_START:
    case Type.USER_DICT_STOP:
    case Type.USER_DICT_REMOVE_ENTRY:
      return Source.OP_BG;

    // Background -> Options
    case Type.USER_DICT_ENTRIES:
      return Source.BG_OP;

    // Background->Background
    case Type.HEARTBEAT:
      return Source.BG_BG;
    default:
      return Source.UNKNOWN;
  }
};
});  // goog.scope