- add sources.
[platform/framework/web/crosswalk.git] / src / ui / gfx / selection_model.cc
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.
4
5 #include "ui/gfx/selection_model.h"
6
7 #include "base/format_macros.h"
8 #include "base/strings/stringprintf.h"
9
10 namespace gfx {
11
12 SelectionModel::SelectionModel()
13     : selection_(0),
14       caret_affinity_(CURSOR_BACKWARD) {}
15
16 SelectionModel::SelectionModel(size_t position, LogicalCursorDirection affinity)
17     : selection_(position),
18       caret_affinity_(affinity) {}
19
20 SelectionModel::SelectionModel(const Range& selection,
21                                LogicalCursorDirection affinity)
22     : selection_(selection),
23       caret_affinity_(affinity) {}
24
25 bool SelectionModel::operator==(const SelectionModel& sel) const {
26   return selection_ == sel.selection() &&
27          caret_affinity_ == sel.caret_affinity();
28 }
29
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}");
38 }
39
40 }  // namespace gfx