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
8 // http://www.apache.org/licenses/LICENSE-2.0
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");
14 goog.provide('i18n.input.chrome.inputview.elements.Element');
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');
24 goog.scope(function() {
29 * The abstract class for element in input view keyboard.
31 * @param {string} id The id.
32 * @param {!i18n.input.chrome.inputview.elements.ElementType} type The element
34 * @param {goog.events.EventTarget=} opt_eventTarget The event target.
36 * @extends {goog.ui.Component}
38 i18n.input.chrome.inputview.elements.Element = function(id, type,
41 this.setParentEventTarget(opt_eventTarget || null);
44 * The id of the element.
51 * The type of the element.
53 * @type {!i18n.input.chrome.inputview.elements.ElementType}
58 * The display of the element.
68 * @type {!goog.events.EventHandler}
70 this.handler = new goog.events.EventHandler(this);
73 * The configuration for the pointer.
75 * @type {!i18n.input.chrome.inputview.PointerConfig}
77 this.pointerConfig = new i18n.input.chrome.inputview.PointerConfig(false,
80 goog.inherits(i18n.input.chrome.inputview.elements.Element, goog.ui.Component);
81 var Element = i18n.input.chrome.inputview.elements.Element;
85 * The width of the element.
89 Element.prototype.width;
93 * The height of the element.
97 Element.prototype.height;
101 * Resizes the element.
103 * @param {number} width The total width.
104 * @param {number} height The total height.
106 Element.prototype.resize = function(width, height) {
108 this.height = height;
113 Element.prototype.createDom = function() {
114 goog.base(this, 'createDom');
116 this.getElement().id = this.id;
117 this.getElement()['view'] = this;
122 Element.prototype.enterDocument = function() {
123 goog.base(this, 'enterDocument');
125 this.display_ = this.getElement().style.display;
130 * Whether the element is visible.
132 * @return {boolean} True if the element is visible.
134 Element.prototype.isVisible = function() {
135 return goog.style.isElementShown(this.getElement());
140 * Sets the visibility of the element.
142 * @param {boolean} visibility True if the element is visible.
144 Element.prototype.setVisible = function(visibility) {
145 this.getElement().style.display = visibility ? this.display_ : 'none';
150 * Updates the element.
152 Element.prototype.update = function() {
153 this.setHighlighted(false);
154 for (var i = 0; i < this.getChildCount(); i++) {
155 var child = /** @type {!Element} */ (
163 * Sets the highlight of the soft key.
165 * @param {boolean} highlight True to set it to be highlighted.
167 Element.prototype.setHighlighted = function(
170 goog.dom.classlist.add(this.getElement(),
171 i18n.input.chrome.inputview.Css.ELEMENT_HIGHLIGHT);
173 goog.dom.classlist.remove(this.getElement(),
174 i18n.input.chrome.inputview.Css.ELEMENT_HIGHLIGHT);
180 Element.prototype.disposeInternal = function() {
181 this.getElement()['view'] = null;
182 goog.dispose(this.handler);
184 goog.base(this, 'disposeInternal');