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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 * @param {remoting.MessageDialog.Result} result | 151 * @param {remoting.MessageDialog.Result} result |
152 * @return {Function} | 152 * @return {Function} |
153 * @private | 153 * @private |
154 */ | 154 */ |
155 remoting.MessageDialog.prototype.onClicked_ = function(result) { | 155 remoting.MessageDialog.prototype.onClicked_ = function(result) { |
156 this.deferred_.resolve(result); | 156 this.deferred_.resolve(result); |
157 this.deferred_ = null; | 157 this.deferred_ = null; |
158 this.dispose(); | 158 this.dispose(); |
159 }; | 159 }; |
160 | 160 |
161 | |
162 | |
163 /** | |
164 * A promise-based dialog implementation using HTML Dialog element. | |
Jamie
2015/05/20 02:20:37
s/Dialog/<dialog>/
kelvinp
2015/05/20 18:13:00
Done.
| |
165 * | |
166 * @param {HTMLDialogElement} dialog | |
167 * @param {HTMLElement} primaryButton | |
168 * @param {HTMLElement=} opt_secondaryButton | |
169 * @constructor | |
170 * | |
171 * @implements {remoting.WindowShape.ClientUI} | |
172 * @implements {base.Disposable} | |
173 */ | |
174 remoting.Html5ModalDialog = function(dialog, primaryButton, | |
175 opt_secondaryButton) { | |
176 /** @private */ | |
177 this.dialog_ = dialog; | |
178 /** @private {base.Disposables} */ | |
179 this.eventHooks_ = new base.Disposables( | |
180 new base.DomEventHook(dialog, 'cancel', this.onCancel_.bind(this), false), | |
kelvinp
2015/05/20 01:27:31
This is called when the user press Escape.
| |
181 new base.DomEventHook( | |
182 primaryButton, 'click', | |
183 this.onClicked_.bind(this, remoting.MessageDialog.Result.PRIMARY), | |
184 false) | |
185 ); | |
186 | |
187 if (opt_secondaryButton) { | |
188 this.eventHooks_.add(new base.DomEventHook( | |
189 opt_secondaryButton, 'click', | |
190 this.onClicked_.bind(this, remoting.MessageDialog.Result.SECONDARY), | |
191 false)); | |
192 } | |
193 | |
194 /** @private {base.Deferred} */ | |
195 this.deferred_ = null; | |
196 remoting.windowShape.registerClientUI(this); | |
197 }; | |
198 | |
199 remoting.Html5ModalDialog.prototype.dispose = function() { | |
200 base.dispose(this.eventHooks_); | |
201 remoting.windowShape.unregisterClientUI(this); | |
202 }; | |
203 | |
204 /** | |
205 * @return {Promise<remoting.MessageDialog.Result>} Promise that resolves with | |
206 * the button clicked. | |
207 */ | |
208 remoting.Html5ModalDialog.prototype.show = function() { | |
209 base.debug.assert(this.deferred_ === null); | |
210 this.deferred_ = new base.Deferred(); | |
211 this.dialog_.showModal(); | |
212 | |
213 remoting.windowShape.centerToDesktop(this.dialog_); | |
214 return this.deferred_.promise(); | |
215 }; | |
216 | |
217 /** @param {Event} e */ | |
218 remoting.Html5ModalDialog.prototype.onCancel_ = function(e) { | |
219 e.preventDefault(); | |
Jamie
2015/05/20 02:20:37
I'm not sure that a generic Html5ModalDialog class
kelvinp
2015/05/20 18:13:00
Done.
| |
220 }; | |
221 | |
222 /** | |
223 * @param {remoting.MessageDialog.Result} result | |
224 * @private | |
225 */ | |
226 remoting.Html5ModalDialog.prototype.onClicked_ = function(result) { | |
227 this.dialog_.close(); | |
228 this.deferred_.resolve(result); | |
229 this.deferred_ = null; | |
230 this.dispose(); | |
231 }; | |
232 | |
233 remoting.Html5ModalDialog.prototype.addToRegion = function(rects) { | |
234 var rect = /** @type {ClientRect} */(this.dialog_.getBoundingClientRect()); | |
235 rects.push({ | |
236 left: rect.left, | |
237 top: rect.top, | |
238 width: rect.width, | |
239 height: rect.height | |
240 }); | |
241 }; | |
242 | |
243 | |
161 /** | 244 /** |
162 * @param {Function} cancelCallback The callback to invoke when the user clicks | 245 * @param {Function} cancelCallback The callback to invoke when the user clicks |
163 * on the cancel button. | 246 * on the cancel button. |
164 * @constructor | 247 * @constructor |
165 */ | 248 */ |
166 remoting.ConnectingDialog = function(cancelCallback) { | 249 remoting.ConnectingDialog = function(cancelCallback) { |
167 /** @private */ | 250 /** @private */ |
168 this.dialog_ = new remoting.MessageDialog( | 251 this.dialog_ = new remoting.MessageDialog( |
169 remoting.AppMode.CLIENT_CONNECTING, | 252 remoting.AppMode.CLIENT_CONNECTING, |
170 document.getElementById('cancel-connect-button')); | 253 document.getElementById('cancel-connect-button')); |
(...skipping 18 matching lines...) Expand all Loading... | |
189 | 272 |
190 /** | 273 /** |
191 * Define the enum at the end of file as JSCompile doesn't understand enums that | 274 * Define the enum at the end of file as JSCompile doesn't understand enums that |
192 * are defined within an IIFE (Immediately Invoked Function Expression). | 275 * are defined within an IIFE (Immediately Invoked Function Expression). |
193 * @enum {number} | 276 * @enum {number} |
194 */ | 277 */ |
195 remoting.MessageDialog.Result = { | 278 remoting.MessageDialog.Result = { |
196 PRIMARY: 0, | 279 PRIMARY: 0, |
197 SECONDARY: 1 | 280 SECONDARY: 1 |
198 }; | 281 }; |
OLD | NEW |