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

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

Issue 2603443002: Clang format JS: Disallow single line functions, conditionals, loops, and switch statements (Closed)
Patch Set: more options Created 4 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 /** @const */ var EventTarget = cr.EventTarget; 6 /** @const */ var EventTarget = cr.EventTarget;
7 7
8 /** 8 /**
9 * Creates a new selection model that is to be used with lists. 9 * Creates a new selection model that is to be used with lists.
10 * 10 *
(...skipping 12 matching lines...) Expand all
23 this.independentLeadItem_ = !cr.isMac && !cr.isChromeOS; 23 this.independentLeadItem_ = !cr.isMac && !cr.isChromeOS;
24 } 24 }
25 25
26 ListSelectionModel.prototype = { 26 ListSelectionModel.prototype = {
27 __proto__: EventTarget.prototype, 27 __proto__: EventTarget.prototype,
28 28
29 /** 29 /**
30 * The number of items in the model. 30 * The number of items in the model.
31 * @type {number} 31 * @type {number}
32 */ 32 */
33 get length() { return this.length_; }, 33 get length() {
34 return this.length_;
35 },
34 36
35 /** 37 /**
36 * The selected indexes. 38 * The selected indexes.
37 * Setter also changes lead and anchor indexes if value list is nonempty. 39 * Setter also changes lead and anchor indexes if value list is nonempty.
38 * @type {!Array} 40 * @type {!Array}
39 */ 41 */
40 get selectedIndexes() { 42 get selectedIndexes() {
41 return Object.keys(this.selectedIndexes_).map(Number); 43 return Object.keys(this.selectedIndexes_).map(Number);
42 }, 44 },
43 set selectedIndexes(selectedIndexes) { 45 set selectedIndexes(selectedIndexes) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 }, 257 },
256 258
257 leadIndex_: -1, 259 leadIndex_: -1,
258 oldLeadIndex_: null, 260 oldLeadIndex_: null,
259 261
260 /** 262 /**
261 * The leadIndex is used with multiple selection and it is the index that 263 * The leadIndex is used with multiple selection and it is the index that
262 * the user is moving using the arrow keys. 264 * the user is moving using the arrow keys.
263 * @type {number} 265 * @type {number}
264 */ 266 */
265 get leadIndex() { return this.leadIndex_; }, 267 get leadIndex() {
268 return this.leadIndex_;
269 },
266 set leadIndex(leadIndex) { 270 set leadIndex(leadIndex) {
267 var oldValue = this.leadIndex_; 271 var oldValue = this.leadIndex_;
268 var newValue = this.adjustIndex_(leadIndex); 272 var newValue = this.adjustIndex_(leadIndex);
269 this.leadIndex_ = newValue; 273 this.leadIndex_ = newValue;
270 // Delays the call of dispatchPropertyChange if batch is running. 274 // Delays the call of dispatchPropertyChange if batch is running.
271 if (!this.changeCount_ && newValue != oldValue) 275 if (!this.changeCount_ && newValue != oldValue)
272 cr.dispatchPropertyChange(this, 'leadIndex', newValue, oldValue); 276 cr.dispatchPropertyChange(this, 'leadIndex', newValue, oldValue);
273 }, 277 },
274 278
275 anchorIndex_: -1, 279 anchorIndex_: -1,
276 oldAnchorIndex_: null, 280 oldAnchorIndex_: null,
277 281
278 /** 282 /**
279 * The anchorIndex is used with multiple selection. 283 * The anchorIndex is used with multiple selection.
280 * @type {number} 284 * @type {number}
281 */ 285 */
282 get anchorIndex() { return this.anchorIndex_; }, 286 get anchorIndex() {
287 return this.anchorIndex_;
288 },
283 set anchorIndex(anchorIndex) { 289 set anchorIndex(anchorIndex) {
284 var oldValue = this.anchorIndex_; 290 var oldValue = this.anchorIndex_;
285 var newValue = this.adjustIndex_(anchorIndex); 291 var newValue = this.adjustIndex_(anchorIndex);
286 this.anchorIndex_ = newValue; 292 this.anchorIndex_ = newValue;
287 // Delays the call of dispatchPropertyChange if batch is running. 293 // Delays the call of dispatchPropertyChange if batch is running.
288 if (!this.changeCount_ && newValue != oldValue) 294 if (!this.changeCount_ && newValue != oldValue)
289 cr.dispatchPropertyChange(this, 'anchorIndex', newValue, oldValue); 295 cr.dispatchPropertyChange(this, 'anchorIndex', newValue, oldValue);
290 }, 296 },
291 297
292 /** 298 /**
(...skipping 11 matching lines...) Expand all
304 var index2 = this.getNearestSelectedIndex_(index); 310 var index2 = this.getNearestSelectedIndex_(index);
305 index = index2; 311 index = index2;
306 } 312 }
307 return index; 313 return index;
308 }, 314 },
309 315
310 /** 316 /**
311 * Whether the selection model supports multiple selected items. 317 * Whether the selection model supports multiple selected items.
312 * @type {boolean} 318 * @type {boolean}
313 */ 319 */
314 get multiple() { return true; }, 320 get multiple() {
321 return true;
322 },
315 323
316 /** 324 /**
317 * Adjusts the selection after reordering of items in the table. 325 * Adjusts the selection after reordering of items in the table.
318 * @param {!Array<number>} permutation The reordering permutation. 326 * @param {!Array<number>} permutation The reordering permutation.
319 */ 327 */
320 adjustToReordering: function(permutation) { 328 adjustToReordering: function(permutation) {
321 this.beginChange(); 329 this.beginChange();
322 var oldLeadIndex = this.leadIndex; 330 var oldLeadIndex = this.leadIndex;
323 var oldAnchorIndex = this.anchorIndex; 331 var oldAnchorIndex = this.anchorIndex;
324 var oldSelectedItemsCount = this.selectedIndexes.length; 332 var oldSelectedItemsCount = this.selectedIndexes.length;
325 333
326 this.selectedIndexes = 334 this.selectedIndexes = this.selectedIndexes
327 this.selectedIndexes 335 .map(function(oldIndex) {
328 .map(function(oldIndex) { return permutation[oldIndex]; }) 336 return permutation[oldIndex];
329 .filter(function(index) { return index != -1; }); 337 })
338 .filter(function(index) {
339 return index != -1;
340 });
dschuyler 2016/12/22 22:34:27 Could this have a cr after the assignment? i.e.
330 341
331 // Will be adjusted in endChange. 342 // Will be adjusted in endChange.
332 if (oldLeadIndex != -1) 343 if (oldLeadIndex != -1)
333 this.leadIndex = permutation[oldLeadIndex]; 344 this.leadIndex = permutation[oldLeadIndex];
334 if (oldAnchorIndex != -1) 345 if (oldAnchorIndex != -1)
335 this.anchorIndex = permutation[oldAnchorIndex]; 346 this.anchorIndex = permutation[oldAnchorIndex];
336 347
337 if (oldSelectedItemsCount && !this.selectedIndexes.length && 348 if (oldSelectedItemsCount && !this.selectedIndexes.length &&
338 this.length_ && oldLeadIndex != -1) { 349 this.length_ && oldLeadIndex != -1) {
339 // All selected items are deleted. We move selection to next item of 350 // All selected items are deleted. We move selection to next item of
340 // last selected item. 351 // last selected item.
341 this.selectedIndexes = [Math.min(oldLeadIndex, this.length_ - 1)]; 352 this.selectedIndexes = [Math.min(oldLeadIndex, this.length_ - 1)];
342 } 353 }
343 354
344 this.endChange(); 355 this.endChange();
345 }, 356 },
346 357
347 /** 358 /**
348 * Adjusts selection model length. 359 * Adjusts selection model length.
349 * @param {number} length New selection model length. 360 * @param {number} length New selection model length.
350 */ 361 */
351 adjustLength: function(length) { this.length_ = length; } 362 adjustLength: function(length) {
363 this.length_ = length;
364 }
352 }; 365 };
353 366
354 return {ListSelectionModel: ListSelectionModel}; 367 return {ListSelectionModel: ListSelectionModel};
355 }); 368 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698