Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / google_input_tools / src / chrome / os / inputview / elements / content / indicator.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.PageIndicator');
15
16 goog.require('goog.dom');
17 goog.require('goog.dom.TagName');
18 goog.require('goog.dom.classlist');
19 goog.require('goog.style');
20 goog.require('i18n.input.chrome.inputview.Css');
21 goog.require('i18n.input.chrome.inputview.elements.Element');
22
23 goog.scope(function() {
24 var ElementType = i18n.input.chrome.inputview.elements.ElementType;
25
26
27
28 /**
29  * The indicator of the current page index.
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 {i18n.input.chrome.inputview.elements.Element}
37  */
38 i18n.input.chrome.inputview.elements.content.PageIndicator = function(id, type,
39     opt_eventTarget) {
40   goog.base(this, id, type, opt_eventTarget);
41 };
42 goog.inherits(i18n.input.chrome.inputview.elements.content.PageIndicator,
43     i18n.input.chrome.inputview.elements.Element);
44 var PageIndicator = i18n.input.chrome.inputview.elements.content.PageIndicator;
45
46
47 /** @override */
48 PageIndicator.prototype.createDom = function() {
49   goog.base(this, 'createDom');
50   var dom = this.getDomHelper();
51   var elem = this.getElement();
52   goog.dom.classlist.add(elem,
53       i18n.input.chrome.inputview.Css.INDICATOR_BACKGROUND);
54   this.bgElem = goog.dom.createDom(goog.dom.TagName.DIV);
55   goog.dom.classlist.add(this.bgElem,
56       i18n.input.chrome.inputview.Css.INDICATOR);
57   dom.appendChild(elem, this.bgElem);
58 };
59
60
61 /** @override */
62 PageIndicator.prototype.resize = function(width, height) {
63   this.bgElem.style.height = height + 'px';
64   this.getElement().style.width = width + 'px';
65   goog.base(this, 'resize', width, height);
66 };
67
68
69 /**
70  * Slide the indicator.
71  *
72  * @param {number} deltaX The x-coordinate of slide distance.
73  * @param {number} totalPages The total number of pages.
74  */
75 PageIndicator.prototype.slide = function(deltaX, totalPages) {
76   var marginLeft = goog.style.getMarginBox(this.bgElem).left +
77       deltaX / totalPages;
78   this.bgElem.style.marginLeft = marginLeft + 'px';
79 };
80
81
82 /**
83  * Move the indicator to indicate a page.
84  *
85  * @param {number} pageNum The page that needs to be indicated.
86  * @param {number} totalPages The total number of pages.
87  */
88 PageIndicator.prototype.gotoPage = function(pageNum, totalPages) {
89   var width = goog.style.getSize(this.getElement()).width;
90   this.bgElem.style.marginLeft = width / totalPages * pageNum + 'px';
91   if (totalPages >= 2) {
92     this.bgElem.style.width = width / totalPages + 'px';
93   } else {
94     this.bgElem.style.width = 0;
95   }
96 };
97 });  // goog.scope
98
99