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

Side by Side 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: Some test cleanup 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/textfield/textfield.h" 5 #include "ui/views/controls/textfield/textfield.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "ui/accessibility/ax_view_state.h" 10 #include "ui/accessibility/ax_view_state.h"
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 1094
1095 OnBeforeUserAction(); 1095 OnBeforeUserAction();
1096 SelectSelectionModel(selection); 1096 SelectSelectionModel(selection);
1097 OnAfterUserAction(); 1097 OnAfterUserAction();
1098 } 1098 }
1099 1099
1100 void Textfield::MoveCaretTo(const gfx::Point& point) { 1100 void Textfield::MoveCaretTo(const gfx::Point& point) {
1101 SelectRect(point, point); 1101 SelectRect(point, point);
1102 } 1102 }
1103 1103
1104 void Textfield::GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) { 1104 void Textfield::GetSelectionEndPoints(ui::SelectionBound* anchor,
1105 ui::SelectionBound* focus) {
1105 gfx::RenderText* render_text = GetRenderText(); 1106 gfx::RenderText* render_text = GetRenderText();
1106 const gfx::SelectionModel& sel = render_text->selection_model(); 1107 const gfx::SelectionModel& sel = render_text->selection_model();
1107 gfx::SelectionModel start_sel = 1108 gfx::SelectionModel start_sel =
1108 render_text->GetSelectionModelForSelectionStart(); 1109 render_text->GetSelectionModelForSelectionStart();
1109 *p1 = render_text->GetCursorBounds(start_sel, true); 1110 gfx::Rect r1 = render_text->GetCursorBounds(start_sel, true);
1110 *p2 = render_text->GetCursorBounds(sel, true); 1111 gfx::Rect r2 = render_text->GetCursorBounds(sel, true);
1112
1113 anchor->edge_top = r1.origin();
1114 anchor->edge_bottom = r1.bottom_left();
1115 focus->edge_top = r2.origin();
1116 focus->edge_bottom = r2.bottom_left();
1117
1118 // Determine the SelectionBound's type for focus and anchor.
1119 // TODO(mfomitchev): Ideally we should have different logical directions for
1120 // start and end to support proper handle direction for mixed LTR/RTL text.
1121 const bool ltr = GetTextDirection() != base::i18n::RIGHT_TO_LEFT;
1122 size_t range_start = sel.selection().start();
1123 size_t range_end = sel.selection().end();
1124
1125 if (range_start == range_end) {
1126 anchor->type = focus->type = ui::SelectionBound::CENTER;
1127 } else if (ltr ^ (range_start < range_end)) {
sky 2014/11/14 02:02:47 WHy ^ and not || ?
mfomitchev 2014/11/14 19:56:27 Any one condition is not enough.. ltr means range
sky 2014/11/14 20:30:57 Yes. I would rather have the more readable version
mfomitchev 2014/11/14 20:46:04 Ok, done. I updated render_widget_host_view_aura.c
1128 anchor->type = ui::SelectionBound::RIGHT;
1129 focus->type = ui::SelectionBound::LEFT;
1130 } else {
1131 anchor->type = ui::SelectionBound::LEFT;
1132 focus->type = ui::SelectionBound::RIGHT;
1133 }
1111 } 1134 }
1112 1135
1113 gfx::Rect Textfield::GetBounds() { 1136 gfx::Rect Textfield::GetBounds() {
1114 return GetLocalBounds(); 1137 return GetLocalBounds();
1115 } 1138 }
1116 1139
1117 gfx::NativeView Textfield::GetNativeView() const { 1140 gfx::NativeView Textfield::GetNativeView() const {
1118 return GetWidget()->GetNativeView(); 1141 return GetWidget()->GetNativeView();
1119 } 1142 }
1120 1143
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 const size_t length = selection_clipboard_text.length(); 1841 const size_t length = selection_clipboard_text.length();
1819 range = gfx::Range(range.start() + length, range.end() + length); 1842 range = gfx::Range(range.start() + length, range.end() + length);
1820 } 1843 }
1821 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); 1844 model_->MoveCursorTo(gfx::SelectionModel(range, affinity));
1822 UpdateAfterChange(true, true); 1845 UpdateAfterChange(true, true);
1823 OnAfterUserAction(); 1846 OnAfterUserAction();
1824 } 1847 }
1825 } 1848 }
1826 1849
1827 } // namespace views 1850 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698