Chromium Code Reviews| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * The last focusable child in the menu's light DOM. | 108 * The last focusable child in the menu's light DOM. |
| 109 * @private {?Element} | 109 * @private {?Element} |
| 110 */ | 110 */ |
| 111 lastFocus_: null, | 111 lastFocus_: null, |
| 112 | 112 |
| 113 /** @override */ | 113 /** @override */ |
| 114 attached: function() { | 114 attached: function() { |
| 115 window.addEventListener('resize', this.closeMenu.bind(this)); | 115 window.addEventListener('resize', this.closeMenu.bind(this)); |
| 116 | |
| 117 var focusableChildren = Polymer.dom(this).querySelectorAll( | |
| 118 '[tabindex],button'); | |
| 119 if (focusableChildren.length > 0) { | |
| 120 this.$.dropdown.focusTarget = focusableChildren[0]; | |
| 121 this.firstFocus_ = focusableChildren[0]; | |
| 122 this.lastFocus_ = focusableChildren[focusableChildren.length - 1]; | |
| 123 } | |
| 124 }, | 116 }, |
| 125 | 117 |
| 126 /** Closes the menu. */ | 118 /** Closes the menu. */ |
| 127 closeMenu: function() { | 119 closeMenu: function() { |
| 128 if (this.root.activeElement == null) { | 120 if (this.root.activeElement == null) { |
| 129 // Something else has taken focus away from the menu. Do not attempt to | 121 // Something else has taken focus away from the menu. Do not attempt to |
| 130 // restore focus to the button which opened the menu. | 122 // restore focus to the button which opened the menu. |
| 131 this.$.dropdown.restoreFocusOnClose = false; | 123 this.$.dropdown.restoreFocusOnClose = false; |
| 132 } | 124 } |
| 133 this.menuOpen = false; | 125 this.menuOpen = false; |
| 134 this.$.dropdown.restoreFocusOnClose = true; | 126 this.$.dropdown.restoreFocusOnClose = true; |
| 135 }, | 127 }, |
| 136 | 128 |
| 137 /** | 129 /** |
| 138 * Opens the menu at the anchor location. | 130 * Opens the menu at the anchor location. |
| 139 * @param {!Element} anchor The location to display the menu. | 131 * @param {!Element} anchor The location to display the menu. |
| 140 * @param {!Object} itemData The contextual item's data. | 132 * @param {!Object} itemData The contextual item's data. |
| 141 */ | 133 */ |
| 142 openMenu: function(anchor, itemData) { | 134 openMenu: function(anchor, itemData) { |
| 143 this.itemData = itemData; | 135 this.itemData = itemData; |
| 144 this.lastAnchor_ = anchor; | 136 this.lastAnchor_ = anchor; |
| 145 | 137 |
| 138 var focusableChildren = Polymer.dom(this).querySelectorAll( | |
| 139 '[tabindex]:not([hidden]),button:not([hidden])'); | |
|
Dan Beam
2016/07/14 17:09:20
and it starts growing
tsergeant
2016/07/15 01:17:48
https://www.youtube.com/watch?v=bWcASV2sey0
https
| |
| 140 if (focusableChildren.length > 0) { | |
| 141 this.$.dropdown.focusTarget = focusableChildren[0]; | |
| 142 this.firstFocus_ = focusableChildren[0]; | |
| 143 this.lastFocus_ = focusableChildren[focusableChildren.length - 1]; | |
| 144 } | |
| 145 | |
| 146 // Move the menu to the anchor. | 146 // Move the menu to the anchor. |
| 147 this.$.dropdown.positionTarget = anchor; | 147 this.$.dropdown.positionTarget = anchor; |
| 148 this.menuOpen = true; | 148 this.menuOpen = true; |
| 149 }, | 149 }, |
| 150 | 150 |
| 151 /** | 151 /** |
| 152 * Toggles the menu for the anchor that is passed in. | 152 * Toggles the menu for the anchor that is passed in. |
| 153 * @param {!Element} anchor The location to display the menu. | 153 * @param {!Element} anchor The location to display the menu. |
| 154 * @param {!Object} itemData The contextual item's data. | 154 * @param {!Object} itemData The contextual item's data. |
| 155 */ | 155 */ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 /** | 188 /** |
| 189 * Ensure the menu is reset properly when it is closed by the dropdown (eg, | 189 * Ensure the menu is reset properly when it is closed by the dropdown (eg, |
| 190 * clicking outside). | 190 * clicking outside). |
| 191 * @private | 191 * @private |
| 192 */ | 192 */ |
| 193 menuOpenChanged_: function() { | 193 menuOpenChanged_: function() { |
| 194 if (!this.menuOpen) | 194 if (!this.menuOpen) |
| 195 this.itemData = null; | 195 this.itemData = null; |
| 196 }, | 196 }, |
| 197 }); | 197 }); |
| OLD | NEW |