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

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

Issue 9390022: Simplify handling of BiDi cursor movement (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 9 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/views/controls/textfield/native_textfield_views.cc
diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc
index 709a031fcd9dccd099b819fa82cfdd469fdf1dc3..82b47e40851111c31eeadae5d71a3bd8d51020ce 100644
--- a/ui/views/controls/textfield/native_textfield_views.cc
+++ b/ui/views/controls/textfield/native_textfield_views.cc
@@ -197,8 +197,7 @@ int NativeTextfieldViews::OnPerformDrop(const DropTargetEvent& event) {
OnBeforeUserAction();
skip_input_method_cancel_composition_ = true;
- // TODO(msw): Remove final reference to FindCursorPosition.
- gfx::SelectionModel drop_destination =
+ gfx::SelectionModel drop_destination_model =
GetRenderText()->FindCursorPosition(event.location());
string16 text;
event.data().GetString(&text);
@@ -210,20 +209,12 @@ int NativeTextfieldViews::OnPerformDrop(const DropTargetEvent& event) {
gfx::SelectionModel selected;
model_->GetSelectionModel(&selected);
// Adjust the drop destination if it is on or after the current selection.
- size_t max_of_selected_range = std::max(selected.selection_start(),
- selected.selection_end());
- size_t min_of_selected_range = std::min(selected.selection_start(),
- selected.selection_end());
- size_t selected_range_length = max_of_selected_range -
- min_of_selected_range;
- size_t drop_destination_end = drop_destination.selection_end();
- if (max_of_selected_range <= drop_destination_end)
- drop_destination_end -= selected_range_length;
- else if (min_of_selected_range <= drop_destination_end)
- drop_destination_end = min_of_selected_range;
- model_->DeleteSelectionAndInsertTextAt(text, drop_destination_end);
+ size_t drop_destination = drop_destination_model.caret_pos();
+ drop_destination -=
+ selected.selection().Intersect(ui::Range(0, drop_destination)).length();
+ model_->DeleteSelectionAndInsertTextAt(text, drop_destination);
} else {
- model_->MoveCursorTo(drop_destination);
+ model_->MoveCursorTo(drop_destination_model);
// Drop always inserts text even if the textfield is not in insert mode.
model_->InsertText(text);
}
@@ -259,19 +250,14 @@ void NativeTextfieldViews::SelectRect(const gfx::Point& start,
if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE)
return;
- gfx::SelectionModel start_pos = GetRenderText()->FindCursorPosition(start);
- gfx::SelectionModel end_pos = GetRenderText()->FindCursorPosition(end);
+ gfx::SelectionModel start_caret = GetRenderText()->FindCursorPosition(start);
+ gfx::SelectionModel end_caret = GetRenderText()->FindCursorPosition(end);
+ gfx::SelectionModel selection(
+ ui::Range(start_caret.caret_pos(), end_caret.caret_pos()),
+ end_caret.caret_affinity());
OnBeforeUserAction();
- // Merge selection models of "start_pos" and "end_pos" so that
- // selection start is the value from "start_pos", while selection end,
- // caret position, and caret placement are values from "end_pos".
- if (start_pos.selection_start() == end_pos.selection_end())
- model_->SelectSelectionModel(end_pos);
- else
- model_->SelectRange(ui::Range(start_pos.selection_start(),
- end_pos.selection_end()));
-
+ model_->SelectSelectionModel(selection);
OnCaretBoundsChanged();
SchedulePaint();
OnAfterUserAction();
@@ -480,7 +466,7 @@ bool NativeTextfieldViews::IsIMEComposing() const {
}
void NativeTextfieldViews::GetSelectedRange(ui::Range* range) const {
- model_->GetSelectedRange(range);
+ *range = GetRenderText()->selection();
}
void NativeTextfieldViews::SelectRange(const ui::Range& range) {
@@ -750,11 +736,7 @@ bool NativeTextfieldViews::GetCompositionTextRange(ui::Range* range) {
bool NativeTextfieldViews::GetSelectionRange(ui::Range* range) {
if (!ImeEditingAllowed())
return false;
-
- gfx::SelectionModel sel;
- model_->GetSelectionModel(&sel);
- range->set_start(sel.selection_start());
- range->set_end(sel.selection_end());
+ GetSelectedRange(range);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698