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

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

Issue 851853002: It is time. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Trying to reup because the last upload failed. Created 5 years, 11 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
« no previous file with comments | « ui/views/view_model.h ('k') | ui/views/view_model_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/views/view_model.h"
6
7 #include "base/logging.h"
8 #include "ui/views/view.h"
9
10 namespace views {
11
12 ViewModelBase::~ViewModelBase() {
13 // view are owned by their parent, no need to delete them.
14 }
15
16 void ViewModelBase::Remove(int index) {
17 if (index == -1)
18 return;
19
20 check_index(index);
21 entries_.erase(entries_.begin() + index);
22 }
23
24 void ViewModelBase::Move(int index, int target_index) {
25 DCHECK_LT(index, static_cast<int>(entries_.size()));
26 DCHECK_GE(index, 0);
27 DCHECK_LT(target_index, static_cast<int>(entries_.size()));
28 DCHECK_GE(target_index, 0);
29
30 if (index == target_index)
31 return;
32 Entry entry(entries_[index]);
33 entries_.erase(entries_.begin() + index);
34 entries_.insert(entries_.begin() + target_index, entry);
35 }
36
37 void ViewModelBase::MoveViewOnly(int index, int target_index) {
38 if (index == target_index)
39 return;
40 if (target_index < index) {
41 View* view = entries_[index].view;
42 for (int i = index; i > target_index; --i)
43 entries_[i].view = entries_[i - 1].view;
44 entries_[target_index].view = view;
45 } else {
46 View* view = entries_[index].view;
47 for (int i = index; i < target_index; ++i)
48 entries_[i].view = entries_[i + 1].view;
49 entries_[target_index].view = view;
50 }
51 }
52
53 void ViewModelBase::Clear() {
54 Entries entries;
55 entries.swap(entries_);
56 for (size_t i = 0; i < entries.size(); ++i)
57 delete entries[i].view;
58 }
59
60 int ViewModelBase::GetIndexOfView(const View* view) const {
61 for (size_t i = 0; i < entries_.size(); ++i) {
62 if (entries_[i].view == view)
63 return static_cast<int>(i);
64 }
65 return -1;
66 }
67
68 ViewModelBase::ViewModelBase() {
69 }
70
71 void ViewModelBase::AddUnsafe(View* view, int index) {
72 DCHECK_LE(index, static_cast<int>(entries_.size()));
73 DCHECK_GE(index, 0);
74 Entry entry;
75 entry.view = view;
76 entries_.insert(entries_.begin() + index, entry);
77 }
78
79 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view_model.h ('k') | ui/views/view_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698