Chromium Code Reviews| Index: ui/touch_selection/touch_selection_controller.cc |
| diff --git a/ui/touch_selection/touch_selection_controller.cc b/ui/touch_selection/touch_selection_controller.cc |
| index 3d52b4c3e423f276b65541c1491b0e260411fb86..5923d953cdd0c5dd3440b88b75a8794773fd9cfe 100644 |
| --- a/ui/touch_selection/touch_selection_controller.cc |
| +++ b/ui/touch_selection/touch_selection_controller.cc |
| @@ -59,6 +59,7 @@ TouchSelectionController::TouchSelectionController( |
| selection_empty_(false), |
| selection_editable_(false), |
| temporarily_hidden_(false), |
| + longpress_drag_selector_(this, tap_slop), |
| selection_handle_dragged_(false) { |
| DCHECK(client_); |
| } |
| @@ -126,6 +127,9 @@ void TouchSelectionController::OnSelectionBoundsChanged( |
| } |
| bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) { |
| + if (longpress_drag_selector_.WillHandleTouchEvent(event)) |
| + return true; |
| + |
| if (is_insertion_active_) { |
| DCHECK(insertion_handle_); |
| return insertion_handle_->WillHandleTouchEvent(event); |
| @@ -151,7 +155,9 @@ bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) { |
| return false; |
| } |
| -void TouchSelectionController::OnLongPressEvent() { |
| +void TouchSelectionController::OnLongPressEvent(base::TimeTicks event_time, |
| + const gfx::PointF& position) { |
| + longpress_drag_selector_.OnLongPressEvent(event_time, position); |
| response_pending_input_event_ = LONG_PRESS; |
| ShowSelectionHandlesAutomatically(); |
| ShowInsertionHandleAutomatically(); |
| @@ -191,14 +197,7 @@ void TouchSelectionController::SetTemporarilyHidden(bool hidden) { |
| if (temporarily_hidden_ == hidden) |
| return; |
| temporarily_hidden_ = hidden; |
| - |
| - TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true); |
| - if (is_selection_active_) { |
| - start_selection_handle_->SetVisible(GetStartVisible(), animation_style); |
| - end_selection_handle_->SetVisible(GetEndVisible(), animation_style); |
| - } |
| - if (is_insertion_active_) |
| - insertion_handle_->SetVisible(GetStartVisible(), animation_style); |
| + OnHandleVisibilityOverrideMaybeChanged(); |
| } |
| void TouchSelectionController::OnSelectionEditable(bool editable) { |
| @@ -269,19 +268,35 @@ const gfx::PointF& TouchSelectionController::GetEndPosition() const { |
| return end_.edge_bottom(); |
| } |
| -void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { |
| - if (&handle == insertion_handle_.get()) { |
| +void TouchSelectionController::OnDragBegin( |
| + const TouchSelectionDraggable& draggable, |
| + const gfx::PointF& drag_position) { |
| + OnHandleVisibilityOverrideMaybeChanged(); |
| + |
| + if (&draggable == insertion_handle_.get()) { |
| client_->OnSelectionEvent(INSERTION_DRAG_STARTED); |
| + drag_line_offset_ = GetStartLineOffset(); |
| return; |
| } |
| - gfx::PointF base, extent; |
| - if (&handle == start_selection_handle_.get()) { |
| - base = end_selection_handle_->position() + GetEndLineOffset(); |
| - extent = start_selection_handle_->position() + GetStartLineOffset(); |
| + DCHECK(is_selection_active_); |
| + |
| + gfx::PointF base = GetStartPosition() + GetStartLineOffset(); |
| + gfx::PointF extent = GetEndPosition() + GetEndLineOffset(); |
| + if (&draggable == start_selection_handle_.get()) { |
| + std::swap(base, extent); |
| + drag_line_offset_ = GetStartLineOffset(); |
| + } else if (&draggable == end_selection_handle_.get()) { |
| + drag_line_offset_ = GetEndLineOffset(); |
| } else { |
| - base = start_selection_handle_->position() + GetStartLineOffset(); |
| - extent = end_selection_handle_->position() + GetEndLineOffset(); |
| + DCHECK_EQ(&draggable, &longpress_drag_selector_); |
| + if ((drag_position - GetStartPosition()).LengthSquared() < |
|
mfomitchev
2015/04/23 21:05:53
Can we just pass an enum in OnDragBegin indicating
jdduke (slow)
2015/04/27 20:24:25
The problem is that the TouchHandle has no awarene
mfomitchev
2015/04/28 02:17:30
Yeah, I was implying we'd pass the type to the Tou
|
| + (drag_position - GetEndPosition()).LengthSquared()) { |
| + std::swap(base, extent); |
| + drag_line_offset_ = GetStartLineOffset(); |
| + } else { |
| + drag_line_offset_ = GetEndLineOffset(); |
| + } |
| } |
| selection_handle_dragged_ = true; |
| @@ -291,23 +306,23 @@ void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { |
| client_->OnSelectionEvent(SELECTION_DRAG_STARTED); |
| } |
| -void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, |
| - const gfx::PointF& position) { |
| +void TouchSelectionController::OnDragUpdate( |
| + const TouchSelectionDraggable& draggable, |
| + const gfx::PointF& drag_position) { |
| // As the position corresponds to the bottom left point of the selection |
| // bound, offset it by half the corresponding line height. |
| - gfx::Vector2dF line_offset = &handle == start_selection_handle_.get() |
| - ? GetStartLineOffset() |
| - : GetEndLineOffset(); |
| - gfx::PointF line_position = position + line_offset; |
| - if (&handle == insertion_handle_.get()) { |
| + gfx::PointF line_position = drag_position + drag_line_offset_; |
| + if (&draggable == insertion_handle_.get()) { |
| client_->MoveCaret(line_position); |
| } else { |
| client_->MoveRangeSelectionExtent(line_position); |
| } |
| } |
| -void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) { |
| - if (&handle == insertion_handle_.get()) |
| +void TouchSelectionController::OnDragEnd( |
| + const TouchSelectionDraggable& draggable) { |
| + OnHandleVisibilityOverrideMaybeChanged(); |
| + if (&draggable == insertion_handle_.get()) |
| client_->OnSelectionEvent(INSERTION_DRAG_STOPPED); |
| else |
| client_->OnSelectionEvent(SELECTION_DRAG_STOPPED); |
| @@ -444,6 +459,8 @@ void TouchSelectionController::ActivateSelection() { |
| selection_handle_dragged_ = false; |
| selection_start_time_ = base::TimeTicks::Now(); |
| response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; |
| + longpress_drag_selector_.OnSelectionActivated(GetStartPosition(), |
| + GetEndPosition()); |
| client_->OnSelectionEvent(SELECTION_SHOWN); |
| } |
| } |
| @@ -454,6 +471,7 @@ void TouchSelectionController::DeactivateSelection() { |
| DCHECK(start_selection_handle_); |
| DCHECK(end_selection_handle_); |
| LogSelectionEnd(); |
| + longpress_drag_selector_.OnSelectionDeactivated(); |
| start_selection_handle_->SetEnabled(false); |
| end_selection_handle_->SetEnabled(false); |
| is_selection_active_ = false; |
| @@ -469,6 +487,16 @@ void TouchSelectionController::ResetCachedValuesIfInactive() { |
| end_orientation_ = TouchHandleOrientation::UNDEFINED; |
| } |
| +void TouchSelectionController::OnHandleVisibilityOverrideMaybeChanged() { |
|
mfomitchev
2015/04/23 21:05:53
Can we call this something like UpdateHandleVisibi
jdduke (slow)
2015/04/27 20:24:25
Done.
|
| + TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true); |
| + if (is_selection_active_) { |
| + start_selection_handle_->SetVisible(GetStartVisible(), animation_style); |
| + end_selection_handle_->SetVisible(GetEndVisible(), animation_style); |
| + } |
| + if (is_insertion_active_) |
| + insertion_handle_->SetVisible(GetStartVisible(), animation_style); |
| +} |
| + |
| gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { |
| return ComputeLineOffsetFromBottom(start_); |
| } |
| @@ -478,11 +506,17 @@ gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const { |
| } |
| bool TouchSelectionController::GetStartVisible() const { |
| - return start_.visible() && !temporarily_hidden_; |
| + if (!start_.visible()) |
| + return false; |
| + |
| + return !temporarily_hidden_ && !longpress_drag_selector_.IsActive(); |
| } |
| bool TouchSelectionController::GetEndVisible() const { |
| - return end_.visible() && !temporarily_hidden_; |
| + if (!end_.visible()) |
| + return false; |
| + |
| + return !temporarily_hidden_ && !longpress_drag_selector_.IsActive(); |
| } |
| TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( |