Index: third_party/polymer/v0_8/components/iron-behaviors/iron-button-state.html |
diff --git a/third_party/polymer/v0_8/components/iron-behaviors/iron-button-state.html b/third_party/polymer/v0_8/components/iron-behaviors/iron-button-state.html |
index 803664266d1e50903f2512feac3f4f36b96d6364..bc7249a0939a74c84d943b7cf8f50f6711fe9739 100644 |
--- a/third_party/polymer/v0_8/components/iron-behaviors/iron-button-state.html |
+++ b/third_party/polymer/v0_8/components/iron-behaviors/iron-button-state.html |
@@ -1,4 +1,5 @@ |
<!-- |
+@license |
Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt |
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
@@ -8,11 +9,13 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN |
--> |
<link rel="import" href="../polymer/polymer.html"> |
+<link rel="import" href="../iron-a11y-keys-behavior/iron-a11y-keys-behavior.html"> |
<link rel="import" href="iron-control-state.html"> |
<script> |
- Polymer.IronButtonState = { |
+ /** @polymerBehavior Polymer.IronButtonState */ |
+ Polymer.IronButtonStateImpl = { |
properties: { |
@@ -26,6 +29,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN |
pressed: { |
type: Boolean, |
readOnly: true, |
+ value: false, |
reflectToAttribute: true, |
observer: '_pressedChanged' |
}, |
@@ -40,6 +44,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN |
*/ |
toggles: { |
type: Boolean, |
+ value: false, |
reflectToAttribute: true |
}, |
@@ -52,21 +57,49 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN |
*/ |
active: { |
type: Boolean, |
+ value: false, |
notify: true, |
reflectToAttribute: true, |
observer: '_activeChanged' |
- } |
+ }, |
+ |
+ /** |
+ * True if the element is currently being pressed by a "pointer," which |
+ * is loosely defined as mouse or touch input (but specifically excluding |
+ * keyboard input). |
+ */ |
+ pointerDown: { |
+ type: Boolean, |
+ readOnly: true, |
+ value: false |
+ }, |
+ /** |
+ * True if the input device that caused the element to receive focus |
+ * was a keyboard. |
+ */ |
+ receivedFocusFromKeyboard: { |
+ type: Boolean, |
+ readOnly: true |
+ } |
}, |
listeners: { |
- mousedown: '_downHandler', |
- mouseup: '_upHandler', |
- keydown: '_keyDownHandler', |
- keyup: '_keyUpHandler', |
+ down: '_downHandler', |
+ up: '_upHandler', |
tap: '_tapHandler' |
}, |
+ observers: [ |
+ '_detectKeyboardFocus(focused)' |
+ ], |
+ |
+ keyBindings: { |
+ 'enter:keydown': '_asyncClick', |
+ 'space:keydown': '_spaceKeyDownHandler', |
+ 'space:keyup': '_spaceKeyUpHandler', |
+ }, |
+ |
_tapHandler: function() { |
if (this.toggles) { |
// a tap is needed to toggle the active state |
@@ -76,6 +109,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN |
} |
}, |
+ _detectKeyboardFocus: function(focused) { |
+ this._setReceivedFocusFromKeyboard(!this.pointerDown && focused); |
+ }, |
+ |
// to emulate native checkbox, (de-)activations from a user interaction fire |
// 'change' events |
_userActivate: function(active) { |
@@ -84,33 +121,28 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN |
}, |
_downHandler: function() { |
+ this._setPointerDown(true); |
this._setPressed(true); |
+ this._setReceivedFocusFromKeyboard(false); |
}, |
- _upHandler: function(e) { |
+ _upHandler: function() { |
+ this._setPointerDown(false); |
this._setPressed(false); |
}, |
- _keyDownHandler: function(e) { |
- switch(e.keyCode) { |
- case this.keyCodes.ENTER_KEY: |
- this._asyncClick(); |
- break; |
- |
- case this.keyCodes.SPACE: |
- this._setPressed(true); |
- break; |
- |
- } |
+ _spaceKeyDownHandler: function(event) { |
+ var keyboardEvent = event.detail.keyboardEvent; |
+ keyboardEvent.preventDefault(); |
+ keyboardEvent.stopImmediatePropagation(); |
+ this._setPressed(true); |
}, |
- _keyUpHandler: function(e) { |
- if (e.keyCode == this.keyCodes.SPACE) { |
- if (this.pressed) { |
- this._asyncClick(); |
- } |
- this._setPressed(false); |
+ _spaceKeyUpHandler: function() { |
+ if (this.pressed) { |
+ this._asyncClick(); |
} |
+ this._setPressed(false); |
}, |
// trigger click asynchronously, the asynchrony is useful to allow one |
@@ -128,14 +160,17 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN |
}, |
_activeChanged: function(active) { |
- this.setAttribute('aria-pressed', active ? 'true' : 'false'); |
+ if (this.toggles) { |
+ this.setAttribute('aria-pressed', active ? 'true' : 'false'); |
+ } else { |
+ this.removeAttribute('aria-pressed'); |
+ } |
this._changedButtonState(); |
}, |
_controlStateChanged: function() { |
if (this.disabled) { |
this._setPressed(false); |
- this.active = false; |
} else { |
this._changedButtonState(); |
} |
@@ -151,4 +186,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN |
}; |
+ /** @polymerBehavior Polymer.IronButtonState */ |
+ Polymer.IronButtonState = [ |
+ Polymer.IronA11yKeysBehavior, |
+ Polymer.IronButtonStateImpl |
+ ]; |
+ |
</script> |