OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
(...skipping 1840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 if (controller_) | 1851 if (controller_) |
1852 controller_->OnAfterCutOrCopy(ui::CLIPBOARD_TYPE_SELECTION); | 1852 controller_->OnAfterCutOrCopy(ui::CLIPBOARD_TYPE_SELECTION); |
1853 } | 1853 } |
1854 #endif | 1854 #endif |
1855 } | 1855 } |
1856 | 1856 |
1857 void Textfield::PasteSelectionClipboard(const ui::MouseEvent& event) { | 1857 void Textfield::PasteSelectionClipboard(const ui::MouseEvent& event) { |
1858 DCHECK(event.IsOnlyMiddleMouseButton()); | 1858 DCHECK(event.IsOnlyMiddleMouseButton()); |
1859 DCHECK(!read_only()); | 1859 DCHECK(!read_only()); |
1860 base::string16 selection_clipboard_text = GetSelectionClipboardText(); | 1860 base::string16 selection_clipboard_text = GetSelectionClipboardText(); |
| 1861 OnBeforeUserAction(); |
| 1862 const gfx::SelectionModel mouse = |
| 1863 GetRenderText()->FindCursorPosition(event.location()); |
| 1864 if (!HasFocus()) |
| 1865 RequestFocus(); |
| 1866 model_->MoveCursorTo(mouse); |
1861 if (!selection_clipboard_text.empty()) { | 1867 if (!selection_clipboard_text.empty()) { |
1862 OnBeforeUserAction(); | |
1863 gfx::Range range = GetSelectionModel().selection(); | |
1864 gfx::LogicalCursorDirection affinity = GetSelectionModel().caret_affinity(); | |
1865 const gfx::SelectionModel mouse = | |
1866 GetRenderText()->FindCursorPosition(event.location()); | |
1867 model_->MoveCursorTo(mouse); | |
1868 model_->InsertText(selection_clipboard_text); | 1868 model_->InsertText(selection_clipboard_text); |
1869 // Update the new selection range as needed. | |
1870 if (range.GetMin() >= mouse.caret_pos()) { | |
1871 const size_t length = selection_clipboard_text.length(); | |
1872 range = gfx::Range(range.start() + length, range.end() + length); | |
1873 } | |
1874 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | |
1875 UpdateAfterChange(true, true); | 1869 UpdateAfterChange(true, true); |
1876 OnAfterUserAction(); | |
1877 } | 1870 } |
| 1871 OnAfterUserAction(); |
1878 } | 1872 } |
1879 | 1873 |
1880 } // namespace views | 1874 } // namespace views |
OLD | NEW |