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

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

Issue 7461102: modification to RenderText for inheritance/SelectionModel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: update per comments Created 9 years, 5 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
« no previous file with comments | « ui/gfx/render_text.cc ('k') | views/controls/textfield/native_textfield_views_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/controls/textfield/native_textfield_views.cc
===================================================================
--- views/controls/textfield/native_textfield_views.cc (revision 95245)
+++ views/controls/textfield/native_textfield_views.cc (working copy)
@@ -200,7 +200,7 @@
skip_input_method_cancel_composition_ = true;
// TODO(msw): Remove final reference to FindCursorPosition.
- size_t drop_destination =
+ gfx::SelectionModel drop_destination =
GetRenderText()->FindCursorPosition(event.location());
string16 text;
event.data().GetString(&text);
@@ -212,13 +212,16 @@
ui::Range selected_range;
model_->GetSelectedRange(&selected_range);
// Adjust the drop destination if it is on or after the current selection.
- if (selected_range.GetMax() <= drop_destination)
- drop_destination -= selected_range.length();
- else if (selected_range.GetMin() <= drop_destination)
- drop_destination = selected_range.GetMin();
- model_->DeleteSelectionAndInsertTextAt(text, drop_destination);
+ if (selected_range.GetMax() <= drop_destination.selection_end())
+ drop_destination.set_selection_end(
+ drop_destination.selection_end() - selected_range.length());
+ else if (selected_range.GetMin() <= drop_destination.selection_end())
+ drop_destination.set_selection_end(selected_range.GetMin());
+ model_->DeleteSelectionAndInsertTextAt(text,
+ drop_destination.selection_end());
} else {
- model_->MoveCursorTo(drop_destination, false);
+ drop_destination.set_selection_start(drop_destination.selection_end());
+ model_->MoveCursorTo(drop_destination);
// Drop always inserts text even if the textfield is not in insert mode.
model_->InsertText(text);
}
@@ -251,9 +254,23 @@
void NativeTextfieldViews::SelectRect(const gfx::Point& start,
const gfx::Point& end) {
- size_t start_pos = GetRenderText()->FindCursorPosition(start);
- size_t end_pos = GetRenderText()->FindCursorPosition(end);
- SetSelectionRange(ui::Range(start_pos, end_pos));
+ if (GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE)
+ return;
+
+ gfx::SelectionModel start_pos = GetRenderText()->FindCursorPosition(start);
+ gfx::SelectionModel end_pos = GetRenderText()->FindCursorPosition(end);
+
+ 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".
+ gfx::SelectionModel sel(end_pos);
+ sel.set_selection_start(start_pos.selection_start());
+ model_->SelectSelectionModel(sel);
+
+ OnCaretBoundsChanged();
+ SchedulePaint();
+ OnAfterUserAction();
}
gfx::NativeCursor NativeTextfieldViews::GetCursor(const MouseEvent& event) {
@@ -672,9 +689,7 @@
}
gfx::Rect NativeTextfieldViews::GetCaretBounds() {
- gfx::RenderText* render_text = GetRenderText();
- return render_text->GetCursorBounds(render_text->GetCursorPosition(),
- render_text->insert_mode());
+ return GetRenderText()->CursorBounds();
}
bool NativeTextfieldViews::HasCompositionText() {
@@ -966,9 +981,11 @@
if (!touch_selection_controller_.get())
return;
gfx::RenderText* render_text = GetRenderText();
- ui::Range range = render_text->GetSelection();
- gfx::Rect start_cursor = render_text->GetCursorBounds(range.start(), false);
- gfx::Rect end_cursor = render_text->GetCursorBounds(range.end(), false);
+ const gfx::SelectionModel& sel = render_text->selection_model();
+ gfx::SelectionModel start_sel(sel.selection_start(), sel.selection_start(),
+ sel.selection_start(), gfx::SelectionModel::LEADING);
+ gfx::Rect start_cursor = render_text->GetCursorBounds(start_sel, false);
+ gfx::Rect end_cursor = render_text->GetCursorBounds(sel, false);
gfx::Rect display_rect = render_text->display_rect();
int total_offset_x = display_rect.x() + render_text->display_offset().x();
int total_offset_y = display_rect.y() + render_text->display_offset().y() +
« no previous file with comments | « ui/gfx/render_text.cc ('k') | views/controls/textfield/native_textfield_views_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698