OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** @suppress {duplicate} */ | 5 /** @suppress {duplicate} */ |
6 var remoting = remoting || {}; | 6 var remoting = remoting || {}; |
7 | 7 |
8 (function() { | 8 (function() { |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // before the password field gets hidden, to work around a Blink | 83 // before the password field gets hidden, to work around a Blink |
84 // clipboard-handling bug - http://crbug.com/281523. | 84 // clipboard-handling bug - http://crbug.com/281523. |
85 that.cancelButton_.focus(); | 85 that.cancelButton_.focus(); |
86 handler(); | 86 handler(); |
87 base.dispose(that.eventHooks_); | 87 base.dispose(that.eventHooks_); |
88 that.eventHooks_ = null; | 88 that.eventHooks_ = null; |
89 that.deferred_ = null; | 89 that.deferred_ = null; |
90 }; | 90 }; |
91 }; | 91 }; |
92 | 92 |
93 })(); | 93 /** |
| 94 * A helper class for implementing MessageDialog with a primary and |
| 95 * and secondary button using remoting.setMode(). |
| 96 * |
| 97 * @param {remoting.AppMode} mode |
| 98 * @param {HTMLElement} primaryButton |
| 99 * @param {HTMLElement=} opt_secondaryButton |
| 100 * @constructor |
| 101 */ |
| 102 remoting.MessageDialog = function(mode, primaryButton, opt_secondaryButton) { |
| 103 /** @private @const */ |
| 104 this.mode_ = mode; |
| 105 /** @private @const */ |
| 106 this.primaryButton_ = primaryButton; |
| 107 /** @private @const */ |
| 108 this.secondaryButton_ = opt_secondaryButton; |
| 109 /** @private {base.Deferred} */ |
| 110 this.deferred_ = null; |
| 111 /** @private {base.Disposables} */ |
| 112 this.eventHooks_ = null; |
| 113 }; |
| 114 |
| 115 /** |
| 116 * @return {Promise<remoting.MessageDialog.Result>} Promise that resolves with |
| 117 * the button clicked. |
| 118 */ |
| 119 remoting.MessageDialog.prototype.show = function() { |
| 120 this.eventHooks_ = new base.Disposables(new base.DomEventHook( |
| 121 this.primaryButton_, 'click', |
| 122 this.onClicked_.bind(this, remoting.MessageDialog.Result.PRIMARY), |
| 123 false)); |
| 124 |
| 125 if (this.secondaryButton_) { |
| 126 this.eventHooks_.add(new base.DomEventHook( |
| 127 this.secondaryButton_, 'click', |
| 128 this.onClicked_.bind(this, remoting.MessageDialog.Result.SECONDARY), |
| 129 false)); |
| 130 } |
| 131 |
| 132 base.debug.assert(this.deferred_ === null); |
| 133 this.deferred_ = new base.Deferred(); |
| 134 remoting.setMode(this.mode_); |
| 135 return this.deferred_.promise(); |
| 136 }; |
| 137 |
| 138 /** |
| 139 * @param {remoting.MessageDialog.Result} result |
| 140 * @return {Function} |
| 141 * @private |
| 142 */ |
| 143 remoting.MessageDialog.prototype.onClicked_ = function(result) { |
| 144 this.deferred_.resolve(result); |
| 145 base.dispose(this.eventHooks_); |
| 146 this.eventHooks_ = null; |
| 147 this.deferred_ = null; |
| 148 }; |
| 149 |
| 150 })(); |
| 151 |
| 152 /** |
| 153 * Define the enum at the end of file as JSCompile doesn't understand enums that |
| 154 * are defined within an IIFE (Immediately Invoked Function Expression). |
| 155 * @enum {number} |
| 156 */ |
| 157 remoting.MessageDialog.Result = { |
| 158 PRIMARY: 0, |
| 159 SECONDARY: 1 |
| 160 }; |
OLD | NEW |