Chromium Code Reviews| 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 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::OnSelectionBoundsChanged( | 69 void TouchSelectionController::OnSelectionBoundsChanged( |
| 70 const SelectionBound& start, | 70 const SelectionBound& start, |
| 71 const SelectionBound& end) { | 71 const SelectionBound& end, |
| 72 if (start == start_ && end_ == end) | 72 const gfx::SizeF& root_layer_size, |
|
jdduke (slow)
2015/03/16 22:01:45
The size/offet should probably be in a separate me
AviD
2015/03/19 13:13:33
Done.
| |
| 73 const gfx::Vector2dF& offset) { | |
| 74 if (start == start_ && end_ == end && root_layer_size != root_layer_size_ && | |
| 75 offset != content_offset_) | |
| 73 return; | 76 return; |
| 74 | 77 |
| 75 start_ = start; | 78 start_ = start; |
| 76 end_ = end; | 79 end_ = end; |
| 80 root_layer_size_ = root_layer_size; | |
| 81 content_offset_ = offset; | |
| 82 viewport_rect_.SetRect(offset.x(), offset.y(), root_layer_size.width(), | |
| 83 root_layer_size.height()); | |
| 77 start_orientation_ = ToTouchHandleOrientation(start_.type()); | 84 start_orientation_ = ToTouchHandleOrientation(start_.type()); |
| 78 end_orientation_ = ToTouchHandleOrientation(end_.type()); | 85 end_orientation_ = ToTouchHandleOrientation(end_.type()); |
| 86 SetInvertedOrientation(); | |
| 79 | 87 |
| 80 if (!activate_selection_automatically_ && | 88 if (!activate_selection_automatically_ && |
| 81 !activate_insertion_automatically_) { | 89 !activate_insertion_automatically_) { |
| 82 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); | 90 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); |
| 83 return; | 91 return; |
| 84 } | 92 } |
| 85 | 93 |
| 86 // Ensure that |response_pending_input_event_| is cleared after the method | 94 // Ensure that |response_pending_input_event_| is cleared after the method |
| 87 // completes, while also making its current value available for the duration | 95 // completes, while also making its current value available for the duration |
| 88 // of the call. | 96 // of the call. |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 void TouchSelectionController::ResetCachedValuesIfInactive() { | 430 void TouchSelectionController::ResetCachedValuesIfInactive() { |
| 423 if (is_selection_active_ || is_insertion_active_) | 431 if (is_selection_active_ || is_insertion_active_) |
| 424 return; | 432 return; |
| 425 start_ = SelectionBound(); | 433 start_ = SelectionBound(); |
| 426 end_ = SelectionBound(); | 434 end_ = SelectionBound(); |
| 427 start_orientation_ = TouchHandleOrientation::UNDEFINED; | 435 start_orientation_ = TouchHandleOrientation::UNDEFINED; |
| 428 end_orientation_ = TouchHandleOrientation::UNDEFINED; | 436 end_orientation_ = TouchHandleOrientation::UNDEFINED; |
| 429 } | 437 } |
| 430 | 438 |
| 431 const gfx::PointF& TouchSelectionController::GetStartPosition() const { | 439 const gfx::PointF& TouchSelectionController::GetStartPosition() const { |
| 440 bool top_handle = | |
| 441 start_orientation_ == TouchHandleOrientation::LEFT_INVERTED || | |
| 442 start_orientation_ == TouchHandleOrientation::LEFT_FLIPPED_INVERTED; | |
| 443 if (top_handle) | |
| 444 return start_.edge_top(); | |
| 432 return start_.edge_bottom(); | 445 return start_.edge_bottom(); |
| 433 } | 446 } |
| 434 | 447 |
| 435 const gfx::PointF& TouchSelectionController::GetEndPosition() const { | 448 const gfx::PointF& TouchSelectionController::GetEndPosition() const { |
| 449 bool top_handle = | |
| 450 end_orientation_ == TouchHandleOrientation::RIGHT_INVERTED || | |
| 451 end_orientation_ == TouchHandleOrientation::RIGHT_FLIPPED_INVERTED; | |
| 452 if (top_handle) | |
| 453 return end_.edge_top(); | |
| 436 return end_.edge_bottom(); | 454 return end_.edge_bottom(); |
| 437 } | 455 } |
| 438 | 456 |
| 457 void TouchSelectionController::SetInvertedOrientation() { | |
| 458 if (!start_selection_handle_ || !end_selection_handle_) | |
| 459 return; | |
| 460 | |
| 461 TouchHandleOrientation old_start_orientation = start_orientation_; | |
| 462 TouchHandleOrientation old_end_orientation = end_orientation_; | |
| 463 | |
| 464 gfx::RectF start_size = start_selection_handle_->GetHandleBounds(); | |
| 465 gfx::RectF end_size = end_selection_handle_->GetHandleBounds(); | |
| 466 | |
| 467 int start_handle_state = 0; | |
| 468 int end_handle_state = 0; | |
| 469 | |
| 470 if (start_.edge_bottom().y() + start_size.height() > | |
| 471 viewport_rect_.height()) { | |
| 472 start_orientation_ = TouchHandleOrientation::LEFT_INVERTED; | |
| 473 start_handle_state++; | |
| 474 } | |
| 475 | |
| 476 if (end_.edge_bottom().y() + end_size.height() > viewport_rect_.height()) { | |
| 477 end_orientation_ = TouchHandleOrientation::RIGHT_INVERTED; | |
| 478 end_handle_state++; | |
| 479 } | |
| 480 | |
| 481 if (start_.edge_top().x() - end_size.width() < viewport_rect_.x()) { | |
| 482 start_orientation_ = TouchHandleOrientation::LEFT_FLIPPED; | |
| 483 start_handle_state++; | |
| 484 } | |
| 485 | |
| 486 if (end_.edge_top().x() + start_size.width() > viewport_rect_.width()) { | |
| 487 end_orientation_ = TouchHandleOrientation::RIGHT_FLIPPED; | |
| 488 end_handle_state++; | |
| 489 } | |
| 490 | |
| 491 if (start_handle_state == 2) { | |
| 492 start_orientation_ = TouchHandleOrientation::LEFT_FLIPPED_INVERTED; | |
| 493 } else if (start_handle_state == 0) { | |
| 494 start_orientation_ = old_start_orientation; | |
| 495 } | |
| 496 | |
| 497 if (end_handle_state == 2) { | |
| 498 end_orientation_ = TouchHandleOrientation::RIGHT_FLIPPED_INVERTED; | |
| 499 } else if (end_handle_state == 0) { | |
| 500 end_orientation_ = old_end_orientation; | |
| 501 } | |
| 502 } | |
| 503 | |
| 439 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { | 504 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { |
| 440 return ComputeLineOffsetFromBottom(start_); | 505 return ComputeLineOffsetFromBottom(start_); |
| 441 } | 506 } |
| 442 | 507 |
| 443 gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const { | 508 gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const { |
| 444 return ComputeLineOffsetFromBottom(end_); | 509 return ComputeLineOffsetFromBottom(end_); |
| 445 } | 510 } |
| 446 | 511 |
| 447 bool TouchSelectionController::GetStartVisible() const { | 512 bool TouchSelectionController::GetStartVisible() const { |
| 448 return start_.visible() && !temporarily_hidden_; | 513 return start_.visible() && !temporarily_hidden_; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 468 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 533 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
| 469 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 534 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
| 470 duration, | 535 duration, |
| 471 base::TimeDelta::FromMilliseconds(500), | 536 base::TimeDelta::FromMilliseconds(500), |
| 472 base::TimeDelta::FromSeconds(60), | 537 base::TimeDelta::FromSeconds(60), |
| 473 60); | 538 60); |
| 474 } | 539 } |
| 475 } | 540 } |
| 476 | 541 |
| 477 } // namespace ui | 542 } // namespace ui |
| OLD | NEW |