Home | History | Annotate | Download | only in gfx
      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), caret_affinity_(CURSOR_BACKWARD) {}
     14 
     15 SelectionModel::SelectionModel(size_t position, LogicalCursorDirection affinity)
     16   : selection_(position), caret_affinity_(affinity) {}
     17 
     18 SelectionModel::SelectionModel(ui::Range selection,
     19                                LogicalCursorDirection affinity)
     20   : selection_(selection), caret_affinity_(affinity) {}
     21 
     22 bool SelectionModel::operator==(const SelectionModel& sel) const {
     23   return selection_ == sel.selection() &&
     24          caret_affinity_ == sel.caret_affinity();
     25 }
     26 
     27 std::string SelectionModel::ToString() const {
     28   std::string str = "{";
     29   if (selection().is_empty())
     30     base::StringAppendF(&str, "%" PRIuS, caret_pos());
     31   else
     32     str += selection().ToString();
     33   const bool backward = caret_affinity() == CURSOR_BACKWARD;
     34   return str + (backward ? ",BACKWARD}" : ",FORWARD}");
     35 }
     36 
     37 }  // namespace gfx
     38