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

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: fix a lint error 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
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,9 @@
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));
+ gfx::SelectionModel start_pos = GetRenderText()->FindCursorPosition(start);
+ gfx::SelectionModel end_pos = GetRenderText()->FindCursorPosition(end);
+ SetMergedSelectionModel(start_pos, end_pos);
msw 2011/08/03 19:46:39 Inline SetMergedSelectionModel here.
xji 2011/08/03 22:40:32 Done.
}
gfx::NativeCursor NativeTextfieldViews::GetCursor(const MouseEvent& event) {
@@ -502,6 +505,13 @@
model_->ClearEditHistory();
}
+void NativeTextfieldViews::SelectSelectionModel(
+ const gfx::SelectionModel& sel) {
+ model_->SelectSelectionModel(sel);
+ OnCaretBoundsChanged();
+ SchedulePaint();
+}
+
/////////////////////////////////////////////////////////////////
// NativeTextfieldViews, ui::SimpleMenuModel::Delegate overrides:
@@ -672,9 +682,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() {
@@ -755,6 +763,22 @@
return textfield_;
}
+bool NativeTextfieldViews::SetMergedSelectionModel(
+ const gfx::SelectionModel& start, const gfx::SelectionModel& end) {
+ if (GetTextInputType() != ui::TEXT_INPUT_TYPE_TEXT)
msw 2011/08/03 19:46:39 This will block password fields as well, this shou
xji 2011/08/03 22:40:32 Done.
+ return false;
+ if (start.selection_end() == end.selection_end()
+ && start.selection_end() == std::numeric_limits<size_t>::max())
msw 2011/08/03 19:46:39 What inspired this check? Perhaps we should be doi
xji 2011/08/03 22:40:32 Honestly, I do not know. In SetSelectionRange(), i
+ return false;
+
+ OnBeforeUserAction();
+ gfx::SelectionModel sel(end);
+ sel.set_selection_start(start.selection_start());
+ SelectSelectionModel(sel);
msw 2011/08/03 19:46:39 Inline SelectSelectionModel here.
xji 2011/08/03 22:40:32 Done.
+ OnAfterUserAction();
+ return true;
+}
+
void NativeTextfieldViews::OnCompositionTextConfirmedOrCleared() {
if (skip_input_method_cancel_composition_)
return;
@@ -966,9 +990,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() +

Powered by Google App Engine
This is Rietveld 408576698