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

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

Issue 8527015: Fix omnibox mouse click highlight/word select/focus issue in aura build. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix minor coding style issue. Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « views/controls/textfield/native_textfield_views.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 89
90 NativeTextfieldViews::~NativeTextfieldViews() { 90 NativeTextfieldViews::~NativeTextfieldViews() {
91 } 91 }
92 92
93 //////////////////////////////////////////////////////////////////////////////// 93 ////////////////////////////////////////////////////////////////////////////////
94 // NativeTextfieldViews, View overrides: 94 // NativeTextfieldViews, View overrides:
95 95
96 bool NativeTextfieldViews::OnMousePressed(const MouseEvent& event) { 96 bool NativeTextfieldViews::OnMousePressed(const MouseEvent& event) {
97 OnBeforeUserAction(); 97 OnBeforeUserAction();
98 textfield_->RequestFocus(); 98 TrackMouseClicks(event);
99 99
100 if (event.IsOnlyLeftMouseButton()) { 100 // Allow the textfield/omnibox to optionally handle the mouse pressed event.
101 base::TimeDelta time_delta = event.time_stamp() - last_click_time_; 101 // This should be removed once native textfield implementations are
102 gfx::Point location_delta = event.location().Subtract(last_click_location_); 102 // consolidated to textfield.
103 if (time_delta.InMilliseconds() <= GetDoubleClickInterval() && 103 if (!textfield_->OnMousePressed(event))
104 !ExceededDragThreshold(location_delta.x(), location_delta.y())) { 104 HandleMousePressEvent(event);
105 aggregated_clicks_ = (aggregated_clicks_ + 1) % 3;
106 } else {
107 aggregated_clicks_ = 0;
108 }
109 last_click_time_ = event.time_stamp();
110 last_click_location_ = event.location();
111
112 initiating_drag_ = false;
113 bool can_drag = true;
114 #if defined(TOUCH_UI)
115 can_drag = false;
116 #endif
117 switch(aggregated_clicks_) {
118 case 0:
119 if (can_drag && GetRenderText()->IsPointInSelection(event.location()))
120 initiating_drag_ = true;
121 else
122 MoveCursorTo(event.location(), event.IsShiftDown());
123 break;
124 case 1:
125 model_->SelectWord();
126 OnCaretBoundsChanged();
127 break;
128 case 2:
129 model_->SelectAll();
130 OnCaretBoundsChanged();
131 break;
132 default:
133 NOTREACHED();
134 }
135 SchedulePaint();
136 }
137 105
138 OnAfterUserAction(); 106 OnAfterUserAction();
139 return true; 107 return true;
140 } 108 }
141 109
142 bool NativeTextfieldViews::OnMouseDragged(const MouseEvent& event) { 110 bool NativeTextfieldViews::OnMouseDragged(const MouseEvent& event) {
143 // Don't adjust the cursor on a potential drag and drop. 111 // Don't adjust the cursor on a potential drag and drop.
144 if (initiating_drag_) 112 if (initiating_drag_)
145 return true; 113 return true;
146 114
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 // Calls TextfieldController::ContentsChanged() explicitly if the paste action 1026 // Calls TextfieldController::ContentsChanged() explicitly if the paste action
1059 // did not change the content at all. See http://crbug.com/79002 1027 // did not change the content at all. See http://crbug.com/79002
1060 if (success && GetText() == textfield_->text()) { 1028 if (success && GetText() == textfield_->text()) {
1061 TextfieldController* controller = textfield_->GetController(); 1029 TextfieldController* controller = textfield_->GetController();
1062 if (controller) 1030 if (controller)
1063 controller->ContentsChanged(textfield_, textfield_->text()); 1031 controller->ContentsChanged(textfield_, textfield_->text());
1064 } 1032 }
1065 return success; 1033 return success;
1066 } 1034 }
1067 1035
1036 void NativeTextfieldViews::TrackMouseClicks(const MouseEvent& event) {
1037 if (event.IsOnlyLeftMouseButton()) {
1038 base::TimeDelta time_delta = event.time_stamp() - last_click_time_;
1039 gfx::Point location_delta = event.location().Subtract(last_click_location_);
1040 if (time_delta.InMilliseconds() <= GetDoubleClickInterval() &&
1041 !ExceededDragThreshold(location_delta.x(), location_delta.y())) {
1042 aggregated_clicks_ = (aggregated_clicks_ + 1) % 3;
1043 } else {
1044 aggregated_clicks_ = 0;
1045 }
1046 last_click_time_ = event.time_stamp();
1047 last_click_location_ = event.location();
1048 }
1049 }
1050
1051 void NativeTextfieldViews::HandleMousePressEvent(const MouseEvent& event) {
1052 if (event.IsOnlyLeftMouseButton()) {
1053 textfield_->RequestFocus();
1054
1055 initiating_drag_ = false;
1056 bool can_drag = true;
1057 #if defined(TOUCH_UI)
1058 // Temporarily disable drag and drop on touch builds; see crbug.com/97845.
1059 can_drag = false;
1060 #endif
1061 switch(aggregated_clicks_) {
1062 case 0:
1063 if (can_drag && GetRenderText()->IsPointInSelection(event.location()))
1064 initiating_drag_ = true;
1065 else
1066 MoveCursorTo(event.location(), event.IsShiftDown());
1067 break;
1068 case 1:
1069 model_->SelectWord();
1070 OnCaretBoundsChanged();
1071 break;
1072 case 2:
1073 model_->SelectAll();
1074 OnCaretBoundsChanged();
1075 break;
1076 default:
1077 NOTREACHED();
1078 }
1079 SchedulePaint();
1080 }
1081 }
1082
1068 // static 1083 // static
1069 bool NativeTextfieldViews::ShouldInsertChar(char16 ch, int flags) { 1084 bool NativeTextfieldViews::ShouldInsertChar(char16 ch, int flags) {
1070 // Filter out all control characters, including tab and new line characters, 1085 // Filter out all control characters, including tab and new line characters,
1071 // and all characters with Alt modifier. But we need to allow characters with 1086 // and all characters with Alt modifier. But we need to allow characters with
1072 // AltGr modifier. 1087 // AltGr modifier.
1073 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different 1088 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different
1074 // flag that we don't care about. 1089 // flag that we don't care about.
1075 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && 1090 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) &&
1076 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; 1091 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN;
1077 } 1092 }
1078 1093
1079 #if defined(USE_AURA) 1094 #if defined(USE_AURA)
1080 // static 1095 // static
1081 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( 1096 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper(
1082 Textfield* field) { 1097 Textfield* field) {
1083 return new NativeTextfieldViews(field); 1098 return new NativeTextfieldViews(field);
1084 } 1099 }
1085 #endif 1100 #endif
1086 1101
1087 } // namespace views 1102 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/native_textfield_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698