Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js

Issue 2803543003: WebUI: fix cr-action-menu keyboard off-by-one issue (Closed)
Patch Set: merge Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/webui/cr_elements/cr_action_menu_test.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/cr_elements/cr_action_menu_test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698