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

Side by Side Diff: ui/webui/resources/js/cr/ui/focus_row.js

Issue 2749513004: MD Settings: adjust iron-list focus row behaviors. (Closed)
Patch Set: add tests for new focusRowBehavior Created 3 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 cr.define('cr.ui', function() { 5 cr.define('cr.ui', function() {
6 /** 6 /**
7 * A class to manage focus between given horizontally arranged elements. 7 * A class to manage focus between given horizontally arranged elements.
8 * 8 *
9 * Pressing left cycles backward and pressing right cycles forward in item 9 * Pressing left cycles backward and pressing right cycles forward in item
10 * order. Pressing Home goes to the beginning of the list and End goes to the 10 * order. Pressing Home goes to the beginning of the list and End goes to the
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 * Example: an (X) button might be 'delete' or 'close'. 98 * Example: an (X) button might be 'delete' or 'close'.
99 * 99 *
100 * When FocusRow is used within a FocusGrid, these types are used to 100 * When FocusRow is used within a FocusGrid, these types are used to
101 * determine equivalent controls when Up/Down are pressed to change rows. 101 * determine equivalent controls when Up/Down are pressed to change rows.
102 * 102 *
103 * Another example: mutually exclusive controls that hide eachother on 103 * Another example: mutually exclusive controls that hide eachother on
104 * activation (i.e. Play/Pause) could use the same type (i.e. 'play-pause') 104 * activation (i.e. Play/Pause) could use the same type (i.e. 'play-pause')
105 * to indicate they're equivalent. 105 * to indicate they're equivalent.
106 * 106 *
107 * @param {string} type The type of element to track focus of. 107 * @param {string} type The type of element to track focus of.
108 * @param {string} query The selector of the element from this row's root. 108 * @param {string|HTMLElement} query The selector of the element from this
hcarmona 2017/03/16 21:31:54 nit: rename |query| to |selector|
scottchen 2017/03/17 21:26:59 good idea, wasn't sure what to name it.
109 * row's root, or the element itself.
109 * @return {boolean} Whether a new item was added. 110 * @return {boolean} Whether a new item was added.
110 */ 111 */
111 addItem: function(type, query) { 112 addItem: function(type, query) {
112 assert(type); 113 assert(type);
113 114
114 var element = this.root.querySelector(query); 115 var element;
116 if (query instanceof HTMLElement)
117 element = query;
118 else
119 element = this.root.querySelector(/** @type {string} */ (query));
115 if (!element) 120 if (!element)
116 return false; 121 return false;
117 122
118 element.setAttribute('focus-type', type); 123 element.setAttribute('focus-type', type);
119 element.tabIndex = this.isActive() ? 0 : -1; 124 element.tabIndex = this.isActive() ? 0 : -1;
120 125
121 this.eventTracker.add(element, 'blur', this.onBlur_.bind(this)); 126 this.eventTracker.add(element, 'blur', this.onBlur_.bind(this));
122 this.eventTracker.add(element, 'focus', this.onFocus_.bind(this)); 127 this.eventTracker.add(element, 'focus', this.onFocus_.bind(this));
123 this.eventTracker.add(element, 'keydown', this.onKeydown_.bind(this)); 128 this.eventTracker.add(element, 'keydown', this.onKeydown_.bind(this));
124 this.eventTracker.add(element, 'mousedown', this.onMousedown_.bind(this)); 129 this.eventTracker.add(element, 'mousedown', this.onMousedown_.bind(this));
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 this.getEquivalentElement(elementToFocus).focus(); 289 this.getEquivalentElement(elementToFocus).focus();
285 e.preventDefault(); 290 e.preventDefault();
286 } 291 }
287 }, 292 },
288 }; 293 };
289 294
290 return { 295 return {
291 FocusRow: FocusRow, 296 FocusRow: FocusRow,
292 }; 297 };
293 }); 298 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698