Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / google_input_tools / src / chrome / os / inputview / elements / content / spacekey.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 goog.provide('i18n.input.chrome.inputview.elements.content.SpaceKey');
15
16 goog.require('goog.dom');
17 goog.require('goog.dom.classlist');
18 goog.require('i18n.input.chrome.inputview.Css');
19 goog.require('i18n.input.chrome.inputview.StateType');
20 goog.require('i18n.input.chrome.inputview.elements.ElementType');
21 goog.require('i18n.input.chrome.inputview.elements.content.FunctionalKey');
22
23
24
25 goog.scope(function() {
26
27
28
29 /**
30  * The space key.
31  *
32  * @param {string} id the id.
33  * @param {!i18n.input.chrome.inputview.StateManager} stateManager The state
34  *     manager.
35  * @param {string} title The keyboard title.
36  * @param {!Array.<string>=} opt_characters The characters.
37  * @param {goog.events.EventTarget=} opt_eventTarget The event target.
38  * @param {string=} opt_iconCss The icon CSS class
39  * @constructor
40  * @extends {i18n.input.chrome.inputview.elements.content.FunctionalKey}
41  */
42 i18n.input.chrome.inputview.elements.content.SpaceKey = function(id,
43     stateManager, title, opt_characters, opt_eventTarget, opt_iconCss) {
44   goog.base(this, id, i18n.input.chrome.inputview.elements.ElementType.
45       SPACE_KEY, opt_iconCss ? '' : title, opt_iconCss || '', opt_eventTarget);
46
47   /**
48    * The characters.
49    *
50    * @type {!Array.<string>}
51    * @private
52    */
53   this.characters_ = opt_characters || [];
54
55   /**
56    * The state manager.
57    *
58    * @type {!i18n.input.chrome.inputview.StateManager}
59    * @private
60    */
61   this.stateManager_ = stateManager;
62
63   // Double click on space key may convert two spaces to a period followed by a
64   // space.
65   this.pointerConfig.dblClick = true;
66   this.pointerConfig.dblClickDelay = 1000;
67 };
68 goog.inherits(i18n.input.chrome.inputview.elements.content.SpaceKey,
69     i18n.input.chrome.inputview.elements.content.FunctionalKey);
70 var SpaceKey = i18n.input.chrome.inputview.elements.content.SpaceKey;
71
72
73 /** @override */
74 SpaceKey.prototype.createDom = function() {
75   goog.base(this, 'createDom');
76
77   goog.dom.classlist.remove(this.bgElem,
78       i18n.input.chrome.inputview.Css.SPECIAL_KEY_BG);
79 };
80
81
82 /**
83  * Gets the character.
84  *
85  * @return {string} The character.
86  */
87 SpaceKey.prototype.getCharacter = function() {
88   if (this.characters_) {
89     // The index is based on the characters in order:
90     // 0: Default
91     // 1: Shift
92     // 2: ALTGR
93     // 3: SHIFT + ALTGR
94     var index = this.stateManager_.hasState(i18n.input.chrome.inputview.
95         StateType.SHIFT) ? 1 : 0 + this.stateManager_.hasState(
96             i18n.input.chrome.inputview.StateType.ALTGR) ? 2 : 0;
97     if (this.characters_.length > index && this.characters_[index]) {
98       return this.characters_[index];
99     }
100   }
101   return ' ';
102 };
103
104
105 /**
106  * Updates the title on the space key.
107  *
108  * @param {string} title .
109  * @param {boolean} visible True to set title visible.
110  */
111 SpaceKey.prototype.updateTitle = function(title, visible) {
112   if (this.textElem) {
113     this.text = title;
114     goog.dom.setTextContent(this.textElem, visible ? title : '');
115     goog.dom.classlist.add(this.textElem,
116         i18n.input.chrome.inputview.Css.TITLE);
117   }
118 };
119
120 });  // goog.scope