Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: third_party/google_input_tools/src/chrome/os/inputview/imewindows/gesturepreviewwindow.js

Issue 1576613002: Update Google Input Tools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing APIs, remove bade dependencies. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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.GesturePreviewWindow');
15
16 goog.require('goog.dom.TagName');
17 goog.require('goog.dom.classlist');
18 goog.require('goog.math.Coordinate');
19 goog.require('i18n.input.chrome.FloatingWindow');
20 goog.require('i18n.input.chrome.inputview.Css');
21
22
23 goog.scope(function() {
24 var Css = i18n.input.chrome.inputview.Css;
25 var FloatingWindow = i18n.input.chrome.FloatingWindow;
26 var TagName = goog.dom.TagName;
27
28
29
30 /**
31 * The gesture preview window.
32 *
33 * @param {!chrome.app.window.AppWindow} parentWindow The parent app window.
34 * @constructor
35 * @extends {i18n.input.chrome.FloatingWindow}
36 */
37 i18n.input.chrome.inputview.GesturePreviewWindow = function(parentWindow) {
38 i18n.input.chrome.inputview.GesturePreviewWindow.base(
39 this, 'constructor', parentWindow, undefined,
40 GesturePreviewWindow.CSS_FILE_);
41 this.setVisible(false);
42 this.render();
43 };
44 var GesturePreviewWindow = i18n.input.chrome.inputview.GesturePreviewWindow;
45 goog.inherits(GesturePreviewWindow, FloatingWindow);
46
47
48 /**
49 * The CSS file name for the gesture preview.
50 *
51 * @private @const {string}
52 */
53 GesturePreviewWindow.CSS_FILE_ = 'gesturepreviewwindow_css.css';
54
55
56 /**
57 * The total padding on the sides of the word.
58 *
59 * @private @const {number}
60 */
61 GesturePreviewWindow.PADDING_SIDE_ = 70;
62
63
64 /**
65 * The number of pixels to provide per character.
66 *
67 * @private @const {number}
68 */
69 GesturePreviewWindow.PER_CHAR_WIDTH_ = 10;
70
71
72 /**
73 * The height of the floating window.
74 *
75 * @private @const {number}
76 */
77 GesturePreviewWindow.WINDOW_HEIGHT_ = 68;
78
79
80 /**
81 * The vertical offset of the preview window.
82 * This moves the window out from underneath the user's finger.
83 *
84 * @private @const {number}
85 */
86 GesturePreviewWindow.Y_OFFSET_ = -140;
87
88
89 /**
90 * The div that contains the preview text.
91 *
92 * @private {Element}
93 */
94 GesturePreviewWindow.prototype.textDiv_;
95
96
97 /** @override */
98 GesturePreviewWindow.prototype.createDom = function() {
99 GesturePreviewWindow.base(this, 'createDom');
100 var container = this.getElement();
101 goog.dom.classlist.add(container, Css.GESTURE_PREVIEW_CONTAINER);
102 };
103
104
105 /**
106 * Shows the gesture preview window.
107 *
108 * @param {string} word The word to display in the preview window.
109 */
110 GesturePreviewWindow.prototype.show = function(word) {
111 this.setWord(word);
112 this.resize(
113 this.calculateWindowWidth_(word.length),
114 GesturePreviewWindow.WINDOW_HEIGHT_);
115 this.setVisible(true);
116 };
117
118
119 /**
120 * Sets the word to show in the preview window.
121 *
122 * @param {string} word The word to show in the preview.
123 */
124 GesturePreviewWindow.prototype.setWord = function(word) {
125 if (!this.textDiv_) {
126 var dom = this.getDomHelper();
127 this.textDiv_ = dom.createDom(TagName.DIV, Css.GESTURE_PREVIEW_TEXT);
128 dom.appendChild(this.getElement(), this.textDiv_);
129 }
130 this.textDiv_.textContent = word;
131 };
132
133
134 /**
135 * Calculates the current width of the gesture preview window.
136 *
137 * @param {number} length The length of string to support.
138 * @private
139 * @return {number}
140 */
141 GesturePreviewWindow.prototype.calculateWindowWidth_ = function(length) {
142 // TODO(stevet): Use the true width of the word instead of this estimate.
143 return GesturePreviewWindow.PADDING_SIDE_ +
144 GesturePreviewWindow.PER_CHAR_WIDTH_ * length;
145 };
146
147
148 /**
149 * Hides the gesture preview window.
150 */
151 GesturePreviewWindow.prototype.hide = function() {
152 this.setVisible(false);
153 };
154
155
156 /** @override */
157 GesturePreviewWindow.prototype.reposition = function(position) {
158 position.y += Math.round(GesturePreviewWindow.Y_OFFSET_);
159 position.x -= Math.round(this.parentWindow.contentWindow.innerWidth / 2);
160 GesturePreviewWindow.base(
161 this, 'reposition', convertToScreenCoordinate(position));
162 };
163
164
165 /**
166 * Converts coordinate in the keyboard window to coordinate in screen.
167 *
168 * @param {!goog.math.Coordinate} coordinate The coordinate in keyboard window.
169 * @return {!goog.math.Coordinate} The coordinate in screen.
170 */
171 function convertToScreenCoordinate(coordinate) {
172 var screenCoordinate = coordinate.clone();
173 // This is a hack. Ideally, we should be able to use window.screenX/Y to get
174 // coordinate of the top left corner of VK window. But VK window is special
175 // and the values are set to 0 all the time. We should fix the problem in
176 // Chrome.
177 screenCoordinate.y += screen.height - window.innerHeight;
178 return screenCoordinate;
179 };
180 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698