OLD | NEW |
(Empty) | |
| 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.Element'); |
| 15 |
| 16 goog.require('goog.dom.classlist'); |
| 17 goog.require('goog.events.EventHandler'); |
| 18 goog.require('goog.style'); |
| 19 goog.require('goog.ui.Component'); |
| 20 goog.require('i18n.input.chrome.inputview.Css'); |
| 21 goog.require('i18n.input.chrome.inputview.PointerConfig'); |
| 22 |
| 23 |
| 24 goog.scope(function() { |
| 25 |
| 26 |
| 27 |
| 28 /** |
| 29 * The abstract class for element in input view keyboard. |
| 30 * |
| 31 * @param {string} id The id. |
| 32 * @param {!i18n.input.chrome.inputview.elements.ElementType} type The element |
| 33 * type. |
| 34 * @param {goog.events.EventTarget=} opt_eventTarget The event target. |
| 35 * @constructor |
| 36 * @extends {goog.ui.Component} |
| 37 */ |
| 38 i18n.input.chrome.inputview.elements.Element = function(id, type, |
| 39 opt_eventTarget) { |
| 40 goog.base(this); |
| 41 this.setParentEventTarget(opt_eventTarget || null); |
| 42 |
| 43 /** |
| 44 * The id of the element. |
| 45 * |
| 46 * @type {string} |
| 47 */ |
| 48 this.id = id; |
| 49 |
| 50 /** |
| 51 * The type of the element. |
| 52 * |
| 53 * @type {!i18n.input.chrome.inputview.elements.ElementType} |
| 54 */ |
| 55 this.type = type; |
| 56 |
| 57 /** |
| 58 * The display of the element. |
| 59 * |
| 60 * @type {string} |
| 61 * @private |
| 62 */ |
| 63 this.display_ = ''; |
| 64 |
| 65 /** |
| 66 * The event handler. |
| 67 * |
| 68 * @type {!goog.events.EventHandler} |
| 69 */ |
| 70 this.handler = new goog.events.EventHandler(this); |
| 71 |
| 72 /** |
| 73 * The configuration for the pointer. |
| 74 * |
| 75 * @type {!i18n.input.chrome.inputview.PointerConfig} |
| 76 */ |
| 77 this.pointerConfig = new i18n.input.chrome.inputview.PointerConfig(false, |
| 78 false, false); |
| 79 }; |
| 80 goog.inherits(i18n.input.chrome.inputview.elements.Element, goog.ui.Component); |
| 81 var Element = i18n.input.chrome.inputview.elements.Element; |
| 82 |
| 83 |
| 84 /** |
| 85 * The width of the element. |
| 86 * |
| 87 * @type {number} |
| 88 */ |
| 89 Element.prototype.width; |
| 90 |
| 91 |
| 92 /** |
| 93 * The height of the element. |
| 94 * |
| 95 * @type {number} |
| 96 */ |
| 97 Element.prototype.height; |
| 98 |
| 99 |
| 100 /** |
| 101 * Resizes the element. |
| 102 * |
| 103 * @param {number} width The total width. |
| 104 * @param {number} height The total height. |
| 105 */ |
| 106 Element.prototype.resize = function(width, height) { |
| 107 this.width = width; |
| 108 this.height = height; |
| 109 }; |
| 110 |
| 111 |
| 112 /** @override */ |
| 113 Element.prototype.createDom = function() { |
| 114 goog.base(this, 'createDom'); |
| 115 |
| 116 this.getElement().id = this.id; |
| 117 this.getElement()['view'] = this; |
| 118 }; |
| 119 |
| 120 |
| 121 /** @override */ |
| 122 Element.prototype.enterDocument = function() { |
| 123 goog.base(this, 'enterDocument'); |
| 124 |
| 125 this.display_ = this.getElement().style.display; |
| 126 }; |
| 127 |
| 128 |
| 129 /** |
| 130 * Whether the element is visible. |
| 131 * |
| 132 * @return {boolean} True if the element is visible. |
| 133 */ |
| 134 Element.prototype.isVisible = function() { |
| 135 return goog.style.isElementShown(this.getElement()); |
| 136 }; |
| 137 |
| 138 |
| 139 /** |
| 140 * Sets the visibility of the element. |
| 141 * |
| 142 * @param {boolean} visibility True if the element is visible. |
| 143 */ |
| 144 Element.prototype.setVisible = function(visibility) { |
| 145 this.getElement().style.display = visibility ? this.display_ : 'none'; |
| 146 }; |
| 147 |
| 148 |
| 149 /** |
| 150 * Updates the element. |
| 151 */ |
| 152 Element.prototype.update = function() { |
| 153 this.setHighlighted(false); |
| 154 for (var i = 0; i < this.getChildCount(); i++) { |
| 155 var child = /** @type {!Element} */ ( |
| 156 this.getChildAt(i)); |
| 157 child.update(); |
| 158 } |
| 159 }; |
| 160 |
| 161 |
| 162 /** |
| 163 * Sets the highlight of the soft key. |
| 164 * |
| 165 * @param {boolean} highlight True to set it to be highlighted. |
| 166 */ |
| 167 Element.prototype.setHighlighted = function( |
| 168 highlight) { |
| 169 if (highlight) { |
| 170 goog.dom.classlist.add(this.getElement(), |
| 171 i18n.input.chrome.inputview.Css.ELEMENT_HIGHLIGHT); |
| 172 } else { |
| 173 goog.dom.classlist.remove(this.getElement(), |
| 174 i18n.input.chrome.inputview.Css.ELEMENT_HIGHLIGHT); |
| 175 } |
| 176 }; |
| 177 |
| 178 |
| 179 /** @override */ |
| 180 Element.prototype.disposeInternal = function() { |
| 181 this.getElement()['view'] = null; |
| 182 goog.dispose(this.handler); |
| 183 |
| 184 goog.base(this, 'disposeInternal'); |
| 185 }; |
| 186 |
| 187 }); // goog.scope |
OLD | NEW |