OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 'use strict'; | |
6 | |
7 /** @suppress {duplicate} */ | 5 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 6 var remoting = remoting || {}; |
9 | 7 |
8 (function() { | |
9 | |
10 'use strict'; | |
11 | |
12 var instance_ = null; | |
13 | |
10 /** | 14 /** |
11 * @constructor | 15 * @constructor |
12 * @implements {remoting.WindowShape.ClientUI} | 16 * @implements {remoting.WindowShape.ClientUI} |
13 * @param {HTMLElement} element The dialog DOM element. | 17 * @param {HTMLElement} rootElement The dialog DOM element. |
18 * @private | |
14 */ | 19 */ |
15 remoting.AuthDialog = function(element) { | 20 remoting.AuthDialog = function(rootElement) { |
16 /** | 21 /** |
17 * @type {HTMLElement} | 22 * @type {HTMLElement} |
18 * @private | 23 * @private |
19 */ | 24 */ |
20 this.element_ = element; | 25 this.rootElement_ = rootElement; |
26 | |
27 /** | |
28 * @type {HTMLElement} | |
29 * @private | |
30 */ | |
31 this.borderElement_ = rootElement.querySelector('#auth-dialog-border'); | |
Jamie
2015/01/28 20:52:09
In general, I like this model of using querySelect
kelvinp
2015/01/29 01:05:34
That's exactly my motivation of the change. I tri
Jamie
2015/01/29 01:52:34
Acknowledged.
| |
32 | |
33 /** | |
34 * @type {HTMLElement} | |
35 * @private | |
36 */ | |
37 this.authButton_ = rootElement.querySelector('#auth-button'); | |
38 | |
39 /** | |
40 * @type {base.Deferred} | |
Jamie
2015/01/28 20:52:09
Unrelated to this CL: Whenever I see base.Deferred
kelvinp
2015/01/29 01:05:34
Acknowledged. Deferred is actually a standard name
| |
41 * @private | |
42 */ | |
43 this.onAuthButtonDeferred_ = null; | |
44 | |
45 this.authButton_.addEventListener('click', this.onClick_.bind(this), false); | |
46 remoting.windowShape.addCallback(this); | |
21 }; | 47 }; |
22 | 48 |
23 /** | 49 /** |
24 * @param {Array.<{left: number, top: number, width: number, height: number}>} | 50 * @param {Array.<{left: number, top: number, width: number, height: number}>} |
25 * rects List of rectangles. | 51 * rects List of rectangles. |
26 */ | 52 */ |
27 remoting.AuthDialog.prototype.addToRegion = function(rects) { | 53 remoting.AuthDialog.prototype.addToRegion = function(rects) { |
28 var rect = /** @type {ClientRect} */(this.element_.getBoundingClientRect()); | 54 var rect = |
55 /** @type {ClientRect} */(this.borderElement_.getBoundingClientRect()); | |
29 rects.push({left: rect.left, | 56 rects.push({left: rect.left, |
30 top: rect.top, | 57 top: rect.top, |
31 width: rect.width, | 58 width: rect.width, |
32 height: rect.height}); | 59 height: rect.height}); |
33 } | 60 }; |
34 | 61 |
35 /** @type {remoting.AuthDialog} */ | 62 /** @private */ |
36 remoting.authDialog = null; | 63 remoting.AuthDialog.prototype.onClick_ = function() { |
64 this.rootElement_.hidden = true; | |
65 this.onAuthButtonDeferred_.resolve(); | |
Jamie
2015/01/28 20:52:09
Maybe assert that the deferred object is non-null
kelvinp
2015/01/29 01:05:35
Done. I will assert null in show(). However, I d
| |
66 this.onAuthButtonDeferred_ = null; | |
67 remoting.windowShape.updateClientWindowShape(); | |
68 }; | |
69 | |
70 /** | |
71 * @return {Promise} A Promise object that resolves when the user clicks on the | |
72 * auth button. | |
73 */ | |
74 remoting.AuthDialog.prototype.show = function() { | |
75 base.debug.assert(!this.isVisible()); | |
76 this.rootElement_.hidden = false; | |
77 this.onAuthButtonDeferred_ = new base.Deferred(); | |
78 return this.onAuthButtonDeferred_.promise(); | |
79 }; | |
80 | |
81 /** | |
82 * @return {boolean} whether the auth dialog is visible or not. | |
83 */ | |
84 remoting.AuthDialog.prototype.isVisible = function() { | |
85 return !this.rootElement_.hidden; | |
86 }; | |
87 | |
88 /** | |
89 * @return {Promise} A Promise object that resolves when the user clicks on the | |
90 * auth button. | |
91 */ | |
92 remoting.AuthDialog.show = function() { | |
Jamie
2015/01/28 20:52:09
Having both a static and a non-static show() metho
kelvinp
2015/01/29 01:05:34
Done.
| |
93 if (!instance_) { | |
94 var rootElement = document.getElementById('auth-dialog'); | |
95 instance_ = new remoting.AuthDialog(rootElement); | |
96 } | |
97 | |
98 if (instance_.isVisible()) { | |
99 return Promise.reject('Auth dialog is already showing.'); | |
100 } | |
101 | |
102 return instance_.show(); | |
103 }; | |
104 | |
105 })(); | |
OLD | NEW |