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

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

Issue 927743002: Focus and trail cursor on Views Textfield selection clipboard paste. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Leave the test disabled... Created 5 years, 10 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
OLDNEW
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 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (!selection_clipboard_text.empty()) { 1861 if (!selection_clipboard_text.empty()) {
1862 OnBeforeUserAction(); 1862 OnBeforeUserAction();
1863 gfx::Range range = GetSelectionModel().selection();
1864 gfx::LogicalCursorDirection affinity = GetSelectionModel().caret_affinity();
1865 const gfx::SelectionModel mouse = 1863 const gfx::SelectionModel mouse =
1866 GetRenderText()->FindCursorPosition(event.location()); 1864 GetRenderText()->FindCursorPosition(event.location());
1865 if (!HasFocus())
1866 RequestFocus();
1867 model_->MoveCursorTo(mouse); 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(); 1870 OnAfterUserAction();
1877 } 1871 }
1878 } 1872 }
1879 1873
1880 } // namespace views 1874 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/textfield/textfield_unittest.cc » ('j') | ui/views/controls/textfield/textfield_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698