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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 selection_handle_dragged_(false) { | 61 selection_handle_dragged_(false) { |
62 DCHECK(client_); | 62 DCHECK(client_); |
63 } | 63 } |
64 | 64 |
65 TouchSelectionController::~TouchSelectionController() { | 65 TouchSelectionController::~TouchSelectionController() { |
66 } | 66 } |
67 | 67 |
68 void TouchSelectionController::OnSelectionBoundsChanged( | 68 void TouchSelectionController::OnSelectionBoundsChanged( |
69 const SelectionBound& start, | 69 const SelectionBound& start, |
70 const SelectionBound& end) { | 70 const SelectionBound& end) { |
71 if (!force_next_update_ && start == start_ && end_ == end) | 71 if (start == start_ && end_ == end) |
72 return; | 72 return; |
73 | 73 |
74 start_ = start; | 74 start_ = start; |
75 end_ = end; | 75 end_ = end; |
76 start_orientation_ = ToTouchHandleOrientation(start_.type()); | 76 start_orientation_ = ToTouchHandleOrientation(start_.type()); |
77 end_orientation_ = ToTouchHandleOrientation(end_.type()); | 77 end_orientation_ = ToTouchHandleOrientation(end_.type()); |
78 force_next_update_ = false; | |
79 | 78 |
80 if (!activate_selection_automatically_ && | 79 if (!activate_selection_automatically_ && |
81 !activate_insertion_automatically_) { | 80 !activate_insertion_automatically_) { |
82 DCHECK_EQ(INACTIVE, active_status_); | 81 DCHECK_EQ(INACTIVE, active_status_); |
83 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); | 82 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); |
84 return; | 83 return; |
85 } | 84 } |
86 | 85 |
87 // Ensure that |response_pending_input_event_| is cleared after the method | 86 // Ensure that |response_pending_input_event_| is cleared after the method |
88 // completes, while also making its current value available for the duration | 87 // completes, while also making its current value available for the duration |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 return end_selection_handle_->WillHandleTouchEvent(event); | 148 return end_selection_handle_->WillHandleTouchEvent(event); |
150 } | 149 } |
151 | 150 |
152 return false; | 151 return false; |
153 } | 152 } |
154 | 153 |
155 void TouchSelectionController::OnLongPressEvent() { | 154 void TouchSelectionController::OnLongPressEvent() { |
156 response_pending_input_event_ = LONG_PRESS; | 155 response_pending_input_event_ = LONG_PRESS; |
157 ShowSelectionHandlesAutomatically(); | 156 ShowSelectionHandlesAutomatically(); |
158 ShowInsertionHandleAutomatically(); | 157 ShowInsertionHandleAutomatically(); |
159 ForceNextUpdateIfInactive(); | 158 ResetCachedValuesIfInactive(); |
160 } | 159 } |
161 | 160 |
162 void TouchSelectionController::AllowShowingFromCurrentSelection() { | 161 void TouchSelectionController::AllowShowingFromCurrentSelection() { |
163 if (active_status_ != INACTIVE) | 162 if (active_status_ != INACTIVE) |
164 return; | 163 return; |
165 | 164 |
166 activate_selection_automatically_ = true; | 165 activate_selection_automatically_ = true; |
167 activate_insertion_automatically_ = true; | 166 activate_insertion_automatically_ = true; |
168 if (GetStartPosition() != GetEndPosition()) { | 167 if (GetStartPosition() != GetEndPosition()) { |
169 OnSelectionChanged(); | 168 OnSelectionChanged(); |
170 } else if (start_orientation_ == TouchHandleOrientation::CENTER && | 169 } else if (start_orientation_ == TouchHandleOrientation::CENTER && |
171 selection_editable_) { | 170 selection_editable_) { |
172 OnInsertionChanged(); | 171 OnInsertionChanged(); |
173 } | 172 } |
174 } | 173 } |
175 | 174 |
176 void TouchSelectionController::OnTapEvent() { | 175 void TouchSelectionController::OnTapEvent() { |
177 response_pending_input_event_ = TAP; | 176 response_pending_input_event_ = TAP; |
178 if (active_status_ != SELECTION_ACTIVE) | 177 if (active_status_ != SELECTION_ACTIVE) |
179 activate_selection_automatically_ = false; | 178 activate_selection_automatically_ = false; |
180 ShowInsertionHandleAutomatically(); | 179 ShowInsertionHandleAutomatically(); |
181 if (selection_empty_ && !show_on_tap_for_empty_editable_) | 180 if (selection_empty_ && !show_on_tap_for_empty_editable_) |
182 DeactivateInsertion(); | 181 DeactivateInsertion(); |
183 ForceNextUpdateIfInactive(); | 182 ResetCachedValuesIfInactive(); |
184 } | 183 } |
185 | 184 |
186 void TouchSelectionController::HideAndDisallowShowingAutomatically() { | 185 void TouchSelectionController::HideAndDisallowShowingAutomatically() { |
187 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; | 186 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; |
188 DeactivateInsertion(); | 187 DeactivateInsertion(); |
189 DeactivateSelection(); | 188 DeactivateSelection(); |
190 activate_insertion_automatically_ = false; | 189 activate_insertion_automatically_ = false; |
191 activate_selection_automatically_ = false; | 190 activate_selection_automatically_ = false; |
192 } | 191 } |
193 | 192 |
194 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { | 193 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { |
195 if (temporarily_hidden_ == hidden) | 194 if (temporarily_hidden_ == hidden) |
196 return; | 195 return; |
197 temporarily_hidden_ = hidden; | 196 temporarily_hidden_ = hidden; |
198 | 197 |
199 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true); | 198 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true); |
200 if (active_status_ == SELECTION_ACTIVE) { | 199 if (active_status_ == SELECTION_ACTIVE) { |
201 start_selection_handle_->SetVisible(GetStartVisible(), animation_style); | 200 start_selection_handle_->SetVisible(GetStartVisible(), animation_style); |
202 end_selection_handle_->SetVisible(GetEndVisible(), animation_style); | 201 end_selection_handle_->SetVisible(GetEndVisible(), animation_style); |
203 } else if (active_status_ == INSERTION_ACTIVE) { | 202 } else if (active_status_ == INSERTION_ACTIVE) { |
204 insertion_handle_->SetVisible(GetStartVisible(), animation_style); | 203 insertion_handle_->SetVisible(GetStartVisible(), animation_style); |
205 } | 204 } |
206 } | 205 } |
207 | 206 |
208 void TouchSelectionController::OnSelectionEditable(bool editable) { | 207 void TouchSelectionController::OnSelectionEditable(bool editable) { |
209 if (selection_editable_ == editable) | 208 if (selection_editable_ == editable) |
210 return; | 209 return; |
211 selection_editable_ = editable; | 210 selection_editable_ = editable; |
212 ForceNextUpdateIfInactive(); | 211 ResetCachedValuesIfInactive(); |
213 if (!selection_editable_) | 212 if (!selection_editable_) |
214 DeactivateInsertion(); | 213 DeactivateInsertion(); |
215 } | 214 } |
216 | 215 |
217 void TouchSelectionController::OnSelectionEmpty(bool empty) { | 216 void TouchSelectionController::OnSelectionEmpty(bool empty) { |
218 if (selection_empty_ == empty) | 217 if (selection_empty_ == empty) |
219 return; | 218 return; |
220 selection_empty_ = empty; | 219 selection_empty_ = empty; |
221 ForceNextUpdateIfInactive(); | 220 ResetCachedValuesIfInactive(); |
222 } | 221 } |
223 | 222 |
224 bool TouchSelectionController::Animate(base::TimeTicks frame_time) { | 223 bool TouchSelectionController::Animate(base::TimeTicks frame_time) { |
225 if (active_status_ == INSERTION_ACTIVE) | 224 if (active_status_ == INSERTION_ACTIVE) |
226 return insertion_handle_->Animate(frame_time); | 225 return insertion_handle_->Animate(frame_time); |
227 | 226 |
228 if (active_status_ == SELECTION_ACTIVE) { | 227 if (active_status_ == SELECTION_ACTIVE) { |
229 bool needs_animate = start_selection_handle_->Animate(frame_time); | 228 bool needs_animate = start_selection_handle_->Animate(frame_time); |
230 needs_animate |= end_selection_handle_->Animate(frame_time); | 229 needs_animate |= end_selection_handle_->Animate(frame_time); |
231 return needs_animate; | 230 return needs_animate; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 } | 333 } |
335 | 334 |
336 float TouchSelectionController::GetTapSlop() const { | 335 float TouchSelectionController::GetTapSlop() const { |
337 return tap_slop_; | 336 return tap_slop_; |
338 } | 337 } |
339 | 338 |
340 void TouchSelectionController::ShowInsertionHandleAutomatically() { | 339 void TouchSelectionController::ShowInsertionHandleAutomatically() { |
341 if (activate_insertion_automatically_) | 340 if (activate_insertion_automatically_) |
342 return; | 341 return; |
343 activate_insertion_automatically_ = true; | 342 activate_insertion_automatically_ = true; |
344 ForceNextUpdateIfInactive(); | 343 ResetCachedValuesIfInactive(); |
345 } | 344 } |
346 | 345 |
347 void TouchSelectionController::ShowSelectionHandlesAutomatically() { | 346 void TouchSelectionController::ShowSelectionHandlesAutomatically() { |
348 if (activate_selection_automatically_) | 347 if (activate_selection_automatically_) |
349 return; | 348 return; |
350 activate_selection_automatically_ = true; | 349 activate_selection_automatically_ = true; |
351 ForceNextUpdateIfInactive(); | 350 ResetCachedValuesIfInactive(); |
352 } | 351 } |
353 | 352 |
354 void TouchSelectionController::OnInsertionChanged() { | 353 void TouchSelectionController::OnInsertionChanged() { |
355 DeactivateSelection(); | 354 DeactivateSelection(); |
356 | 355 |
357 if (response_pending_input_event_ == TAP && selection_empty_ && | 356 if (response_pending_input_event_ == TAP && selection_empty_ && |
358 !show_on_tap_for_empty_editable_) { | 357 !show_on_tap_for_empty_editable_) { |
359 HideAndDisallowShowingAutomatically(); | 358 HideAndDisallowShowingAutomatically(); |
360 return; | 359 return; |
361 } | 360 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 return; | 456 return; |
458 DCHECK(start_selection_handle_); | 457 DCHECK(start_selection_handle_); |
459 DCHECK(end_selection_handle_); | 458 DCHECK(end_selection_handle_); |
460 LogSelectionEnd(); | 459 LogSelectionEnd(); |
461 start_selection_handle_->SetEnabled(false); | 460 start_selection_handle_->SetEnabled(false); |
462 end_selection_handle_->SetEnabled(false); | 461 end_selection_handle_->SetEnabled(false); |
463 active_status_ = INACTIVE; | 462 active_status_ = INACTIVE; |
464 client_->OnSelectionEvent(SELECTION_CLEARED); | 463 client_->OnSelectionEvent(SELECTION_CLEARED); |
465 } | 464 } |
466 | 465 |
467 void TouchSelectionController::ForceNextUpdateIfInactive() { | 466 void TouchSelectionController::ResetCachedValuesIfInactive() { |
468 if (active_status_ == INACTIVE) | 467 if (active_status_ != INACTIVE) |
469 force_next_update_ = true; | 468 return; |
| 469 start_ = SelectionBound(); |
| 470 end_ = SelectionBound(); |
| 471 start_orientation_ = TouchHandleOrientation::UNDEFINED; |
| 472 end_orientation_ = TouchHandleOrientation::UNDEFINED; |
470 } | 473 } |
471 | 474 |
472 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { | 475 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { |
473 return ComputeLineOffsetFromBottom(start_); | 476 return ComputeLineOffsetFromBottom(start_); |
474 } | 477 } |
475 | 478 |
476 gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const { | 479 gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const { |
477 return ComputeLineOffsetFromBottom(end_); | 480 return ComputeLineOffsetFromBottom(end_); |
478 } | 481 } |
479 | 482 |
(...skipping 21 matching lines...) Expand all Loading... |
501 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 504 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
502 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 505 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
503 duration, | 506 duration, |
504 base::TimeDelta::FromMilliseconds(500), | 507 base::TimeDelta::FromMilliseconds(500), |
505 base::TimeDelta::FromSeconds(60), | 508 base::TimeDelta::FromSeconds(60), |
506 60); | 509 60); |
507 } | 510 } |
508 } | 511 } |
509 | 512 |
510 } // namespace ui | 513 } // namespace ui |
OLD | NEW |