| 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 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 TouchSelectionController::TouchSelectionController( | 43 TouchSelectionController::TouchSelectionController( |
| 44 TouchSelectionControllerClient* client, | 44 TouchSelectionControllerClient* client, |
| 45 base::TimeDelta tap_timeout, | 45 base::TimeDelta tap_timeout, |
| 46 float tap_slop, | 46 float tap_slop, |
| 47 bool show_on_tap_for_empty_editable) | 47 bool show_on_tap_for_empty_editable) |
| 48 : client_(client), | 48 : client_(client), |
| 49 tap_timeout_(tap_timeout), | 49 tap_timeout_(tap_timeout), |
| 50 tap_slop_(tap_slop), | 50 tap_slop_squared_(static_cast<double>(tap_slop) * tap_slop), |
| 51 show_on_tap_for_empty_editable_(show_on_tap_for_empty_editable), | 51 show_on_tap_for_empty_editable_(show_on_tap_for_empty_editable), |
| 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 longpress_drag_selector_(this), |
| 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 |
| 69 void TouchSelectionController::OnSelectionBoundsChanged( | 70 void TouchSelectionController::OnSelectionBoundsChanged( |
| 70 const SelectionBound& start, | 71 const SelectionBound& start, |
| 71 const SelectionBound& end) { | 72 const SelectionBound& end) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 85 | 86 |
| 86 // Ensure that |response_pending_input_event_| is cleared after the method | 87 // Ensure that |response_pending_input_event_| is cleared after the method |
| 87 // completes, while also making its current value available for the duration | 88 // completes, while also making its current value available for the duration |
| 88 // of the call. | 89 // of the call. |
| 89 InputEventType causal_input_event = response_pending_input_event_; | 90 InputEventType causal_input_event = response_pending_input_event_; |
| 90 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; | 91 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; |
| 91 base::AutoReset<InputEventType> auto_reset_response_pending_input_event( | 92 base::AutoReset<InputEventType> auto_reset_response_pending_input_event( |
| 92 &response_pending_input_event_, causal_input_event); | 93 &response_pending_input_event_, causal_input_event); |
| 93 | 94 |
| 94 const bool is_selection_dragging = | 95 const bool is_selection_dragging = |
| 95 is_selection_active_ && (start_selection_handle_->is_dragging() || | 96 is_selection_active_ && (start_selection_handle_->IsActive() || |
| 96 end_selection_handle_->is_dragging()); | 97 end_selection_handle_->IsActive()); |
| 97 | 98 |
| 98 // It's possible that the bounds temporarily overlap while a selection handle | 99 // It's possible that the bounds temporarily overlap while a selection handle |
| 99 // is being dragged, incorrectly reporting a CENTER orientation. | 100 // is being dragged, incorrectly reporting a CENTER orientation. |
| 100 // TODO(jdduke): This safeguard is racy, as it's possible the delayed response | 101 // TODO(jdduke): This safeguard is racy, as it's possible the delayed response |
| 101 // from handle positioning occurs *after* the handle dragging has ceased. | 102 // from handle positioning occurs *after* the handle dragging has ceased. |
| 102 // Instead, prevent selection -> insertion transitions without an intervening | 103 // Instead, prevent selection -> insertion transitions without an intervening |
| 103 // action or selection clearing of some sort, crbug.com/392696. | 104 // action or selection clearing of some sort, crbug.com/392696. |
| 104 if (is_selection_dragging) { | 105 if (is_selection_dragging) { |
| 105 if (start_orientation_ == TouchHandleOrientation::CENTER) | 106 if (start_orientation_ == TouchHandleOrientation::CENTER) |
| 106 start_orientation_ = start_selection_handle_->orientation(); | 107 start_orientation_ = start_selection_handle_->orientation(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 119 if (start_orientation_ == TouchHandleOrientation::CENTER && | 120 if (start_orientation_ == TouchHandleOrientation::CENTER && |
| 120 selection_editable_) { | 121 selection_editable_) { |
| 121 OnInsertionChanged(); | 122 OnInsertionChanged(); |
| 122 return; | 123 return; |
| 123 } | 124 } |
| 124 | 125 |
| 125 HideAndDisallowShowingAutomatically(); | 126 HideAndDisallowShowingAutomatically(); |
| 126 } | 127 } |
| 127 | 128 |
| 128 bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) { | 129 bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) { |
| 130 if (longpress_drag_selector_.WillHandleTouchEvent(event)) |
| 131 return true; |
| 132 |
| 129 if (is_insertion_active_) { | 133 if (is_insertion_active_) { |
| 130 DCHECK(insertion_handle_); | 134 DCHECK(insertion_handle_); |
| 131 return insertion_handle_->WillHandleTouchEvent(event); | 135 return insertion_handle_->WillHandleTouchEvent(event); |
| 132 } | 136 } |
| 133 | 137 |
| 134 if (is_selection_active_) { | 138 if (is_selection_active_) { |
| 135 DCHECK(start_selection_handle_); | 139 DCHECK(start_selection_handle_); |
| 136 DCHECK(end_selection_handle_); | 140 DCHECK(end_selection_handle_); |
| 137 if (start_selection_handle_->is_dragging()) | 141 if (start_selection_handle_->IsActive()) |
| 138 return start_selection_handle_->WillHandleTouchEvent(event); | 142 return start_selection_handle_->WillHandleTouchEvent(event); |
| 139 | 143 |
| 140 if (end_selection_handle_->is_dragging()) | 144 if (end_selection_handle_->IsActive()) |
| 141 return end_selection_handle_->WillHandleTouchEvent(event); | 145 return end_selection_handle_->WillHandleTouchEvent(event); |
| 142 | 146 |
| 143 const gfx::PointF event_pos(event.GetX(), event.GetY()); | 147 const gfx::PointF event_pos(event.GetX(), event.GetY()); |
| 144 if ((event_pos - GetStartPosition()).LengthSquared() <= | 148 if ((event_pos - GetStartPosition()).LengthSquared() <= |
| 145 (event_pos - GetEndPosition()).LengthSquared()) | 149 (event_pos - GetEndPosition()).LengthSquared()) |
| 146 return start_selection_handle_->WillHandleTouchEvent(event); | 150 return start_selection_handle_->WillHandleTouchEvent(event); |
| 147 else | 151 else |
| 148 return end_selection_handle_->WillHandleTouchEvent(event); | 152 return end_selection_handle_->WillHandleTouchEvent(event); |
| 149 } | 153 } |
| 150 | 154 |
| 151 return false; | 155 return false; |
| 152 } | 156 } |
| 153 | 157 |
| 154 void TouchSelectionController::OnLongPressEvent() { | 158 void TouchSelectionController::OnLongPressEvent(base::TimeTicks event_time, |
| 159 const gfx::PointF& position) { |
| 160 longpress_drag_selector_.OnLongPressEvent(event_time, position); |
| 155 response_pending_input_event_ = LONG_PRESS; | 161 response_pending_input_event_ = LONG_PRESS; |
| 156 ShowSelectionHandlesAutomatically(); | 162 ShowSelectionHandlesAutomatically(); |
| 157 ShowInsertionHandleAutomatically(); | 163 ShowInsertionHandleAutomatically(); |
| 158 ResetCachedValuesIfInactive(); | 164 ResetCachedValuesIfInactive(); |
| 159 } | 165 } |
| 160 | 166 |
| 161 void TouchSelectionController::AllowShowingFromCurrentSelection() { | 167 void TouchSelectionController::AllowShowingFromCurrentSelection() { |
| 162 if (is_selection_active_ || is_insertion_active_) | 168 if (is_selection_active_ || is_insertion_active_) |
| 163 return; | 169 return; |
| 164 | 170 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 184 DeactivateInsertion(); | 190 DeactivateInsertion(); |
| 185 DeactivateSelection(); | 191 DeactivateSelection(); |
| 186 activate_insertion_automatically_ = false; | 192 activate_insertion_automatically_ = false; |
| 187 activate_selection_automatically_ = false; | 193 activate_selection_automatically_ = false; |
| 188 } | 194 } |
| 189 | 195 |
| 190 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { | 196 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { |
| 191 if (temporarily_hidden_ == hidden) | 197 if (temporarily_hidden_ == hidden) |
| 192 return; | 198 return; |
| 193 temporarily_hidden_ = hidden; | 199 temporarily_hidden_ = hidden; |
| 194 | 200 RefreshHandleVisibility(); |
| 195 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true); | |
| 196 if (is_selection_active_) { | |
| 197 start_selection_handle_->SetVisible(GetStartVisible(), animation_style); | |
| 198 end_selection_handle_->SetVisible(GetEndVisible(), animation_style); | |
| 199 } | |
| 200 if (is_insertion_active_) | |
| 201 insertion_handle_->SetVisible(GetStartVisible(), animation_style); | |
| 202 } | 201 } |
| 203 | 202 |
| 204 void TouchSelectionController::OnSelectionEditable(bool editable) { | 203 void TouchSelectionController::OnSelectionEditable(bool editable) { |
| 205 if (selection_editable_ == editable) | 204 if (selection_editable_ == editable) |
| 206 return; | 205 return; |
| 207 selection_editable_ = editable; | 206 selection_editable_ = editable; |
| 208 ResetCachedValuesIfInactive(); | 207 ResetCachedValuesIfInactive(); |
| 209 if (!selection_editable_) | 208 if (!selection_editable_) |
| 210 DeactivateInsertion(); | 209 DeactivateInsertion(); |
| 211 } | 210 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 261 } |
| 263 | 262 |
| 264 const gfx::PointF& TouchSelectionController::GetStartPosition() const { | 263 const gfx::PointF& TouchSelectionController::GetStartPosition() const { |
| 265 return start_.edge_bottom(); | 264 return start_.edge_bottom(); |
| 266 } | 265 } |
| 267 | 266 |
| 268 const gfx::PointF& TouchSelectionController::GetEndPosition() const { | 267 const gfx::PointF& TouchSelectionController::GetEndPosition() const { |
| 269 return end_.edge_bottom(); | 268 return end_.edge_bottom(); |
| 270 } | 269 } |
| 271 | 270 |
| 272 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { | 271 void TouchSelectionController::OnDragBegin( |
| 273 if (&handle == insertion_handle_.get()) { | 272 const TouchSelectionDraggable& draggable, |
| 273 const gfx::PointF& drag_position) { |
| 274 if (&draggable == insertion_handle_.get()) { |
| 274 client_->OnSelectionEvent(INSERTION_DRAG_STARTED); | 275 client_->OnSelectionEvent(INSERTION_DRAG_STARTED); |
| 276 drag_line_offset_ = GetStartLineOffset(); |
| 275 return; | 277 return; |
| 276 } | 278 } |
| 277 | 279 |
| 278 gfx::PointF base, extent; | 280 DCHECK(is_selection_active_); |
| 279 if (&handle == start_selection_handle_.get()) { | 281 |
| 280 base = end_selection_handle_->position() + GetEndLineOffset(); | 282 bool extend_selection_start = false; |
| 281 extent = start_selection_handle_->position() + GetStartLineOffset(); | 283 if (&draggable == start_selection_handle_.get()) { |
| 284 extend_selection_start = true; |
| 285 } else if (&draggable == end_selection_handle_.get()) { |
| 286 extend_selection_start = false; |
| 282 } else { | 287 } else { |
| 283 base = start_selection_handle_->position() + GetStartLineOffset(); | 288 DCHECK_EQ(&draggable, &longpress_drag_selector_); |
| 284 extent = end_selection_handle_->position() + GetEndLineOffset(); | 289 extend_selection_start = |
| 290 (drag_position - GetStartPosition()).LengthSquared() < |
| 291 (drag_position - GetEndPosition()).LengthSquared(); |
| 285 } | 292 } |
| 293 |
| 294 gfx::PointF base = GetStartPosition() + GetStartLineOffset(); |
| 295 gfx::PointF extent = GetEndPosition() + GetEndLineOffset(); |
| 296 if (extend_selection_start) { |
| 297 std::swap(base, extent); |
| 298 drag_line_offset_ = GetStartLineOffset(); |
| 299 } else { |
| 300 drag_line_offset_ = GetEndLineOffset(); |
| 301 } |
| 302 |
| 286 selection_handle_dragged_ = true; | 303 selection_handle_dragged_ = true; |
| 287 | 304 |
| 288 // When moving the handle we want to move only the extent point. Before doing | 305 // When moving the handle we want to move only the extent point. Before doing |
| 289 // so we must make sure that the base point is set correctly. | 306 // so we must make sure that the base point is set correctly. |
| 290 client_->SelectBetweenCoordinates(base, extent); | 307 client_->SelectBetweenCoordinates(base, extent); |
| 291 client_->OnSelectionEvent(SELECTION_DRAG_STARTED); | 308 client_->OnSelectionEvent(SELECTION_DRAG_STARTED); |
| 292 } | 309 } |
| 293 | 310 |
| 294 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, | 311 void TouchSelectionController::OnDragUpdate( |
| 295 const gfx::PointF& position) { | 312 const TouchSelectionDraggable& draggable, |
| 313 const gfx::PointF& drag_position) { |
| 296 // As the position corresponds to the bottom left point of the selection | 314 // As the position corresponds to the bottom left point of the selection |
| 297 // bound, offset it by half the corresponding line height. | 315 // bound, offset it by half the corresponding line height. |
| 298 gfx::Vector2dF line_offset = &handle == start_selection_handle_.get() | 316 gfx::PointF line_position = drag_position + drag_line_offset_; |
| 299 ? GetStartLineOffset() | 317 if (&draggable == insertion_handle_.get()) { |
| 300 : GetEndLineOffset(); | |
| 301 gfx::PointF line_position = position + line_offset; | |
| 302 if (&handle == insertion_handle_.get()) { | |
| 303 client_->MoveCaret(line_position); | 318 client_->MoveCaret(line_position); |
| 304 } else { | 319 } else { |
| 305 client_->MoveRangeSelectionExtent(line_position); | 320 client_->MoveRangeSelectionExtent(line_position); |
| 306 } | 321 } |
| 307 } | 322 } |
| 308 | 323 |
| 309 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) { | 324 void TouchSelectionController::OnDragEnd( |
| 310 if (&handle == insertion_handle_.get()) | 325 const TouchSelectionDraggable& draggable) { |
| 326 if (&draggable == insertion_handle_.get()) |
| 311 client_->OnSelectionEvent(INSERTION_DRAG_STOPPED); | 327 client_->OnSelectionEvent(INSERTION_DRAG_STOPPED); |
| 312 else | 328 else |
| 313 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED); | 329 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED); |
| 314 } | 330 } |
| 315 | 331 |
| 332 bool TouchSelectionController::IsWithinTapSlop( |
| 333 const gfx::Vector2dF& delta) const { |
| 334 return delta.LengthSquared() < tap_slop_squared_; |
| 335 } |
| 336 |
| 316 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { | 337 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { |
| 317 if (insertion_handle_ && &handle == insertion_handle_.get()) | 338 if (insertion_handle_ && &handle == insertion_handle_.get()) |
| 318 client_->OnSelectionEvent(INSERTION_TAPPED); | 339 client_->OnSelectionEvent(INSERTION_TAPPED); |
| 319 } | 340 } |
| 320 | 341 |
| 321 void TouchSelectionController::SetNeedsAnimate() { | 342 void TouchSelectionController::SetNeedsAnimate() { |
| 322 client_->SetNeedsAnimate(); | 343 client_->SetNeedsAnimate(); |
| 323 } | 344 } |
| 324 | 345 |
| 325 scoped_ptr<TouchHandleDrawable> TouchSelectionController::CreateDrawable() { | 346 scoped_ptr<TouchHandleDrawable> TouchSelectionController::CreateDrawable() { |
| 326 return client_->CreateDrawable(); | 347 return client_->CreateDrawable(); |
| 327 } | 348 } |
| 328 | 349 |
| 329 base::TimeDelta TouchSelectionController::GetTapTimeout() const { | 350 base::TimeDelta TouchSelectionController::GetTapTimeout() const { |
| 330 return tap_timeout_; | 351 return tap_timeout_; |
| 331 } | 352 } |
| 332 | 353 |
| 333 float TouchSelectionController::GetTapSlop() const { | 354 void TouchSelectionController::OnLongPressDragActiveStateChanged() { |
| 334 return tap_slop_; | 355 // The handles should remain hidden for the duration of a longpress drag, |
| 356 // including the time between a longpress and the start of drag motion. |
| 357 RefreshHandleVisibility(); |
| 358 } |
| 359 |
| 360 gfx::PointF TouchSelectionController::GetSelectionStart() const { |
| 361 return GetStartPosition(); |
| 362 } |
| 363 |
| 364 gfx::PointF TouchSelectionController::GetSelectionEnd() const { |
| 365 return GetEndPosition(); |
| 335 } | 366 } |
| 336 | 367 |
| 337 void TouchSelectionController::ShowInsertionHandleAutomatically() { | 368 void TouchSelectionController::ShowInsertionHandleAutomatically() { |
| 338 if (activate_insertion_automatically_) | 369 if (activate_insertion_automatically_) |
| 339 return; | 370 return; |
| 340 activate_insertion_automatically_ = true; | 371 activate_insertion_automatically_ = true; |
| 341 ResetCachedValuesIfInactive(); | 372 ResetCachedValuesIfInactive(); |
| 342 } | 373 } |
| 343 | 374 |
| 344 void TouchSelectionController::ShowSelectionHandlesAutomatically() { | 375 void TouchSelectionController::ShowSelectionHandlesAutomatically() { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 // intervening SELECTION_CLEARED update to avoid unnecessary state changes. | 468 // intervening SELECTION_CLEARED update to avoid unnecessary state changes. |
| 438 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) { | 469 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) { |
| 439 if (is_selection_active_) { | 470 if (is_selection_active_) { |
| 440 // The active selection session finishes with the start of the new one. | 471 // The active selection session finishes with the start of the new one. |
| 441 LogSelectionEnd(); | 472 LogSelectionEnd(); |
| 442 } | 473 } |
| 443 is_selection_active_ = true; | 474 is_selection_active_ = true; |
| 444 selection_handle_dragged_ = false; | 475 selection_handle_dragged_ = false; |
| 445 selection_start_time_ = base::TimeTicks::Now(); | 476 selection_start_time_ = base::TimeTicks::Now(); |
| 446 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; | 477 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; |
| 478 longpress_drag_selector_.OnSelectionActivated(); |
| 447 client_->OnSelectionEvent(SELECTION_SHOWN); | 479 client_->OnSelectionEvent(SELECTION_SHOWN); |
| 448 } | 480 } |
| 449 } | 481 } |
| 450 | 482 |
| 451 void TouchSelectionController::DeactivateSelection() { | 483 void TouchSelectionController::DeactivateSelection() { |
| 452 if (!is_selection_active_) | 484 if (!is_selection_active_) |
| 453 return; | 485 return; |
| 454 DCHECK(start_selection_handle_); | 486 DCHECK(start_selection_handle_); |
| 455 DCHECK(end_selection_handle_); | 487 DCHECK(end_selection_handle_); |
| 456 LogSelectionEnd(); | 488 LogSelectionEnd(); |
| 489 longpress_drag_selector_.OnSelectionDeactivated(); |
| 457 start_selection_handle_->SetEnabled(false); | 490 start_selection_handle_->SetEnabled(false); |
| 458 end_selection_handle_->SetEnabled(false); | 491 end_selection_handle_->SetEnabled(false); |
| 459 is_selection_active_ = false; | 492 is_selection_active_ = false; |
| 460 client_->OnSelectionEvent(SELECTION_CLEARED); | 493 client_->OnSelectionEvent(SELECTION_CLEARED); |
| 461 } | 494 } |
| 462 | 495 |
| 463 void TouchSelectionController::ResetCachedValuesIfInactive() { | 496 void TouchSelectionController::ResetCachedValuesIfInactive() { |
| 464 if (is_selection_active_ || is_insertion_active_) | 497 if (is_selection_active_ || is_insertion_active_) |
| 465 return; | 498 return; |
| 466 start_ = SelectionBound(); | 499 start_ = SelectionBound(); |
| 467 end_ = SelectionBound(); | 500 end_ = SelectionBound(); |
| 468 start_orientation_ = TouchHandleOrientation::UNDEFINED; | 501 start_orientation_ = TouchHandleOrientation::UNDEFINED; |
| 469 end_orientation_ = TouchHandleOrientation::UNDEFINED; | 502 end_orientation_ = TouchHandleOrientation::UNDEFINED; |
| 470 } | 503 } |
| 471 | 504 |
| 505 void TouchSelectionController::RefreshHandleVisibility() { |
| 506 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true); |
| 507 if (is_selection_active_) { |
| 508 start_selection_handle_->SetVisible(GetStartVisible(), animation_style); |
| 509 end_selection_handle_->SetVisible(GetEndVisible(), animation_style); |
| 510 } |
| 511 if (is_insertion_active_) |
| 512 insertion_handle_->SetVisible(GetStartVisible(), animation_style); |
| 513 } |
| 514 |
| 472 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { | 515 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { |
| 473 return ComputeLineOffsetFromBottom(start_); | 516 return ComputeLineOffsetFromBottom(start_); |
| 474 } | 517 } |
| 475 | 518 |
| 476 gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const { | 519 gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const { |
| 477 return ComputeLineOffsetFromBottom(end_); | 520 return ComputeLineOffsetFromBottom(end_); |
| 478 } | 521 } |
| 479 | 522 |
| 480 bool TouchSelectionController::GetStartVisible() const { | 523 bool TouchSelectionController::GetStartVisible() const { |
| 481 return start_.visible() && !temporarily_hidden_; | 524 if (!start_.visible()) |
| 525 return false; |
| 526 |
| 527 return !temporarily_hidden_ && !longpress_drag_selector_.IsActive(); |
| 482 } | 528 } |
| 483 | 529 |
| 484 bool TouchSelectionController::GetEndVisible() const { | 530 bool TouchSelectionController::GetEndVisible() const { |
| 485 return end_.visible() && !temporarily_hidden_; | 531 if (!end_.visible()) |
| 532 return false; |
| 533 |
| 534 return !temporarily_hidden_ && !longpress_drag_selector_.IsActive(); |
| 486 } | 535 } |
| 487 | 536 |
| 488 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( | 537 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( |
| 489 bool was_active) const { | 538 bool was_active) const { |
| 490 return was_active && client_->SupportsAnimation() | 539 return was_active && client_->SupportsAnimation() |
| 491 ? TouchHandle::ANIMATION_SMOOTH | 540 ? TouchHandle::ANIMATION_SMOOTH |
| 492 : TouchHandle::ANIMATION_NONE; | 541 : TouchHandle::ANIMATION_NONE; |
| 493 } | 542 } |
| 494 | 543 |
| 495 void TouchSelectionController::LogSelectionEnd() { | 544 void TouchSelectionController::LogSelectionEnd() { |
| 496 // TODO(mfomitchev): Once we are able to tell the difference between | 545 // TODO(mfomitchev): Once we are able to tell the difference between |
| 497 // 'successful' and 'unsuccessful' selections - log | 546 // 'successful' and 'unsuccessful' selections - log |
| 498 // Event.TouchSelection.Duration instead and get rid of | 547 // Event.TouchSelection.Duration instead and get rid of |
| 499 // Event.TouchSelectionD.WasDraggeduration. | 548 // Event.TouchSelectionD.WasDraggeduration. |
| 500 if (selection_handle_dragged_) { | 549 if (selection_handle_dragged_) { |
| 501 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 550 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
| 502 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 551 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
| 503 duration, | 552 duration, |
| 504 base::TimeDelta::FromMilliseconds(500), | 553 base::TimeDelta::FromMilliseconds(500), |
| 505 base::TimeDelta::FromSeconds(60), | 554 base::TimeDelta::FromSeconds(60), |
| 506 60); | 555 60); |
| 507 } | 556 } |
| 508 } | 557 } |
| 509 | 558 |
| 510 } // namespace ui | 559 } // namespace ui |
| OLD | NEW |