Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / google_input_tools / src / chrome / os / inputview / elements / content / candidate.js
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.content.Candidate');
15
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');
21
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;
27
28
29
30 /**
31  * The candidate component.
32  *
33  * @param {string} id .
34  * @param {!Object} candidate .
35  * @param {i18n.input.chrome.inputview.elements.content.Candidate.Type}
36  *     candidateType .
37  * @param {number} height .
38  * @param {boolean} isDefault .
39  * @param {number=} opt_width .
40  * @param {goog.events.EventTarget=} opt_eventTarget .
41  * @constructor
42  * @extends {i18n.input.chrome.inputview.elements.Element}
43  */
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);
47
48   /** @type {!Object} */
49   this.candidate = candidate;
50
51   /** @type {i18n.input.chrome.inputview.elements.content.Candidate.Type} */
52   this.candidateType = candidateType;
53
54   /** @type {number} */
55   this.width = opt_width || 0;
56
57   /** @type {number} */
58   this.height = height;
59
60   /** @type {boolean} */
61   this.isDefault = isDefault;
62 };
63 var Candidate = i18n.input.chrome.inputview.elements.content.Candidate;
64 goog.inherits(Candidate, i18n.input.chrome.inputview.elements.Element);
65
66
67 /**
68  * The type of this candidate.
69  *
70  * @enum {number}
71  */
72 Candidate.Type = {
73   CANDIDATE: 0,
74   NUMBER: 1
75 };
76
77
78 /** @override */
79 Candidate.prototype.createDom = function() {
80   goog.base(this, 'createDom');
81
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);
87   }
88   dom.setTextContent(elem, this.candidate[Name.CANDIDATE]);
89   elem.style.height = this.height + 'px';
90   if (this.width > 0) {
91     elem.style.width = this.width + 'px';
92   }
93   if (this.isDefault) {
94     goog.dom.classlist.add(elem, Css.CANDIDATE_DEFAULT);
95   }
96   if (!!this.candidate[Name.IS_AUTOCORRECT]) {
97     goog.dom.classlist.add(elem, Css.CANDIDATE_AUTOCORRECT);
98   }
99 };
100
101
102 /** @override */
103 Candidate.prototype.setHighlighted = function(highlight) {
104   if (highlight) {
105     goog.dom.classlist.add(this.getElement(), Css.CANDIDATE_HIGHLIGHT);
106   } else {
107     goog.dom.classlist.remove(this.getElement(), Css.CANDIDATE_HIGHLIGHT);
108   }
109 };
110
111
112 });  // goog.scope
113