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