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

Unified Diff: chrome/browser/resources/shared/js/cr/ui/list.js

Issue 7063007: Revert 86065 - Move sorting logic from table to list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/shared/js/cr/ui/list.js
===================================================================
--- chrome/browser/resources/shared/js/cr/ui/list.js (revision 86337)
+++ chrome/browser/resources/shared/js/cr/ui/list.js (working copy)
@@ -160,23 +160,26 @@
/**
* The data model driving the list.
- * @type {ArrayDataModel}
+ * @type {ListDataModel}
*/
set dataModel(dataModel) {
if (this.dataModel_ != dataModel) {
- if (!this.boundHandleDataModelPermuted_) {
- this.boundHandleDataModelPermuted_ =
- this.handleDataModelPermuted_.bind(this);
+ if (!this.boundHandleDataModelSplice_) {
+ this.boundHandleDataModelSplice_ =
+ this.handleDataModelSplice_.bind(this);
this.boundHandleDataModelChange_ =
this.handleDataModelChange_.bind(this);
+ this.boundHandleSorted_ =
+ this.handleSorted_.bind(this);
}
if (this.dataModel_) {
- this.dataModel_.removeEventListener(
- 'permuted',
- this.boundHandleDataModelPermuted_);
+ this.dataModel_.removeEventListener('splice',
+ this.boundHandleDataModelSplice_);
this.dataModel_.removeEventListener('change',
this.boundHandleDataModelChange_);
+ this.dataModel_.removeEventListener('sorted',
+ this.boundHandleSorted_);
}
this.dataModel_ = dataModel;
@@ -184,14 +187,15 @@
this.cachedItems_ = {};
this.selectionModel.clear();
if (dataModel)
- this.selectionModel.adjustLength(dataModel.length);
+ this.selectionModel.adjust(0, 0, dataModel.length);
if (this.dataModel_) {
- this.dataModel_.addEventListener(
- 'permuted',
- this.boundHandleDataModelPermuted_);
+ this.dataModel_.addEventListener('splice',
+ this.boundHandleDataModelSplice_);
this.dataModel_.addEventListener('change',
this.boundHandleDataModelChange_);
+ this.dataModel_.addEventListener('sorted',
+ this.boundHandleSorted_);
}
this.redraw();
@@ -550,46 +554,43 @@
}
},
- /**
- * This handles data model 'permuted' event.
- * this event is dispatched as a part of sort or splice.
- * We need to
- * - adjust the cache.
- * - adjust selection.
- * - redraw.
- * - scroll the list to show selection.
- * It is important that the cache adjustment happens before selection model
- * adjustments.
- * @param {Event} e The 'permuted' event.
- */
- handleDataModelPermuted_: function(e) {
- var newCachedItems = {};
+ handleDataModelSplice_: function(e) {
+ this.selectionModel.adjust(e.index, e.removed.length, e.added.length);
+ // Remove the cache of everything above index.
for (var index in this.cachedItems_) {
- if (e.permutation[index] != -1)
- newCachedItems[e.permutation[index]] = this.cachedItems_[index];
- else
+ if (index >= e.index)
delete this.cachedItems_[index];
}
- this.cachedItems_ = newCachedItems;
-
- var sm = this.selectionModel;
- sm.adjustToReordering(e.permutation);
-
this.redraw();
-
- if (sm.leadIndex != -1)
- this.scrollIndexIntoView(sm.leadIndex);
},
handleDataModelChange_: function(e) {
if (e.index >= this.firstIndex_ && e.index < this.lastIndex_) {
- if (this.cachedItems_[index])
- delete this.cachedItems_[index];
+ 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.
@@ -930,13 +931,6 @@
},
/**
- * Invalidates list by removing cached items.
- */
- invalidate: function() {
- this.cachedItems_ = {};
- },
-
- /**
* Redraws a single item.
* @param {number} index The row index to redraw.
*/

Powered by Google App Engine
This is Rietveld 408576698