Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / google_input_tools / src / chrome / os / inputview / hwt_util.js
1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
2 // limitations under the License.
3 // See the License for the specific language governing permissions and
4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5 // distributed under the License is distributed on an "AS-IS" BASIS,
6 // Unless required by applicable law or agreed to in writing, software
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // You may obtain a copy of the License at
11 // you may not use this file except in compliance with the License.
12 // Licensed under the Apache License, Version 2.0 (the "License");
13 //
14
15 /**
16  * @fileoverview Defines the class i18n.input.hwt.util.
17  * @author fengyuan@google.com (Feng Yuan)
18  */
19
20 goog.provide('i18n.input.hwt.util');
21
22
23 goog.require('goog.array');
24 goog.require('goog.events.EventType');
25 goog.require('i18n.input.common.dom');
26
27
28 /**
29  * Listens MOUSEUP on page scope.
30  *
31  * @param {goog.events.EventHandler} eventHandler The event handler.
32  * @param {Document} topDocument The top document.
33  * @param {goog.events.EventType | !Array.<goog.events.EventType>} eventType
34  *     The event type to listen.
35  * @param {Function} callback The callback method.
36  */
37 i18n.input.hwt.util.listenPageEvent = function(eventHandler, topDocument,
38     eventType, callback) {
39   // Ideally we'd just listen for MOUSEUP on the canvas, but that
40   // doesn't work if the mouseup event happens outside the canvas,
41   // and in particular if it happens in an iframe.  So we have to
42   // listen on the document and any embedded iframes.  We'll also
43   // use this handler to cancel auto-repeat when holding down
44   // the backspace button, in case the user releases the button
45   // elsewhere.
46   eventHandler.listen(topDocument, goog.events.EventType.MOUSEUP,
47       callback, true);
48   goog.array.forEach(i18n.input.common.dom.getSameDomainDocuments(topDocument),
49       function(frameDoc) {
50         try {
51           // In IE and FF3.5, some iframe is not allowed to access.
52           // It throws exception when access the iframe property.
53           eventHandler.listen(frameDoc, goog.events.EventType.MOUSEUP,
54               callback, true);
55         } catch (e) {}
56       });
57 };
58
59
60 /**
61  * The default candidate map of handwriting pad.
62  * Key: language code.
63  * Value: candidate list.
64  *
65  * @type {!Object.<string, !Array.<string>>}
66  */
67 i18n.input.hwt.util.DEFAULT_CANDIDATE_MAP = {
68   '': [',', '.', '?', '!', ':', '\'', '"', ';', '@'],
69   'es': [',', '.', '¿', '?', '¡', '!', ':', '\'', '"'],
70   'ja': [',', '。', '?', '!', ':', '「', '」', ';'],
71   'zh-Hans': [',', '。', '?', '!', ':', '“', '”', ';'],
72   'zh-Hant': [',', '。', '?', '!', ':', '「', '」', ';']
73 };
74