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

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

Issue 2603443002: Clang format JS: Disallow single line functions, conditionals, loops, and switch statements (Closed)
Patch Set: update c/b/r/ as well Created 3 years, 12 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 grid of focusable elements in a 2D grid. For example, 7 * A class to manage grid of focusable elements in a 2D grid. For example,
8 * given this grid: 8 * given this grid:
9 * 9 *
10 * focusable [focused] focusable (row: 0, col: 1) 10 * focusable [focused] focusable (row: 0, col: 1)
(...skipping 25 matching lines...) Expand all
36 /** @private {boolean} */ 36 /** @private {boolean} */
37 ignoreFocusChange_: false, 37 ignoreFocusChange_: false,
38 38
39 /** @override */ 39 /** @override */
40 onFocus: function(row, e) { 40 onFocus: function(row, e) {
41 if (this.ignoreFocusChange_) 41 if (this.ignoreFocusChange_)
42 this.ignoreFocusChange_ = false; 42 this.ignoreFocusChange_ = false;
43 else 43 else
44 this.lastFocused_ = e.currentTarget; 44 this.lastFocused_ = e.currentTarget;
45 45
46 this.rows.forEach(function(r) { r.makeActive(r == row); }); 46 this.rows.forEach(function(r) {
47 r.makeActive(r == row);
48 });
47 }, 49 },
48 50
49 /** @override */ 51 /** @override */
50 onKeydown: function(row, e) { 52 onKeydown: function(row, e) {
51 var rowIndex = this.rows.indexOf(row); 53 var rowIndex = this.rows.indexOf(row);
52 assert(rowIndex >= 0); 54 assert(rowIndex >= 0);
53 55
54 var newRow = -1; 56 var newRow = -1;
55 57
56 if (e.key == 'ArrowUp') 58 if (e.key == 'ArrowUp')
(...skipping 13 matching lines...) Expand all
70 return true; 72 return true;
71 } 73 }
72 74
73 return false; 75 return false;
74 }, 76 },
75 77
76 /** 78 /**
77 * Unregisters event handlers and removes all |this.rows|. 79 * Unregisters event handlers and removes all |this.rows|.
78 */ 80 */
79 destroy: function() { 81 destroy: function() {
80 this.rows.forEach(function(row) { row.destroy(); }); 82 this.rows.forEach(function(row) {
83 row.destroy();
84 });
81 this.rows.length = 0; 85 this.rows.length = 0;
82 }, 86 },
83 87
84 /** 88 /**
85 * @param {!Element} target A target item to find in this grid. 89 * @param {!Element} target A target item to find in this grid.
86 * @return {number} The row index. -1 if not found. 90 * @return {number} The row index. -1 if not found.
87 */ 91 */
88 getRowIndexForTarget: function(target) { 92 getRowIndexForTarget: function(target) {
89 for (var i = 0; i < this.rows.length; ++i) { 93 for (var i = 0; i < this.rows.length; ++i) {
90 if (this.rows[i].getElements().indexOf(target) >= 0) 94 if (this.rows[i].getElements().indexOf(target) >= 0)
(...skipping 11 matching lines...) Expand all
102 if (this.rows[i].root == root) 106 if (this.rows[i].root == root)
103 return this.rows[i]; 107 return this.rows[i];
104 } 108 }
105 return null; 109 return null;
106 }, 110 },
107 111
108 /** 112 /**
109 * Adds |row| to the end of this list. 113 * Adds |row| to the end of this list.
110 * @param {!cr.ui.FocusRow} row The row that needs to be added to this grid. 114 * @param {!cr.ui.FocusRow} row The row that needs to be added to this grid.
111 */ 115 */
112 addRow: function(row) { this.addRowBefore(row, null); }, 116 addRow: function(row) {
117 this.addRowBefore(row, null);
118 },
113 119
114 /** 120 /**
115 * Adds |row| before |nextRow|. If |nextRow| is not in the list or it's 121 * Adds |row| before |nextRow|. If |nextRow| is not in the list or it's
116 * null, |row| is added to the end. 122 * null, |row| is added to the end.
117 * @param {!cr.ui.FocusRow} row The row that needs to be added to this grid. 123 * @param {!cr.ui.FocusRow} row The row that needs to be added to this grid.
118 * @param {cr.ui.FocusRow} nextRow The row that should follow |row|. 124 * @param {cr.ui.FocusRow} nextRow The row that should follow |row|.
119 */ 125 */
120 addRowBefore: function(row, nextRow) { 126 addRowBefore: function(row, nextRow) {
121 row.delegate = row.delegate || this; 127 row.delegate = row.delegate || this;
122 128
(...skipping 28 matching lines...) Expand all
151 } 157 }
152 158
153 this.rows[0].makeActive(true); 159 this.rows[0].makeActive(true);
154 }, 160 },
155 }; 161 };
156 162
157 return { 163 return {
158 FocusGrid: FocusGrid, 164 FocusGrid: FocusGrid,
159 }; 165 };
160 }); 166 });
OLDNEW
« no previous file with comments | « ui/webui/resources/js/cr/ui/expandable_bubble.js ('k') | ui/webui/resources/js/cr/ui/focus_manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698