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

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

Issue 1865063004: views: support vertical-drag-to-end on textfields (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor some textfield unittests Created 4 years, 8 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 18 matching lines...) Expand all
29 #include "ui/views/background.h" 29 #include "ui/views/background.h"
30 #include "ui/views/controls/focusable_border.h" 30 #include "ui/views/controls/focusable_border.h"
31 #include "ui/views/controls/label.h" 31 #include "ui/views/controls/label.h"
32 #include "ui/views/controls/menu/menu_runner.h" 32 #include "ui/views/controls/menu/menu_runner.h"
33 #include "ui/views/controls/native/native_view_host.h" 33 #include "ui/views/controls/native/native_view_host.h"
34 #include "ui/views/controls/textfield/textfield_controller.h" 34 #include "ui/views/controls/textfield/textfield_controller.h"
35 #include "ui/views/drag_utils.h" 35 #include "ui/views/drag_utils.h"
36 #include "ui/views/metrics.h" 36 #include "ui/views/metrics.h"
37 #include "ui/views/native_cursor.h" 37 #include "ui/views/native_cursor.h"
38 #include "ui/views/painter.h" 38 #include "ui/views/painter.h"
39 #include "ui/views/style/platform_style.h"
39 #include "ui/views/views_delegate.h" 40 #include "ui/views/views_delegate.h"
40 #include "ui/views/widget/widget.h" 41 #include "ui/views/widget/widget.h"
41 42
42 #if defined(OS_WIN) 43 #if defined(OS_WIN)
43 #include "base/win/win_util.h" 44 #include "base/win/win_util.h"
44 #endif 45 #endif
45 46
46 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 47 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
47 #include "base/strings/utf_string_conversions.h" 48 #include "base/strings/utf_string_conversions.h"
48 #include "ui/events/linux/text_edit_command_auralinux.h" 49 #include "ui/events/linux/text_edit_command_auralinux.h"
(...skipping 1680 matching lines...) Expand 10 before | Expand all | Expand 10 after
1729 canvas->Restore(); 1730 canvas->Restore();
1730 } 1731 }
1731 1732
1732 void Textfield::MoveCursorTo(const gfx::Point& point, bool select) { 1733 void Textfield::MoveCursorTo(const gfx::Point& point, bool select) {
1733 if (model_->MoveCursorTo(point, select)) 1734 if (model_->MoveCursorTo(point, select))
1734 UpdateAfterChange(false, true); 1735 UpdateAfterChange(false, true);
1735 } 1736 }
1736 1737
1737 void Textfield::SelectThroughLastDragLocation() { 1738 void Textfield::SelectThroughLastDragLocation() {
1738 OnBeforeUserAction(); 1739 OnBeforeUserAction();
1739 model_->MoveCursorTo(last_drag_location_, true); 1740
1741 const bool drags_to_end = PlatformStyle::kTextfieldDragVerticallyDragsToEnd;
1742 if (drags_to_end && last_drag_location_.y() < 0) {
1743 model_->MoveCursor(gfx::BreakType::LINE_BREAK,
1744 gfx::VisualCursorDirection::CURSOR_LEFT, true);
1745 } else if (drags_to_end && last_drag_location_.y() > height()) {
1746 model_->MoveCursor(gfx::BreakType::LINE_BREAK,
1747 gfx::VisualCursorDirection::CURSOR_RIGHT, true);
1748 } else {
1749 model_->MoveCursorTo(last_drag_location_, true);
1750 }
1751
1740 if (aggregated_clicks_ == 1) { 1752 if (aggregated_clicks_ == 1) {
1741 model_->SelectWord(); 1753 model_->SelectWord();
1742 // Expand the selection so the initially selected word remains selected. 1754 // Expand the selection so the initially selected word remains selected.
1743 gfx::Range selection = GetRenderText()->selection(); 1755 gfx::Range selection = GetRenderText()->selection();
1744 const size_t min = std::min(selection.GetMin(), 1756 const size_t min = std::min(selection.GetMin(),
1745 double_click_word_.GetMin()); 1757 double_click_word_.GetMin());
1746 const size_t max = std::max(selection.GetMax(), 1758 const size_t max = std::max(selection.GetMax(),
1747 double_click_word_.GetMax()); 1759 double_click_word_.GetMax());
1748 const bool reversed = selection.is_reversed(); 1760 const bool reversed = selection.is_reversed();
1749 selection.set_start(reversed ? max : min); 1761 selection.set_start(reversed ? max : min);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 RequestFocus(); 1903 RequestFocus();
1892 model_->MoveCursorTo(mouse); 1904 model_->MoveCursorTo(mouse);
1893 if (!selection_clipboard_text.empty()) { 1905 if (!selection_clipboard_text.empty()) {
1894 model_->InsertText(selection_clipboard_text); 1906 model_->InsertText(selection_clipboard_text);
1895 UpdateAfterChange(true, true); 1907 UpdateAfterChange(true, true);
1896 } 1908 }
1897 OnAfterUserAction(); 1909 OnAfterUserAction();
1898 } 1910 }
1899 1911
1900 } // namespace views 1912 } // 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