diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-18 15:02:15 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-18 15:02:15 +0000 |
commit | c6ff734cef5b4f50bc63cf8cefd180d65405dba9 (patch) | |
tree | f09e3bd7664ecfd54531fdbc04f28612ec88e909 /ui | |
parent | 570aaf9d7628cdc7888713d316b0030a3c3d34ff (diff) | |
download | chromium_src-c6ff734cef5b4f50bc63cf8cefd180d65405dba9.zip chromium_src-c6ff734cef5b4f50bc63cf8cefd180d65405dba9.tar.gz chromium_src-c6ff734cef5b4f50bc63cf8cefd180d65405dba9.tar.bz2 |
ui: Change ListModel to operate in size_t instead of int.
R=xiyuan@chromium.org
TBR=sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10408009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137862 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/app_list/app_list_model.cc | 6 | ||||
-rw-r--r-- | ui/app_list/app_list_model.h | 8 | ||||
-rw-r--r-- | ui/app_list/app_list_model_view.cc | 12 | ||||
-rw-r--r-- | ui/app_list/app_list_model_view.h | 6 | ||||
-rw-r--r-- | ui/base/models/list_model.h | 28 | ||||
-rw-r--r-- | ui/base/models/list_model_observer.h | 10 | ||||
-rw-r--r-- | ui/base/models/list_model_unittest.cc | 22 |
7 files changed, 47 insertions, 45 deletions
diff --git a/ui/app_list/app_list_model.cc b/ui/app_list/app_list_model.cc index 529ed16..f0f8f11 100644 --- a/ui/app_list/app_list_model.cc +++ b/ui/app_list/app_list_model.cc @@ -16,15 +16,15 @@ void AppListModel::AddItem(AppListItemModel* item) { items_.Add(item); } -void AppListModel::AddItemAt(int index, AppListItemModel* item) { +void AppListModel::AddItemAt(size_t index, AppListItemModel* item) { items_.AddAt(index, item); } -void AppListModel::DeleteItemAt(int index) { +void AppListModel::DeleteItemAt(size_t index) { items_.DeleteAt(index); } -AppListItemModel* AppListModel::GetItemAt(int index) { +AppListItemModel* AppListModel::GetItemAt(size_t index) { return items_.GetItemAt(index); } diff --git a/ui/app_list/app_list_model.h b/ui/app_list/app_list_model.h index 03faefd..b49f162 100644 --- a/ui/app_list/app_list_model.h +++ b/ui/app_list/app_list_model.h @@ -21,16 +21,16 @@ class APP_LIST_EXPORT AppListModel { // Adds an item to the model. The model takes ownership of |item|. void AddItem(AppListItemModel* item); - void AddItemAt(int index, AppListItemModel* item); + void AddItemAt(size_t index, AppListItemModel* item); - void DeleteItemAt(int index); + void DeleteItemAt(size_t index); - AppListItemModel* GetItemAt(int index); + AppListItemModel* GetItemAt(size_t index); void AddObserver(ui::ListModelObserver* observer); void RemoveObserver(ui::ListModelObserver* observer); - int item_count() const { return items_.item_count(); } + size_t item_count() const { return items_.item_count(); } private: typedef ui::ListModel<AppListItemModel> Items; diff --git a/ui/app_list/app_list_model_view.cc b/ui/app_list/app_list_model_view.cc index 868a748..e594277 100644 --- a/ui/app_list/app_list_model_view.cc +++ b/ui/app_list/app_list_model_view.cc @@ -136,7 +136,7 @@ void AppListModelView::Update() { if (!model_ || model_->item_count() == 0) return; - for (int i = 0; i < model_->item_count(); ++i) + for (size_t i = 0; i < model_->item_count(); ++i) AddChildView(new AppListItemView(this, model_->GetItemAt(i), listener_)); Layout(); @@ -296,8 +296,8 @@ void AppListModelView::OnPaintFocusBorder(gfx::Canvas* canvas) { // Override to not paint focus frame. } -void AppListModelView::ListItemsAdded(int start, int count) { - for (int i = start; i < start + count; ++i) { +void AppListModelView::ListItemsAdded(size_t start, size_t count) { + for (size_t i = start; i < start + count; ++i) { AddChildViewAt(new AppListItemView(this, model_->GetItemAt(i), listener_), i); } @@ -305,15 +305,15 @@ void AppListModelView::ListItemsAdded(int start, int count) { SchedulePaint(); } -void AppListModelView::ListItemsRemoved(int start, int count) { - for (int i = 0; i < count; ++i) +void AppListModelView::ListItemsRemoved(size_t start, size_t count) { + for (size_t i = 0; i < count; ++i) delete child_at(start); Layout(); SchedulePaint(); } -void AppListModelView::ListItemsChanged(int start, int count) { +void AppListModelView::ListItemsChanged(size_t start, size_t count) { NOTREACHED(); } diff --git a/ui/app_list/app_list_model_view.h b/ui/app_list/app_list_model_view.h index a0c9fa1..89fc7f6 100644 --- a/ui/app_list/app_list_model_view.h +++ b/ui/app_list/app_list_model_view.h @@ -71,9 +71,9 @@ class APP_LIST_EXPORT AppListModelView : public views::View, virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; // Overridden from ListModelObserver: - virtual void ListItemsAdded(int start, int count) OVERRIDE; - virtual void ListItemsRemoved(int start, int count) OVERRIDE; - virtual void ListItemsChanged(int start, int count) OVERRIDE; + virtual void ListItemsAdded(size_t start, size_t count) OVERRIDE; + virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE; + virtual void ListItemsChanged(size_t start, size_t count) OVERRIDE; // Overridden from PaginationModelObserver: virtual void TotalPagesChanged() OVERRIDE; diff --git a/ui/base/models/list_model.h b/ui/base/models/list_model.h index 9352fa5..cf30df2 100644 --- a/ui/base/models/list_model.h +++ b/ui/base/models/list_model.h @@ -24,16 +24,16 @@ class ListModel { virtual ~ListModel() {} // Adds |item| to the model at given |index|. - virtual void AddAt(int index, ItemType* item) { - DCHECK(index >= 0 && index <= item_count()); + virtual void AddAt(size_t index, ItemType* item) { + DCHECK_LE(index, item_count()); items_->insert(items_.begin() + index, item); NotifyItemsAdded(index, 1); } // Removes an item at given |index| from the model. Note the removed item // is NOT deleted and it's up to the caller to delete it. - virtual ItemType* RemoveAt(int index) { - DCHECK(index >= 0 && index < item_count()); + virtual ItemType* RemoveAt(size_t index) { + DCHECK_LT(index, item_count()); ItemType* item = items_[index]; items_->erase(items_.begin() + index); NotifyItemsRemoved(index, 1); @@ -42,19 +42,19 @@ class ListModel { // Removes all items from the model. This does NOT delete the items. virtual void RemoveAll() { - int count = item_count(); + size_t count = item_count(); items_->clear(); NotifyItemsRemoved(0, count); } // Removes an item at given |index| from the model and deletes it. - virtual void DeleteAt(int index) { + virtual void DeleteAt(size_t index) { delete RemoveAt(index); } // Removes and deletes all items from the model. virtual void DeleteAll() { - int count = item_count(); + size_t count = item_count(); items_.reset(); NotifyItemsRemoved(0, count); } @@ -72,31 +72,31 @@ class ListModel { observers_.RemoveObserver(observer); } - void NotifyItemsAdded(int start, int count) { + void NotifyItemsAdded(size_t start, size_t count) { FOR_EACH_OBSERVER(ListModelObserver, observers_, ListItemsAdded(start, count)); } - void NotifyItemsRemoved(int start, int count) { + void NotifyItemsRemoved(size_t start, size_t count) { FOR_EACH_OBSERVER(ListModelObserver, observers_, ListItemsRemoved(start, count)); } - void NotifyItemsChanged(int start, int count) { + void NotifyItemsChanged(size_t start, size_t count) { FOR_EACH_OBSERVER(ListModelObserver, observers_, ListItemsChanged(start, count)); } - int item_count() const { return static_cast<int>(items_.size()); } + size_t item_count() const { return items_.size(); } - const ItemType* GetItemAt(int index) const { - DCHECK(index >= 0 && index < item_count()); + const ItemType* GetItemAt(size_t index) const { + DCHECK_LT(index, item_count()); return items_[index]; } - ItemType* GetItemAt(int index) { + ItemType* GetItemAt(size_t index) { return const_cast<ItemType*>( const_cast<const ListModel<ItemType>*>(this)->GetItemAt(index)); } diff --git a/ui/base/models/list_model_observer.h b/ui/base/models/list_model_observer.h index 65b22a8..49d4030 100644 --- a/ui/base/models/list_model_observer.h +++ b/ui/base/models/list_model_observer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -6,6 +6,8 @@ #define UI_BASE_MODELS_LIST_MODEL_OBSERVER_H_ #pragma once +#include <stddef.h> + #include "ui/base/ui_export.h" namespace ui { @@ -13,14 +15,14 @@ namespace ui { class UI_EXPORT ListModelObserver { public: // Invoked after items has been added to the model. - virtual void ListItemsAdded(int start, int count) = 0; + virtual void ListItemsAdded(size_t start, size_t count) = 0; // Invoked after items has been removed. |start| is the index before the // removal. - virtual void ListItemsRemoved(int start, int count) = 0; + virtual void ListItemsRemoved(size_t start, size_t count) = 0; // Invoked after items has been changed. - virtual void ListItemsChanged(int start, int count) = 0; + virtual void ListItemsChanged(size_t start, size_t count) = 0; protected: virtual ~ListModelObserver() {} diff --git a/ui/base/models/list_model_unittest.cc b/ui/base/models/list_model_unittest.cc index 2dcaf4d..75921f7 100644 --- a/ui/base/models/list_model_unittest.cc +++ b/ui/base/models/list_model_unittest.cc @@ -31,9 +31,9 @@ class ListModelTest : public testing::Test, changed_count_(0) { } - void ExpectCountsEqual(int added_count, - int removed_count, - int changed_count) { + void ExpectCountsEqual(size_t added_count, + size_t removed_count, + size_t changed_count) { EXPECT_EQ(added_count, added_count_); EXPECT_EQ(removed_count, removed_count_); EXPECT_EQ(changed_count, changed_count_); @@ -44,20 +44,20 @@ class ListModelTest : public testing::Test, } // ListModelObserver implementation: - virtual void ListItemsAdded(int start, int count) OVERRIDE { + virtual void ListItemsAdded(size_t start, size_t count) OVERRIDE { added_count_ += count; } - virtual void ListItemsRemoved(int start, int count) OVERRIDE { + virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE { removed_count_ += count; } - virtual void ListItemsChanged(int start, int count) OVERRIDE { + virtual void ListItemsChanged(size_t start, size_t count) OVERRIDE { changed_count_ += count; } private: - int added_count_; - int removed_count_; - int changed_count_; + size_t added_count_; + size_t removed_count_; + size_t changed_count_; DISALLOW_COPY_AND_ASSIGN(ListModelTest); }; @@ -79,7 +79,7 @@ TEST_F(ListModelTest, Add) { ExpectCountsEqual(3, 0, 0); // Total 3 items in mode. - EXPECT_EQ(3, model.item_count()); + EXPECT_EQ(3U, model.item_count()); // First one should be FooItem(2), followed by FooItem(0) and FooItem(1) EXPECT_EQ(2, model.GetItemAt(0)->id()); @@ -101,7 +101,7 @@ TEST_F(ListModelTest, Remove) { model.DeleteAt(1); ExpectCountsEqual(0, 1, 0); - EXPECT_EQ(2, model.item_count()); + EXPECT_EQ(2U, model.item_count()); EXPECT_EQ(0, model.GetItemAt(0)->id()); EXPECT_EQ(2, model.GetItemAt(1)->id()); |