Use int64 more pervasively in storing time s/ms/us values.
[chromium-blink-merge.git] / ui / views / view_model.cc
blob14f60e03e25484c4a0a21a7709e73ba4f77a5764
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.
5 #include "ui/views/view_model.h"
7 #include "base/logging.h"
8 #include "ui/views/view.h"
10 namespace views {
12 ViewModelBase::~ViewModelBase() {
13 // view are owned by their parent, no need to delete them.
16 void ViewModelBase::Remove(int index) {
17 if (index == -1)
18 return;
20 check_index(index);
21 entries_.erase(entries_.begin() + index);
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);
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);
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;
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;
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);
65 return -1;
68 ViewModelBase::ViewModelBase() {
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);
79 } // namespace views