| 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/native_textfield_views.h" | 5 #include "ui/views/controls/textfield/native_textfield_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 set_context_menu_controller(this); | 94 set_context_menu_controller(this); |
| 95 set_drag_controller(this); | 95 set_drag_controller(this); |
| 96 } | 96 } |
| 97 | 97 |
| 98 NativeTextfieldViews::~NativeTextfieldViews() { | 98 NativeTextfieldViews::~NativeTextfieldViews() { |
| 99 } | 99 } |
| 100 | 100 |
| 101 //////////////////////////////////////////////////////////////////////////////// | 101 //////////////////////////////////////////////////////////////////////////////// |
| 102 // NativeTextfieldViews, View overrides: | 102 // NativeTextfieldViews, View overrides: |
| 103 | 103 |
| 104 bool NativeTextfieldViews::OnMousePressed(const MouseEvent& event) { | 104 bool NativeTextfieldViews::OnMousePressed(const ui::MouseEvent& event) { |
| 105 OnBeforeUserAction(); | 105 OnBeforeUserAction(); |
| 106 TrackMouseClicks(event); | 106 TrackMouseClicks(event); |
| 107 // TODO: Remove once NativeTextfield implementations are consolidated to | 107 // TODO: Remove once NativeTextfield implementations are consolidated to |
| 108 // Textfield. | 108 // Textfield. |
| 109 if (!textfield_->OnMousePressed(event)) | 109 if (!textfield_->OnMousePressed(event)) |
| 110 HandleMousePressEvent(event); | 110 HandleMousePressEvent(event); |
| 111 OnAfterUserAction(); | 111 OnAfterUserAction(); |
| 112 return true; | 112 return true; |
| 113 } | 113 } |
| 114 | 114 |
| 115 bool NativeTextfieldViews::ExceededDragThresholdFromLastClickLocation( | 115 bool NativeTextfieldViews::ExceededDragThresholdFromLastClickLocation( |
| 116 const MouseEvent& event) { | 116 const ui::MouseEvent& event) { |
| 117 gfx::Point location_delta = event.location().Subtract(last_click_location_); | 117 gfx::Point location_delta = event.location().Subtract(last_click_location_); |
| 118 return ExceededDragThreshold(location_delta.x(), location_delta.y()); | 118 return ExceededDragThreshold(location_delta.x(), location_delta.y()); |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool NativeTextfieldViews::OnMouseDragged(const MouseEvent& event) { | 121 bool NativeTextfieldViews::OnMouseDragged(const ui::MouseEvent& event) { |
| 122 // Don't adjust the cursor on a potential drag and drop, or if the mouse | 122 // Don't adjust the cursor on a potential drag and drop, or if the mouse |
| 123 // movement from the last mouse click does not exceed the drag threshold. | 123 // movement from the last mouse click does not exceed the drag threshold. |
| 124 if (initiating_drag_ || !ExceededDragThresholdFromLastClickLocation(event)) | 124 if (initiating_drag_ || !ExceededDragThresholdFromLastClickLocation(event)) |
| 125 return true; | 125 return true; |
| 126 | 126 |
| 127 OnBeforeUserAction(); | 127 OnBeforeUserAction(); |
| 128 // TODO: Remove once NativeTextfield implementations are consolidated to | 128 // TODO: Remove once NativeTextfield implementations are consolidated to |
| 129 // Textfield. | 129 // Textfield. |
| 130 if (!textfield_->OnMouseDragged(event)) { | 130 if (!textfield_->OnMouseDragged(event)) { |
| 131 if (MoveCursorTo(event.location(), true)) | 131 if (MoveCursorTo(event.location(), true)) |
| 132 SchedulePaint(); | 132 SchedulePaint(); |
| 133 } | 133 } |
| 134 OnAfterUserAction(); | 134 OnAfterUserAction(); |
| 135 return true; | 135 return true; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void NativeTextfieldViews::OnMouseReleased(const MouseEvent& event) { | 138 void NativeTextfieldViews::OnMouseReleased(const ui::MouseEvent& event) { |
| 139 OnBeforeUserAction(); | 139 OnBeforeUserAction(); |
| 140 // TODO: Remove once NativeTextfield implementations are consolidated to | 140 // TODO: Remove once NativeTextfield implementations are consolidated to |
| 141 // Textfield. | 141 // Textfield. |
| 142 textfield_->OnMouseReleased(event); | 142 textfield_->OnMouseReleased(event); |
| 143 // Cancel suspected drag initiations, the user was clicking in the selection. | 143 // Cancel suspected drag initiations, the user was clicking in the selection. |
| 144 if (initiating_drag_ && MoveCursorTo(event.location(), false)) | 144 if (initiating_drag_ && MoveCursorTo(event.location(), false)) |
| 145 SchedulePaint(); | 145 SchedulePaint(); |
| 146 initiating_drag_ = false; | 146 initiating_drag_ = false; |
| 147 OnAfterUserAction(); | 147 OnAfterUserAction(); |
| 148 } | 148 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 ui::Range(start_caret.caret_pos(), end_caret.caret_pos()), | 289 ui::Range(start_caret.caret_pos(), end_caret.caret_pos()), |
| 290 end_caret.caret_affinity()); | 290 end_caret.caret_affinity()); |
| 291 | 291 |
| 292 OnBeforeUserAction(); | 292 OnBeforeUserAction(); |
| 293 model_->SelectSelectionModel(selection); | 293 model_->SelectSelectionModel(selection); |
| 294 OnCaretBoundsChanged(); | 294 OnCaretBoundsChanged(); |
| 295 SchedulePaint(); | 295 SchedulePaint(); |
| 296 OnAfterUserAction(); | 296 OnAfterUserAction(); |
| 297 } | 297 } |
| 298 | 298 |
| 299 gfx::NativeCursor NativeTextfieldViews::GetCursor(const MouseEvent& event) { | 299 gfx::NativeCursor NativeTextfieldViews::GetCursor(const ui::MouseEvent& event) { |
| 300 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); | 300 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); |
| 301 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED; | 301 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED; |
| 302 bool text_cursor = !initiating_drag_ && (drag_event || !in_selection); | 302 bool text_cursor = !initiating_drag_ && (drag_event || !in_selection); |
| 303 #if defined(USE_AURA) | 303 #if defined(USE_AURA) |
| 304 return text_cursor ? ui::kCursorIBeam : ui::kCursorNull; | 304 return text_cursor ? ui::kCursorIBeam : ui::kCursorNull; |
| 305 #elif defined(OS_WIN) | 305 #elif defined(OS_WIN) |
| 306 static HCURSOR ibeam = LoadCursor(NULL, IDC_IBEAM); | 306 static HCURSOR ibeam = LoadCursor(NULL, IDC_IBEAM); |
| 307 static HCURSOR arrow = LoadCursor(NULL, IDC_ARROW); | 307 static HCURSOR arrow = LoadCursor(NULL, IDC_ARROW); |
| 308 return text_cursor ? ibeam : arrow; | 308 return text_cursor ? ibeam : arrow; |
| 309 #endif | 309 #endif |
| (...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 // action did not change the content at all. See http://crbug.com/79002 | 1158 // action did not change the content at all. See http://crbug.com/79002 |
| 1159 if (new_text == original_text) { | 1159 if (new_text == original_text) { |
| 1160 TextfieldController* controller = textfield_->GetController(); | 1160 TextfieldController* controller = textfield_->GetController(); |
| 1161 if (controller) | 1161 if (controller) |
| 1162 controller->ContentsChanged(textfield_, textfield_->text()); | 1162 controller->ContentsChanged(textfield_, textfield_->text()); |
| 1163 } | 1163 } |
| 1164 } | 1164 } |
| 1165 return success; | 1165 return success; |
| 1166 } | 1166 } |
| 1167 | 1167 |
| 1168 void NativeTextfieldViews::TrackMouseClicks(const MouseEvent& event) { | 1168 void NativeTextfieldViews::TrackMouseClicks(const ui::MouseEvent& event) { |
| 1169 if (event.IsOnlyLeftMouseButton()) { | 1169 if (event.IsOnlyLeftMouseButton()) { |
| 1170 base::TimeDelta time_delta = event.time_stamp() - last_click_time_; | 1170 base::TimeDelta time_delta = event.time_stamp() - last_click_time_; |
| 1171 if (time_delta.InMilliseconds() <= GetDoubleClickInterval() && | 1171 if (time_delta.InMilliseconds() <= GetDoubleClickInterval() && |
| 1172 !ExceededDragThresholdFromLastClickLocation(event)) { | 1172 !ExceededDragThresholdFromLastClickLocation(event)) { |
| 1173 aggregated_clicks_ = (aggregated_clicks_ + 1) % 3; | 1173 aggregated_clicks_ = (aggregated_clicks_ + 1) % 3; |
| 1174 } else { | 1174 } else { |
| 1175 aggregated_clicks_ = 0; | 1175 aggregated_clicks_ = 0; |
| 1176 } | 1176 } |
| 1177 last_click_time_ = event.time_stamp(); | 1177 last_click_time_ = event.time_stamp(); |
| 1178 last_click_location_ = event.location(); | 1178 last_click_location_ = event.location(); |
| 1179 } | 1179 } |
| 1180 } | 1180 } |
| 1181 | 1181 |
| 1182 void NativeTextfieldViews::HandleMousePressEvent(const MouseEvent& event) { | 1182 void NativeTextfieldViews::HandleMousePressEvent(const ui::MouseEvent& event) { |
| 1183 if (event.IsOnlyLeftMouseButton()) { | 1183 if (event.IsOnlyLeftMouseButton()) { |
| 1184 textfield_->RequestFocus(); | 1184 textfield_->RequestFocus(); |
| 1185 | 1185 |
| 1186 initiating_drag_ = false; | 1186 initiating_drag_ = false; |
| 1187 bool can_drag = true; | 1187 bool can_drag = true; |
| 1188 | 1188 |
| 1189 switch (aggregated_clicks_) { | 1189 switch (aggregated_clicks_) { |
| 1190 case 0: | 1190 case 0: |
| 1191 if (can_drag && GetRenderText()->IsPointInSelection(event.location())) | 1191 if (can_drag && GetRenderText()->IsPointInSelection(event.location())) |
| 1192 initiating_drag_ = true; | 1192 initiating_drag_ = true; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1220 // Filter out all control characters, including tab and new line characters, | 1220 // Filter out all control characters, including tab and new line characters, |
| 1221 // and all characters with Alt modifier. But we need to allow characters with | 1221 // and all characters with Alt modifier. But we need to allow characters with |
| 1222 // AltGr modifier. | 1222 // AltGr modifier. |
| 1223 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different | 1223 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different |
| 1224 // flag that we don't care about. | 1224 // flag that we don't care about. |
| 1225 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && | 1225 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && |
| 1226 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; | 1226 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; |
| 1227 } | 1227 } |
| 1228 | 1228 |
| 1229 } // namespace views | 1229 } // namespace views |
| OLD | NEW |