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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 selection_empty_(false), | 59 selection_empty_(false), |
60 selection_editable_(false), | 60 selection_editable_(false), |
61 temporarily_hidden_(false), | 61 temporarily_hidden_(false), |
62 selection_handle_dragged_(false) { | 62 selection_handle_dragged_(false) { |
63 DCHECK(client_); | 63 DCHECK(client_); |
64 } | 64 } |
65 | 65 |
66 TouchSelectionController::~TouchSelectionController() { | 66 TouchSelectionController::~TouchSelectionController() { |
67 } | 67 } |
68 | 68 |
| 69 void TouchSelectionController::OnViewportChanged( |
| 70 const gfx::RectF viewport_rect) { |
| 71 // Trigger a force update if the viewport is changed, so that |
| 72 // it triggers a call to change the mirror values if required. |
| 73 if (viewport_rect_ == viewport_rect) |
| 74 return; |
| 75 |
| 76 viewport_rect_ = viewport_rect; |
| 77 |
| 78 if (active_status_ == INACTIVE) |
| 79 return; |
| 80 |
| 81 if (active_status_ == INSERTION_ACTIVE) { |
| 82 DCHECK(insertion_handle_); |
| 83 insertion_handle_->SetViewportRect(viewport_rect); |
| 84 } else if (active_status_ == SELECTION_ACTIVE) { |
| 85 DCHECK(start_selection_handle_); |
| 86 DCHECK(end_selection_handle_); |
| 87 start_selection_handle_->SetViewportRect(viewport_rect); |
| 88 end_selection_handle_->SetViewportRect(viewport_rect); |
| 89 } |
| 90 } |
| 91 |
69 void TouchSelectionController::OnSelectionBoundsChanged( | 92 void TouchSelectionController::OnSelectionBoundsChanged( |
70 const SelectionBound& start, | 93 const SelectionBound& start, |
71 const SelectionBound& end) { | 94 const SelectionBound& end) { |
72 if (!force_next_update_ && start == start_ && end_ == end) | 95 if (!force_next_update_ && start == start_ && end_ == end) |
73 return; | 96 return; |
74 | 97 |
75 start_ = start; | 98 start_ = start; |
76 end_ = end; | 99 end_ = end; |
77 start_orientation_ = ToTouchHandleOrientation(start_.type()); | 100 start_orientation_ = ToTouchHandleOrientation(start_.type()); |
78 end_orientation_ = ToTouchHandleOrientation(end_.type()); | 101 end_orientation_ = ToTouchHandleOrientation(end_.type()); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 } | 307 } |
285 | 308 |
286 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { | 309 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { |
287 if (&handle == insertion_handle_.get()) { | 310 if (&handle == insertion_handle_.get()) { |
288 client_->OnSelectionEvent(INSERTION_DRAG_STARTED); | 311 client_->OnSelectionEvent(INSERTION_DRAG_STARTED); |
289 return; | 312 return; |
290 } | 313 } |
291 | 314 |
292 gfx::PointF base, extent; | 315 gfx::PointF base, extent; |
293 if (&handle == start_selection_handle_.get()) { | 316 if (&handle == start_selection_handle_.get()) { |
294 base = end_selection_handle_->position() + GetEndLineOffset(); | 317 base = end_selection_handle_->focus_bottom() + GetEndLineOffset(); |
295 extent = start_selection_handle_->position() + GetStartLineOffset(); | 318 extent = start_selection_handle_->focus_bottom() + GetStartLineOffset(); |
296 } else { | 319 } else { |
297 base = start_selection_handle_->position() + GetStartLineOffset(); | 320 base = start_selection_handle_->focus_bottom() + GetStartLineOffset(); |
298 extent = end_selection_handle_->position() + GetEndLineOffset(); | 321 extent = end_selection_handle_->focus_bottom() + GetEndLineOffset(); |
299 } | 322 } |
300 selection_handle_dragged_ = true; | 323 selection_handle_dragged_ = true; |
301 | 324 |
302 // When moving the handle we want to move only the extent point. Before doing | 325 // When moving the handle we want to move only the extent point. Before doing |
303 // so we must make sure that the base point is set correctly. | 326 // so we must make sure that the base point is set correctly. |
304 client_->SelectBetweenCoordinates(base, extent); | 327 client_->SelectBetweenCoordinates(base, extent); |
305 client_->OnSelectionEvent(SELECTION_DRAG_STARTED); | 328 client_->OnSelectionEvent(SELECTION_DRAG_STARTED); |
306 } | 329 } |
307 | 330 |
308 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, | 331 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 if (!activate_insertion_automatically_) | 412 if (!activate_insertion_automatically_) |
390 return; | 413 return; |
391 | 414 |
392 const bool was_active = active_status_ == INSERTION_ACTIVE; | 415 const bool was_active = active_status_ == INSERTION_ACTIVE; |
393 const gfx::PointF position = GetStartPosition(); | 416 const gfx::PointF position = GetStartPosition(); |
394 if (!was_active) | 417 if (!was_active) |
395 ActivateInsertion(); | 418 ActivateInsertion(); |
396 else | 419 else |
397 client_->OnSelectionEvent(INSERTION_MOVED); | 420 client_->OnSelectionEvent(INSERTION_MOVED); |
398 | 421 |
| 422 insertion_handle_->SetFocus(start_.edge_top(), start_.edge_bottom()); |
399 insertion_handle_->SetVisible(GetStartVisible(), | 423 insertion_handle_->SetVisible(GetStartVisible(), |
400 GetAnimationStyle(was_active)); | 424 GetAnimationStyle(was_active)); |
401 insertion_handle_->SetPosition(position); | |
402 } | 425 } |
403 | 426 |
404 void TouchSelectionController::OnSelectionChanged() { | 427 void TouchSelectionController::OnSelectionChanged() { |
405 DeactivateInsertion(); | 428 DeactivateInsertion(); |
406 | 429 |
407 if (!activate_selection_automatically_) | 430 if (!activate_selection_automatically_) |
408 return; | 431 return; |
409 | 432 |
410 const bool was_active = active_status_ == SELECTION_ACTIVE; | 433 const bool was_active = active_status_ == SELECTION_ACTIVE; |
411 if (!was_active || response_pending_input_event_ == LONG_PRESS) | 434 if (!was_active || response_pending_input_event_ == LONG_PRESS) |
412 ActivateSelection(); | 435 ActivateSelection(); |
413 else | 436 else |
414 client_->OnSelectionEvent(SELECTION_MOVED); | 437 client_->OnSelectionEvent(SELECTION_MOVED); |
415 | 438 |
416 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active); | 439 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active); |
| 440 |
| 441 start_selection_handle_->SetFocus(start_.edge_top(), start_.edge_bottom()); |
| 442 end_selection_handle_->SetFocus(end_.edge_top(), end_.edge_bottom()); |
| 443 |
| 444 start_selection_handle_->SetOrientation(start_orientation_); |
| 445 end_selection_handle_->SetOrientation(end_orientation_); |
| 446 |
417 start_selection_handle_->SetVisible(GetStartVisible(), animation); | 447 start_selection_handle_->SetVisible(GetStartVisible(), animation); |
418 end_selection_handle_->SetVisible(GetEndVisible(), animation); | 448 end_selection_handle_->SetVisible(GetEndVisible(), animation); |
419 | 449 |
420 start_selection_handle_->SetPosition(GetStartPosition()); | |
421 end_selection_handle_->SetPosition(GetEndPosition()); | |
422 } | 450 } |
423 | 451 |
424 void TouchSelectionController::ActivateInsertion() { | 452 void TouchSelectionController::ActivateInsertion() { |
425 DCHECK_NE(SELECTION_ACTIVE, active_status_); | 453 DCHECK_NE(SELECTION_ACTIVE, active_status_); |
426 | 454 |
427 if (!insertion_handle_) | 455 if (!insertion_handle_) |
428 insertion_handle_.reset( | 456 insertion_handle_.reset( |
429 new TouchHandle(this, TouchHandleOrientation::CENTER)); | 457 new TouchHandle(this, TouchHandleOrientation::CENTER, viewport_rect_)); |
430 | 458 |
431 if (active_status_ == INACTIVE) { | 459 if (active_status_ == INACTIVE) { |
432 active_status_ = INSERTION_ACTIVE; | 460 active_status_ = INSERTION_ACTIVE; |
| 461 insertion_handle_->SetViewportRect(viewport_rect_); |
433 insertion_handle_->SetEnabled(true); | 462 insertion_handle_->SetEnabled(true); |
434 client_->OnSelectionEvent(INSERTION_SHOWN); | 463 client_->OnSelectionEvent(INSERTION_SHOWN); |
435 } | 464 } |
436 } | 465 } |
437 | 466 |
438 void TouchSelectionController::DeactivateInsertion() { | 467 void TouchSelectionController::DeactivateInsertion() { |
439 if (active_status_ != INSERTION_ACTIVE) | 468 if (active_status_ != INSERTION_ACTIVE) |
440 return; | 469 return; |
441 DCHECK(insertion_handle_); | 470 DCHECK(insertion_handle_); |
442 active_status_ = INACTIVE; | 471 active_status_ = INACTIVE; |
443 insertion_handle_->SetEnabled(false); | 472 insertion_handle_->SetEnabled(false); |
444 client_->OnSelectionEvent(INSERTION_CLEARED); | 473 client_->OnSelectionEvent(INSERTION_CLEARED); |
445 } | 474 } |
446 | 475 |
447 void TouchSelectionController::ActivateSelection() { | 476 void TouchSelectionController::ActivateSelection() { |
448 DCHECK_NE(INSERTION_ACTIVE, active_status_); | 477 DCHECK_NE(INSERTION_ACTIVE, active_status_); |
449 | 478 |
450 if (!start_selection_handle_) { | 479 if (!start_selection_handle_) { |
451 start_selection_handle_.reset(new TouchHandle(this, start_orientation_)); | 480 start_selection_handle_.reset( |
| 481 new TouchHandle(this, start_orientation_, viewport_rect_)); |
452 } else { | 482 } else { |
| 483 start_selection_handle_->SetViewportRect(viewport_rect_); |
453 start_selection_handle_->SetEnabled(true); | 484 start_selection_handle_->SetEnabled(true); |
454 start_selection_handle_->SetOrientation(start_orientation_); | |
455 } | 485 } |
456 | 486 |
457 if (!end_selection_handle_) { | 487 if (!end_selection_handle_) { |
458 end_selection_handle_.reset(new TouchHandle(this, end_orientation_)); | 488 end_selection_handle_.reset( |
| 489 new TouchHandle(this, end_orientation_, viewport_rect_)); |
459 } else { | 490 } else { |
| 491 end_selection_handle_->SetViewportRect(viewport_rect_); |
460 end_selection_handle_->SetEnabled(true); | 492 end_selection_handle_->SetEnabled(true); |
461 end_selection_handle_->SetOrientation(end_orientation_); | |
462 } | 493 } |
463 | 494 |
464 // As a long press received while a selection is already active may trigger | 495 // As a long press received while a selection is already active may trigger |
465 // an entirely new selection, notify the client but avoid sending an | 496 // an entirely new selection, notify the client but avoid sending an |
466 // intervening SELECTION_CLEARED update to avoid unnecessary state changes. | 497 // intervening SELECTION_CLEARED update to avoid unnecessary state changes. |
467 if (active_status_ == INACTIVE || | 498 if (active_status_ == INACTIVE || |
468 response_pending_input_event_ == LONG_PRESS) { | 499 response_pending_input_event_ == LONG_PRESS) { |
469 if (active_status_ == SELECTION_ACTIVE) { | 500 if (active_status_ == SELECTION_ACTIVE) { |
470 // The active selection session finishes with the start of the new one. | 501 // The active selection session finishes with the start of the new one. |
471 LogSelectionEnd(); | 502 LogSelectionEnd(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 564 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
534 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 565 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
535 duration, | 566 duration, |
536 base::TimeDelta::FromMilliseconds(500), | 567 base::TimeDelta::FromMilliseconds(500), |
537 base::TimeDelta::FromSeconds(60), | 568 base::TimeDelta::FromSeconds(60), |
538 60); | 569 60); |
539 } | 570 } |
540 } | 571 } |
541 | 572 |
542 } // namespace ui | 573 } // namespace ui |
OLD | NEW |