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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 if ((event_pos - GetStartPosition()).LengthSquared() <= | 144 if ((event_pos - GetStartPosition()).LengthSquared() <= |
145 (event_pos - GetEndPosition()).LengthSquared()) | 145 (event_pos - GetEndPosition()).LengthSquared()) |
146 return start_selection_handle_->WillHandleTouchEvent(event); | 146 return start_selection_handle_->WillHandleTouchEvent(event); |
147 else | 147 else |
148 return end_selection_handle_->WillHandleTouchEvent(event); | 148 return end_selection_handle_->WillHandleTouchEvent(event); |
149 } | 149 } |
150 | 150 |
151 return false; | 151 return false; |
152 } | 152 } |
153 | 153 |
154 void TouchSelectionController::OnLongPressEvent() { | 154 bool TouchSelectionController::WillHandleLongPressEvent( |
155 const gfx::PointF& location) { | |
156 if (WillHandleTapOrLongPress(location)) | |
157 return true; | |
158 | |
155 response_pending_input_event_ = LONG_PRESS; | 159 response_pending_input_event_ = LONG_PRESS; |
156 ShowSelectionHandlesAutomatically(); | 160 ShowSelectionHandlesAutomatically(); |
157 ShowInsertionHandleAutomatically(); | 161 ShowInsertionHandleAutomatically(); |
158 ResetCachedValuesIfInactive(); | 162 ResetCachedValuesIfInactive(); |
163 return false; | |
164 } | |
165 | |
166 bool TouchSelectionController::WillHandleTapEvent(const gfx::PointF& location) { | |
167 if (WillHandleTapOrLongPress(location)) | |
168 return true; | |
169 | |
170 response_pending_input_event_ = TAP; | |
171 activate_selection_automatically_ = false; | |
jdduke (slow)
2015/05/08 22:05:52
This will need to be rebased.
Donn Denman
2015/05/11 21:23:39
Done.
| |
172 ShowInsertionHandleAutomatically(); | |
173 if (selection_empty_ && !show_on_tap_for_empty_editable_) | |
174 DeactivateInsertion(); | |
175 ResetCachedValuesIfInactive(); | |
176 return false; | |
177 } | |
178 | |
179 bool TouchSelectionController::WillHandleTapOrLongPress( | |
180 const gfx::PointF& location) { | |
181 // If there is an active selection that was not triggered by a user gesture, | |
182 // allow showing the handles for that selection if a gesture occurs within | |
183 // the selection rect. Note that this hit test is at best a crude | |
184 // approximation, and may swallow taps that actually fall outside the | |
185 // real selection. | |
186 if (!is_selection_active_ && !is_insertion_active_) { | |
187 if (GetStartPosition() != GetEndPosition() && | |
188 RectFBetweenSelectionBounds(start_, end_).Contains(location)) { | |
189 AllowShowingFromCurrentSelection(); | |
190 return true; | |
191 } | |
192 } | |
193 return false; | |
159 } | 194 } |
160 | 195 |
161 void TouchSelectionController::AllowShowingFromCurrentSelection() { | 196 void TouchSelectionController::AllowShowingFromCurrentSelection() { |
162 if (is_selection_active_ || is_insertion_active_) | 197 if (is_selection_active_ || is_insertion_active_) |
163 return; | 198 return; |
164 | 199 |
165 activate_selection_automatically_ = true; | 200 activate_selection_automatically_ = true; |
166 activate_insertion_automatically_ = true; | 201 activate_insertion_automatically_ = true; |
167 if (GetStartPosition() != GetEndPosition()) | 202 if (GetStartPosition() != GetEndPosition()) |
168 OnSelectionChanged(); | 203 OnSelectionChanged(); |
169 else if (start_orientation_ == TouchHandleOrientation::CENTER && | 204 else if (start_orientation_ == TouchHandleOrientation::CENTER && |
170 selection_editable_) | 205 selection_editable_) |
171 OnInsertionChanged(); | 206 OnInsertionChanged(); |
172 } | 207 } |
173 | 208 |
174 void TouchSelectionController::OnTapEvent() { | |
175 response_pending_input_event_ = TAP; | |
176 activate_selection_automatically_ = false; | |
177 ShowInsertionHandleAutomatically(); | |
178 if (selection_empty_ && !show_on_tap_for_empty_editable_) | |
179 DeactivateInsertion(); | |
180 ResetCachedValuesIfInactive(); | |
181 } | |
182 | |
183 void TouchSelectionController::HideAndDisallowShowingAutomatically() { | 209 void TouchSelectionController::HideAndDisallowShowingAutomatically() { |
184 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; | 210 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; |
185 DeactivateInsertion(); | 211 DeactivateInsertion(); |
186 DeactivateSelection(); | 212 DeactivateSelection(); |
187 activate_insertion_automatically_ = false; | 213 activate_insertion_automatically_ = false; |
188 activate_selection_automatically_ = false; | 214 activate_selection_automatically_ = false; |
189 } | 215 } |
190 | 216 |
191 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { | 217 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { |
192 if (temporarily_hidden_ == hidden) | 218 if (temporarily_hidden_ == hidden) |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 528 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
503 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 529 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
504 duration, | 530 duration, |
505 base::TimeDelta::FromMilliseconds(500), | 531 base::TimeDelta::FromMilliseconds(500), |
506 base::TimeDelta::FromSeconds(60), | 532 base::TimeDelta::FromSeconds(60), |
507 60); | 533 60); |
508 } | 534 } |
509 } | 535 } |
510 | 536 |
511 } // namespace ui | 537 } // namespace ui |
OLD | NEW |