Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: ui/gfx/selection_model.cc

Issue 9390022: Simplify handling of BiDi cursor movement (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make set_selection_start private, fix accidental inclusion of local hacks Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698