ApplicationImpl cleanup, part 1:
[chromium-blink-merge.git] / third_party / google_input_tools / src / chrome / os / floatingwindow / floatingwindow.js
blob8881658abf2de0b18192bf85de3b92999ba4bd52
1 // Copyright 2015 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");
14 goog.provide('i18n.input.chrome.FloatingWindow');
16 goog.require('goog.dom.DomHelper');
17 goog.require('goog.dom.TagName');
18 goog.require('goog.style');
19 goog.require('goog.ui.Container');
20 goog.require('i18n.input.chrome.Env');
21 goog.require('i18n.input.chrome.FloatingWindowDragger');
24 goog.scope(function() {
25 var Env = i18n.input.chrome.Env;
26 var FloatingWindowDragger = i18n.input.chrome.FloatingWindowDragger;
30 /**
31 * The floating window in chrome OS.
33 * @param {!chrome.app.window.AppWindow} parentWindow The parent app window.
34 * @param {boolean=} opt_enableDragger Whether to enable dragger feature.
35 * @param {string=} opt_cssFile The optional css file.
36 * @constructor
37 * @extends {goog.ui.Container}
39 i18n.input.chrome.FloatingWindow = function(parentWindow, opt_enableDragger,
40 opt_cssFile) {
41 goog.base(this, undefined, undefined,
42 new goog.dom.DomHelper(parentWindow.contentWindow.document));
44 /**
45 * The parent app window.
47 * @protected {!chrome.app.window.AppWindow}
49 this.parentWindow = parentWindow;
51 /** @protected {!Env} */
52 this.env = Env.getInstance();
54 /** @protected {boolean} */
55 this.enableDragger = goog.isDef(opt_enableDragger) ? opt_enableDragger : true;
57 if (opt_cssFile) {
58 this.installCss(opt_cssFile);
61 var FloatingWindow = i18n.input.chrome.FloatingWindow;
62 goog.inherits(FloatingWindow, goog.ui.Container);
65 /**
66 * The dragger for floating window.
68 * @private {FloatingWindowDragger}
70 FloatingWindow.prototype.dragger_;
73 /**
74 * Install css in this windows.
76 * @param {string} file The css file.
78 FloatingWindow.prototype.installCss = function(file) {
79 var dh = this.getDomHelper();
80 var doc = dh.getDocument();
81 var head = dh.getElementsByTagNameAndClass('head')[0];
83 var styleSheet = dh.createDom(goog.dom.TagName.LINK, {
84 'rel': 'stylesheet',
85 'href': file
86 });
87 dh.appendChild(head, styleSheet);
91 /** @override */
92 FloatingWindow.prototype.enterDocument = function() {
93 goog.base(this, 'enterDocument');
95 this.setFocusable(false);
96 this.setFocusableChildrenAllowed(false);
98 if (this.enableDragger) {
99 this.dragger_ = new FloatingWindowDragger(
100 this.parentWindow, this.getElement());
105 /** @override */
106 FloatingWindow.prototype.setVisible = function(isVisible) {
107 if (isVisible) {
108 this.parentWindow.show();
109 } else {
110 this.parentWindow.hide();
112 return goog.base(this, 'setVisible', isVisible);
117 * Changes the position of the floating window.
119 * @param {!goog.math.Coordinate} position The coordinate of the position of the
120 * screen.
122 FloatingWindow.prototype.reposition = function(position) {
123 var outerBounds = this.parentWindow.outerBounds;
124 if (outerBounds.left != position.x || outerBounds.top != position.y) {
125 outerBounds.setPosition(position.x, position.y);
131 * Changes the size of the floating window.
133 * @param {number} width The width of the new window.
134 * @param {number} height The height of the new window.
136 FloatingWindow.prototype.resize = function(width, height) {
137 this.parentWindow.outerBounds.setSize(width, height);
142 * Gets the size of the floating window.
144 * @return {!goog.math.Size} The element's size.
146 FloatingWindow.prototype.size = function() {
147 return goog.style.getSize(this.getElement());
151 /** @override */
152 FloatingWindow.prototype.disposeInternal = function() {
153 this.parentWindow.close();
154 goog.dispose(this.dragger_);
155 goog.base(this, 'disposeInternal');
157 }); // goog.scope