Android Chromoting: Remove exit-fullscreen button.
[chromium-blink-merge.git] / remoting / webapp / base / js / input_dialog.js
bloba429400a37f5fa5eebcb7bd45f9afb5a7eb60b49
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /** @suppress {duplicate} */
6 var remoting = remoting || {};
8 (function() {
10 'use strict';
12 /**
13 * A helper class for implementing dialogs with an input field using
14 * remoting.setMode().
16 * @param {remoting.AppMode} mode
17 * @param {HTMLElement} formElement
18 * @param {HTMLElement} inputField
19 * @param {HTMLElement} cancelButton
21 * @constructor
23 remoting.InputDialog = function(mode, formElement, inputField, cancelButton) {
24 /** @private */
25 this.appMode_ = mode;
26 /** @private */
27 this.formElement_ = formElement;
28 /** @private */
29 this.cancelButton_ = cancelButton;
30 /** @private */
31 this.inputField_ = inputField;
32 /** @private {base.Deferred} */
33 this.deferred_ = null;
34 /** @private {base.Disposables} */
35 this.eventHooks_ = null;
38 /**
39 * @return {Promise<string>} Promise that resolves with the value of the
40 * inputField or rejects with |remoting.Error.CANCELLED| if the user clicks
41 * on the cancel button.
43 remoting.InputDialog.prototype.show = function() {
44 var onCancel = this.createFormEventHandler_(this.onCancel_.bind(this));
45 var onOk = this.createFormEventHandler_(this.onSubmit_.bind(this));
47 this.eventHooks_ = new base.Disposables(
48 new base.DomEventHook(this.formElement_, 'submit', onOk, false),
49 new base.DomEventHook(this.cancelButton_, 'click', onCancel, false));
50 base.debug.assert(this.deferred_ === null);
51 this.deferred_ = new base.Deferred();
52 remoting.setMode(this.appMode_);
53 return this.deferred_.promise();
56 /** @private */
57 remoting.InputDialog.prototype.onSubmit_ = function() {
58 this.deferred_.resolve(this.inputField_.value);
61 /** @private */
62 remoting.InputDialog.prototype.onCancel_ = function() {
63 this.deferred_.reject(new remoting.Error(remoting.Error.Tag.CANCELLED));
66 /**
67 * @param {function():void} handler
68 * @return {Function}
69 * @private
71 remoting.InputDialog.prototype.createFormEventHandler_ = function(handler) {
72 var that = this;
73 return function (/** Event */ e) {
74 // Prevents form submission from reloading the v1 app.
75 e.preventDefault();
77 // Set the focus away from the password field. This has to be done
78 // before the password field gets hidden, to work around a Blink
79 // clipboard-handling bug - http://crbug.com/281523.
80 that.cancelButton_.focus();
81 handler();
82 base.dispose(that.eventHooks_);
83 that.eventHooks_ = null;
84 that.deferred_ = null;
88 })();