Service workers: Allow HTTPS pages arrived at via HTTP redirect to use SW
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components-chromium / iron-behaviors / iron-control-state-extracted.js
blobc00882f2f43ffc80c31f5bec89ece0af452ab38a
1 /**
2    * @demo demo/index.html
3    * @polymerBehavior
4    */
5   Polymer.IronControlState = {
7     properties: {
9       /**
10        * If true, the element currently has focus.
11        */
12       focused: {
13         type: Boolean,
14         value: false,
15         notify: true,
16         readOnly: true,
17         reflectToAttribute: true
18       },
20       /**
21        * If true, the user cannot interact with this element.
22        */
23       disabled: {
24         type: Boolean,
25         value: false,
26         notify: true,
27         observer: '_disabledChanged',
28         reflectToAttribute: true
29       },
31       _oldTabIndex: {
32         type: Number
33       },
35       _boundFocusBlurHandler: {
36         type: Function,
37         value: function() {
38           return this._focusBlurHandler.bind(this);
39         }
40       }
42     },
44     observers: [
45       '_changedControlState(focused, disabled)'
46     ],
48     ready: function() {
49       this.addEventListener('focus', this._boundFocusBlurHandler, true);
50       this.addEventListener('blur', this._boundFocusBlurHandler, true);
51     },
53     _focusBlurHandler: function(event) {
54       var target = event.path ? event.path[0] : event.target;
55       if (target === this) {
56         var focused = event.type === 'focus';
57         this._setFocused(focused);
58       } else if (!this.shadowRoot) {
59         this.fire(event.type, {sourceEvent: event}, {
60           node: this,
61           bubbles: event.bubbles,
62           cancelable: event.cancelable
63         });
64       }
65     },
67     _disabledChanged: function(disabled, old) {
68       this.setAttribute('aria-disabled', disabled ? 'true' : 'false');
69       this.style.pointerEvents = disabled ? 'none' : '';
70       if (disabled) {
71         this._oldTabIndex = this.tabIndex;
72         this.focused = false;
73         this.tabIndex = -1;
74       } else if (this._oldTabIndex !== undefined) {
75         this.tabIndex = this._oldTabIndex;
76       }
77     },
79     _changedControlState: function() {
80       // _controlStateChanged is abstract, follow-on behaviors may implement it
81       if (this._controlStateChanged) {
82         this._controlStateChanged();
83       }
84     }
86   };