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 } | 149 } |
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::WillHandleTapEvent(const gfx::PointF& location) { |
| 157 if (WillHandleTapOrLongPress(location)) |
| 158 return true; |
| 159 |
| 160 response_pending_input_event_ = TAP; |
| 161 if (active_status_ != SELECTION_ACTIVE) |
| 162 activate_selection_automatically_ = false; |
| 163 ShowInsertionHandleAutomatically(); |
| 164 if (selection_empty_ && !show_on_tap_for_empty_editable_) |
| 165 DeactivateInsertion(); |
| 166 ForceNextUpdateIfInactive(); |
| 167 return false; |
| 168 } |
| 169 |
| 170 bool TouchSelectionController::WillHandleLongPressEvent( |
| 171 const gfx::PointF& location) { |
| 172 if (WillHandleTapOrLongPress(location)) |
| 173 return true; |
| 174 |
157 response_pending_input_event_ = LONG_PRESS; | 175 response_pending_input_event_ = LONG_PRESS; |
158 ShowSelectionHandlesAutomatically(); | 176 ShowSelectionHandlesAutomatically(); |
159 ShowInsertionHandleAutomatically(); | 177 ShowInsertionHandleAutomatically(); |
160 ForceNextUpdateIfInactive(); | 178 ForceNextUpdateIfInactive(); |
| 179 return false; |
161 } | 180 } |
162 | 181 |
163 void TouchSelectionController::AllowShowingFromCurrentSelection() { | 182 void TouchSelectionController::AllowShowingFromCurrentSelection() { |
164 if (active_status_ != INACTIVE) | 183 if (active_status_ != INACTIVE) |
165 return; | 184 return; |
166 | 185 |
167 activate_selection_automatically_ = true; | 186 activate_selection_automatically_ = true; |
168 activate_insertion_automatically_ = true; | 187 activate_insertion_automatically_ = true; |
169 if (GetStartPosition() != GetEndPosition()) { | 188 if (GetStartPosition() != GetEndPosition()) { |
170 OnSelectionChanged(); | 189 OnSelectionChanged(); |
171 } else if (start_orientation_ == TouchHandleOrientation::CENTER && | 190 } else if (start_orientation_ == TouchHandleOrientation::CENTER && |
172 selection_editable_) { | 191 selection_editable_) { |
173 OnInsertionChanged(); | 192 OnInsertionChanged(); |
174 } | 193 } |
175 } | 194 } |
176 | 195 |
177 void TouchSelectionController::OnTapEvent() { | |
178 response_pending_input_event_ = TAP; | |
179 if (active_status_ != SELECTION_ACTIVE) | |
180 activate_selection_automatically_ = false; | |
181 ShowInsertionHandleAutomatically(); | |
182 if (selection_empty_ && !show_on_tap_for_empty_editable_) | |
183 DeactivateInsertion(); | |
184 ForceNextUpdateIfInactive(); | |
185 } | |
186 | |
187 void TouchSelectionController::HideAndDisallowShowingAutomatically() { | 196 void TouchSelectionController::HideAndDisallowShowingAutomatically() { |
188 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; | 197 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; |
189 DeactivateInsertion(); | 198 DeactivateInsertion(); |
190 DeactivateSelection(); | 199 DeactivateSelection(); |
191 activate_insertion_automatically_ = false; | 200 activate_insertion_automatically_ = false; |
192 activate_selection_automatically_ = false; | 201 activate_selection_automatically_ = false; |
193 } | 202 } |
194 | 203 |
195 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { | 204 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { |
196 if (temporarily_hidden_ == hidden) | 205 if (temporarily_hidden_ == hidden) |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 ForceNextUpdateIfInactive(); | 354 ForceNextUpdateIfInactive(); |
346 } | 355 } |
347 | 356 |
348 void TouchSelectionController::ShowSelectionHandlesAutomatically() { | 357 void TouchSelectionController::ShowSelectionHandlesAutomatically() { |
349 if (activate_selection_automatically_) | 358 if (activate_selection_automatically_) |
350 return; | 359 return; |
351 activate_selection_automatically_ = true; | 360 activate_selection_automatically_ = true; |
352 ForceNextUpdateIfInactive(); | 361 ForceNextUpdateIfInactive(); |
353 } | 362 } |
354 | 363 |
| 364 bool TouchSelectionController::WillHandleTapOrLongPress( |
| 365 const gfx::PointF& location) { |
| 366 // If there is an active selection that was not triggered by a user gesture, |
| 367 // allow showing the handles for that selection if a gesture occurs within |
| 368 // the selection rect. Note that this hit test is at best a crude |
| 369 // approximation, and may swallow taps that actually fall outside the |
| 370 // real selection. |
| 371 if (active_status_ == INACTIVE && |
| 372 GetStartPosition() != GetEndPosition() && |
| 373 RectFBetweenSelectionBounds(start_, end_).Contains(location)) { |
| 374 AllowShowingFromCurrentSelection(); |
| 375 return true; |
| 376 } |
| 377 return false; |
| 378 } |
| 379 |
355 void TouchSelectionController::OnInsertionChanged() { | 380 void TouchSelectionController::OnInsertionChanged() { |
356 DeactivateSelection(); | 381 DeactivateSelection(); |
357 | 382 |
358 if (response_pending_input_event_ == TAP && selection_empty_ && | 383 if (response_pending_input_event_ == TAP && selection_empty_ && |
359 !show_on_tap_for_empty_editable_) { | 384 !show_on_tap_for_empty_editable_) { |
360 HideAndDisallowShowingAutomatically(); | 385 HideAndDisallowShowingAutomatically(); |
361 return; | 386 return; |
362 } | 387 } |
363 | 388 |
364 if (!activate_insertion_automatically_) | 389 if (!activate_insertion_automatically_) |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 527 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
503 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 528 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
504 duration, | 529 duration, |
505 base::TimeDelta::FromMilliseconds(500), | 530 base::TimeDelta::FromMilliseconds(500), |
506 base::TimeDelta::FromSeconds(60), | 531 base::TimeDelta::FromSeconds(60), |
507 60); | 532 60); |
508 } | 533 } |
509 } | 534 } |
510 | 535 |
511 } // namespace ui | 536 } // namespace ui |
OLD | NEW |