OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/touch_selection/touch_selection_controller.h" | 5 #include "ui/touch_selection/touch_selection_controller.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 | 10 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 if ((event_pos - GetStartPosition()).LengthSquared() <= | 146 if ((event_pos - GetStartPosition()).LengthSquared() <= |
147 (event_pos - GetEndPosition()).LengthSquared()) | 147 (event_pos - GetEndPosition()).LengthSquared()) |
148 return start_selection_handle_->WillHandleTouchEvent(event); | 148 return start_selection_handle_->WillHandleTouchEvent(event); |
149 else | 149 else |
150 return end_selection_handle_->WillHandleTouchEvent(event); | 150 return end_selection_handle_->WillHandleTouchEvent(event); |
151 } | 151 } |
152 | 152 |
153 return false; | 153 return false; |
154 } | 154 } |
155 | 155 |
156 void TouchSelectionController::OnLongPressEvent() { | 156 bool TouchSelectionController::WillHandleLongPressEvent( |
| 157 const gfx::PointF& location) { |
| 158 if (WillHandleTapOrLongPress(location)) |
| 159 return true; |
| 160 |
157 response_pending_input_event_ = LONG_PRESS; | 161 response_pending_input_event_ = LONG_PRESS; |
158 ShowSelectionHandlesAutomatically(); | 162 ShowSelectionHandlesAutomatically(); |
159 ShowInsertionHandleAutomatically(); | 163 ShowInsertionHandleAutomatically(); |
160 ResetCachedValuesIfInactive(); | 164 ResetCachedValuesIfInactive(); |
| 165 return false; |
| 166 } |
| 167 |
| 168 bool TouchSelectionController::WillHandleTapEvent(const gfx::PointF& location) { |
| 169 if (WillHandleTapOrLongPress(location)) |
| 170 return true; |
| 171 |
| 172 response_pending_input_event_ = TAP; |
| 173 if (!is_selection_active_) |
| 174 activate_selection_automatically_ = false; |
| 175 ShowInsertionHandleAutomatically(); |
| 176 if (selection_empty_ && !show_on_tap_for_empty_editable_) |
| 177 DeactivateInsertion(); |
| 178 ResetCachedValuesIfInactive(); |
| 179 return false; |
| 180 } |
| 181 |
| 182 bool TouchSelectionController::WillHandleTapOrLongPress( |
| 183 const gfx::PointF& location) { |
| 184 // If there is an active selection that was not triggered by a user gesture, |
| 185 // allow showing the handles for that selection if a gesture occurs within |
| 186 // the selection rect. Note that this hit test is at best a crude |
| 187 // approximation, and may swallow taps that actually fall outside the |
| 188 // real selection. |
| 189 if (!is_selection_active_ && !is_insertion_active_) { |
| 190 if (GetStartPosition() != GetEndPosition() && |
| 191 RectFBetweenSelectionBounds(start_, end_).Contains(location)) { |
| 192 AllowShowingFromCurrentSelection(); |
| 193 return true; |
| 194 } |
| 195 } |
| 196 return false; |
161 } | 197 } |
162 | 198 |
163 void TouchSelectionController::AllowShowingFromCurrentSelection() { | 199 void TouchSelectionController::AllowShowingFromCurrentSelection() { |
164 if (is_selection_active_ || is_insertion_active_) | 200 if (is_selection_active_ || is_insertion_active_) |
165 return; | 201 return; |
166 | 202 |
167 activate_selection_automatically_ = true; | 203 activate_selection_automatically_ = true; |
168 activate_insertion_automatically_ = true; | 204 activate_insertion_automatically_ = true; |
169 if (GetStartPosition() != GetEndPosition()) | 205 if (GetStartPosition() != GetEndPosition()) |
170 OnSelectionChanged(); | 206 OnSelectionChanged(); |
171 else if (start_orientation_ == TouchHandleOrientation::CENTER && | 207 else if (start_orientation_ == TouchHandleOrientation::CENTER && |
172 selection_editable_) | 208 selection_editable_) |
173 OnInsertionChanged(); | 209 OnInsertionChanged(); |
174 } | 210 } |
175 | 211 |
176 void TouchSelectionController::OnTapEvent() { | |
177 response_pending_input_event_ = TAP; | |
178 if (!is_selection_active_) | |
179 activate_selection_automatically_ = false; | |
180 ShowInsertionHandleAutomatically(); | |
181 if (selection_empty_ && !show_on_tap_for_empty_editable_) | |
182 DeactivateInsertion(); | |
183 ResetCachedValuesIfInactive(); | |
184 } | |
185 | |
186 void TouchSelectionController::HideAndDisallowShowingAutomatically() { | 212 void TouchSelectionController::HideAndDisallowShowingAutomatically() { |
187 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; | 213 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; |
188 DeactivateInsertion(); | 214 DeactivateInsertion(); |
189 DeactivateSelection(); | 215 DeactivateSelection(); |
190 activate_insertion_automatically_ = false; | 216 activate_insertion_automatically_ = false; |
191 activate_selection_automatically_ = false; | 217 activate_selection_automatically_ = false; |
192 } | 218 } |
193 | 219 |
194 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { | 220 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { |
195 if (temporarily_hidden_ == hidden) | 221 if (temporarily_hidden_ == hidden) |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 531 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
506 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 532 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
507 duration, | 533 duration, |
508 base::TimeDelta::FromMilliseconds(500), | 534 base::TimeDelta::FromMilliseconds(500), |
509 base::TimeDelta::FromSeconds(60), | 535 base::TimeDelta::FromSeconds(60), |
510 60); | 536 60); |
511 } | 537 } |
512 } | 538 } |
513 | 539 |
514 } // namespace ui | 540 } // namespace ui |
OLD | NEW |