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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 response_pending_input_event_(INPUT_EVENT_TYPE_NONE), | 52 response_pending_input_event_(INPUT_EVENT_TYPE_NONE), |
53 start_orientation_(TouchHandleOrientation::UNDEFINED), | 53 start_orientation_(TouchHandleOrientation::UNDEFINED), |
54 end_orientation_(TouchHandleOrientation::UNDEFINED), | 54 end_orientation_(TouchHandleOrientation::UNDEFINED), |
55 is_insertion_active_(false), | 55 is_insertion_active_(false), |
56 activate_insertion_automatically_(false), | 56 activate_insertion_automatically_(false), |
57 is_selection_active_(false), | 57 is_selection_active_(false), |
58 activate_selection_automatically_(false), | 58 activate_selection_automatically_(false), |
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 viewport_size_changed_(false), | |
62 selection_handle_dragged_(false) { | 63 selection_handle_dragged_(false) { |
63 DCHECK(client_); | 64 DCHECK(client_); |
64 } | 65 } |
65 | 66 |
66 TouchSelectionController::~TouchSelectionController() { | 67 TouchSelectionController::~TouchSelectionController() { |
67 } | 68 } |
68 | 69 |
70 void TouchSelectionController::OnViewportChanged( | |
71 const gfx::RectF viewport_rect) { | |
72 if (viewport_rect_ == viewport_rect) | |
73 return; | |
74 viewport_size_changed_ = true; | |
75 viewport_rect_ = viewport_rect; | |
76 } | |
77 | |
69 void TouchSelectionController::OnSelectionBoundsChanged( | 78 void TouchSelectionController::OnSelectionBoundsChanged( |
70 const SelectionBound& start, | 79 const SelectionBound& start, |
71 const SelectionBound& end) { | 80 const SelectionBound& end) { |
72 if (start == start_ && end_ == end) | 81 if (start == start_ && end_ == end && !viewport_size_changed_) |
73 return; | 82 return; |
74 | 83 |
75 start_ = start; | 84 start_ = start; |
76 end_ = end; | 85 end_ = end; |
77 start_orientation_ = ToTouchHandleOrientation(start_.type()); | 86 start_orientation_ = ToTouchHandleOrientation(start_.type()); |
78 end_orientation_ = ToTouchHandleOrientation(end_.type()); | 87 end_orientation_ = ToTouchHandleOrientation(end_.type()); |
88 SetInvertedOrientation(); | |
89 viewport_size_changed_ = false; | |
79 | 90 |
80 if (!activate_selection_automatically_ && | 91 if (!activate_selection_automatically_ && |
81 !activate_insertion_automatically_) { | 92 !activate_insertion_automatically_) { |
82 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); | 93 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); |
83 return; | 94 return; |
84 } | 95 } |
85 | 96 |
86 // Ensure that |response_pending_input_event_| is cleared after the method | 97 // Ensure that |response_pending_input_event_| is cleared after the method |
87 // completes, while also making its current value available for the duration | 98 // completes, while also making its current value available for the duration |
88 // of the call. | 99 // of the call. |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 void TouchSelectionController::ResetCachedValuesIfInactive() { | 433 void TouchSelectionController::ResetCachedValuesIfInactive() { |
423 if (is_selection_active_ || is_insertion_active_) | 434 if (is_selection_active_ || is_insertion_active_) |
424 return; | 435 return; |
425 start_ = SelectionBound(); | 436 start_ = SelectionBound(); |
426 end_ = SelectionBound(); | 437 end_ = SelectionBound(); |
427 start_orientation_ = TouchHandleOrientation::UNDEFINED; | 438 start_orientation_ = TouchHandleOrientation::UNDEFINED; |
428 end_orientation_ = TouchHandleOrientation::UNDEFINED; | 439 end_orientation_ = TouchHandleOrientation::UNDEFINED; |
429 } | 440 } |
430 | 441 |
431 const gfx::PointF& TouchSelectionController::GetStartPosition() const { | 442 const gfx::PointF& TouchSelectionController::GetStartPosition() const { |
443 bool top_handle = | |
444 start_orientation_ == TouchHandleOrientation::LEFT_INVERTED || | |
jdduke (slow)
2015/03/19 18:56:39
Why does the position change depending on the orie
jdduke (slow)
2015/03/23 21:05:31
Nevermind, it sounds like if we mirror the handle
AviD
2015/03/26 14:53:11
Right, it is to position the handles above the tex
| |
445 start_orientation_ == TouchHandleOrientation::LEFT_FLIPPED_INVERTED; | |
446 if (top_handle) | |
447 return start_.edge_top(); | |
432 return start_.edge_bottom(); | 448 return start_.edge_bottom(); |
433 } | 449 } |
434 | 450 |
435 const gfx::PointF& TouchSelectionController::GetEndPosition() const { | 451 const gfx::PointF& TouchSelectionController::GetEndPosition() const { |
452 bool top_handle = | |
453 end_orientation_ == TouchHandleOrientation::RIGHT_INVERTED || | |
454 end_orientation_ == TouchHandleOrientation::RIGHT_FLIPPED_INVERTED; | |
455 if (top_handle) | |
456 return end_.edge_top(); | |
436 return end_.edge_bottom(); | 457 return end_.edge_bottom(); |
437 } | 458 } |
438 | 459 |
460 void TouchSelectionController::SetInvertedOrientation() { | |
461 if (!start_selection_handle_ || !end_selection_handle_) | |
462 return; | |
463 | |
464 TouchHandleOrientation old_start_orientation = start_orientation_; | |
465 TouchHandleOrientation old_end_orientation = end_orientation_; | |
466 | |
467 gfx::RectF start_size = start_selection_handle_->GetHandleBounds(); | |
468 gfx::RectF end_size = end_selection_handle_->GetHandleBounds(); | |
469 | |
470 int start_handle_state = 0; | |
471 int end_handle_state = 0; | |
472 | |
473 if (start_.edge_bottom().y() + start_size.height() > | |
474 viewport_rect_.height()) { | |
475 start_orientation_ = TouchHandleOrientation::LEFT_INVERTED; | |
476 start_handle_state++; | |
477 } | |
478 | |
479 if (end_.edge_bottom().y() + end_size.height() > viewport_rect_.height()) { | |
480 end_orientation_ = TouchHandleOrientation::RIGHT_INVERTED; | |
481 end_handle_state++; | |
482 } | |
483 | |
484 if (start_.edge_top().x() - end_size.width() < viewport_rect_.x()) { | |
485 start_orientation_ = TouchHandleOrientation::LEFT_FLIPPED; | |
486 start_handle_state++; | |
487 } | |
488 | |
489 if (end_.edge_top().x() + start_size.width() > viewport_rect_.width()) { | |
490 end_orientation_ = TouchHandleOrientation::RIGHT_FLIPPED; | |
491 end_handle_state++; | |
492 } | |
493 | |
494 if (start_handle_state == 2) { | |
jdduke (slow)
2015/03/19 18:56:39
Flipped vs inverted is confusing.
What if, instea
jdduke (slow)
2015/03/23 21:05:31
I wonder if it's worth having the TouchHandle be r
AviD
2015/03/26 14:53:10
I will try this approach with the next patch.
| |
495 start_orientation_ = TouchHandleOrientation::LEFT_FLIPPED_INVERTED; | |
496 } else if (start_handle_state == 0) { | |
497 start_orientation_ = old_start_orientation; | |
498 } | |
499 | |
500 if (end_handle_state == 2) { | |
501 end_orientation_ = TouchHandleOrientation::RIGHT_FLIPPED_INVERTED; | |
502 } else if (end_handle_state == 0) { | |
503 end_orientation_ = old_end_orientation; | |
504 } | |
505 } | |
506 | |
439 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { | 507 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { |
440 return ComputeLineOffsetFromBottom(start_); | 508 return ComputeLineOffsetFromBottom(start_); |
441 } | 509 } |
442 | 510 |
443 gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const { | 511 gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const { |
444 return ComputeLineOffsetFromBottom(end_); | 512 return ComputeLineOffsetFromBottom(end_); |
445 } | 513 } |
446 | 514 |
447 bool TouchSelectionController::GetStartVisible() const { | 515 bool TouchSelectionController::GetStartVisible() const { |
448 return start_.visible() && !temporarily_hidden_; | 516 return start_.visible() && !temporarily_hidden_; |
(...skipping 19 matching lines...) Expand all Loading... | |
468 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 536 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
469 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 537 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
470 duration, | 538 duration, |
471 base::TimeDelta::FromMilliseconds(500), | 539 base::TimeDelta::FromMilliseconds(500), |
472 base::TimeDelta::FromSeconds(60), | 540 base::TimeDelta::FromSeconds(60), |
473 60); | 541 60); |
474 } | 542 } |
475 } | 543 } |
476 | 544 |
477 } // namespace ui | 545 } // namespace ui |
OLD | NEW |