Chromium Code Reviews| Index: ui/gfx/selection_model.cc |
| diff --git a/ui/gfx/selection_model.cc b/ui/gfx/selection_model.cc |
| index 3dec8be443e086c31235ba65b734778f18271f36..e883543b5f857af0469b28b6ae376fed98fc812e 100644 |
| --- a/ui/gfx/selection_model.cc |
| +++ b/ui/gfx/selection_model.cc |
| @@ -4,47 +4,33 @@ |
| #include "ui/gfx/selection_model.h" |
| -namespace gfx { |
| - |
| -SelectionModel::SelectionModel() { |
| - Init(0, 0, 0, LEADING); |
| -} |
| +#include <ostream> |
| -SelectionModel::SelectionModel(size_t pos) { |
| - Init(pos, pos, pos, LEADING); |
| -} |
| +namespace gfx { |
| -SelectionModel::SelectionModel(size_t end, |
| - size_t pos, |
| - CaretPlacement placement) { |
| - Init(end, end, pos, placement); |
| -} |
| +SelectionModel::SelectionModel() |
| + : selection_(0), caret_affinity_(CURSOR_BACKWARD) {} |
| -SelectionModel::SelectionModel(size_t start, |
| - size_t end, |
| - size_t pos, |
| - CaretPlacement placement) { |
| - Init(start, end, pos, placement); |
| -} |
| +SelectionModel::SelectionModel(size_t position, LogicalCursorDirection affinity) |
| + : selection_(position), caret_affinity_(affinity) {} |
| -SelectionModel::~SelectionModel() { |
| -} |
| +SelectionModel::SelectionModel(ui::Range selection, |
| + LogicalCursorDirection affinity) |
| + : selection_(selection), caret_affinity_(affinity) {} |
| -bool SelectionModel::Equals(const SelectionModel& sel) const { |
| - return selection_start_ == sel.selection_start() && |
| - selection_end_ == sel.selection_end() && |
| - caret_pos_ == sel.caret_pos() && |
| - caret_placement_ == sel.caret_placement(); |
| +bool SelectionModel::operator==(const SelectionModel& sel) const { |
| + return selection_ == sel.selection() && |
| + caret_affinity_ == sel.caret_affinity(); |
| } |
| -void SelectionModel::Init(size_t start, |
| - size_t end, |
| - size_t pos, |
| - CaretPlacement placement) { |
| - selection_start_ = start; |
| - selection_end_ = end; |
| - caret_pos_ = pos; |
| - caret_placement_ = placement; |
| +std::ostream& operator<<(std::ostream& out, const SelectionModel& sel) { |
| + out << '{'; |
| + if (sel.selection().is_empty()) |
| + out << sel.caret_pos(); |
| + else |
| + out << sel.selection(); |
| + bool backward = sel.caret_affinity() == CURSOR_FORWARD; |
|
xji
2012/02/24 20:16:52
s/CURSOR_FORWARD/CURSOR_BACKWARD/
benrg
2012/03/07 01:04:44
Oops.
|
| + return out << (backward ? ",BACKWARD}" : ",FORWARD}"); |
| } |
| } // namespace gfx |