OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/view_model.h" | 5 #include "ui/views/view_model.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/views/view.h" | 8 #include "ui/views/view.h" |
9 | 9 |
10 namespace views { | 10 namespace views { |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 void ViewModel::Remove(int index) { | 27 void ViewModel::Remove(int index) { |
28 if (index == -1) | 28 if (index == -1) |
29 return; | 29 return; |
30 | 30 |
31 check_index(index); | 31 check_index(index); |
32 entries_.erase(entries_.begin() + index); | 32 entries_.erase(entries_.begin() + index); |
33 } | 33 } |
34 | 34 |
35 void ViewModel::Move(int index, int target_index) { | 35 void ViewModel::Move(int index, int target_index) { |
| 36 DCHECK_LT(index, static_cast<int>(entries_.size())); |
| 37 DCHECK_GE(index, 0); |
| 38 DCHECK_LT(target_index, static_cast<int>(entries_.size())); |
| 39 DCHECK_GE(target_index, 0); |
| 40 |
36 if (index == target_index) | 41 if (index == target_index) |
37 return; | 42 return; |
38 Entry entry(entries_[index]); | 43 Entry entry(entries_[index]); |
39 entries_.erase(entries_.begin() + index); | 44 entries_.erase(entries_.begin() + index); |
40 entries_.insert(entries_.begin() + target_index, entry); | 45 entries_.insert(entries_.begin() + target_index, entry); |
41 } | 46 } |
42 | 47 |
43 void ViewModel::MoveViewOnly(int index, int target_index) { | 48 void ViewModel::MoveViewOnly(int index, int target_index) { |
44 if (index == target_index) | 49 if (index == target_index) |
45 return; | 50 return; |
(...skipping 19 matching lines...) Expand all Loading... |
65 | 70 |
66 int ViewModel::GetIndexOfView(const View* view) const { | 71 int ViewModel::GetIndexOfView(const View* view) const { |
67 for (size_t i = 0; i < entries_.size(); ++i) { | 72 for (size_t i = 0; i < entries_.size(); ++i) { |
68 if (entries_[i].view == view) | 73 if (entries_[i].view == view) |
69 return static_cast<int>(i); | 74 return static_cast<int>(i); |
70 } | 75 } |
71 return -1; | 76 return -1; |
72 } | 77 } |
73 | 78 |
74 } // namespace views | 79 } // namespace views |
OLD | NEW |