| 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 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
| 11 | 11 |
| 12 namespace ui { | 12 namespace ui { |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 gfx::Vector2dF ComputeLineOffsetFromBottom(const SelectionBound& bound) { | 15 gfx::Vector2dF ComputeLineOffsetFromBottom(const gfx::SelectionBound& bound) { |
| 16 gfx::Vector2dF line_offset = | 16 gfx::Vector2dF line_offset = |
| 17 gfx::ScaleVector2d(bound.edge_top() - bound.edge_bottom(), 0.5f); | 17 gfx::ScaleVector2d(bound.edge_top() - bound.edge_bottom(), 0.5f); |
| 18 // An offset of 8 DIPs is sufficient for most line sizes. For small lines, | 18 // An offset of 8 DIPs is sufficient for most line sizes. For small lines, |
| 19 // using half the line height avoids synthesizing a point on a line above | 19 // using half the line height avoids synthesizing a point on a line above |
| 20 // (or below) the intended line. | 20 // (or below) the intended line. |
| 21 const gfx::Vector2dF kMaxLineOffset(8.f, 8.f); | 21 const gfx::Vector2dF kMaxLineOffset(8.f, 8.f); |
| 22 line_offset.SetToMin(kMaxLineOffset); | 22 line_offset.SetToMin(kMaxLineOffset); |
| 23 line_offset.SetToMax(-kMaxLineOffset); | 23 line_offset.SetToMax(-kMaxLineOffset); |
| 24 return line_offset; | 24 return line_offset; |
| 25 } | 25 } |
| 26 | 26 |
| 27 TouchHandleOrientation ToTouchHandleOrientation(SelectionBound::Type type) { | 27 TouchHandleOrientation ToTouchHandleOrientation( |
| 28 gfx::SelectionBound::Type type) { |
| 28 switch (type) { | 29 switch (type) { |
| 29 case SelectionBound::LEFT: | 30 case gfx::SelectionBound::LEFT: |
| 30 return TouchHandleOrientation::LEFT; | 31 return TouchHandleOrientation::LEFT; |
| 31 case SelectionBound::RIGHT: | 32 case gfx::SelectionBound::RIGHT: |
| 32 return TouchHandleOrientation::RIGHT; | 33 return TouchHandleOrientation::RIGHT; |
| 33 case SelectionBound::CENTER: | 34 case gfx::SelectionBound::CENTER: |
| 34 return TouchHandleOrientation::CENTER; | 35 return TouchHandleOrientation::CENTER; |
| 35 case SelectionBound::EMPTY: | 36 case gfx::SelectionBound::EMPTY: |
| 36 return TouchHandleOrientation::UNDEFINED; | 37 return TouchHandleOrientation::UNDEFINED; |
| 37 } | 38 } |
| 38 NOTREACHED() << "Invalid selection bound type: " << type; | 39 NOTREACHED() << "Invalid selection bound type: " << type; |
| 39 return TouchHandleOrientation::UNDEFINED; | 40 return TouchHandleOrientation::UNDEFINED; |
| 40 } | 41 } |
| 41 | 42 |
| 42 } // namespace | 43 } // namespace |
| 43 | 44 |
| 44 TouchSelectionController::Config::Config() | 45 TouchSelectionController::Config::Config() |
| 45 : max_tap_duration(base::TimeDelta::FromMilliseconds(300)), | 46 : max_tap_duration(base::TimeDelta::FromMilliseconds(300)), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 69 anchor_drag_to_selection_start_(false), | 70 anchor_drag_to_selection_start_(false), |
| 70 longpress_drag_selector_(this), | 71 longpress_drag_selector_(this), |
| 71 selection_handle_dragged_(false) { | 72 selection_handle_dragged_(false) { |
| 72 DCHECK(client_); | 73 DCHECK(client_); |
| 73 } | 74 } |
| 74 | 75 |
| 75 TouchSelectionController::~TouchSelectionController() { | 76 TouchSelectionController::~TouchSelectionController() { |
| 76 } | 77 } |
| 77 | 78 |
| 78 void TouchSelectionController::OnSelectionBoundsChanged( | 79 void TouchSelectionController::OnSelectionBoundsChanged( |
| 79 const SelectionBound& start, | 80 const gfx::SelectionBound& start, |
| 80 const SelectionBound& end) { | 81 const gfx::SelectionBound& end) { |
| 81 if (!force_next_update_ && start == start_ && end_ == end) | 82 if (!force_next_update_ && start == start_ && end_ == end) |
| 82 return; | 83 return; |
| 83 | 84 |
| 84 // Notify if selection bounds have just been established or dissolved. | 85 // Notify if selection bounds have just been established or dissolved. |
| 85 if (start.type() != SelectionBound::EMPTY && | 86 if (start.type() != gfx::SelectionBound::EMPTY && |
| 86 start_.type() == SelectionBound::EMPTY) { | 87 start_.type() == gfx::SelectionBound::EMPTY) { |
| 87 client_->OnSelectionEvent(SELECTION_ESTABLISHED); | 88 client_->OnSelectionEvent(SELECTION_ESTABLISHED); |
| 88 } else if (start.type() == SelectionBound::EMPTY && | 89 } else if (start.type() == gfx::SelectionBound::EMPTY && |
| 89 start_.type() != SelectionBound::EMPTY) { | 90 start_.type() != gfx::SelectionBound::EMPTY) { |
| 90 client_->OnSelectionEvent(SELECTION_DISSOLVED); | 91 client_->OnSelectionEvent(SELECTION_DISSOLVED); |
| 91 } | 92 } |
| 92 | 93 |
| 93 // Swap the Handles when the start and end selection points cross each other. | 94 // Swap the Handles when the start and end selection points cross each other. |
| 94 if (active_status_ == SELECTION_ACTIVE) { | 95 if (active_status_ == SELECTION_ACTIVE) { |
| 95 if ((start_selection_handle_->IsActive() && | 96 if ((start_selection_handle_->IsActive() && |
| 96 end_.edge_bottom() == start.edge_bottom()) || | 97 end_.edge_bottom() == start.edge_bottom()) || |
| 97 (end_selection_handle_->IsActive() && | 98 (end_selection_handle_->IsActive() && |
| 98 end.edge_bottom() == start_.edge_bottom())) { | 99 end.edge_bottom() == start_.edge_bottom())) { |
| 99 start_selection_handle_.swap(end_selection_handle_); | 100 start_selection_handle_.swap(end_selection_handle_); |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 end_selection_handle_->SetEnabled(false); | 619 end_selection_handle_->SetEnabled(false); |
| 619 active_status_ = INACTIVE; | 620 active_status_ = INACTIVE; |
| 620 client_->OnSelectionEvent(SELECTION_HANDLES_CLEARED); | 621 client_->OnSelectionEvent(SELECTION_HANDLES_CLEARED); |
| 621 } | 622 } |
| 622 | 623 |
| 623 void TouchSelectionController::ForceNextUpdateIfInactive() { | 624 void TouchSelectionController::ForceNextUpdateIfInactive() { |
| 624 // Only force the update if the reported selection is non-empty but still | 625 // Only force the update if the reported selection is non-empty but still |
| 625 // considered "inactive", i.e., it wasn't preceded by a user gesture or | 626 // considered "inactive", i.e., it wasn't preceded by a user gesture or |
| 626 // the handles have since been explicitly hidden. | 627 // the handles have since been explicitly hidden. |
| 627 if (active_status_ == INACTIVE && | 628 if (active_status_ == INACTIVE && |
| 628 start_.type() != SelectionBound::EMPTY && | 629 start_.type() != gfx::SelectionBound::EMPTY && |
| 629 end_.type() != SelectionBound::EMPTY) { | 630 end_.type() != gfx::SelectionBound::EMPTY) { |
| 630 force_next_update_ = true; | 631 force_next_update_ = true; |
| 631 } | 632 } |
| 632 } | 633 } |
| 633 | 634 |
| 634 void TouchSelectionController::UpdateHandleLayoutIfNecessary() { | 635 void TouchSelectionController::UpdateHandleLayoutIfNecessary() { |
| 635 if (active_status_ == INSERTION_ACTIVE) { | 636 if (active_status_ == INSERTION_ACTIVE) { |
| 636 DCHECK(insertion_handle_); | 637 DCHECK(insertion_handle_); |
| 637 insertion_handle_->UpdateHandleLayout(); | 638 insertion_handle_->UpdateHandleLayout(); |
| 638 } else if (active_status_ == SELECTION_ACTIVE) { | 639 } else if (active_status_ == SELECTION_ACTIVE) { |
| 639 DCHECK(start_selection_handle_); | 640 DCHECK(start_selection_handle_); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 695 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
| 695 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 696 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
| 696 duration, | 697 duration, |
| 697 base::TimeDelta::FromMilliseconds(500), | 698 base::TimeDelta::FromMilliseconds(500), |
| 698 base::TimeDelta::FromSeconds(60), | 699 base::TimeDelta::FromSeconds(60), |
| 699 60); | 700 60); |
| 700 } | 701 } |
| 701 } | 702 } |
| 702 | 703 |
| 703 } // namespace ui | 704 } // namespace ui |
| OLD | NEW |