| OLD | NEW |
| 1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. | 1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. |
| 2 // limitations under the License. | 2 // limitations under the License. |
| 3 // See the License for the specific language governing permissions and | 3 // See the License for the specific language governing permissions and |
| 4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 5 // distributed under the License is distributed on an "AS-IS" BASIS, | 5 // distributed under the License is distributed on an "AS-IS" BASIS, |
| 6 // Unless required by applicable law or agreed to in writing, software | 6 // Unless required by applicable law or agreed to in writing, software |
| 7 // | 7 // |
| 8 // http://www.apache.org/licenses/LICENSE-2.0 | 8 // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 // | 9 // |
| 10 // You may obtain a copy of the License at | 10 // You may obtain a copy of the License at |
| 11 // you may not use this file except in compliance with the License. | 11 // you may not use this file except in compliance with the License. |
| 12 // Licensed under the Apache License, Version 2.0 (the "License"); | 12 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 13 // | 13 // |
| 14 goog.provide('i18n.input.chrome.inputview.KeyboardContainer'); | 14 goog.provide('i18n.input.chrome.inputview.KeyboardContainer'); |
| 15 | 15 |
| 16 goog.require('goog.dom.TagName'); | 16 goog.require('goog.dom.TagName'); |
| 17 goog.require('goog.dom.classlist'); | 17 goog.require('goog.dom.classlist'); |
| 18 goog.require('goog.i18n.bidi'); | 18 goog.require('goog.i18n.bidi'); |
| 19 goog.require('goog.ui.Container'); | |
| 20 goog.require('i18n.input.chrome.inputview.Css'); | 19 goog.require('i18n.input.chrome.inputview.Css'); |
| 21 goog.require('i18n.input.chrome.inputview.GlobalFlags'); | 20 goog.require('i18n.input.chrome.inputview.GlobalFlags'); |
| 21 goog.require('i18n.input.chrome.inputview.elements.Element'); |
| 22 goog.require('i18n.input.chrome.inputview.elements.ElementType'); |
| 22 goog.require('i18n.input.chrome.inputview.elements.content.AltDataView'); | 23 goog.require('i18n.input.chrome.inputview.elements.content.AltDataView'); |
| 23 goog.require('i18n.input.chrome.inputview.elements.content.CandidateView'); | 24 goog.require('i18n.input.chrome.inputview.elements.content.CandidateView'); |
| 24 goog.require('i18n.input.chrome.inputview.elements.content.EmojiView'); | 25 goog.require('i18n.input.chrome.inputview.elements.content.EmojiView'); |
| 25 goog.require('i18n.input.chrome.inputview.elements.content.ExpandedCandidateView
'); | 26 goog.require('i18n.input.chrome.inputview.elements.content.ExpandedCandidateView
'); |
| 26 goog.require('i18n.input.chrome.inputview.elements.content.GestureCanvasView'); | 27 goog.require('i18n.input.chrome.inputview.elements.content.GestureCanvasView'); |
| 27 goog.require('i18n.input.chrome.inputview.elements.content.HandwritingView'); | 28 goog.require('i18n.input.chrome.inputview.elements.content.HandwritingView'); |
| 28 goog.require('i18n.input.chrome.inputview.elements.content.KeysetView'); | 29 goog.require('i18n.input.chrome.inputview.elements.content.KeysetView'); |
| 29 goog.require('i18n.input.chrome.inputview.elements.content.MenuView'); | 30 goog.require('i18n.input.chrome.inputview.elements.content.MenuView'); |
| 30 goog.require('i18n.input.chrome.inputview.elements.content.SelectView'); | 31 goog.require('i18n.input.chrome.inputview.elements.content.SelectView'); |
| 31 goog.require('i18n.input.chrome.inputview.elements.content.SwipeView'); | 32 goog.require('i18n.input.chrome.inputview.elements.content.SwipeView'); |
| 32 goog.require('i18n.input.chrome.inputview.elements.content.VoiceView'); | 33 goog.require('i18n.input.chrome.inputview.elements.content.VoiceView'); |
| 33 | 34 |
| 34 | 35 |
| 35 | 36 |
| 36 goog.scope(function() { | 37 goog.scope(function() { |
| 37 var Css = i18n.input.chrome.inputview.Css; | 38 var Css = i18n.input.chrome.inputview.Css; |
| 38 var EmojiView = i18n.input.chrome.inputview.elements.content.EmojiView; | 39 var EmojiView = i18n.input.chrome.inputview.elements.content.EmojiView; |
| 39 var HandwritingView = i18n.input.chrome.inputview.elements.content. | 40 var HandwritingView = i18n.input.chrome.inputview.elements.content. |
| 40 HandwritingView; | 41 HandwritingView; |
| 41 var KeysetView = i18n.input.chrome.inputview.elements.content.KeysetView; | 42 var KeysetView = i18n.input.chrome.inputview.elements.content.KeysetView; |
| 42 var SpecNodeName = i18n.input.chrome.inputview.SpecNodeName; | |
| 43 var content = i18n.input.chrome.inputview.elements.content; | 43 var content = i18n.input.chrome.inputview.elements.content; |
| 44 var ElementType = i18n.input.chrome.inputview.elements.ElementType; |
| 44 | 45 |
| 45 | 46 |
| 46 | 47 |
| 47 /** | 48 /** |
| 48 * The keyboard container. | 49 * The keyboard container. |
| 49 * | 50 * |
| 50 * @param {!i18n.input.chrome.inputview.Adapter} adapter . | 51 * @param {!i18n.input.chrome.inputview.Adapter} adapter . |
| 51 * @param {!i18n.input.chrome.sounds.SoundController} soundController . | 52 * @param {!i18n.input.chrome.sounds.SoundController} soundController . |
| 53 * @param {goog.events.EventTarget=} opt_eventTarget The parent event target. |
| 52 * @constructor | 54 * @constructor |
| 53 * @extends {goog.ui.Container} | 55 * @extends {i18n.input.chrome.inputview.elements.Element} |
| 54 */ | 56 */ |
| 57 // TODO(bshe): Move this file to elements/content |
| 55 i18n.input.chrome.inputview.KeyboardContainer = | 58 i18n.input.chrome.inputview.KeyboardContainer = |
| 56 function(adapter, soundController) { | 59 function(adapter, soundController, opt_eventTarget) { |
| 57 goog.base(this); | 60 goog.base(this, '', ElementType.KEYBOARD_CONTAINER_VIEW, opt_eventTarget); |
| 58 | 61 |
| 59 /** @type {!content.CandidateView} */ | 62 /** @type {!content.CandidateView} */ |
| 60 this.candidateView = new content.CandidateView( | 63 this.candidateView = new content.CandidateView( |
| 61 'candidateView', adapter, this); | 64 'candidateView', adapter, this); |
| 62 | 65 |
| 63 /** @type {!content.AltDataView} */ | 66 /** @type {!content.AltDataView} */ |
| 64 this.altDataView = new content.AltDataView(this); | 67 this.altDataView = new content.AltDataView(this); |
| 65 | 68 |
| 66 /** @type {!content.SwipeView} */ | 69 /** @type {!content.SwipeView} */ |
| 67 this.swipeView = new content.SwipeView(adapter, this); | 70 this.swipeView = new content.SwipeView(adapter, this); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 93 this.keysetViewMap = {}; | 96 this.keysetViewMap = {}; |
| 94 | 97 |
| 95 /** | 98 /** |
| 96 * The bus channel to communicate with background. | 99 * The bus channel to communicate with background. |
| 97 * | 100 * |
| 98 * @private {!i18n.input.chrome.inputview.Adapter} | 101 * @private {!i18n.input.chrome.inputview.Adapter} |
| 99 */ | 102 */ |
| 100 this.adapter_ = adapter; | 103 this.adapter_ = adapter; |
| 101 }; | 104 }; |
| 102 goog.inherits(i18n.input.chrome.inputview.KeyboardContainer, | 105 goog.inherits(i18n.input.chrome.inputview.KeyboardContainer, |
| 103 goog.ui.Container); | 106 i18n.input.chrome.inputview.elements.Element); |
| 104 var KeyboardContainer = i18n.input.chrome.inputview.KeyboardContainer; | 107 var KeyboardContainer = i18n.input.chrome.inputview.KeyboardContainer; |
| 105 | 108 |
| 106 | 109 |
| 107 /** @type {!KeysetView} */ | 110 /** @type {!KeysetView} */ |
| 108 KeyboardContainer.prototype.currentKeysetView; | 111 KeyboardContainer.prototype.currentKeysetView; |
| 109 | 112 |
| 110 | 113 |
| 111 /** | 114 /** |
| 112 * The padding bottom of the whole keyboard. | 115 * The padding bottom of the whole keyboard. |
| 113 * | 116 * |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 this.expandedCandidateView.render(this.wrapperDiv_); | 154 this.expandedCandidateView.render(this.wrapperDiv_); |
| 152 this.expandedCandidateView.setVisible(false); | 155 this.expandedCandidateView.setVisible(false); |
| 153 if (this.adapter_.isGestureTypingEnabled()) { | 156 if (this.adapter_.isGestureTypingEnabled()) { |
| 154 this.gestureCanvasView.render(this.wrapperDiv_); | 157 this.gestureCanvasView.render(this.wrapperDiv_); |
| 155 } | 158 } |
| 156 goog.dom.classlist.add(elem, Css.CONTAINER); | 159 goog.dom.classlist.add(elem, Css.CONTAINER); |
| 157 }; | 160 }; |
| 158 | 161 |
| 159 | 162 |
| 160 /** @override */ | 163 /** @override */ |
| 161 KeyboardContainer.prototype.enterDocument = function() { | |
| 162 goog.base(this, 'enterDocument'); | |
| 163 | |
| 164 this.setFocusable(false); | |
| 165 this.setFocusableChildrenAllowed(false); | |
| 166 }; | |
| 167 | |
| 168 | |
| 169 /** | |
| 170 * Updates the whole keyboard. | |
| 171 */ | |
| 172 KeyboardContainer.prototype.update = function() { | 164 KeyboardContainer.prototype.update = function() { |
| 173 this.currentKeysetView && this.currentKeysetView.update(); | 165 this.currentKeysetView && this.currentKeysetView.update(); |
| 174 }; | 166 }; |
| 175 | 167 |
| 176 | 168 |
| 177 /** | 169 /** |
| 178 * Adds a keyset view. | 170 * Adds a keyset view. |
| 179 * | 171 * |
| 180 * @param {!Object} keysetData . | 172 * @param {!Object} keysetData . |
| 181 * @param {!Object} layoutData . | 173 * @param {!Object} layoutData . |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 for (var name in this.keysetViewMap) { | 218 for (var name in this.keysetViewMap) { |
| 227 var view = this.keysetViewMap[name]; | 219 var view = this.keysetViewMap[name]; |
| 228 if (name == keyset) { | 220 if (name == keyset) { |
| 229 this.candidateView.setVisible(!view.disableCandidateView); | 221 this.candidateView.setVisible(!view.disableCandidateView); |
| 230 // Before setting view visible, activate it first, since activation may | 222 // Before setting view visible, activate it first, since activation may |
| 231 // change view keys. | 223 // change view keys. |
| 232 view.activate(rawKeyset); | 224 view.activate(rawKeyset); |
| 233 view.setVisible(true); | 225 view.setVisible(true); |
| 234 view.update(); | 226 view.update(); |
| 235 if (view.spaceKey) { | 227 if (view.spaceKey) { |
| 236 view.spaceKey.updateTitle(title, !isPasswordBox); | 228 view.spaceKey.updateTitle(title, !isPasswordBox && |
| 229 keyset != 'hwt' && keyset != 'emoji'); |
| 237 } | 230 } |
| 238 if (isA11yMode) { | 231 if (isA11yMode) { |
| 239 goog.dom.classlist.add(this.getElement(), Css.A11Y); | 232 goog.dom.classlist.add(this.getElement(), Css.A11Y); |
| 240 } | 233 } |
| 241 // If current raw keyset is changed, record it. | 234 // If current raw keyset is changed, record it. |
| 242 if (lastRawkeyset != rawKeyset) { | 235 if (lastRawkeyset != rawKeyset) { |
| 243 view.fromKeyset = lastRawkeyset; | 236 view.fromKeyset = lastRawkeyset; |
| 244 } | 237 } |
| 245 if (view instanceof HandwritingView) { | 238 if (view instanceof HandwritingView) { |
| 246 view.setLanguagecode(languageCode); | 239 view.setLanguagecode(languageCode); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 264 | 257 |
| 265 | 258 |
| 266 /** | 259 /** |
| 267 * Resizes the whole keyboard. | 260 * Resizes the whole keyboard. |
| 268 * | 261 * |
| 269 * @param {number} width . | 262 * @param {number} width . |
| 270 * @param {number} height . | 263 * @param {number} height . |
| 271 * @param {number} widthPercent . | 264 * @param {number} widthPercent . |
| 272 * @param {number} candidateViewHeight . | 265 * @param {number} candidateViewHeight . |
| 273 */ | 266 */ |
| 274 KeyboardContainer.prototype.resize = function(width, height, widthPercent, | 267 KeyboardContainer.prototype.setContainerSize = function(width, height, |
| 275 candidateViewHeight) { | 268 widthPercent, candidateViewHeight) { |
| 276 if (!this.currentKeysetView) { | 269 if (!this.currentKeysetView) { |
| 277 return; | 270 return; |
| 278 } | 271 } |
| 279 var elem = this.getElement(); | 272 var elem = this.getElement(); |
| 280 | 273 |
| 281 var h = height; | 274 var h = height; |
| 282 var wrapperMargin = 0; | 275 var wrapperMargin = 0; |
| 283 if (this.currentKeysetView.isTabStyle()) { | 276 if (this.currentKeysetView.isTabStyle()) { |
| 284 h = height - 2 * KeyboardContainer.TAB_MARGIN_; | 277 h = height - 2 * KeyboardContainer.TAB_MARGIN_; |
| 285 wrapperMargin = KeyboardContainer.TAB_MARGIN_; | 278 wrapperMargin = KeyboardContainer.TAB_MARGIN_; |
| 286 } | 279 } |
| 287 this.wrapperDiv_.style.marginTop = this.wrapperDiv_.style.marginBottom = | 280 this.wrapperDiv_.style.marginTop = this.wrapperDiv_.style.marginBottom = |
| 288 wrapperMargin + 'px'; | 281 wrapperMargin + 'px'; |
| 289 h -= KeyboardContainer.PADDING_BOTTOM_; | 282 h -= KeyboardContainer.PADDING_BOTTOM_; |
| 290 elem.style.paddingBottom = KeyboardContainer.PADDING_BOTTOM_ + 'px'; | 283 elem.style.paddingBottom = KeyboardContainer.PADDING_BOTTOM_ + 'px'; |
| 291 | 284 |
| 292 var padding = Math.round((width - width * widthPercent) / 2); | 285 var padding = Math.round((width - width * widthPercent) / 2); |
| 293 var w = width - 2 * padding; | 286 var w = width - 2 * padding; |
| 294 | 287 |
| 295 // Reduce height if candidate view is enabled | 288 // Reduce height if candidate view is enabled |
| 296 h = this.currentKeysetView.disableCandidateView ? h : | 289 h = this.currentKeysetView.disableCandidateView ? h : |
| 297 h - candidateViewHeight; | 290 h - candidateViewHeight; |
| 298 | 291 |
| 292 var backspaceWeight = this.currentKeysetView.backspaceKey ? |
| 293 this.currentKeysetView.backspaceKey.getParent().getWidthInWeight() : 0; |
| 299 this.candidateView.setWidthInWeight( | 294 this.candidateView.setWidthInWeight( |
| 300 this.currentKeysetView.getWidthInWeight()); | 295 this.currentKeysetView.getWidthInWeight(), backspaceWeight); |
| 301 this.candidateView.resize(w, candidateViewHeight); | 296 this.candidateView.resize(w, candidateViewHeight); |
| 302 this.expandedCandidateView.resize(w, h); | 297 this.expandedCandidateView.resize(w, h); |
| 303 if (i18n.input.chrome.inputview.GlobalFlags.isQPInputView) { | 298 if (i18n.input.chrome.inputview.GlobalFlags.isQPInputView) { |
| 304 var candidateElem = this.candidateView.getElement(); | 299 var candidateElem = this.candidateView.getElement(); |
| 305 candidateElem.style.paddingLeft = candidateElem.style.paddingRight = | 300 candidateElem.style.paddingLeft = candidateElem.style.paddingRight = |
| 306 padding + 'px'; | 301 padding + 'px'; |
| 307 this.currentKeysetView.resize(width, h, widthPercent); | 302 this.currentKeysetView.resize(width, h, widthPercent); |
| 308 var expandViewElem = this.expandedCandidateView.getElement(); | 303 var expandViewElem = this.expandedCandidateView.getElement(); |
| 309 expandViewElem.style.marginLeft = expandViewElem.style.marginRight = | 304 expandViewElem.style.marginLeft = expandViewElem.style.marginRight = |
| 310 padding + 'px'; | 305 padding + 'px'; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 /** | 364 /** |
| 370 * Cleans the stokes. | 365 * Cleans the stokes. |
| 371 */ | 366 */ |
| 372 KeyboardContainer.prototype.cleanStroke = function() { | 367 KeyboardContainer.prototype.cleanStroke = function() { |
| 373 if (this.currentKeysetView) { | 368 if (this.currentKeysetView) { |
| 374 this.currentKeysetView.cleanStroke(); | 369 this.currentKeysetView.cleanStroke(); |
| 375 } | 370 } |
| 376 }; | 371 }; |
| 377 | 372 |
| 378 }); // goog.scope | 373 }); // goog.scope |
| OLD | NEW |