Fix testGetVisitedHistoryCallbackAfterDestroy
[chromium-blink-merge.git] / ui / gfx / selection_model.cc
blob5352d8653cd99b447ca4a104345857585ea477c4
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"
10 namespace gfx {
12 SelectionModel::SelectionModel()
13 : selection_(0),
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());
34 else
35 str += selection().ToString();
36 const bool backward = caret_affinity() == CURSOR_BACKWARD;
37 return str + (backward ? ",BACKWARD}" : ",FORWARD}");
40 } // namespace gfx