| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } | 191 } |
| 192 | 192 |
| 193 int NativeTextfieldViews::OnPerformDrop(const DropTargetEvent& event) { | 193 int NativeTextfieldViews::OnPerformDrop(const DropTargetEvent& event) { |
| 194 DCHECK(CanDrop(event.data())); | 194 DCHECK(CanDrop(event.data())); |
| 195 DCHECK(!initiating_drag_ || | 195 DCHECK(!initiating_drag_ || |
| 196 !GetRenderText()->IsPointInSelection(event.location())); | 196 !GetRenderText()->IsPointInSelection(event.location())); |
| 197 OnBeforeUserAction(); | 197 OnBeforeUserAction(); |
| 198 skip_input_method_cancel_composition_ = true; | 198 skip_input_method_cancel_composition_ = true; |
| 199 | 199 |
| 200 // TODO(msw): Remove final reference to FindCursorPosition. | 200 // TODO(msw): Remove final reference to FindCursorPosition. |
| 201 size_t drop_destination = | 201 gfx::SelectionModel drop_destination = |
| 202 GetRenderText()->FindCursorPosition(event.location()); | 202 GetRenderText()->FindCursorPosition(event.location()); |
| 203 string16 text; | 203 string16 text; |
| 204 event.data().GetString(&text); | 204 event.data().GetString(&text); |
| 205 | 205 |
| 206 // We'll delete the current selection for a drag and drop within this view. | 206 // We'll delete the current selection for a drag and drop within this view. |
| 207 bool move = initiating_drag_ && !event.IsControlDown() && | 207 bool move = initiating_drag_ && !event.IsControlDown() && |
| 208 event.source_operations() & ui::DragDropTypes::DRAG_MOVE; | 208 event.source_operations() & ui::DragDropTypes::DRAG_MOVE; |
| 209 if (move) { | 209 if (move) { |
| 210 ui::Range selected_range; | 210 ui::Range selected_range; |
| 211 model_->GetSelectedRange(&selected_range); | 211 model_->GetSelectedRange(&selected_range); |
| 212 // Adjust the drop destination if it is on or after the current selection. | 212 // Adjust the drop destination if it is on or after the current selection. |
| 213 if (selected_range.GetMax() <= drop_destination) | 213 if (selected_range.GetMax() <= drop_destination.selection_end()) |
| 214 drop_destination -= selected_range.length(); | 214 drop_destination.set_selection_end( |
| 215 else if (selected_range.GetMin() <= drop_destination) | 215 drop_destination.selection_end() - selected_range.length()); |
| 216 drop_destination = selected_range.GetMin(); | 216 else if (selected_range.GetMin() <= drop_destination.selection_end()) |
| 217 model_->DeleteSelectionAndInsertTextAt(text, drop_destination); | 217 drop_destination.set_selection_end(selected_range.GetMin()); |
| 218 model_->DeleteSelectionAndInsertTextAt(text, |
| 219 drop_destination.selection_end()); |
| 218 } else { | 220 } else { |
| 219 model_->MoveCursorTo(drop_destination, false); | 221 drop_destination.SetSelectionEmpty(); |
| 222 model_->MoveCursorTo(&drop_destination); |
| 220 // Drop always inserts text even if the textfield is not in insert mode. | 223 // Drop always inserts text even if the textfield is not in insert mode. |
| 221 model_->InsertText(text); | 224 model_->InsertText(text); |
| 222 } | 225 } |
| 223 skip_input_method_cancel_composition_ = false; | 226 skip_input_method_cancel_composition_ = false; |
| 224 UpdateAfterChange(true, true); | 227 UpdateAfterChange(true, true); |
| 225 OnAfterUserAction(); | 228 OnAfterUserAction(); |
| 226 return move ? ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY; | 229 return move ? ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY; |
| 227 } | 230 } |
| 228 | 231 |
| 229 void NativeTextfieldViews::OnDragDone() { | 232 void NativeTextfieldViews::OnDragDone() { |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 | 652 |
| 650 ui::TextInputType NativeTextfieldViews::GetTextInputType() { | 653 ui::TextInputType NativeTextfieldViews::GetTextInputType() { |
| 651 if (textfield_->read_only() || !textfield_->IsEnabled()) | 654 if (textfield_->read_only() || !textfield_->IsEnabled()) |
| 652 return ui::TEXT_INPUT_TYPE_NONE; | 655 return ui::TEXT_INPUT_TYPE_NONE; |
| 653 else if (textfield_->IsPassword()) | 656 else if (textfield_->IsPassword()) |
| 654 return ui::TEXT_INPUT_TYPE_PASSWORD; | 657 return ui::TEXT_INPUT_TYPE_PASSWORD; |
| 655 return ui::TEXT_INPUT_TYPE_TEXT; | 658 return ui::TEXT_INPUT_TYPE_TEXT; |
| 656 } | 659 } |
| 657 | 660 |
| 658 gfx::Rect NativeTextfieldViews::GetCaretBounds() { | 661 gfx::Rect NativeTextfieldViews::GetCaretBounds() { |
| 659 gfx::RenderText* render_text = GetRenderText(); | 662 return GetRenderText()->CursorBounds(); |
| 660 return render_text->GetCursorBounds(render_text->GetCursorPosition(), | |
| 661 render_text->insert_mode()); | |
| 662 } | 663 } |
| 663 | 664 |
| 664 bool NativeTextfieldViews::HasCompositionText() { | 665 bool NativeTextfieldViews::HasCompositionText() { |
| 665 return model_->HasCompositionText(); | 666 return model_->HasCompositionText(); |
| 666 } | 667 } |
| 667 | 668 |
| 668 bool NativeTextfieldViews::GetTextRange(ui::Range* range) { | 669 bool NativeTextfieldViews::GetTextRange(ui::Range* range) { |
| 669 // We don't allow the input method to retrieve or delete content from a | 670 // We don't allow the input method to retrieve or delete content from a |
| 670 // password box. | 671 // password box. |
| 671 if (GetTextInputType() != ui::TEXT_INPUT_TYPE_TEXT) | 672 if (GetTextInputType() != ui::TEXT_INPUT_TYPE_TEXT) |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 // Filter out all control characters, including tab and new line characters, | 978 // Filter out all control characters, including tab and new line characters, |
| 978 // and all characters with Alt modifier. But we need to allow characters with | 979 // and all characters with Alt modifier. But we need to allow characters with |
| 979 // AltGr modifier. | 980 // AltGr modifier. |
| 980 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different | 981 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different |
| 981 // flag that we don't care about. | 982 // flag that we don't care about. |
| 982 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && | 983 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && |
| 983 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; | 984 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; |
| 984 } | 985 } |
| 985 | 986 |
| 986 } // namespace views | 987 } // namespace views |
| OLD | NEW |