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.content.Candidate');
16 goog.require('goog.dom.classlist');
17 goog.require('i18n.input.chrome.inputview.Css');
18 goog.require('i18n.input.chrome.inputview.elements.Element');
19 goog.require('i18n.input.chrome.inputview.elements.ElementType');
20 goog.require('i18n.input.chrome.message.Name');
22 goog.scope(function() {
23 var ElementType = i18n.input.chrome.inputview.elements.ElementType;
24 var Css = i18n.input.chrome.inputview.Css;
25 var TagName = goog.dom.TagName;
26 var Name = i18n.input.chrome.message.Name;
31 * The candidate component.
33 * @param {string} id .
34 * @param {!Object} candidate .
35 * @param {i18n.input.chrome.inputview.elements.content.Candidate.Type}
37 * @param {number} height .
38 * @param {boolean} isDefault .
39 * @param {number=} opt_width .
40 * @param {goog.events.EventTarget=} opt_eventTarget .
42 * @extends {i18n.input.chrome.inputview.elements.Element}
44 i18n.input.chrome.inputview.elements.content.Candidate = function(id,
45 candidate, candidateType, height, isDefault, opt_width, opt_eventTarget) {
46 goog.base(this, id, ElementType.CANDIDATE, opt_eventTarget);
48 /** @type {!Object} */
49 this.candidate = candidate;
51 /** @type {i18n.input.chrome.inputview.elements.content.Candidate.Type} */
52 this.candidateType = candidateType;
55 this.width = opt_width || 0;
60 /** @type {boolean} */
61 this.isDefault = isDefault;
63 var Candidate = i18n.input.chrome.inputview.elements.content.Candidate;
64 goog.inherits(Candidate, i18n.input.chrome.inputview.elements.Element);
68 * The type of this candidate.
79 Candidate.prototype.createDom = function() {
80 goog.base(this, 'createDom');
82 var dom = this.getDomHelper();
83 var elem = this.getElement();
84 goog.dom.classlist.add(elem, Css.CANDIDATE);
85 if (this.candidate['isEmoji']) {
86 goog.dom.classlist.add(elem, Css.EMOJI_FONT);
88 dom.setTextContent(elem, this.candidate[Name.CANDIDATE]);
89 elem.style.height = this.height + 'px';
91 elem.style.width = this.width + 'px';
94 goog.dom.classlist.add(elem, Css.CANDIDATE_DEFAULT);
96 if (!!this.candidate[Name.IS_AUTOCORRECT]) {
97 goog.dom.classlist.add(elem, Css.CANDIDATE_AUTOCORRECT);
103 Candidate.prototype.setHighlighted = function(highlight) {
105 goog.dom.classlist.add(this.getElement(), Css.CANDIDATE_HIGHLIGHT);
107 goog.dom.classlist.remove(this.getElement(), Css.CANDIDATE_HIGHLIGHT);