| 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 325 } |
| 326 | 326 |
| 327 const gfx::PointF& TouchSelectionController::GetStartPosition() const { | 327 const gfx::PointF& TouchSelectionController::GetStartPosition() const { |
| 328 return start_.edge_bottom(); | 328 return start_.edge_bottom(); |
| 329 } | 329 } |
| 330 | 330 |
| 331 const gfx::PointF& TouchSelectionController::GetEndPosition() const { | 331 const gfx::PointF& TouchSelectionController::GetEndPosition() const { |
| 332 return end_.edge_bottom(); | 332 return end_.edge_bottom(); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void TouchSelectionController::OnDragBegin( | 335 void TouchSelectionController::OnDragEvent( |
| 336 const TouchHandleDragEvent event, |
| 337 const TouchSelectionDraggable& draggable, |
| 338 const gfx::PointF& position) { |
| 339 switch (event) { |
| 340 case HANDLE_DRAG_BEGIN: |
| 341 HandleDragBegin(draggable, position); |
| 342 break; |
| 343 case HANDLE_DRAG_UPDATE: |
| 344 HandleDragUpdate(draggable, position); |
| 345 break; |
| 346 case HANDLE_DRAG_END: |
| 347 HandleDragEnd(draggable); |
| 348 default: |
| 349 NOTREACHED() << "Invalid handle drag event"; |
| 350 } |
| 351 } |
| 352 |
| 353 bool TouchSelectionController::IsWithinTapSlop( |
| 354 const gfx::Vector2dF& delta) const { |
| 355 return delta.LengthSquared() < |
| 356 (static_cast<double>(config_.tap_slop) * config_.tap_slop); |
| 357 } |
| 358 |
| 359 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { |
| 360 if (insertion_handle_ && &handle == insertion_handle_.get()) |
| 361 client_->OnSelectionEvent(INSERTION_HANDLE_TAPPED); |
| 362 } |
| 363 |
| 364 void TouchSelectionController::SetNeedsAnimate() { |
| 365 client_->SetNeedsAnimate(); |
| 366 } |
| 367 |
| 368 scoped_ptr<TouchHandleDrawable> TouchSelectionController::CreateDrawable() { |
| 369 return client_->CreateDrawable(); |
| 370 } |
| 371 |
| 372 base::TimeDelta TouchSelectionController::GetMaxTapDuration() const { |
| 373 return config_.max_tap_duration; |
| 374 } |
| 375 |
| 376 bool TouchSelectionController::IsAdaptiveHandleOrientationEnabled() const { |
| 377 return config_.enable_adaptive_handle_orientation; |
| 378 } |
| 379 |
| 380 void TouchSelectionController::HandleDragBegin( |
| 336 const TouchSelectionDraggable& draggable, | 381 const TouchSelectionDraggable& draggable, |
| 337 const gfx::PointF& drag_position) { | 382 const gfx::PointF& drag_position) { |
| 338 if (&draggable == insertion_handle_.get()) { | 383 if (&draggable == insertion_handle_.get()) { |
| 339 DCHECK_EQ(active_status_, INSERTION_ACTIVE); | 384 DCHECK_EQ(active_status_, INSERTION_ACTIVE); |
| 340 client_->OnSelectionEvent(INSERTION_HANDLE_DRAG_STARTED); | 385 client_->OnSelectionEvent(INSERTION_HANDLE_DRAG_STARTED); |
| 341 anchor_drag_to_selection_start_ = true; | 386 anchor_drag_to_selection_start_ = true; |
| 342 return; | 387 return; |
| 343 } | 388 } |
| 344 | 389 |
| 345 DCHECK_EQ(active_status_, SELECTION_ACTIVE); | 390 DCHECK_EQ(active_status_, SELECTION_ACTIVE); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 361 std::swap(base, extent); | 406 std::swap(base, extent); |
| 362 | 407 |
| 363 selection_handle_dragged_ = true; | 408 selection_handle_dragged_ = true; |
| 364 | 409 |
| 365 // When moving the handle we want to move only the extent point. Before doing | 410 // When moving the handle we want to move only the extent point. Before doing |
| 366 // so we must make sure that the base point is set correctly. | 411 // so we must make sure that the base point is set correctly. |
| 367 client_->SelectBetweenCoordinates(base, extent); | 412 client_->SelectBetweenCoordinates(base, extent); |
| 368 client_->OnSelectionEvent(SELECTION_HANDLE_DRAG_STARTED); | 413 client_->OnSelectionEvent(SELECTION_HANDLE_DRAG_STARTED); |
| 369 } | 414 } |
| 370 | 415 |
| 371 void TouchSelectionController::OnDragUpdate( | 416 void TouchSelectionController::HandleDragUpdate( |
| 372 const TouchSelectionDraggable& draggable, | 417 const TouchSelectionDraggable& draggable, |
| 373 const gfx::PointF& drag_position) { | 418 const gfx::PointF& drag_position) { |
| 374 // As the position corresponds to the bottom left point of the selection | 419 // As the position corresponds to the bottom left point of the selection |
| 375 // bound, offset it to some reasonable point on the current line of text. | 420 // bound, offset it to some reasonable point on the current line of text. |
| 376 gfx::Vector2dF line_offset = anchor_drag_to_selection_start_ | 421 gfx::Vector2dF line_offset = anchor_drag_to_selection_start_ |
| 377 ? GetStartLineOffset() | 422 ? GetStartLineOffset() |
| 378 : GetEndLineOffset(); | 423 : GetEndLineOffset(); |
| 379 gfx::PointF line_position = drag_position + line_offset; | 424 gfx::PointF line_position = drag_position + line_offset; |
| 380 if (&draggable == insertion_handle_.get()) | 425 if (&draggable == insertion_handle_.get()) |
| 381 client_->MoveCaret(line_position); | 426 client_->MoveCaret(line_position); |
| 382 else | 427 else |
| 383 client_->MoveRangeSelectionExtent(line_position); | 428 client_->MoveRangeSelectionExtent(line_position); |
| 384 } | 429 } |
| 385 | 430 |
| 386 void TouchSelectionController::OnDragEnd( | 431 void TouchSelectionController::HandleDragEnd( |
| 387 const TouchSelectionDraggable& draggable) { | 432 const TouchSelectionDraggable& draggable) { |
| 388 if (&draggable == insertion_handle_.get()) | 433 if (&draggable == insertion_handle_.get()) |
| 389 client_->OnSelectionEvent(INSERTION_HANDLE_DRAG_STOPPED); | 434 client_->OnSelectionEvent(INSERTION_HANDLE_DRAG_STOPPED); |
| 390 else | 435 else |
| 391 client_->OnSelectionEvent(SELECTION_HANDLE_DRAG_STOPPED); | 436 client_->OnSelectionEvent(SELECTION_HANDLE_DRAG_STOPPED); |
| 392 } | 437 } |
| 393 | 438 |
| 394 bool TouchSelectionController::IsWithinTapSlop( | |
| 395 const gfx::Vector2dF& delta) const { | |
| 396 return delta.LengthSquared() < | |
| 397 (static_cast<double>(config_.tap_slop) * config_.tap_slop); | |
| 398 } | |
| 399 | |
| 400 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { | |
| 401 if (insertion_handle_ && &handle == insertion_handle_.get()) | |
| 402 client_->OnSelectionEvent(INSERTION_HANDLE_TAPPED); | |
| 403 } | |
| 404 | |
| 405 void TouchSelectionController::SetNeedsAnimate() { | |
| 406 client_->SetNeedsAnimate(); | |
| 407 } | |
| 408 | |
| 409 scoped_ptr<TouchHandleDrawable> TouchSelectionController::CreateDrawable() { | |
| 410 return client_->CreateDrawable(); | |
| 411 } | |
| 412 | |
| 413 base::TimeDelta TouchSelectionController::GetMaxTapDuration() const { | |
| 414 return config_.max_tap_duration; | |
| 415 } | |
| 416 | |
| 417 bool TouchSelectionController::IsAdaptiveHandleOrientationEnabled() const { | |
| 418 return config_.enable_adaptive_handle_orientation; | |
| 419 } | |
| 420 | |
| 421 void TouchSelectionController::OnLongPressDragActiveStateChanged() { | 439 void TouchSelectionController::OnLongPressDragActiveStateChanged() { |
| 422 // The handles should remain hidden for the duration of a longpress drag, | 440 // The handles should remain hidden for the duration of a longpress drag, |
| 423 // including the time between a longpress and the start of drag motion. | 441 // including the time between a longpress and the start of drag motion. |
| 424 RefreshHandleVisibility(); | 442 RefreshHandleVisibility(); |
| 425 } | 443 } |
| 426 | 444 |
| 427 gfx::PointF TouchSelectionController::GetSelectionStart() const { | 445 gfx::PointF TouchSelectionController::GetSelectionStart() const { |
| 428 return GetStartPosition(); | 446 return GetStartPosition(); |
| 429 } | 447 } |
| 430 | 448 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 683 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
| 666 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 684 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
| 667 duration, | 685 duration, |
| 668 base::TimeDelta::FromMilliseconds(500), | 686 base::TimeDelta::FromMilliseconds(500), |
| 669 base::TimeDelta::FromSeconds(60), | 687 base::TimeDelta::FromSeconds(60), |
| 670 60); | 688 60); |
| 671 } | 689 } |
| 672 } | 690 } |
| 673 | 691 |
| 674 } // namespace ui | 692 } // namespace ui |
| OLD | NEW |