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 #ifndef UI_VIEWS_VIEW_MODEL_H_ | 5 #ifndef UI_VIEWS_VIEW_MODEL_H_ |
6 #define UI_VIEWS_VIEW_MODEL_H_ | 6 #define UI_VIEWS_VIEW_MODEL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/logging.h" |
12 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
13 #include "ui/views/views_export.h" | 14 #include "ui/views/views_export.h" |
14 | 15 |
15 namespace views { | 16 namespace views { |
16 | 17 |
17 class View; | 18 class View; |
18 | 19 |
19 // ViewModel is used to track an 'interesting' set of a views. Often times | 20 // ViewModel is used to track an 'interesting' set of a views. Often times |
20 // during animations views are removed after a delay, which makes for tricky | 21 // during animations views are removed after a delay, which makes for tricky |
21 // coordinate conversion as you have to account for the possibility of the | 22 // coordinate conversion as you have to account for the possibility of the |
(...skipping 17 matching lines...) Expand all Loading... |
39 void Move(int index, int target_index); | 40 void Move(int index, int target_index); |
40 | 41 |
41 // Returns the number of views. | 42 // Returns the number of views. |
42 int view_size() const { return static_cast<int>(entries_.size()); } | 43 int view_size() const { return static_cast<int>(entries_.size()); } |
43 | 44 |
44 // Removes and deletes all the views. | 45 // Removes and deletes all the views. |
45 void Clear(); | 46 void Clear(); |
46 | 47 |
47 // Returns the view at the specified index. | 48 // Returns the view at the specified index. |
48 View* view_at(int index) const { | 49 View* view_at(int index) const { |
| 50 check_index(index); |
49 return entries_[index].view; | 51 return entries_[index].view; |
50 } | 52 } |
51 | 53 |
52 void set_ideal_bounds(int index, const gfx::Rect& bounds) { | 54 void set_ideal_bounds(int index, const gfx::Rect& bounds) { |
| 55 check_index(index); |
53 entries_[index].ideal_bounds = bounds; | 56 entries_[index].ideal_bounds = bounds; |
54 } | 57 } |
55 | 58 |
56 const gfx::Rect& ideal_bounds(int index) const { | 59 const gfx::Rect& ideal_bounds(int index) const { |
| 60 check_index(index); |
57 return entries_[index].ideal_bounds; | 61 return entries_[index].ideal_bounds; |
58 } | 62 } |
59 | 63 |
60 // Returns the index of the specified view, or -1 if the view isn't in the | 64 // Returns the index of the specified view, or -1 if the view isn't in the |
61 // model. | 65 // model. |
62 int GetIndexOfView(const View* view) const; | 66 int GetIndexOfView(const View* view) const; |
63 | 67 |
64 private: | 68 private: |
65 struct Entry { | 69 struct Entry { |
66 Entry() : view(NULL) {} | 70 Entry() : view(NULL) {} |
67 | 71 |
68 View* view; | 72 View* view; |
69 gfx::Rect ideal_bounds; | 73 gfx::Rect ideal_bounds; |
70 }; | 74 }; |
71 typedef std::vector<Entry> Entries; | 75 typedef std::vector<Entry> Entries; |
72 | 76 |
| 77 #if !defined(NDEBUG) |
| 78 void check_index(int index) const { |
| 79 DCHECK_LT(index, static_cast<int>(entries_.size())); |
| 80 DCHECK_GE(index, 0); |
| 81 } |
| 82 #else |
| 83 void check_index(int index) const {} |
| 84 #endif |
| 85 |
73 Entries entries_; | 86 Entries entries_; |
74 | 87 |
75 DISALLOW_COPY_AND_ASSIGN(ViewModel); | 88 DISALLOW_COPY_AND_ASSIGN(ViewModel); |
76 }; | 89 }; |
77 | 90 |
78 } // namespace views | 91 } // namespace views |
79 | 92 |
80 #endif // UI_VIEWS_VIEW_MODEL_H_ | 93 #endif // UI_VIEWS_VIEW_MODEL_H_ |
OLD | NEW |