3
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
Code distributed by Google as part of the polymer project is also
8
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11
<link rel="import" href="../polymer/polymer.html">
16
* @demo demo/index.html
19
Polymer.IronControlState = {
24
* If true, the element currently has focus.
31
reflectToAttribute: true
35
* If true, the user cannot interact with this element.
41
observer: '_disabledChanged',
42
reflectToAttribute: true
49
_boundFocusBlurHandler: {
52
return this._focusBlurHandler.bind(this);
59
'_changedControlState(focused, disabled)'
63
this.addEventListener('focus', this._boundFocusBlurHandler, true);
64
this.addEventListener('blur', this._boundFocusBlurHandler, true);
67
_focusBlurHandler: function(event) {
68
// NOTE(cdata): if we are in ShadowDOM land, `event.target` will
69
// eventually become `this` due to retargeting; if we are not in
70
// ShadowDOM land, `event.target` will eventually become `this` due
71
// to the second conditional which fires a synthetic event (that is also
72
// handled). In either case, we can disregard `event.path`.
74
if (event.target === this) {
75
this._setFocused(event.type === 'focus');
76
} else if (!this.shadowRoot && !this.isLightDescendant(event.target)) {
77
this.fire(event.type, {sourceEvent: event}, {
79
bubbles: event.bubbles,
80
cancelable: event.cancelable
85
_disabledChanged: function(disabled, old) {
86
this.setAttribute('aria-disabled', disabled ? 'true' : 'false');
87
this.style.pointerEvents = disabled ? 'none' : '';
89
this._oldTabIndex = this.tabIndex;
93
} else if (this._oldTabIndex !== undefined) {
94
this.tabIndex = this._oldTabIndex;
98
_changedControlState: function() {
99
// _controlStateChanged is abstract, follow-on behaviors may implement it
100
if (this._controlStateChanged) {
101
this._controlStateChanged();