[email protected] | d999021 | 2012-03-13 01:09:31 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ed9f8fba | 2011-09-28 21:50:09 | [diff] [blame] | 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/gfx/selection_model.h" | ||||
6 | |||||
[email protected] | 9a55b8c9 | 2012-05-17 20:53:08 | [diff] [blame] | 7 | #include "base/format_macros.h" |
[email protected] | 3b3a3064 | 2013-06-11 19:48:38 | [diff] [blame] | 8 | #include "base/strings/stringprintf.h" |
[email protected] | d999021 | 2012-03-13 01:09:31 | [diff] [blame] | 9 | |
[email protected] | ed9f8fba | 2011-09-28 21:50:09 | [diff] [blame] | 10 | namespace gfx { |
11 | |||||
[email protected] | d999021 | 2012-03-13 01:09:31 | [diff] [blame] | 12 | SelectionModel::SelectionModel() |
[email protected] | 3dfe5c5 | 2013-09-18 22:01:22 | [diff] [blame] | 13 | : selection_(0), |
14 | caret_affinity_(CURSOR_BACKWARD) {} | ||||
[email protected] | d999021 | 2012-03-13 01:09:31 | [diff] [blame] | 15 | |
16 | SelectionModel::SelectionModel(size_t position, LogicalCursorDirection affinity) | ||||
[email protected] | 3dfe5c5 | 2013-09-18 22:01:22 | [diff] [blame] | 17 | : selection_(position), |
18 | caret_affinity_(affinity) {} | ||||
[email protected] | d999021 | 2012-03-13 01:09:31 | [diff] [blame] | 19 | |
[email protected] | 3dfe5c5 | 2013-09-18 22:01:22 | [diff] [blame] | 20 | SelectionModel::SelectionModel(const Range& selection, |
[email protected] | d999021 | 2012-03-13 01:09:31 | [diff] [blame] | 21 | LogicalCursorDirection affinity) |
[email protected] | 3dfe5c5 | 2013-09-18 22:01:22 | [diff] [blame] | 22 | : selection_(selection), |
23 | caret_affinity_(affinity) {} | ||||
[email protected] | d999021 | 2012-03-13 01:09:31 | [diff] [blame] | 24 | |
25 | bool SelectionModel::operator==(const SelectionModel& sel) const { | ||||
26 | return selection_ == sel.selection() && | ||||
27 | caret_affinity_ == sel.caret_affinity(); | ||||
[email protected] | ed9f8fba | 2011-09-28 21:50:09 | [diff] [blame] | 28 | } |
29 | |||||
[email protected] | 9a55b8c9 | 2012-05-17 20:53:08 | [diff] [blame] | 30 | std::string SelectionModel::ToString() const { |
31 | std::string str = "{"; | ||||
32 | if (selection().is_empty()) | ||||
33 | base::StringAppendF(&str, "%" PRIuS, caret_pos()); | ||||
[email protected] | d999021 | 2012-03-13 01:09:31 | [diff] [blame] | 34 | else |
[email protected] | 9a55b8c9 | 2012-05-17 20:53:08 | [diff] [blame] | 35 | str += selection().ToString(); |
36 | const bool backward = caret_affinity() == CURSOR_BACKWARD; | ||||
37 | return str + (backward ? ",BACKWARD}" : ",FORWARD}"); | ||||
[email protected] | ed9f8fba | 2011-09-28 21:50:09 | [diff] [blame] | 38 | } |
39 | |||||
40 | } // namespace gfx |