diff options
| author | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-10 21:04:12 +0000 |
|---|---|---|
| committer | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-10 21:04:12 +0000 |
| commit | bb5accfb91fcf58f33e60591fadb7ea948194db9 (patch) | |
| tree | 390a339935b2034e7090fb5a5619048f93d91239 | |
| parent | 4b7dae01cf23fc5ea48db253bff2225a00d40b5d (diff) | |
| download | chromium_src-bb5accfb91fcf58f33e60591fadb7ea948194db9.zip chromium_src-bb5accfb91fcf58f33e60591fadb7ea948194db9.tar.gz chromium_src-bb5accfb91fcf58f33e60591fadb7ea948194db9.tar.bz2 | |
Merge 84845 - Have List redraw on sort.
BUG=chromium-os:14920
TEST=Click breadcrumbs to cd into a directory with some files, while in thumbnail mode. Double click on a file - the correct file should launch.
Review URL: http://codereview.chromium.org/6997012
TBR=achuith@chromium.org
Review URL: http://codereview.chromium.org/6995033
git-svn-id: svn://svn.chromium.org/chrome/branches/742/src@84848 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 42 insertions, 3 deletions
diff --git a/chrome/browser/resources/shared/js/cr/ui/list.js b/chrome/browser/resources/shared/js/cr/ui/list.js index fc714bc..3d8a79e 100644 --- a/chrome/browser/resources/shared/js/cr/ui/list.js +++ b/chrome/browser/resources/shared/js/cr/ui/list.js @@ -169,6 +169,8 @@ cr.define('cr.ui', function() { this.handleDataModelSplice_.bind(this); this.boundHandleDataModelChange_ = this.handleDataModelChange_.bind(this); + this.boundHandleSorted_ = + this.handleSorted_.bind(this); } if (this.dataModel_) { @@ -176,6 +178,8 @@ cr.define('cr.ui', function() { this.boundHandleDataModelSplice_); this.dataModel_.removeEventListener('change', this.boundHandleDataModelChange_); + this.dataModel_.removeEventListener('sorted', + this.boundHandleSorted_); } this.dataModel_ = dataModel; @@ -190,6 +194,8 @@ cr.define('cr.ui', function() { this.boundHandleDataModelSplice_); this.dataModel_.addEventListener('change', this.boundHandleDataModelChange_); + this.dataModel_.addEventListener('sorted', + this.boundHandleSorted_); } this.redraw(); @@ -560,12 +566,31 @@ cr.define('cr.ui', function() { handleDataModelChange_: function(e) { if (e.index >= this.firstIndex_ && e.index < this.lastIndex_) { - delete this.cachedItems_; + this.cachedItems_ = null; this.redraw(); } }, /** + * This handles data model 'sorted' event. + * After sorting we need to + * - adjust selection. + * - delete the cache. + * - redraw all the items. + * - scroll the list to show selection. + * @param {Event} e The 'sorted' event. + */ + handleSorted_: function(e) { + var sm = this.selectionModel; + sm.adjustToReordering(e.sortPermutation); + + this.cachedItems_ = null; + this.redraw(); + if (sm.leadIndex != -1) + this.scrollIndexIntoView(sm.leadIndex); + }, + + /** * @param {number} index The index of the item. * @return {number} The top position of the item inside the list, not taking * into account lead item. May vary in the case of multiple columns. diff --git a/chrome/browser/resources/shared/js/cr/ui/list_selection_model.js b/chrome/browser/resources/shared/js/cr/ui/list_selection_model.js index 59485f7..fc5710f 100644 --- a/chrome/browser/resources/shared/js/cr/ui/list_selection_model.js +++ b/chrome/browser/resources/shared/js/cr/ui/list_selection_model.js @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -243,6 +243,13 @@ cr.define('cr.ui', function() { }, /** + * Adjusts the selection after reordering of items in the table. + * @param {!Array.<number>} permutation The reordering permutation. + */ + adjustToReordering: function(permutation) { + }, + + /** * Adjust the selection by adding or removing a certain numbers of items. * This should be called by the owner of the selection model as items are * added and removed from the underlying data model. diff --git a/chrome/browser/resources/shared/js/cr/ui/list_single_selection_model.js b/chrome/browser/resources/shared/js/cr/ui/list_single_selection_model.js index ff3c8c6..119f0fb 100644 --- a/chrome/browser/resources/shared/js/cr/ui/list_single_selection_model.js +++ b/chrome/browser/resources/shared/js/cr/ui/list_single_selection_model.js @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -193,6 +193,13 @@ cr.define('cr.ui', function() { }, /** + * Adjusts the selection after reordering of items in the table. + * @param {!Array.<number>} permutation The reordering permutation. + */ + adjustToReordering: function(permutation) { + }, + + /** * Adjust the selection by adding or removing a certain numbers of items. * This should be called by the owner of the selection model as items are * added and removed from the underlying data model. |
