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 Polymer({ | 5 Polymer({ |
6 is: 'cr-action-menu', | 6 is: 'cr-action-menu', |
7 extends: 'dialog', | 7 extends: 'dialog', |
8 | 8 |
9 /** | 9 /** |
10 * List of all options in this action menu. | 10 * List of all options in this action menu. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 */ | 124 */ |
125 getNextOption_: function(step) { | 125 getNextOption_: function(step) { |
126 // Using a counter to ensure no infinite loop occurs if all elements are | 126 // Using a counter to ensure no infinite loop occurs if all elements are |
127 // hidden/disabled. | 127 // hidden/disabled. |
128 var counter = 0; | 128 var counter = 0; |
129 var nextOption = null; | 129 var nextOption = null; |
130 var numOptions = this.options_.length; | 130 var numOptions = this.options_.length; |
131 var focusedIndex = | 131 var focusedIndex = |
132 Array.prototype.indexOf.call(this.options_, this.root.activeElement); | 132 Array.prototype.indexOf.call(this.options_, this.root.activeElement); |
133 | 133 |
| 134 // Handle case where nothing is focused and up is pressed. |
| 135 if (focusedIndex === -1 && step === -1) |
| 136 focusedIndex = 0; |
| 137 |
134 do { | 138 do { |
135 focusedIndex = (numOptions + focusedIndex + step) % numOptions; | 139 focusedIndex = (numOptions + focusedIndex + step) % numOptions; |
136 nextOption = this.options_[focusedIndex]; | 140 nextOption = this.options_[focusedIndex]; |
137 if (nextOption.disabled || nextOption.hidden) | 141 if (nextOption.disabled || nextOption.hidden) |
138 nextOption = null; | 142 nextOption = null; |
139 counter++; | 143 counter++; |
140 } while (!nextOption && counter < numOptions); | 144 } while (!nextOption && counter < numOptions); |
141 | 145 |
142 return nextOption; | 146 return nextOption; |
143 }, | 147 }, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Attempt to show the menu starting from the top of the rectangle and | 187 // Attempt to show the menu starting from the top of the rectangle and |
184 // extending downwards. If that does not fit within the window, fallback to | 188 // extending downwards. If that does not fit within the window, fallback to |
185 // starting from the bottom and extending upwards. | 189 // starting from the bottom and extending upwards. |
186 var top = rect.top + this.offsetHeight <= window.innerHeight ? rect.top : | 190 var top = rect.top + this.offsetHeight <= window.innerHeight ? rect.top : |
187 rect.bottom - | 191 rect.bottom - |
188 this.offsetHeight - Math.max(rect.bottom - window.innerHeight, 0); | 192 this.offsetHeight - Math.max(rect.bottom - window.innerHeight, 0); |
189 | 193 |
190 this.style.top = top + 'px'; | 194 this.style.top = top + 'px'; |
191 }, | 195 }, |
192 }); | 196 }); |
OLD | NEW |