| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 NativeTextfieldViews::~NativeTextfieldViews() { | 99 NativeTextfieldViews::~NativeTextfieldViews() { |
| 100 } | 100 } |
| 101 | 101 |
| 102 //////////////////////////////////////////////////////////////////////////////// | 102 //////////////////////////////////////////////////////////////////////////////// |
| 103 // NativeTextfieldViews, View overrides: | 103 // NativeTextfieldViews, View overrides: |
| 104 | 104 |
| 105 bool NativeTextfieldViews::OnMousePressed(const MouseEvent& event) { | 105 bool NativeTextfieldViews::OnMousePressed(const MouseEvent& event) { |
| 106 OnBeforeUserAction(); | 106 OnBeforeUserAction(); |
| 107 TrackMouseClicks(event); | 107 TrackMouseClicks(event); |
| 108 | 108 // TODO: Remove once NativeTextfield implementations are consolidated to |
| 109 // Allow the textfield/omnibox to optionally handle the mouse pressed event. | 109 // Textfield. |
| 110 // This should be removed once native textfield implementations are | |
| 111 // consolidated to textfield. | |
| 112 if (!textfield_->OnMousePressed(event)) | 110 if (!textfield_->OnMousePressed(event)) |
| 113 HandleMousePressEvent(event); | 111 HandleMousePressEvent(event); |
| 114 | |
| 115 OnAfterUserAction(); | 112 OnAfterUserAction(); |
| 116 return true; | 113 return true; |
| 117 } | 114 } |
| 118 | 115 |
| 119 bool NativeTextfieldViews::ExceededDragThresholdFromLastClickLocation( | 116 bool NativeTextfieldViews::ExceededDragThresholdFromLastClickLocation( |
| 120 const MouseEvent& event) { | 117 const MouseEvent& event) { |
| 121 gfx::Point location_delta = event.location().Subtract(last_click_location_); | 118 gfx::Point location_delta = event.location().Subtract(last_click_location_); |
| 122 return ExceededDragThreshold(location_delta.x(), location_delta.y()); | 119 return ExceededDragThreshold(location_delta.x(), location_delta.y()); |
| 123 } | 120 } |
| 124 | 121 |
| 125 bool NativeTextfieldViews::OnMouseDragged(const MouseEvent& event) { | 122 bool NativeTextfieldViews::OnMouseDragged(const MouseEvent& event) { |
| 126 // Don't adjust the cursor on a potential drag and drop, or if the mouse | 123 // Don't adjust the cursor on a potential drag and drop, or if the mouse |
| 127 // movement from the last mouse click does not exceed the drag threshold. | 124 // movement from the last mouse click does not exceed the drag threshold. |
| 128 if (initiating_drag_ || !ExceededDragThresholdFromLastClickLocation(event)) | 125 if (initiating_drag_ || !ExceededDragThresholdFromLastClickLocation(event)) |
| 129 return true; | 126 return true; |
| 130 | 127 |
| 131 OnBeforeUserAction(); | 128 OnBeforeUserAction(); |
| 132 if (MoveCursorTo(event.location(), true)) | 129 // TODO: Remove once NativeTextfield implementations are consolidated to |
| 133 SchedulePaint(); | 130 // Textfield. |
| 131 if (!textfield_->OnMouseDragged(event)) { |
| 132 if (MoveCursorTo(event.location(), true)) |
| 133 SchedulePaint(); |
| 134 } |
| 134 OnAfterUserAction(); | 135 OnAfterUserAction(); |
| 135 return true; | 136 return true; |
| 136 } | 137 } |
| 137 | 138 |
| 138 void NativeTextfieldViews::OnMouseReleased(const MouseEvent& event) { | 139 void NativeTextfieldViews::OnMouseReleased(const MouseEvent& event) { |
| 139 OnBeforeUserAction(); | 140 OnBeforeUserAction(); |
| 141 // TODO: Remove once NativeTextfield implementations are consolidated to |
| 142 // Textfield. |
| 143 textfield_->OnMouseReleased(event); |
| 140 // Cancel suspected drag initiations, the user was clicking in the selection. | 144 // Cancel suspected drag initiations, the user was clicking in the selection. |
| 141 if (initiating_drag_ && MoveCursorTo(event.location(), false)) | 145 if (initiating_drag_ && MoveCursorTo(event.location(), false)) |
| 142 SchedulePaint(); | 146 SchedulePaint(); |
| 143 initiating_drag_ = false; | 147 initiating_drag_ = false; |
| 144 OnAfterUserAction(); | 148 OnAfterUserAction(); |
| 145 } | 149 } |
| 146 | 150 |
| 147 bool NativeTextfieldViews::OnKeyPressed(const KeyEvent& event) { | 151 bool NativeTextfieldViews::OnKeyPressed(const KeyEvent& event) { |
| 148 // OnKeyPressed/OnKeyReleased/OnFocus/OnBlur will never be invoked on | 152 // OnKeyPressed/OnKeyReleased/OnFocus/OnBlur will never be invoked on |
| 149 // NativeTextfieldViews as it will never gain focus. | 153 // NativeTextfieldViews as it will never gain focus. |
| (...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 | 1154 |
| 1151 #if defined(USE_AURA) | 1155 #if defined(USE_AURA) |
| 1152 // static | 1156 // static |
| 1153 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 1157 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 1154 Textfield* field) { | 1158 Textfield* field) { |
| 1155 return new NativeTextfieldViews(field); | 1159 return new NativeTextfieldViews(field); |
| 1156 } | 1160 } |
| 1157 #endif | 1161 #endif |
| 1158 | 1162 |
| 1159 } // namespace views | 1163 } // namespace views |
| OLD | NEW |