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

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: Removing the SelectionBound test from Android, since touch_editing_controller not included in Andro… 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
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c2a5765370e2f82a51cbe474e44510ff98ef05a7 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -1101,13 +1101,37 @@ 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 anchor_position_index = sel.selection().start();
+ size_t focus_position_index = sel.selection().end();
+
+ if (anchor_position_index == focus_position_index) {
+ anchor->type = focus->type = ui::SelectionBound::CENTER;
+ } else if ((ltr && anchor_position_index < focus_position_index) ||
+ (!ltr && anchor_position_index > focus_position_index)) {
+ anchor->type = ui::SelectionBound::LEFT;
+ focus->type = ui::SelectionBound::RIGHT;
+ } else {
+ anchor->type = ui::SelectionBound::RIGHT;
+ focus->type = ui::SelectionBound::LEFT;
+ }
}
gfx::Rect Textfield::GetBounds() {
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698