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 /** | 5 /** |
6 * @fileoverview Bubble implementation. | 6 * @fileoverview Bubble implementation. |
7 */ | 7 */ |
8 | 8 |
9 // TODO(xiyuan): Move this into shared. | 9 // TODO(xiyuan): Move this into shared. |
10 cr.define('cr.ui', function() { | 10 cr.define('cr.ui', function() { |
11 /** | 11 /** |
12 * Creates a bubble div. | 12 * Creates a bubble div. |
13 * @constructor | 13 * @constructor |
14 * @extends {HTMLDivElement} | 14 * @extends {HTMLDivElement} |
15 */ | 15 */ |
16 var Bubble = cr.ui.define('div'); | 16 var Bubble = cr.ui.define('div'); |
17 | 17 |
18 /** | 18 /** |
19 * Bubble key codes. | 19 * Bubble key codes. |
20 * @enum {number} | 20 * @enum {number} |
21 */ | 21 */ |
22 var KeyCodes = { | 22 var KeyCodes = { |
23 TAB: 'U+0009', | 23 TAB: 'Tab', |
24 ENTER: 'Enter', | 24 ENTER: 'Enter', |
25 ESC: 'U+001B', | 25 ESC: 'Escape', |
26 SPACE: 'U+0020' | 26 SPACE: ' ' |
27 }; | 27 }; |
28 | 28 |
29 /** | 29 /** |
30 * Bubble attachment side. | 30 * Bubble attachment side. |
31 * @enum {string} | 31 * @enum {string} |
32 */ | 32 */ |
33 Bubble.Attachment = { | 33 Bubble.Attachment = { |
34 RIGHT: 'bubble-right', | 34 RIGHT: 'bubble-right', |
35 LEFT: 'bubble-left', | 35 LEFT: 'bubble-left', |
36 TOP: 'bubble-top', | 36 TOP: 'bubble-top', |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 handleDocKeyDown_: function(e) { | 320 handleDocKeyDown_: function(e) { |
321 if (this.hidden) | 321 if (this.hidden) |
322 return; | 322 return; |
323 | 323 |
324 if (this.hideOnKeyPress_) { | 324 if (this.hideOnKeyPress_) { |
325 this.hide(); | 325 this.hide(); |
326 return; | 326 return; |
327 } | 327 } |
328 // Artificial tab-cycle. | 328 // Artificial tab-cycle. |
329 | 329 |
330 if (e.keyIdentifier == KeyCodes.TAB && e.shiftKey == true && | 330 if (e.key == KeyCodes.TAB && e.shiftKey == true && |
331 e.target == this.firstBubbleElement_) { | 331 e.target == this.firstBubbleElement_) { |
332 this.lastBubbleElement_.focus(); | 332 this.lastBubbleElement_.focus(); |
333 e.preventDefault(); | 333 e.preventDefault(); |
334 } | 334 } |
335 if (e.keyIdentifier == KeyCodes.TAB && e.shiftKey == false && | 335 if (e.key == KeyCodes.TAB && e.shiftKey == false && |
336 e.target == this.lastBubbleElement_) { | 336 e.target == this.lastBubbleElement_) { |
337 this.firstBubbleElement_.focus(); | 337 this.firstBubbleElement_.focus(); |
338 e.preventDefault(); | 338 e.preventDefault(); |
339 } | 339 } |
340 // Close bubble on ESC or on hitting spacebar or Enter at close-button. | 340 // Close bubble on ESC or on hitting spacebar or Enter at close-button. |
341 if (e.keyIdentifier == KeyCodes.ESC || | 341 if (e.key == KeyCodes.ESC || |
342 ((e.keyIdentifier == KeyCodes.ENTER || | 342 ((e.key == KeyCodes.ENTER || |
343 e.keyIdentifier == KeyCodes.SPACE) && | 343 e.key == KeyCodes.SPACE) && |
344 e.target && e.target.classList.contains('close-button'))) | 344 e.target && e.target.classList.contains('close-button'))) |
345 this.hide(); | 345 this.hide(); |
346 }, | 346 }, |
347 | 347 |
348 /** | 348 /** |
349 * Handler of window blur event. | 349 * Handler of window blur event. |
350 * @private | 350 * @private |
351 */ | 351 */ |
352 handleWindowBlur_: function(e) { | 352 handleWindowBlur_: function(e) { |
353 if (!this.hidden) | 353 if (!this.hidden) |
354 this.hide(); | 354 this.hide(); |
355 } | 355 } |
356 }; | 356 }; |
357 | 357 |
358 return { | 358 return { |
359 Bubble: Bubble | 359 Bubble: Bubble |
360 }; | 360 }; |
361 }); | 361 }); |
OLD | NEW |