OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 cr.define('cr.ui.dialogs', function() { | 5 cr.define('cr.ui.dialogs', function() { |
6 | 6 |
7 function BaseDialog(parentNode) { | 7 function BaseDialog(parentNode) { |
8 this.parentNode_ = parentNode; | 8 this.parentNode_ = parentNode; |
9 this.document_ = parentNode.ownerDocument; | 9 this.document_ = parentNode.ownerDocument; |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 * | 24 * |
25 * Clients should override these with localized labels. | 25 * Clients should override these with localized labels. |
26 */ | 26 */ |
27 BaseDialog.OK_LABEL = 'Ok'; | 27 BaseDialog.OK_LABEL = 'Ok'; |
28 BaseDialog.CANCEL_LABEL = 'Cancel'; | 28 BaseDialog.CANCEL_LABEL = 'Cancel'; |
29 | 29 |
30 /** | 30 /** |
31 * Number of miliseconds animation is expected to take, plus some margin for | 31 * Number of miliseconds animation is expected to take, plus some margin for |
32 * error. | 32 * error. |
33 */ | 33 */ |
34 BaseDialog.ANIMATION_STABLE_DURATION = 500; | 34 BaseDialog.ANIMATE_STABLE_DURATION = 500; |
35 | 35 |
36 BaseDialog.prototype.initDom_ = function() { | 36 BaseDialog.prototype.initDom_ = function() { |
37 var doc = this.document_; | 37 var doc = this.document_; |
38 this.container_ = doc.createElement('div'); | 38 this.container_ = doc.createElement('div'); |
39 this.container_.className = 'cr-dialog-container'; | 39 this.container_.className = 'cr-dialog-container'; |
40 this.container_.addEventListener('keydown', | 40 this.container_.addEventListener('keydown', |
41 this.onContainerKeyDown_.bind(this)); | 41 this.onContainerKeyDown_.bind(this)); |
42 | 42 |
43 this.frame_ = doc.createElement('div'); | 43 this.frame_ = doc.createElement('div'); |
44 this.frame_.className = 'cr-dialog-frame'; | 44 this.frame_.className = 'cr-dialog-frame'; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 this.onOk_ = onOk; | 116 this.onOk_ = onOk; |
117 this.onCancel_ = onCancel; | 117 this.onCancel_ = onCancel; |
118 | 118 |
119 this.text_.textContent = message; | 119 this.text_.textContent = message; |
120 | 120 |
121 var top = (this.document_.body.clientHeight - | 121 var top = (this.document_.body.clientHeight - |
122 this.frame_.clientHeight) / 2; | 122 this.frame_.clientHeight) / 2; |
123 var left = (this.document_.body.clientWidth - | 123 var left = (this.document_.body.clientWidth - |
124 this.frame_.clientWidth) / 2; | 124 this.frame_.clientWidth) / 2; |
125 | 125 |
| 126 // Disable transitions so that we can set the initial position of the |
| 127 // dialog right away. |
| 128 this.frame_.style.webkitTransitionProperty = ''; |
126 this.frame_.style.top = (top - 50) + 'px'; | 129 this.frame_.style.top = (top - 50) + 'px'; |
127 this.frame_.style.left = (left + 10) + 'px'; | 130 this.frame_.style.left = (left + 10) + 'px'; |
128 | 131 |
129 var self = this; | 132 var self = this; |
130 setTimeout(function () { | 133 setTimeout(function () { |
| 134 // Note that we control the opacity of the *container*, but the top/left |
| 135 // of the *frame*. |
| 136 self.container_.style.opacity = '1'; |
131 self.frame_.style.top = top + 'px'; | 137 self.frame_.style.top = top + 'px'; |
132 self.frame_.style.left = left + 'px'; | 138 self.frame_.style.left = left + 'px'; |
133 self.frame_.style.webkitTransitionProperty = 'left, top'; | 139 self.frame_.style.webkitTransitionProperty = 'left, top'; |
134 self.container_.style.opacity = '1'; | 140 self.initialFocusElement_.focus(); |
135 setTimeout(function() { | 141 setTimeout(function() { |
136 self.initialFocusElement_.focus(); | |
137 if (onShow) | 142 if (onShow) |
138 onShow(); | 143 onShow(); |
139 }, BaseDialog.ANIMATE_STABLE_DURATION); | 144 }, BaseDialog.ANIMATE_STABLE_DURATION); |
140 }, 0); | 145 }, 0); |
141 }; | 146 }; |
142 | 147 |
143 BaseDialog.prototype.hide = function(onHide) { | 148 BaseDialog.prototype.hide = function(onHide) { |
| 149 // Note that we control the opacity of the *container*, but the top/left |
| 150 // of the *frame*. |
144 this.container_.style.opacity = '0'; | 151 this.container_.style.opacity = '0'; |
145 this.frame_.style.top = (parseInt(this.frame_.style.top) + 50) + 'px'; | 152 this.frame_.style.top = (parseInt(this.frame_.style.top) + 50) + 'px'; |
146 this.frame_.style.left = (parseInt(this.frame_.style.left) - 10) + 'px'; | 153 this.frame_.style.left = (parseInt(this.frame_.style.left) - 10) + 'px'; |
147 | 154 |
148 if (this.previousActiveElement_) { | 155 if (this.previousActiveElement_) { |
149 this.previousActiveElement_.focus(); | 156 this.previousActiveElement_.focus(); |
150 } else { | 157 } else { |
151 this.document_.body.focus(); | 158 this.document_.body.focus(); |
152 } | 159 } |
153 | 160 |
154 var self = this; | 161 var self = this; |
155 setTimeout(function() { | 162 setTimeout(function() { |
156 // Wait until the transition is done before removing the dialog. | 163 // Wait until the transition is done before removing the dialog. |
157 self.parentNode_.removeChild(self.container_); | 164 self.parentNode_.removeChild(self.container_); |
158 self.frame_.style.webkitTransitionProperty = ''; | |
159 if (onHide) | 165 if (onHide) |
160 onHide(); | 166 onHide(); |
161 }, BaseDialog.ANIMATE_STABLE_DURATION); | 167 }, BaseDialog.ANIMATE_STABLE_DURATION); |
162 }; | 168 }; |
163 | 169 |
164 /** | 170 /** |
165 * AlertDialog contains just a message and an ok button. | 171 * AlertDialog contains just a message and an ok button. |
166 */ | 172 */ |
167 function AlertDialog(parentNode) { | 173 function AlertDialog(parentNode) { |
168 BaseDialog.apply(this, [parentNode]); | 174 BaseDialog.apply(this, [parentNode]); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 this.onOk_(this.getValue()); | 226 this.onOk_(this.getValue()); |
221 }; | 227 }; |
222 | 228 |
223 return { | 229 return { |
224 BaseDialog: BaseDialog, | 230 BaseDialog: BaseDialog, |
225 AlertDialog: AlertDialog, | 231 AlertDialog: AlertDialog, |
226 ConfirmDialog: ConfirmDialog, | 232 ConfirmDialog: ConfirmDialog, |
227 PromptDialog: PromptDialog | 233 PromptDialog: PromptDialog |
228 }; | 234 }; |
229 }); | 235 }); |
OLD | NEW |