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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Modal dialog base component. | 9 * Modal dialog base component. |
10 * @param {!print_preview.MetricsContext} metricsContext Metrics | 10 * @param {!print_preview.MetricsContext} metricsContext Metrics |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 this.getElement().addEventListener('webkitTransitionEnd', function f(e) { | 34 this.getElement().addEventListener('webkitTransitionEnd', function f(e) { |
35 if (e.target == e.currentTarget && e.propertyName == 'opacity' && | 35 if (e.target == e.currentTarget && e.propertyName == 'opacity' && |
36 e.target.classList.contains('transparent')) { | 36 e.target.classList.contains('transparent')) { |
37 setIsVisible(e.target, false); | 37 setIsVisible(e.target, false); |
38 } | 38 } |
39 }); | 39 }); |
40 | 40 |
41 this.getElement().addEventListener('keydown', function f(e) { | 41 this.getElement().addEventListener('keydown', function f(e) { |
42 // Escape pressed -> cancel the dialog. | 42 // Escape pressed -> cancel the dialog. |
43 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && | 43 if (!e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { |
44 !e.metaKey) { | 44 if (e.keyCode == 27) { |
45 e.stopPropagation(); | 45 e.stopPropagation(); |
46 e.preventDefault(); | 46 e.preventDefault(); |
47 this.cancel(); | 47 this.cancel(); |
| 48 } else if (e.keyCode == 13) { |
| 49 var activeElementTag = document.activeElement ? |
| 50 document.activeElement.tagName.toUpperCase() : ''; |
| 51 if (activeElementTag != 'BUTTON' && activeElementTag != 'SELECT') { |
| 52 if (this.onEnterPressedInternal()) { |
| 53 e.stopPropagation(); |
| 54 e.preventDefault(); |
| 55 } |
| 56 } |
| 57 } |
48 } | 58 } |
49 }.bind(this)); | 59 }.bind(this)); |
50 | 60 |
51 this.tracker.add( | 61 this.tracker.add( |
52 this.getChildElement('.page > .close-button'), | 62 this.getChildElement('.page > .close-button'), |
53 'click', | 63 'click', |
54 this.cancel.bind(this)); | 64 this.cancel.bind(this)); |
55 | 65 |
56 this.tracker.add( | 66 this.tracker.add( |
57 this.getElement(), 'click', this.onOverlayClick_.bind(this)); | 67 this.getElement(), 'click', this.onOverlayClick_.bind(this)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 /** | 100 /** |
91 * @param {boolean} isVisible Whether the component is visible. | 101 * @param {boolean} isVisible Whether the component is visible. |
92 * @protected | 102 * @protected |
93 */ | 103 */ |
94 onSetVisibleInternal: function(isVisible) {}, | 104 onSetVisibleInternal: function(isVisible) {}, |
95 | 105 |
96 /** @protected */ | 106 /** @protected */ |
97 onCancelInternal: function() {}, | 107 onCancelInternal: function() {}, |
98 | 108 |
99 /** | 109 /** |
| 110 * @return {boolean} Whether the event was handled. |
| 111 * @protected |
| 112 */ |
| 113 onEnterPressedInternal: function() { |
| 114 return false; |
| 115 }, |
| 116 |
| 117 /** |
100 * Called when the overlay is clicked. Pulses the page. | 118 * Called when the overlay is clicked. Pulses the page. |
101 * @param {Event} e Contains the element that was clicked. | 119 * @param {Event} e Contains the element that was clicked. |
102 * @private | 120 * @private |
103 */ | 121 */ |
104 onOverlayClick_: function(e) { | 122 onOverlayClick_: function(e) { |
105 if (e.target && e.target.classList.contains('overlay')) | 123 if (e.target && e.target.classList.contains('overlay')) |
106 e.target.querySelector('.page').classList.add('pulse'); | 124 e.target.querySelector('.page').classList.add('pulse'); |
107 }, | 125 }, |
108 | 126 |
109 /** | 127 /** |
110 * Called when an animation ends on the page. | 128 * Called when an animation ends on the page. |
111 * @param {Event} e Contains the target done animating. | 129 * @param {Event} e Contains the target done animating. |
112 * @private | 130 * @private |
113 */ | 131 */ |
114 onAnimationEnd_: function(e) { | 132 onAnimationEnd_: function(e) { |
115 if (e.target && e.animationName == 'pulse') | 133 if (e.target && e.animationName == 'pulse') |
116 e.target.classList.remove('pulse'); | 134 e.target.classList.remove('pulse'); |
117 } | 135 } |
118 }; | 136 }; |
119 | 137 |
120 // Export | 138 // Export |
121 return { | 139 return { |
122 Overlay: Overlay | 140 Overlay: Overlay |
123 }; | 141 }; |
124 }); | 142 }); |
OLD | NEW |