blob: 5352d8653cd99b447ca4a104345857585ea477c4 [file] [log] [blame]
[email protected]d9990212012-03-13 01:09:311// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ed9f8fba2011-09-28 21:50:092// 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]9a55b8c92012-05-17 20:53:087#include "base/format_macros.h"
[email protected]3b3a30642013-06-11 19:48:388#include "base/strings/stringprintf.h"
[email protected]d9990212012-03-13 01:09:319
[email protected]ed9f8fba2011-09-28 21:50:0910namespace gfx {
11
[email protected]d9990212012-03-13 01:09:3112SelectionModel::SelectionModel()
[email protected]3dfe5c52013-09-18 22:01:2213 : selection_(0),
14 caret_affinity_(CURSOR_BACKWARD) {}
[email protected]d9990212012-03-13 01:09:3115
16SelectionModel::SelectionModel(size_t position, LogicalCursorDirection affinity)
[email protected]3dfe5c52013-09-18 22:01:2217 : selection_(position),
18 caret_affinity_(affinity) {}
[email protected]d9990212012-03-13 01:09:3119
[email protected]3dfe5c52013-09-18 22:01:2220SelectionModel::SelectionModel(const Range& selection,
[email protected]d9990212012-03-13 01:09:3121 LogicalCursorDirection affinity)
[email protected]3dfe5c52013-09-18 22:01:2222 : selection_(selection),
23 caret_affinity_(affinity) {}
[email protected]d9990212012-03-13 01:09:3124
25bool SelectionModel::operator==(const SelectionModel& sel) const {
26 return selection_ == sel.selection() &&
27 caret_affinity_ == sel.caret_affinity();
[email protected]ed9f8fba2011-09-28 21:50:0928}
29
[email protected]9a55b8c92012-05-17 20:53:0830std::string SelectionModel::ToString() const {
31 std::string str = "{";
32 if (selection().is_empty())
33 base::StringAppendF(&str, "%" PRIuS, caret_pos());
[email protected]d9990212012-03-13 01:09:3134 else
[email protected]9a55b8c92012-05-17 20:53:0835 str += selection().ToString();
36 const bool backward = caret_affinity() == CURSOR_BACKWARD;
37 return str + (backward ? ",BACKWARD}" : ",FORWARD}");
[email protected]ed9f8fba2011-09-28 21:50:0938}
39
40} // namespace gfx