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/gfx/selection_model.h" | 5 #include "ui/gfx/selection_model.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 | 9 |
10 namespace gfx { | 10 namespace gfx { |
11 | 11 |
12 SelectionModel::SelectionModel() | 12 SelectionModel::SelectionModel() |
13 : selection_(0), caret_affinity_(CURSOR_BACKWARD) {} | 13 : selection_(0), caret_affinity_(CURSOR_BACKWARD) {} |
14 | 14 |
15 SelectionModel::SelectionModel(size_t position, LogicalCursorDirection affinity) | 15 SelectionModel::SelectionModel(size_t position, LogicalCursorDirection affinity) |
16 : selection_(position), caret_affinity_(affinity) {} | 16 : selection_(position), caret_affinity_(affinity) {} |
17 | 17 |
18 SelectionModel::SelectionModel(ui::Range selection, | 18 SelectionModel::SelectionModel(gfx::Range selection, |
19 LogicalCursorDirection affinity) | 19 LogicalCursorDirection affinity) |
20 : selection_(selection), caret_affinity_(affinity) {} | 20 : selection_(selection), caret_affinity_(affinity) {} |
21 | 21 |
22 bool SelectionModel::operator==(const SelectionModel& sel) const { | 22 bool SelectionModel::operator==(const SelectionModel& sel) const { |
23 return selection_ == sel.selection() && | 23 return selection_ == sel.selection() && |
24 caret_affinity_ == sel.caret_affinity(); | 24 caret_affinity_ == sel.caret_affinity(); |
25 } | 25 } |
26 | 26 |
27 std::string SelectionModel::ToString() const { | 27 std::string SelectionModel::ToString() const { |
28 std::string str = "{"; | 28 std::string str = "{"; |
29 if (selection().is_empty()) | 29 if (selection().is_empty()) |
30 base::StringAppendF(&str, "%" PRIuS, caret_pos()); | 30 base::StringAppendF(&str, "%" PRIuS, caret_pos()); |
31 else | 31 else |
32 str += selection().ToString(); | 32 str += selection().ToString(); |
33 const bool backward = caret_affinity() == CURSOR_BACKWARD; | 33 const bool backward = caret_affinity() == CURSOR_BACKWARD; |
34 return str + (backward ? ",BACKWARD}" : ",FORWARD}"); | 34 return str + (backward ? ",BACKWARD}" : ",FORWARD}"); |
35 } | 35 } |
36 | 36 |
37 } // namespace gfx | 37 } // namespace gfx |
OLD | NEW |