OLD | NEW |
---|---|
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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 if (move) { | 219 if (move) { |
220 gfx::SelectionModel selected; | 220 gfx::SelectionModel selected; |
221 model_->GetSelectionModel(&selected); | 221 model_->GetSelectionModel(&selected); |
222 // Adjust the drop destination if it is on or after the current selection. | 222 // Adjust the drop destination if it is on or after the current selection. |
223 size_t max_of_selected_range = std::max(selected.selection_start(), | 223 size_t max_of_selected_range = std::max(selected.selection_start(), |
224 selected.selection_end()); | 224 selected.selection_end()); |
225 size_t min_of_selected_range = std::min(selected.selection_start(), | 225 size_t min_of_selected_range = std::min(selected.selection_start(), |
226 selected.selection_end()); | 226 selected.selection_end()); |
227 size_t selected_range_length = max_of_selected_range - | 227 size_t selected_range_length = max_of_selected_range - |
228 min_of_selected_range; | 228 min_of_selected_range; |
229 if (max_of_selected_range <= drop_destination.selection_end()) | 229 size_t drop_destination_end = drop_destination.selection_end(); |
230 drop_destination.set_selection_end( | 230 if (max_of_selected_range <= drop_destination_end) |
231 drop_destination.selection_end() - selected_range_length); | 231 drop_destination_end -= selected_range_length; |
232 else if (min_of_selected_range <= drop_destination.selection_end()) | 232 else if (min_of_selected_range <= drop_destination_end) |
233 drop_destination.set_selection_end(min_of_selected_range); | 233 drop_destination_end = min_of_selected_range; |
234 model_->DeleteSelectionAndInsertTextAt(text, | 234 model_->DeleteSelectionAndInsertTextAt(text, drop_destination_end); |
235 drop_destination.selection_end()); | |
236 } else { | 235 } else { |
237 drop_destination.set_selection_start(drop_destination.selection_end()); | 236 drop_destination = gfx::SelectionModel(drop_destination.selection_end(), |
msw
2011/10/04 07:25:41
Why make this change? Constructing a new Selection
xji
2011/10/05 01:23:42
Ah, this is not needed. drop_destination's selecti
| |
237 drop_destination.caret_pos(), | |
238 drop_destination.caret_placement()); | |
238 model_->MoveCursorTo(drop_destination); | 239 model_->MoveCursorTo(drop_destination); |
239 // Drop always inserts text even if the textfield is not in insert mode. | 240 // Drop always inserts text even if the textfield is not in insert mode. |
240 model_->InsertText(text); | 241 model_->InsertText(text); |
241 } | 242 } |
242 skip_input_method_cancel_composition_ = false; | 243 skip_input_method_cancel_composition_ = false; |
243 UpdateAfterChange(true, true); | 244 UpdateAfterChange(true, true); |
244 OnAfterUserAction(); | 245 OnAfterUserAction(); |
245 return move ? ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY; | 246 return move ? ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY; |
246 } | 247 } |
247 | 248 |
(...skipping 23 matching lines...) Expand all Loading... | |
271 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) | 272 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) |
272 return; | 273 return; |
273 | 274 |
274 gfx::SelectionModel start_pos = GetRenderText()->FindCursorPosition(start); | 275 gfx::SelectionModel start_pos = GetRenderText()->FindCursorPosition(start); |
275 gfx::SelectionModel end_pos = GetRenderText()->FindCursorPosition(end); | 276 gfx::SelectionModel end_pos = GetRenderText()->FindCursorPosition(end); |
276 | 277 |
277 OnBeforeUserAction(); | 278 OnBeforeUserAction(); |
278 // Merge selection models of "start_pos" and "end_pos" so that | 279 // Merge selection models of "start_pos" and "end_pos" so that |
279 // selection start is the value from "start_pos", while selection end, | 280 // selection start is the value from "start_pos", while selection end, |
280 // caret position, and caret placement are values from "end_pos". | 281 // caret position, and caret placement are values from "end_pos". |
281 gfx::SelectionModel sel(end_pos); | 282 gfx::SelectionModel sel(start_pos.selection_start(), end_pos.selection_end(), |
282 sel.set_selection_start(start_pos.selection_start()); | 283 end_pos.caret_pos(), end_pos.caret_placement()); |
283 model_->SelectSelectionModel(sel); | 284 model_->SelectSelectionModel(sel); |
284 | 285 |
285 OnCaretBoundsChanged(); | 286 OnCaretBoundsChanged(); |
286 SchedulePaint(); | 287 SchedulePaint(); |
287 OnAfterUserAction(); | 288 OnAfterUserAction(); |
288 } | 289 } |
289 | 290 |
290 gfx::NativeCursor NativeTextfieldViews::GetCursor(const MouseEvent& event) { | 291 gfx::NativeCursor NativeTextfieldViews::GetCursor(const MouseEvent& event) { |
291 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); | 292 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); |
292 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED; | 293 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 | 484 |
484 gfx::NativeView NativeTextfieldViews::GetTestingHandle() const { | 485 gfx::NativeView NativeTextfieldViews::GetTestingHandle() const { |
485 NOTREACHED(); | 486 NOTREACHED(); |
486 return NULL; | 487 return NULL; |
487 } | 488 } |
488 | 489 |
489 bool NativeTextfieldViews::IsIMEComposing() const { | 490 bool NativeTextfieldViews::IsIMEComposing() const { |
490 return model_->HasCompositionText(); | 491 return model_->HasCompositionText(); |
491 } | 492 } |
492 | 493 |
494 void NativeTextfieldViews::GetSelectedRange(ui::Range* range) const { | |
495 model_->GetSelectedRange(range); | |
496 } | |
497 | |
498 void NativeTextfieldViews::SelectRange(const ui::Range& range) { | |
499 model_->SelectRange(range); | |
500 OnCaretBoundsChanged(); | |
501 SchedulePaint(); | |
502 } | |
503 | |
493 void NativeTextfieldViews::GetSelectionModel(gfx::SelectionModel* sel) const { | 504 void NativeTextfieldViews::GetSelectionModel(gfx::SelectionModel* sel) const { |
494 model_->GetSelectionModel(sel); | 505 model_->GetSelectionModel(sel); |
495 } | 506 } |
496 | 507 |
497 void NativeTextfieldViews::SelectSelectionModel( | 508 void NativeTextfieldViews::SelectSelectionModel( |
498 const gfx::SelectionModel& sel) { | 509 const gfx::SelectionModel& sel) { |
499 model_->SelectSelectionModel(sel); | 510 model_->SelectSelectionModel(sel); |
500 OnCaretBoundsChanged(); | 511 OnCaretBoundsChanged(); |
501 SchedulePaint(); | 512 SchedulePaint(); |
502 } | 513 } |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
751 range->set_start(sel.selection_start()); | 762 range->set_start(sel.selection_start()); |
752 range->set_end(sel.selection_end()); | 763 range->set_end(sel.selection_end()); |
753 return true; | 764 return true; |
754 } | 765 } |
755 | 766 |
756 bool NativeTextfieldViews::SetSelectionRange(const ui::Range& range) { | 767 bool NativeTextfieldViews::SetSelectionRange(const ui::Range& range) { |
757 if (GetTextInputType() != ui::TEXT_INPUT_TYPE_TEXT || !range.IsValid()) | 768 if (GetTextInputType() != ui::TEXT_INPUT_TYPE_TEXT || !range.IsValid()) |
758 return false; | 769 return false; |
759 | 770 |
760 OnBeforeUserAction(); | 771 OnBeforeUserAction(); |
761 SelectSelectionModel(gfx::SelectionModel(range.start(), range.end())); | 772 SelectRange(range); |
762 OnAfterUserAction(); | 773 OnAfterUserAction(); |
763 return true; | 774 return true; |
764 } | 775 } |
765 | 776 |
766 bool NativeTextfieldViews::DeleteRange(const ui::Range& range) { | 777 bool NativeTextfieldViews::DeleteRange(const ui::Range& range) { |
767 if (GetTextInputType() != ui::TEXT_INPUT_TYPE_TEXT || range.is_empty()) | 778 if (GetTextInputType() != ui::TEXT_INPUT_TYPE_TEXT || range.is_empty()) |
768 return false; | 779 return false; |
769 | 780 |
770 OnBeforeUserAction(); | 781 OnBeforeUserAction(); |
771 gfx::SelectionModel selection(range.start(), range.end()); | 782 model_->SelectRange(range); |
772 model_->SelectSelectionModel(selection); | |
773 if (model_->HasSelection()) { | 783 if (model_->HasSelection()) { |
774 model_->DeleteSelection(); | 784 model_->DeleteSelection(); |
775 UpdateAfterChange(true, true); | 785 UpdateAfterChange(true, true); |
776 } | 786 } |
777 OnAfterUserAction(); | 787 OnAfterUserAction(); |
778 return true; | 788 return true; |
779 } | 789 } |
780 | 790 |
781 bool NativeTextfieldViews::GetTextFromRange( | 791 bool NativeTextfieldViews::GetTextFromRange( |
782 const ui::Range& range, | 792 const ui::Range& range, |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1063 | 1073 |
1064 #if defined(USE_AURA) | 1074 #if defined(USE_AURA) |
1065 // static | 1075 // static |
1066 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 1076 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
1067 Textfield* field) { | 1077 Textfield* field) { |
1068 return new NativeTextfieldViews(field); | 1078 return new NativeTextfieldViews(field); |
1069 } | 1079 } |
1070 #endif | 1080 #endif |
1071 | 1081 |
1072 } // namespace views | 1082 } // namespace views |
OLD | NEW |