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

Unified Diff: ui/views/controls/textfield/textfield.cc

Issue 700563002: Implementing directional text selection handles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new_assets_text
Patch Set: Addressing review feedback. Created 6 years, 1 month 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/views/controls/textfield/textfield.cc
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
index 5a0cad8d9135cfa18a5c69a8b1c2d4781501fea9..ecdfb3903110ccbe0a5f2e146e1b2cba101f838a 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -1101,13 +1101,36 @@ void Textfield::MoveCaretTo(const gfx::Point& point) {
SelectRect(point, point);
}
-void Textfield::GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) {
+void Textfield::GetSelectionEndPoints(ui::SelectionBound* anchor,
+ ui::SelectionBound* focus) {
gfx::RenderText* render_text = GetRenderText();
const gfx::SelectionModel& sel = render_text->selection_model();
gfx::SelectionModel start_sel =
render_text->GetSelectionModelForSelectionStart();
- *p1 = render_text->GetCursorBounds(start_sel, true);
- *p2 = render_text->GetCursorBounds(sel, true);
+ gfx::Rect r1 = render_text->GetCursorBounds(start_sel, true);
+ gfx::Rect r2 = render_text->GetCursorBounds(sel, true);
+
+ anchor->edge_top = r1.origin();
+ anchor->edge_bottom = r1.bottom_left();
+ focus->edge_top = r2.origin();
+ focus->edge_bottom = r2.bottom_left();
+
+ // Determine the SelectionBound's type for focus and anchor.
+ // TODO(mfomitchev): Ideally we should have different logical directions for
+ // start and end to support proper handle direction for mixed LTR/RTL text.
+ const bool ltr = GetTextDirection() != base::i18n::RIGHT_TO_LEFT;
+ size_t range_start = sel.selection().start();
+ size_t range_end = sel.selection().end();
+
+ if (range_start == range_end) {
+ anchor->type = focus->type = ui::SelectionBound::CENTER;
+ } else if (ltr ^ (range_start < range_end)) {
+ anchor->type = ui::SelectionBound::RIGHT;
+ focus->type = ui::SelectionBound::LEFT;
+ } else {
+ anchor->type = ui::SelectionBound::LEFT;
+ focus->type = ui::SelectionBound::RIGHT;
+ }
}
gfx::Rect Textfield::GetBounds() {

Powered by Google App Engine
This is Rietveld 408576698