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

Unified Diff: ui/views/view_model.cc

Issue 598013003: Added views::ViewModelT<T>, a type-safe template version of ViewModel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@appsgridview-static-casts
Patch Set: Fix browser_test compile on ChromeOS (missing include). Created 6 years, 2 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
« no previous file with comments | « ui/views/view_model.h ('k') | ui/views/view_model_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/view_model.cc
diff --git a/ui/views/view_model.cc b/ui/views/view_model.cc
index a0a754964508c83023fceda8da5cef8f1fcabcb0..14f60e03e25484c4a0a21a7709e73ba4f77a5764 100644
--- a/ui/views/view_model.cc
+++ b/ui/views/view_model.cc
@@ -9,22 +9,11 @@
namespace views {
-ViewModel::ViewModel() {
-}
-
-ViewModel::~ViewModel() {
+ViewModelBase::~ViewModelBase() {
// view are owned by their parent, no need to delete them.
}
-void ViewModel::Add(View* view, int index) {
- DCHECK_LE(index, static_cast<int>(entries_.size()));
- DCHECK_GE(index, 0);
- Entry entry;
- entry.view = view;
- entries_.insert(entries_.begin() + index, entry);
-}
-
-void ViewModel::Remove(int index) {
+void ViewModelBase::Remove(int index) {
if (index == -1)
return;
@@ -32,7 +21,7 @@ void ViewModel::Remove(int index) {
entries_.erase(entries_.begin() + index);
}
-void ViewModel::Move(int index, int target_index) {
+void ViewModelBase::Move(int index, int target_index) {
DCHECK_LT(index, static_cast<int>(entries_.size()));
DCHECK_GE(index, 0);
DCHECK_LT(target_index, static_cast<int>(entries_.size()));
@@ -45,7 +34,7 @@ void ViewModel::Move(int index, int target_index) {
entries_.insert(entries_.begin() + target_index, entry);
}
-void ViewModel::MoveViewOnly(int index, int target_index) {
+void ViewModelBase::MoveViewOnly(int index, int target_index) {
if (index == target_index)
return;
if (target_index < index) {
@@ -61,14 +50,14 @@ void ViewModel::MoveViewOnly(int index, int target_index) {
}
}
-void ViewModel::Clear() {
+void ViewModelBase::Clear() {
Entries entries;
entries.swap(entries_);
for (size_t i = 0; i < entries.size(); ++i)
delete entries[i].view;
}
-int ViewModel::GetIndexOfView(const View* view) const {
+int ViewModelBase::GetIndexOfView(const View* view) const {
for (size_t i = 0; i < entries_.size(); ++i) {
if (entries_[i].view == view)
return static_cast<int>(i);
@@ -76,4 +65,15 @@ int ViewModel::GetIndexOfView(const View* view) const {
return -1;
}
+ViewModelBase::ViewModelBase() {
+}
+
+void ViewModelBase::AddUnsafe(View* view, int index) {
+ DCHECK_LE(index, static_cast<int>(entries_.size()));
+ DCHECK_GE(index, 0);
+ Entry entry;
+ entry.view = view;
+ entries_.insert(entries_.begin() + index, entry);
+}
+
} // namespace views
« no previous file with comments | « ui/views/view_model.h ('k') | ui/views/view_model_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698