OLD | NEW |
1 /** | 1 /** |
2 * @demo demo/index.html | 2 * @demo demo/index.html |
3 * @polymerBehavior Polymer.IronButtonState | 3 * @polymerBehavior Polymer.IronButtonState |
4 */ | 4 */ |
5 Polymer.IronButtonStateImpl = { | 5 Polymer.IronButtonStateImpl = { |
6 | 6 |
7 properties: { | 7 properties: { |
8 | 8 |
9 /** | 9 /** |
10 * If true, the user is currently holding down the button. | 10 * If true, the user is currently holding down the button. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 this._setPointerDown(true); | 113 this._setPointerDown(true); |
114 this._setPressed(true); | 114 this._setPressed(true); |
115 this._setReceivedFocusFromKeyboard(false); | 115 this._setReceivedFocusFromKeyboard(false); |
116 }, | 116 }, |
117 | 117 |
118 _upHandler: function() { | 118 _upHandler: function() { |
119 this._setPointerDown(false); | 119 this._setPointerDown(false); |
120 this._setPressed(false); | 120 this._setPressed(false); |
121 }, | 121 }, |
122 | 122 |
123 __isFocusedLightDescendant: function(target) { | |
124 var root = Polymer.dom(this).getOwnerRoot() || document; | |
125 var focusedElement = root.activeElement; | |
126 | |
127 // TODO(noms): remove the `this !== target` check once polymer#2610 is fix
ed. | |
128 return this !== target && this.isLightDescendant(target) && target == focu
sedElement; | |
129 }, | |
130 | |
131 /** | 123 /** |
132 * @param {!KeyboardEvent} event . | 124 * @param {!KeyboardEvent} event . |
133 */ | 125 */ |
134 _spaceKeyDownHandler: function(event) { | 126 _spaceKeyDownHandler: function(event) { |
135 var keyboardEvent = event.detail.keyboardEvent; | 127 var keyboardEvent = event.detail.keyboardEvent; |
136 var target = Polymer.dom(keyboardEvent).localTarget; | 128 var target = Polymer.dom(keyboardEvent).localTarget; |
137 | 129 |
138 // Ignore the event if this is coming from a focused light child, since th
at | 130 // Ignore the event if this is coming from a focused light child, since th
at |
139 // element will deal with it. | 131 // element will deal with it. |
140 if (this.__isFocusedLightDescendant(target)) | 132 if (this.isLightDescendant(target)) |
141 return; | 133 return; |
142 | 134 |
143 keyboardEvent.preventDefault(); | 135 keyboardEvent.preventDefault(); |
144 keyboardEvent.stopImmediatePropagation(); | 136 keyboardEvent.stopImmediatePropagation(); |
145 this._setPressed(true); | 137 this._setPressed(true); |
146 }, | 138 }, |
147 | 139 |
148 /** | 140 /** |
149 * @param {!KeyboardEvent} event . | 141 * @param {!KeyboardEvent} event . |
150 */ | 142 */ |
151 _spaceKeyUpHandler: function(event) { | 143 _spaceKeyUpHandler: function(event) { |
152 var keyboardEvent = event.detail.keyboardEvent; | 144 var keyboardEvent = event.detail.keyboardEvent; |
153 var target = Polymer.dom(keyboardEvent).localTarget; | 145 var target = Polymer.dom(keyboardEvent).localTarget; |
154 | 146 |
155 // Ignore the event if this is coming from a focused light child, since th
at | 147 // Ignore the event if this is coming from a focused light child, since th
at |
156 // element will deal with it. | 148 // element will deal with it. |
157 if (this.__isFocusedLightDescendant(target)) | 149 if (this.isLightDescendant(target)) |
158 return; | 150 return; |
159 | 151 |
160 if (this.pressed) { | 152 if (this.pressed) { |
161 this._asyncClick(); | 153 this._asyncClick(); |
162 } | 154 } |
163 this._setPressed(false); | 155 this._setPressed(false); |
164 }, | 156 }, |
165 | 157 |
166 // trigger click asynchronously, the asynchrony is useful to allow one | 158 // trigger click asynchronously, the asynchrony is useful to allow one |
167 // event handler to unwind before triggering another event | 159 // event handler to unwind before triggering another event |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 } | 201 } |
210 } | 202 } |
211 | 203 |
212 }; | 204 }; |
213 | 205 |
214 /** @polymerBehavior */ | 206 /** @polymerBehavior */ |
215 Polymer.IronButtonState = [ | 207 Polymer.IronButtonState = [ |
216 Polymer.IronA11yKeysBehavior, | 208 Polymer.IronA11yKeysBehavior, |
217 Polymer.IronButtonStateImpl | 209 Polymer.IronButtonStateImpl |
218 ]; | 210 ]; |
OLD | NEW |