diff options
author | Valerio Virgillito | 2012-05-16 15:23:48 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-05-16 15:23:48 -0700 |
commit | 13ae16997d4bbca14e255d5989d1c44a76eac72c (patch) | |
tree | d9ebb1dcc6bebee4cb910b950ecb67c1a2d593cd /node_modules/montage/ui/composer/key-composer.js | |
parent | 99f16ae08fbb0a6dfe6008c9833f2253b18c19e5 (diff) | |
download | ninja-13ae16997d4bbca14e255d5989d1c44a76eac72c.tar.gz |
montage v.0.10 integration
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'node_modules/montage/ui/composer/key-composer.js')
-rw-r--r-- | node_modules/montage/ui/composer/key-composer.js | 385 |
1 files changed, 385 insertions, 0 deletions
diff --git a/node_modules/montage/ui/composer/key-composer.js b/node_modules/montage/ui/composer/key-composer.js new file mode 100644 index 00000000..9d2c0f14 --- /dev/null +++ b/node_modules/montage/ui/composer/key-composer.js | |||
@@ -0,0 +1,385 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /** | ||
7 | @module montage/ui/composer/key-composer | ||
8 | @requires montage | ||
9 | @requires montage/ui/composer/composer | ||
10 | */ | ||
11 | var Montage = require("montage").Montage, | ||
12 | Composer = require("ui/composer/composer").Composer; | ||
13 | |||
14 | |||
15 | /** | ||
16 | @module montage/ui/composer/key-composer | ||
17 | */ | ||
18 | |||
19 | |||
20 | /* Event type dispatched by KeyComposer */ | ||
21 | var KEYPRESS_EVENT_TYPE = "keyPress", | ||
22 | LONGKEYPRESS_EVENT_TYPE = "longKeyPress", | ||
23 | KEYRELEASE_EVENT_TYPE = "keyRelease"; | ||
24 | |||
25 | |||
26 | /** | ||
27 | @class module:montage/ui/composer/key-composer.KeyComposer | ||
28 | @classdesc Create a virtual key composed of none or several key modifiers (shift, control, alt and meta) and one native key. | ||
29 | @extends module:montage/ui/composer/composer.Composer | ||
30 | */ | ||
31 | var KeyComposer = exports.KeyComposer = Montage.create(Composer, /** @lends module:montage/ui/composer/key-composer.KeyComposer# */ { | ||
32 | |||
33 | /** | ||
34 | * @private | ||
35 | */ | ||
36 | _isLoaded: { | ||
37 | value: false | ||
38 | }, | ||
39 | |||
40 | /** | ||
41 | * @private | ||
42 | */ | ||
43 | _shouldDispatchEvent: { | ||
44 | value: false | ||
45 | }, | ||
46 | |||
47 | /** | ||
48 | * @private | ||
49 | */ | ||
50 | shouldDispatchLongPress: { | ||
51 | value: false | ||
52 | }, | ||
53 | |||
54 | /** | ||
55 | @private | ||
56 | */ | ||
57 | _longPressTimeout: { | ||
58 | value: null | ||
59 | }, | ||
60 | |||
61 | /** | ||
62 | * @private | ||
63 | */ | ||
64 | _keyRegistered: { | ||
65 | value: false | ||
66 | }, | ||
67 | |||
68 | /** | ||
69 | * @private | ||
70 | */ | ||
71 | _keys:{ | ||
72 | value: null | ||
73 | }, | ||
74 | |||
75 | /** | ||
76 | The sequence of keys to compose. | ||
77 | @type {string} | ||
78 | @default null | ||
79 | */ | ||
80 | keys: { | ||
81 | get: function() { | ||
82 | return this._keys; | ||
83 | }, | ||
84 | set: function(keys) { | ||
85 | if (this._keyRegistered) { | ||
86 | KeyManagerProxy.defaultKeyManager.unregisterKey(this); | ||
87 | this._keys = keys; | ||
88 | KeyManagerProxy.defaultKeyManager.registerKey(this); | ||
89 | } else { | ||
90 | this._keys = keys; | ||
91 | } | ||
92 | } | ||
93 | }, | ||
94 | |||
95 | /** | ||
96 | * @private | ||
97 | */ | ||
98 | _identifier: { value: null }, | ||
99 | |||
100 | /** | ||
101 | The keyComposer's identifier. | ||
102 | @type {string} | ||
103 | @default null | ||
104 | */ | ||
105 | identifier: { | ||
106 | get: function() { | ||
107 | return this._identifier; | ||
108 | }, | ||
109 | set: function(identifier) { | ||
110 | this._identifier = identifier; | ||
111 | } | ||
112 | }, | ||
113 | |||
114 | /** | ||
115 | Create a ComposerKey. | ||
116 | The key will only dispatch events when the component's element is in the native key event target path. | ||
117 | If no identifier is provided, the keys and component's identifier will be used to generate an identifier. | ||
118 | Note: You do not have to call KeyComposer.create() before calling this method. | ||
119 | @function | ||
120 | @param {Object} component. The component to attach the keyComposer to. | ||
121 | @param {Object} keys. The key sequence. | ||
122 | @param {Object} identifier. The identifier. | ||
123 | @returns {Object} the newly created KeyComposer Object | ||
124 | */ | ||
125 | createKey: { | ||
126 | value: function(component, keys, identifier) { | ||
127 | var key = this; | ||
128 | |||
129 | if (this === KeyComposer) { | ||
130 | // This function has been called without creating a new instance of KeyComposer first | ||
131 | key = KeyComposer.create(); | ||
132 | } | ||
133 | |||
134 | if (!identifier) { | ||
135 | if (component.identifier) { | ||
136 | identifier = component.identifier + keys.toLowerCase().replace(/[ +]/g).toCapitalized(); | ||
137 | } else { | ||
138 | identifier = keys.toLowerCase().replace(/[ +]/g); | ||
139 | } | ||
140 | } | ||
141 | key.keys = keys; | ||
142 | key.identifier = identifier; | ||
143 | |||
144 | // console.log("CREATING KEY:", component, key, key.identifier); | ||
145 | |||
146 | component.addComposer(key); | ||
147 | |||
148 | return key; | ||
149 | } | ||
150 | }, | ||
151 | |||
152 | /** | ||
153 | Create a global composerKey. | ||
154 | A global key will dispatch events without requiring the component's element be in the native key event target path | ||
155 | If no identifier is provided, the keys and component's identifier will be used to generate an identifier. | ||
156 | Note: You do not have to call KeyComposer.create() before calling this method. | ||
157 | @function | ||
158 | @param {Object} component. The component to attach the keyComposer to. | ||
159 | @param {Object} keys. The key sequence. | ||
160 | @param {Object} identifier. The identifier. | ||
161 | @returns {Object} the newly created KeyComposer Object | ||
162 | */ | ||
163 | createGlobalKey: { | ||
164 | value: function(component, keys, identifier) { | ||
165 | var key = this; | ||
166 | |||
167 | if (this === KeyComposer) { | ||
168 | // This function has been called without creating a new instance of KeyComposer first | ||
169 | key = KeyComposer.create(); | ||
170 | } | ||
171 | |||
172 | key.keys = keys; | ||
173 | key.identifier = identifier; | ||
174 | // console.log("CREATING GLOBAL KEY:", component, key); | ||
175 | |||
176 | component.addComposerForElement(key, window); | ||
177 | |||
178 | return key; | ||
179 | } | ||
180 | }, | ||
181 | |||
182 | /** | ||
183 | load method | ||
184 | @private | ||
185 | */ | ||
186 | load: { | ||
187 | value: function() { | ||
188 | // Only register the key if somebody is listening for, else let do it later | ||
189 | // console.log("--- load", this.identifier); | ||
190 | this._isLoaded = true; | ||
191 | if (this._shouldDispatchEvent && !this._keyRegistered) { | ||
192 | KeyManagerProxy.defaultKeyManager.registerKey(this); | ||
193 | this._keyRegistered = true; | ||
194 | } | ||
195 | } | ||
196 | }, | ||
197 | |||
198 | /** | ||
199 | unload method | ||
200 | @private | ||
201 | */ | ||
202 | unload: { | ||
203 | value: function() { | ||
204 | this._isLoaded = false; | ||
205 | KeyManagerProxy.defaultKeyManager.unregisterKey(this); | ||
206 | this._keyRegistered = false; | ||
207 | } | ||
208 | }, | ||
209 | |||
210 | /** | ||
211 | Add an event listener to the composerKey. | ||
212 | @function | ||
213 | @param {string} type. Any of the following types: keyPress, longKeyPress and keyRelease. | ||
214 | @param {Object|function} listener. The listener object or function to call when dispatching the event. | ||
215 | @param {boolean} useCapture. Specify if the listener want to be called during the capture phase of the event. | ||
216 | */ | ||
217 | addEventListener: { | ||
218 | value: function(type, listener, useCapture) { | ||
219 | // Optimisation so that we don't dispatch an event if we do not need to | ||
220 | // console.log("--- addEventListener", this.identifier); | ||
221 | var component = this.component; | ||
222 | |||