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

Side by Side Diff: ui/views/view_model.cc

Issue 10213011: Attempt 3 at a better touch tabstrip. There is still a bunch to do, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove Tab::GetTouchModeMinimumSize Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/view_model.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
11 11
12 ViewModel::ViewModel() { 12 ViewModel::ViewModel() {
13 } 13 }
14 14
15 ViewModel::~ViewModel() { 15 ViewModel::~ViewModel() {
16 // view are owned by their parent, no need to delete them. 16 // view are owned by their parent, no need to delete them.
17 } 17 }
18 18
19 void ViewModel::Add(View* view, int index) { 19 void ViewModel::Add(View* view, int index) {
20 DCHECK_LE(index, static_cast<int>(entries_.size()));
21 DCHECK_GE(index, 0);
20 Entry entry; 22 Entry entry;
21 entry.view = view; 23 entry.view = view;
22 entries_.insert(entries_.begin() + index, entry); 24 entries_.insert(entries_.begin() + index, entry);
23 } 25 }
24 26
25 void ViewModel::Remove(int index) { 27 void ViewModel::Remove(int index) {
26 if (index == -1) 28 if (index == -1)
27 return; 29 return;
28 30
31 check_index(index);
29 entries_.erase(entries_.begin() + index); 32 entries_.erase(entries_.begin() + index);
30 } 33 }
31 34
32 void ViewModel::Move(int index, int target_index) { 35 void ViewModel::Move(int index, int target_index) {
33 if (index == target_index) 36 if (index == target_index)
34 return; 37 return;
35 Entry entry(entries_[index]); 38 Entry entry(entries_[index]);
36 entries_.erase(entries_.begin() + index); 39 entries_.erase(entries_.begin() + index);
37 entries_.insert(entries_.begin() + target_index, entry); 40 entries_.insert(entries_.begin() + target_index, entry);
38 } 41 }
39 42
40 void ViewModel::Clear() { 43 void ViewModel::Clear() {
41 Entries entries; 44 Entries entries;
42 entries.swap(entries_); 45 entries.swap(entries_);
43 for (size_t i = 0; i < entries.size(); ++i) 46 for (size_t i = 0; i < entries.size(); ++i)
44 delete entries[i].view; 47 delete entries[i].view;
45 } 48 }
46 49
47 int ViewModel::GetIndexOfView(const View* view) const { 50 int ViewModel::GetIndexOfView(const View* view) const {
48 for (size_t i = 0; i < entries_.size(); ++i) { 51 for (size_t i = 0; i < entries_.size(); ++i) {
49 if (entries_[i].view == view) 52 if (entries_[i].view == view)
50 return static_cast<int>(i); 53 return static_cast<int>(i);
51 } 54 }
52 return -1; 55 return -1;
53 } 56 }
54 57
55 } // namespace views 58 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view_model.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698