From fdf13c6c6d1b5d9c3b524d7d24e8f19a8d51908f Mon Sep 17 00:00:00 2001 From: "satorux@chromium.org" Date: Wed, 11 Aug 2010 07:13:15 +0000 Subject: Use ListSingleSelectionModel in LanguageList. Users shouldn't be able to select multiple languages in the list. TEST=manually confirmed that multiple selection with Ctrl-click is now impossible BUG=chromium-os:4573 Review URL: http://codereview.chromium.org/3058059 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55682 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/resources/options.html | 1 + .../resources/options/chromeos_language_list.js | 24 ++++++++-------------- chrome/browser/resources/shared_resources.grd | 2 ++ 3 files changed, 12 insertions(+), 15 deletions(-) (limited to 'chrome') diff --git a/chrome/browser/resources/options.html b/chrome/browser/resources/options.html index a5ec32d1..1dfd0a0 100644 --- a/chrome/browser/resources/options.html +++ b/chrome/browser/resources/options.html @@ -14,6 +14,7 @@ + diff --git a/chrome/browser/resources/options/chromeos_language_list.js b/chrome/browser/resources/options/chromeos_language_list.js index c6e6033..a29f7aa 100644 --- a/chrome/browser/resources/options/chromeos_language_list.js +++ b/chrome/browser/resources/options/chromeos_language_list.js @@ -3,10 +3,11 @@ // found in the LICENSE file. cr.define('options.language', function() { - const List = cr.ui.List; - const ListItem = cr.ui.ListItem; const ArrayDataModel = cr.ui.ArrayDataModel; const LanguageOptions = options.LanguageOptions; + const List = cr.ui.List; + const ListItem = cr.ui.ListItem; + const ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; /** * Creates a new language list. @@ -42,6 +43,7 @@ cr.define('options.language', function() { /** @inheritDoc */ decorate: function() { List.prototype.decorate.call(this); + this.selectionModel = new ListSingleSelectionModel; // HACK(arv): http://crbug.com/40902 window.addEventListener('resize', cr.bind(this.redraw, this)); @@ -90,18 +92,10 @@ cr.define('options.language', function() { if (this.selectionModel.selectedIndex >= 0 && // Don't allow removing the last language. this.dataModel.length > 1) { - // TODO(satorux): Until we switch to the single selection model, - // it's possible that multiple languages are selected, but we don't - // handle that case here. - var originalIndex = this.selectionModel.selectedIndex; this.dataModel.splice(this.selectionModel.selectedIndex, 1); - // Select the item at the original index if possible. Otherwise, - // select the last item. - // TODO(satorux): This should be handled by the selection model - // See crbug.com/49893. - this.selectionModel.selectedIndex = Math.min( - originalIndex, - this.dataModel.length - 1); + // Once the selected item is removed, there will be no selected item. + // Select the item pointed by the lead index. + this.selectionModel.selectedIndex = this.selectionModel.leadIndex; this.updateBackend_(); } }, @@ -136,8 +130,8 @@ cr.define('options.language', function() { this.selectionModel.selectedIndex = originalSelectedIndex; } else if (this.dataModel.length > 0){ // Otherwise, select the first item if it's not empty. - // TODO(satorux): Switch to a single item selection model that does - // not allow no selection, one it's ready: crbug.com/49893 + // Note that ListSingleSelectionModel won't select an item + // automatically, hence we manually select the first item here. this.selectionModel.selectedIndex = 0; } }, diff --git a/chrome/browser/resources/shared_resources.grd b/chrome/browser/resources/shared_resources.grd index b0f8731..5512265 100644 --- a/chrome/browser/resources/shared_resources.grd +++ b/chrome/browser/resources/shared_resources.grd @@ -50,6 +50,8 @@ without changes to the corresponding grd file. paaaae --> file="shared/js/cr/ui/list_selection_controller.js" type="BINDATA" /> +