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.PageIndicator');
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');
23 goog.scope(function() {
24 var ElementType = i18n.input.chrome.inputview.elements.ElementType;
29 * The indicator of the current page index.
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 {i18n.input.chrome.inputview.elements.Element}
38 i18n.input.chrome.inputview.elements.content.PageIndicator = function(id, type,
40 goog.base(this, id, type, opt_eventTarget);
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;
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);
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);
70 * Slide the indicator.
72 * @param {number} deltaX The x-coordinate of slide distance.
73 * @param {number} totalPages The total number of pages.
75 PageIndicator.prototype.slide = function(deltaX, totalPages) {
76 var marginLeft = goog.style.getMarginBox(this.bgElem).left +
78 this.bgElem.style.marginLeft = marginLeft + 'px';
83 * Move the indicator to indicate a page.
85 * @param {number} pageNum The page that needs to be indicated.
86 * @param {number} totalPages The total number of pages.
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';
94 this.bgElem.style.width = 0;