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

Side by Side Diff: views/controls/textfield/native_textfield_views.cc

Issue 8044004: Clean up of SelectionModel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/controls/textfield/native_textfield_views.h" 5 #include "views/controls/textfield/native_textfield_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 if (move) { 218 if (move) {
219 gfx::SelectionModel selected; 219 gfx::SelectionModel selected;
220 model_->GetSelectionModel(&selected); 220 model_->GetSelectionModel(&selected);
221 // Adjust the drop destination if it is on or after the current selection. 221 // Adjust the drop destination if it is on or after the current selection.
222 size_t max_of_selected_range = std::max(selected.selection_start(), 222 size_t max_of_selected_range = std::max(selected.selection_start(),
223 selected.selection_end()); 223 selected.selection_end());
224 size_t min_of_selected_range = std::min(selected.selection_start(), 224 size_t min_of_selected_range = std::min(selected.selection_start(),
225 selected.selection_end()); 225 selected.selection_end());
226 size_t selected_range_length = max_of_selected_range - 226 size_t selected_range_length = max_of_selected_range -
227 min_of_selected_range; 227 min_of_selected_range;
228 if (max_of_selected_range <= drop_destination.selection_end()) 228 size_t drop_destination_end = drop_destination.selection_end();
229 drop_destination.set_selection_end( 229 if (max_of_selected_range <= drop_destination_end)
230 drop_destination.selection_end() - selected_range_length); 230 drop_destination_end -= selected_range_length;
231 else if (min_of_selected_range <= drop_destination.selection_end()) 231 else if (min_of_selected_range <= drop_destination_end)
232 drop_destination.set_selection_end(min_of_selected_range); 232 drop_destination_end = min_of_selected_range;
233 model_->DeleteSelectionAndInsertTextAt(text, 233 model_->DeleteSelectionAndInsertTextAt(text, drop_destination_end);
234 drop_destination.selection_end());
235 } else { 234 } else {
236 drop_destination.set_selection_start(drop_destination.selection_end()); 235 drop_destination.set_selection_start(drop_destination.selection_end());
237 model_->MoveCursorTo(drop_destination); 236 model_->MoveCursorTo(drop_destination);
238 // Drop always inserts text even if the textfield is not in insert mode. 237 // Drop always inserts text even if the textfield is not in insert mode.
239 model_->InsertText(text); 238 model_->InsertText(text);
240 } 239 }
241 skip_input_method_cancel_composition_ = false; 240 skip_input_method_cancel_composition_ = false;
242 UpdateAfterChange(true, true); 241 UpdateAfterChange(true, true);
243 OnAfterUserAction(); 242 OnAfterUserAction();
244 return move ? ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY; 243 return move ? ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY;
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 void NativeTextfieldViews::OnCaretBoundsChanged() { 1005 void NativeTextfieldViews::OnCaretBoundsChanged() {
1007 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. 1006 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320.
1008 if (textfield_->GetInputMethod()) 1007 if (textfield_->GetInputMethod())
1009 textfield_->GetInputMethod()->OnCaretBoundsChanged(textfield_); 1008 textfield_->GetInputMethod()->OnCaretBoundsChanged(textfield_);
1010 1009
1011 // Notify selection controller 1010 // Notify selection controller
1012 if (!touch_selection_controller_.get()) 1011 if (!touch_selection_controller_.get())
1013 return; 1012 return;
1014 gfx::RenderText* render_text = GetRenderText(); 1013 gfx::RenderText* render_text = GetRenderText();
1015 const gfx::SelectionModel& sel = render_text->selection_model(); 1014 const gfx::SelectionModel& sel = render_text->selection_model();
1016 gfx::SelectionModel start_sel(sel.selection_start(), sel.selection_start(), 1015 gfx::SelectionModel start_sel =
1017 sel.selection_start(), gfx::SelectionModel::LEADING); 1016 render_text->GetSelectionModelForSelectionStart();
1018 gfx::Rect start_cursor = render_text->GetCursorBounds(start_sel, false); 1017 gfx::Rect start_cursor = render_text->GetCursorBounds(start_sel, true);
1019 gfx::Rect end_cursor = render_text->GetCursorBounds(sel, false); 1018 gfx::Rect end_cursor = render_text->GetCursorBounds(sel, true);
1020 gfx::Point start(start_cursor.x(), start_cursor.bottom() - 1); 1019 gfx::Point start(start_cursor.x(), start_cursor.bottom() - 1);
1021 gfx::Point end(end_cursor.x(), end_cursor.bottom() - 1); 1020 gfx::Point end(end_cursor.x(), end_cursor.bottom() - 1);
1022 touch_selection_controller_->SelectionChanged(start, end); 1021 touch_selection_controller_->SelectionChanged(start, end);
1023 } 1022 }
1024 1023
1025 void NativeTextfieldViews::OnBeforeUserAction() { 1024 void NativeTextfieldViews::OnBeforeUserAction() {
1026 TextfieldController* controller = textfield_->GetController(); 1025 TextfieldController* controller = textfield_->GetController();
1027 if (controller) 1026 if (controller)
1028 controller->OnBeforeUserAction(textfield_); 1027 controller->OnBeforeUserAction(textfield_);
1029 } 1028 }
(...skipping 30 matching lines...) Expand all
1060 1059
1061 #if defined(USE_AURA) 1060 #if defined(USE_AURA)
1062 // static 1061 // static
1063 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( 1062 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper(
1064 Textfield* field) { 1063 Textfield* field) {
1065 return new NativeTextfieldViews(field); 1064 return new NativeTextfieldViews(field);
1066 } 1065 }
1067 #endif 1066 #endif
1068 1067
1069 } // namespace views 1068 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698