Chromium Code Reviews| 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 // require: event_tracker.js | 5 // require: event_tracker.js |
| 6 | 6 |
| 7 cr.define('cr.ui', function() { | 7 cr.define('cr.ui', function() { |
| 8 | 8 |
| 9 // The arrow location specifies how the arrow and bubble are positioned in | 9 // The arrow location specifies how the arrow and bubble are positioned in |
| 10 // relation to the anchor node. | 10 // relation to the anchor node. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * Handles close event which is triggered when the close button | 85 * Handles close event which is triggered when the close button |
| 86 * is clicked. By default is set to this.hide. | 86 * is clicked. By default is set to this.hide. |
| 87 * @param {function} A function with no parameters | 87 * @param {function} A function with no parameters |
| 88 */ | 88 */ |
| 89 set handleCloseEvent(func) { | 89 set handleCloseEvent(func) { |
| 90 this.handleCloseEvent_ = func; | 90 this.handleCloseEvent_ = func; |
| 91 }, | 91 }, |
| 92 | 92 |
| 93 captureFocus_: true, | |
|
Evan Stade
2011/11/14 19:20:52
meh, you can probably just assume this should alwa
Dan Beam
2011/11/15 04:15:10
Done.
| |
| 94 | |
| 95 /** | |
| 96 * Tells the bubble whether it should attempt to capture focus like native | |
| 97 * dialog UI (i.e. wrench menu). | |
| 98 * @param {boolean} capture Whether or not to capture focus. | |
| 99 */ | |
| 100 set captureFocus(capture) { | |
| 101 this.captureFocus_ = !!capture; | |
| 102 }, | |
| 103 | |
| 93 /** | 104 /** |
| 94 * Sets the anchor node, i.e. the node that this bubble points at. | 105 * Sets the anchor node, i.e. the node that this bubble points at. |
| 95 * @param {HTMLElement} node The new anchor node. | 106 * @param {HTMLElement} node The new anchor node. |
| 96 */ | 107 */ |
| 97 set anchorNode(node) { | 108 set anchorNode(node) { |
| 98 this.anchorNode_ = node; | 109 this.anchorNode_ = node; |
| 99 | 110 |
| 100 if (!this.hidden) | 111 if (!this.hidden) |
| 101 this.reposition(); | 112 this.reposition(); |
| 102 }, | 113 }, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 anchorMid - ARROW_OFFSET_X; | 177 anchorMid - ARROW_OFFSET_X; |
| 167 } | 178 } |
| 168 var top = this.isTop_ ? clientRect.bottom + ARROW_OFFSET_Y : | 179 var top = this.isTop_ ? clientRect.bottom + ARROW_OFFSET_Y : |
| 169 clientRect.top - this.clientHeight - ARROW_OFFSET_Y; | 180 clientRect.top - this.clientHeight - ARROW_OFFSET_Y; |
| 170 | 181 |
| 171 this.style.left = left + 'px'; | 182 this.style.left = left + 'px'; |
| 172 this.style.top = top + 'px'; | 183 this.style.top = top + 'px'; |
| 173 }, | 184 }, |
| 174 | 185 |
| 175 /** | 186 /** |
| 176 * Starts showing the bubble. The bubble will grab input and show until the | 187 * Starts showing the bubble. The bubble will grab input and show until the |
|
Evan Stade
2011/11/14 19:20:52
also remove the "grab input" part of this comment
Dan Beam
2011/11/15 04:15:10
Done.
| |
| 177 * user clicks away. | 188 * user clicks away. |
| 178 */ | 189 */ |
| 179 show: function() { | 190 show: function() { |
| 180 if (!this.hidden) | 191 if (!this.hidden) |
| 181 return; | 192 return; |
| 182 | 193 |
| 183 document.body.appendChild(this); | 194 document.body.appendChild(this); |
| 184 this.hidden = false; | 195 this.hidden = false; |
| 185 this.reposition(); | 196 this.reposition(); |
| 186 this.showTime_ = Date.now(); | 197 this.showTime_ = Date.now(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 } else if (!this.contains(e.target)) { | 231 } else if (!this.contains(e.target)) { |
| 221 if (Date.now() - this.showTime_ < this.deactivateToDismissDelay_) | 232 if (Date.now() - this.showTime_ < this.deactivateToDismissDelay_) |
| 222 return; | 233 return; |
| 223 this.hide(); | 234 this.hide(); |
| 224 } else { | 235 } else { |
| 225 return; | 236 return; |
| 226 } | 237 } |
| 227 break; | 238 break; |
| 228 } | 239 } |
| 229 | 240 |
| 230 e.stopPropagation(); | 241 if (this.captureFocus_) { |
| 231 e.preventDefault(); | 242 e.stopPropagation(); |
| 243 e.preventDefault(); | |
| 244 } | |
| 245 | |
| 232 return; | 246 return; |
| 233 }, | 247 }, |
| 234 }; | 248 }; |
| 235 | 249 |
| 236 return { | 250 return { |
| 237 ArrowLocation : ArrowLocation, | 251 ArrowLocation : ArrowLocation, |
| 238 Bubble : Bubble, | 252 Bubble : Bubble, |
| 239 BubbleAlignment : BubbleAlignment | 253 BubbleAlignment : BubbleAlignment |
| 240 }; | 254 }; |
| 241 }); | 255 }); |
| OLD | NEW |