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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 MouseEvent& event) { |
105 OnBeforeUserAction(); | 105 OnBeforeUserAction(); |
106 TrackMouseClicks(event); | 106 TrackMouseClicks(event); |
107 | 107 // TODO: Remove once NativeTextfield implementations are consolidated to |
108 // Allow the textfield/omnibox to optionally handle the mouse pressed event. | 108 // Textfield. |
109 // This should be removed once native textfield implementations are | |
110 // consolidated to textfield. | |
111 if (!textfield_->OnMousePressed(event)) | 109 if (!textfield_->OnMousePressed(event)) |
112 HandleMousePressEvent(event); | 110 HandleMousePressEvent(event); |
113 | |
114 OnAfterUserAction(); | 111 OnAfterUserAction(); |
115 return true; | 112 return true; |
116 } | 113 } |
117 | 114 |
118 bool NativeTextfieldViews::ExceededDragThresholdFromLastClickLocation( | 115 bool NativeTextfieldViews::ExceededDragThresholdFromLastClickLocation( |
119 const MouseEvent& event) { | 116 const MouseEvent& event) { |
120 gfx::Point location_delta = event.location().Subtract(last_click_location_); | 117 gfx::Point location_delta = event.location().Subtract(last_click_location_); |
121 return ExceededDragThreshold(location_delta.x(), location_delta.y()); | 118 return ExceededDragThreshold(location_delta.x(), location_delta.y()); |
122 } | 119 } |
123 | 120 |
124 bool NativeTextfieldViews::OnMouseDragged(const MouseEvent& event) { | 121 bool NativeTextfieldViews::OnMouseDragged(const MouseEvent& event) { |
125 // 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 |
126 // 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. |
127 if (initiating_drag_ || !ExceededDragThresholdFromLastClickLocation(event)) | 124 if (initiating_drag_ || !ExceededDragThresholdFromLastClickLocation(event)) |
128 return true; | 125 return true; |
129 | 126 |
130 OnBeforeUserAction(); | 127 OnBeforeUserAction(); |
131 if (MoveCursorTo(event.location(), true)) | 128 // TODO: Remove once NativeTextfield implementations are consolidated to |
132 SchedulePaint(); | 129 // Textfield. |
| 130 if (!textfield_->OnMouseDragged(event)) { |
| 131 if (MoveCursorTo(event.location(), true)) |
| 132 SchedulePaint(); |
| 133 } |
133 OnAfterUserAction(); | 134 OnAfterUserAction(); |
134 return true; | 135 return true; |
135 } | 136 } |
136 | 137 |
137 void NativeTextfieldViews::OnMouseReleased(const MouseEvent& event) { | 138 void NativeTextfieldViews::OnMouseReleased(const MouseEvent& event) { |
138 OnBeforeUserAction(); | 139 OnBeforeUserAction(); |
| 140 // TODO: Remove once NativeTextfield implementations are consolidated to |
| 141 // Textfield. |
| 142 textfield_->OnMouseReleased(event); |
139 // Cancel suspected drag initiations, the user was clicking in the selection. | 143 // Cancel suspected drag initiations, the user was clicking in the selection. |
140 if (initiating_drag_ && MoveCursorTo(event.location(), false)) | 144 if (initiating_drag_ && MoveCursorTo(event.location(), false)) |
141 SchedulePaint(); | 145 SchedulePaint(); |
142 initiating_drag_ = false; | 146 initiating_drag_ = false; |
143 OnAfterUserAction(); | 147 OnAfterUserAction(); |
144 } | 148 } |
145 | 149 |
146 bool NativeTextfieldViews::OnKeyPressed(const KeyEvent& event) { | 150 bool NativeTextfieldViews::OnKeyPressed(const KeyEvent& event) { |
147 // OnKeyPressed/OnKeyReleased/OnFocus/OnBlur will never be invoked on | 151 // OnKeyPressed/OnKeyReleased/OnFocus/OnBlur will never be invoked on |
148 // NativeTextfieldViews as it will never gain focus. | 152 // NativeTextfieldViews as it will never gain focus. |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 | 1143 |
1140 #if defined(USE_AURA) | 1144 #if defined(USE_AURA) |
1141 // static | 1145 // static |
1142 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 1146 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
1143 Textfield* field) { | 1147 Textfield* field) { |
1144 return new NativeTextfieldViews(field); | 1148 return new NativeTextfieldViews(field); |
1145 } | 1149 } |
1146 #endif | 1150 #endif |
1147 | 1151 |
1148 } // namespace views | 1152 } // namespace views |
OLD | NEW |