OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gfx/selection_model.h" | 5 #include "ui/gfx/selection_model.h" |
6 | 6 |
| 7 #include <ostream> |
| 8 |
7 namespace gfx { | 9 namespace gfx { |
8 | 10 |
9 SelectionModel::SelectionModel() { | 11 SelectionModel::SelectionModel() |
10 Init(0, 0, 0, LEADING); | 12 : selection_(0), caret_affinity_(CURSOR_BACKWARD) {} |
| 13 |
| 14 SelectionModel::SelectionModel(size_t position, LogicalCursorDirection affinity) |
| 15 : selection_(position), caret_affinity_(affinity) {} |
| 16 |
| 17 SelectionModel::SelectionModel(ui::Range selection, |
| 18 LogicalCursorDirection affinity) |
| 19 : selection_(selection), caret_affinity_(affinity) {} |
| 20 |
| 21 bool SelectionModel::operator==(const SelectionModel& sel) const { |
| 22 return selection_ == sel.selection() && |
| 23 caret_affinity_ == sel.caret_affinity(); |
11 } | 24 } |
12 | 25 |
13 SelectionModel::SelectionModel(size_t pos) { | 26 std::ostream& operator<<(std::ostream& out, const SelectionModel& sel) { |
14 Init(pos, pos, pos, LEADING); | 27 out << '{'; |
15 } | 28 if (sel.selection().is_empty()) |
16 | 29 out << sel.caret_pos(); |
17 SelectionModel::SelectionModel(size_t end, | 30 else |
18 size_t pos, | 31 out << sel.selection(); |
19 CaretPlacement placement) { | 32 bool backward = sel.caret_affinity() == CURSOR_BACKWARD; |
20 Init(end, end, pos, placement); | 33 return out << (backward ? ",BACKWARD}" : ",FORWARD}"); |
21 } | |
22 | |
23 SelectionModel::SelectionModel(size_t start, | |
24 size_t end, | |
25 size_t pos, | |
26 CaretPlacement placement) { | |
27 Init(start, end, pos, placement); | |
28 } | |
29 | |
30 SelectionModel::~SelectionModel() { | |
31 } | |
32 | |
33 bool SelectionModel::Equals(const SelectionModel& sel) const { | |
34 return selection_start_ == sel.selection_start() && | |
35 selection_end_ == sel.selection_end() && | |
36 caret_pos_ == sel.caret_pos() && | |
37 caret_placement_ == sel.caret_placement(); | |
38 } | |
39 | |
40 void SelectionModel::Init(size_t start, | |
41 size_t end, | |
42 size_t pos, | |
43 CaretPlacement placement) { | |
44 selection_start_ = start; | |
45 selection_end_ = end; | |
46 caret_pos_ = pos; | |
47 caret_placement_ = placement; | |
48 } | 34 } |
49 | 35 |
50 } // namespace gfx | 36 } // namespace gfx |
OLD | NEW |