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/base/models/list_selection_model.h" | 5 #include "ui/base/models/list_selection_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <valarray> | 8 #include <valarray> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" |
11 | 12 |
12 namespace ui { | 13 namespace ui { |
13 | 14 |
14 // static | 15 // static |
15 const int ListSelectionModel::kUnselectedIndex = -1; | 16 const int ListSelectionModel::kUnselectedIndex = -1; |
16 | 17 |
17 static void IncrementFromImpl(int index, int* value) { | 18 static void IncrementFromImpl(int index, int* value) { |
18 if (*value >= index) | 19 if (*value >= index) |
19 (*value)++; | 20 (*value)++; |
20 } | 21 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 } | 61 } |
61 | 62 |
62 void ListSelectionModel::SetSelectedIndex(int index) { | 63 void ListSelectionModel::SetSelectedIndex(int index) { |
63 anchor_ = active_ = index; | 64 anchor_ = active_ = index; |
64 selected_indices_.clear(); | 65 selected_indices_.clear(); |
65 if (index != kUnselectedIndex) | 66 if (index != kUnselectedIndex) |
66 selected_indices_.push_back(index); | 67 selected_indices_.push_back(index); |
67 } | 68 } |
68 | 69 |
69 bool ListSelectionModel::IsSelected(int index) const { | 70 bool ListSelectionModel::IsSelected(int index) const { |
70 return std::find(selected_indices_.begin(), selected_indices_.end(), index) != | 71 return base::ContainsValue(selected_indices_, index); |
71 selected_indices_.end(); | |
72 } | 72 } |
73 | 73 |
74 void ListSelectionModel::AddIndexToSelection(int index) { | 74 void ListSelectionModel::AddIndexToSelection(int index) { |
75 if (!IsSelected(index)) { | 75 if (!IsSelected(index)) { |
76 selected_indices_.push_back(index); | 76 selected_indices_.push_back(index); |
77 std::sort(selected_indices_.begin(), selected_indices_.end()); | 77 std::sort(selected_indices_.begin(), selected_indices_.end()); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 void ListSelectionModel::RemoveIndexFromSelection(int index) { | 81 void ListSelectionModel::RemoveIndexFromSelection(int index) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 anchor_ = source.anchor_; | 144 anchor_ = source.anchor_; |
145 } | 145 } |
146 | 146 |
147 bool ListSelectionModel::Equals(const ListSelectionModel& rhs) const { | 147 bool ListSelectionModel::Equals(const ListSelectionModel& rhs) const { |
148 return active_ == rhs.active() && | 148 return active_ == rhs.active() && |
149 anchor_ == rhs.anchor() && | 149 anchor_ == rhs.anchor() && |
150 selected_indices() == rhs.selected_indices(); | 150 selected_indices() == rhs.selected_indices(); |
151 } | 151 } |
152 | 152 |
153 } // namespace ui | 153 } // namespace ui |
OLD | NEW |