Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / google_input_tools / src / chrome / os / inputview / elements / layout / handwritinglayout.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.layout.HandwritingLayout');
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.inputview.elements.Weightable');
21
22
23 goog.scope(function() {
24
25
26
27 /**
28  * The linear layout.
29  *
30  * @param {string} id The id.
31  * @param {goog.events.EventTarget=} opt_eventTarget The event target.
32  * @constructor
33  * @extends {i18n.input.chrome.inputview.elements.Element}
34  * @implements {i18n.input.chrome.inputview.elements.Weightable}
35  */
36 i18n.input.chrome.inputview.elements.layout.HandwritingLayout = function(id,
37     opt_eventTarget) {
38   goog.base(this, id, i18n.input.chrome.inputview.elements.ElementType.
39       HANDWRITING_LAYOUT, opt_eventTarget);
40 };
41 goog.inherits(i18n.input.chrome.inputview.elements.layout.HandwritingLayout,
42     i18n.input.chrome.inputview.elements.Element);
43 var HandwritingLayout =
44     i18n.input.chrome.inputview.elements.layout.HandwritingLayout;
45
46
47 /**
48  * The height in weight unit.
49  *
50  * @type {number}
51  * @private
52  */
53 HandwritingLayout.prototype.heightInWeight_ = 0;
54
55
56 /**
57  * The width in weight unit.
58  *
59  * @type {number}
60  * @private
61  */
62 HandwritingLayout.prototype.widthInWeight_ = 0;
63
64
65 /** @override */
66 HandwritingLayout.prototype.createDom = function() {
67   goog.base(this, 'createDom');
68
69   goog.dom.classlist.add(this.getElement(), i18n.input.chrome.inputview.Css.
70       HANDWRITING_LAYOUT);
71 };
72
73
74 /** @override */
75 HandwritingLayout.prototype.enterDocument = function() {
76   goog.base(this, 'enterDocument');
77
78   this.calculate_();
79 };
80
81
82 /**
83  * Gets the first child.
84  *
85  * @private
86  */
87 HandwritingLayout.prototype.calculate_ = function() {
88   var child = /** @type {i18n.input.chrome.inputview.elements.Weightable} */ (
89       this.getChildAt(0));
90   this.heightInWeight_ = child.getHeightInWeight();
91   this.widthInWeight_ = child.getWidthInWeight();
92 };
93
94
95 /** @override */
96 HandwritingLayout.prototype.getHeightInWeight = function() {
97   return this.heightInWeight_;
98 };
99
100
101 /** @override */
102 HandwritingLayout.prototype.getWidthInWeight = function() {
103   return this.widthInWeight_;
104 };
105
106
107 /** @override */
108 HandwritingLayout.prototype.resize = function(width, height) {
109   goog.base(this, 'resize', width, height);
110   for (var i = 0; i < this.getChildCount(); i++) {
111     var child = /** @type {i18n.input.chrome.inputview.elements.Element} */ (
112         this.getChildAt(i));
113     child.resize(
114         Math.ceil(width * child.getWidthInWeight() / this.widthInWeight_),
115         Math.ceil(height * child.getHeightInWeight() / this.heightInWeight_));
116     // 85/140 = 0.6
117     child.getElement().style.top =
118         Math.ceil(height * 0.6 / this.heightInWeight_);
119   }
120 };
121 });  // goog.scope