| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** Same as paper-menu-button's custom easing cubic-bezier param. */ | 5 /** Same as paper-menu-button's custom easing cubic-bezier param. */ |
| 6 var SLIDE_CUBIC_BEZIER = 'cubic-bezier(0.3, 0.95, 0.5, 1)'; | 6 var SLIDE_CUBIC_BEZIER = 'cubic-bezier(0.3, 0.95, 0.5, 1)'; |
| 7 | 7 |
| 8 Polymer({ | 8 Polymer({ |
| 9 is: 'cr-shared-menu', | 9 is: 'cr-shared-menu', |
| 10 | 10 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 86 }]; | 86 }]; |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 }, | 89 }, |
| 90 | 90 |
| 91 keyBindings: { | 91 keyBindings: { |
| 92 'tab': 'onTabPressed_', | 92 'tab': 'onTabPressed_', |
| 93 }, | 93 }, |
| 94 | 94 |
| 95 listeners: { |
| 96 'dropdown.iron-overlay-canceled': 'onOverlayCanceled_', |
| 97 }, |
| 98 |
| 95 /** | 99 /** |
| 96 * The last anchor that was used to open a menu. It's necessary for toggling. | 100 * The last anchor that was used to open a menu. It's necessary for toggling. |
| 97 * @private {?Element} | 101 * @private {?Element} |
| 98 */ | 102 */ |
| 99 lastAnchor_: null, | 103 lastAnchor_: null, |
| 100 | 104 |
| 101 /** | 105 /** |
| 102 * The first focusable child in the menu's light DOM. | 106 * The first focusable child in the menu's light DOM. |
| 103 * @private {?Element} | 107 * @private {?Element} |
| 104 */ | 108 */ |
| (...skipping 22 matching lines...) Expand all Loading... |
| 127 }, | 131 }, |
| 128 | 132 |
| 129 /** | 133 /** |
| 130 * Opens the menu at the anchor location. | 134 * Opens the menu at the anchor location. |
| 131 * @param {!Element} anchor The location to display the menu. | 135 * @param {!Element} anchor The location to display the menu. |
| 132 * @param {!Object} itemData The contextual item's data. | 136 * @param {!Object} itemData The contextual item's data. |
| 133 */ | 137 */ |
| 134 openMenu: function(anchor, itemData) { | 138 openMenu: function(anchor, itemData) { |
| 135 this.itemData = itemData; | 139 this.itemData = itemData; |
| 136 this.lastAnchor_ = anchor; | 140 this.lastAnchor_ = anchor; |
| 141 this.$.dropdown.restoreFocusOnClose = true; |
| 137 | 142 |
| 138 var focusableChildren = Polymer.dom(this).querySelectorAll( | 143 var focusableChildren = Polymer.dom(this).querySelectorAll( |
| 139 '[tabindex]:not([hidden]),button:not([hidden])'); | 144 '[tabindex]:not([hidden]),button:not([hidden])'); |
| 140 if (focusableChildren.length > 0) { | 145 if (focusableChildren.length > 0) { |
| 141 this.$.dropdown.focusTarget = focusableChildren[0]; | 146 this.$.dropdown.focusTarget = focusableChildren[0]; |
| 142 this.firstFocus_ = focusableChildren[0]; | 147 this.firstFocus_ = focusableChildren[0]; |
| 143 this.lastFocus_ = focusableChildren[focusableChildren.length - 1]; | 148 this.lastFocus_ = focusableChildren[focusableChildren.length - 1]; |
| 144 } | 149 } |
| 145 | 150 |
| 146 // Move the menu to the anchor. | 151 // Move the menu to the anchor. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 192 |
| 188 /** | 193 /** |
| 189 * Ensure the menu is reset properly when it is closed by the dropdown (eg, | 194 * Ensure the menu is reset properly when it is closed by the dropdown (eg, |
| 190 * clicking outside). | 195 * clicking outside). |
| 191 * @private | 196 * @private |
| 192 */ | 197 */ |
| 193 menuOpenChanged_: function() { | 198 menuOpenChanged_: function() { |
| 194 if (!this.menuOpen) | 199 if (!this.menuOpen) |
| 195 this.itemData = null; | 200 this.itemData = null; |
| 196 }, | 201 }, |
| 202 |
| 203 /** |
| 204 * Prevent focus restoring when tapping outside the menu. This stops the |
| 205 * focus moving around unexpectedly when closing the menu with the mouse. |
| 206 * @param {CustomEvent} e |
| 207 * @private |
| 208 */ |
| 209 onOverlayCanceled_: function(e) { |
| 210 if (e.detail.type == 'tap') |
| 211 this.$.dropdown.restoreFocusOnClose = false; |
| 212 }, |
| 197 }); | 213 }); |
| OLD | NEW |