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/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 Loading... | |
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 } | 105 } |
oshima
2011/11/14 19:31:09
nuke {}
jennyz
2011/11/14 19:50:14
Done.
| |
137 | 106 |
138 OnAfterUserAction(); | 107 OnAfterUserAction(); |
139 return true; | 108 return true; |
140 } | 109 } |
141 | 110 |
142 bool NativeTextfieldViews::OnMouseDragged(const MouseEvent& event) { | 111 bool NativeTextfieldViews::OnMouseDragged(const MouseEvent& event) { |
143 // Don't adjust the cursor on a potential drag and drop. | 112 // Don't adjust the cursor on a potential drag and drop. |
144 if (initiating_drag_) | 113 if (initiating_drag_) |
145 return true; | 114 return true; |
146 | 115 |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1058 // Calls TextfieldController::ContentsChanged() explicitly if the paste action | 1027 // Calls TextfieldController::ContentsChanged() explicitly if the paste action |
1059 // did not change the content at all. See http://crbug.com/79002 | 1028 // did not change the content at all. See http://crbug.com/79002 |
1060 if (success && GetText() == textfield_->text()) { | 1029 if (success && GetText() == textfield_->text()) { |
1061 TextfieldController* controller = textfield_->GetController(); | 1030 TextfieldController* controller = textfield_->GetController(); |
1062 if (controller) | 1031 if (controller) |
1063 controller->ContentsChanged(textfield_, textfield_->text()); | 1032 controller->ContentsChanged(textfield_, textfield_->text()); |
1064 } | 1033 } |
1065 return success; | 1034 return success; |
1066 } | 1035 } |
1067 | 1036 |
1037 void NativeTextfieldViews::TrackMouseClicks(const MouseEvent& event) { | |
1038 if (event.IsOnlyLeftMouseButton()) { | |
1039 base::TimeDelta time_delta = event.time_stamp() - last_click_time_; | |
1040 gfx::Point location_delta = event.location().Subtract(last_click_location_); | |
1041 if (time_delta.InMilliseconds() <= GetDoubleClickInterval() && | |
1042 !ExceededDragThreshold(location_delta.x(), location_delta.y())) { | |
1043 aggregated_clicks_ = (aggregated_clicks_ + 1) % 3; | |
1044 } else { | |
1045 aggregated_clicks_ = 0; | |
1046 } | |
1047 last_click_time_ = event.time_stamp(); | |
1048 last_click_location_ = event.location(); | |
1049 } | |
1050 } | |
1051 | |
1052 void NativeTextfieldViews::HandleMousePressEvent(const MouseEvent& event) { | |
1053 if (event.IsOnlyLeftMouseButton()) { | |
1054 textfield_->RequestFocus(); | |
1055 | |
1056 initiating_drag_ = false; | |
1057 bool can_drag = true; | |
1058 #if defined(TOUCH_UI) | |
1059 // Temporarily disable drag and drop on touch builds; see crbug.com/97845. | |
1060 can_drag = false; | |
1061 #endif | |
1062 switch(aggregated_clicks_) { | |
1063 case 0: | |
1064 if (can_drag && GetRenderText()->IsPointInSelection(event.location())) | |
1065 initiating_drag_ = true; | |
1066 else | |
1067 MoveCursorTo(event.location(), event.IsShiftDown()); | |
1068 break; | |
1069 case 1: | |
1070 model_->SelectWord(); | |
1071 OnCaretBoundsChanged(); | |
1072 break; | |
1073 case 2: | |
1074 model_->SelectAll(); | |
1075 OnCaretBoundsChanged(); | |
1076 break; | |
1077 default: | |
1078 NOTREACHED(); | |
1079 } | |
1080 SchedulePaint(); | |
1081 } | |
1082 } | |
1083 | |
1068 // static | 1084 // static |
1069 bool NativeTextfieldViews::ShouldInsertChar(char16 ch, int flags) { | 1085 bool NativeTextfieldViews::ShouldInsertChar(char16 ch, int flags) { |
1070 // Filter out all control characters, including tab and new line characters, | 1086 // 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 | 1087 // and all characters with Alt modifier. But we need to allow characters with |
1072 // AltGr modifier. | 1088 // AltGr modifier. |
1073 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different | 1089 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different |
1074 // flag that we don't care about. | 1090 // flag that we don't care about. |
1075 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && | 1091 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && |
1076 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; | 1092 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; |
1077 } | 1093 } |
1078 | 1094 |
1079 #if defined(USE_AURA) | 1095 #if defined(USE_AURA) |
1080 // static | 1096 // static |
1081 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 1097 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
1082 Textfield* field) { | 1098 Textfield* field) { |
1083 return new NativeTextfieldViews(field); | 1099 return new NativeTextfieldViews(field); |
1084 } | 1100 } |
1085 #endif | 1101 #endif |
1086 | 1102 |
1087 } // namespace views | 1103 } // namespace views |
OLD | NEW |