| 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 "content/browser/renderer_host/input/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 "third_party/WebKit/public/web/WebInputEvent.h" | |
| 10 | 9 |
| 11 namespace content { | 10 namespace ui { |
| 12 namespace { | 11 namespace { |
| 13 | 12 |
| 14 TouchHandleOrientation ToTouchHandleOrientation(cc::SelectionBoundType type) { | 13 TouchHandleOrientation ToTouchHandleOrientation(SelectionBound::Type type) { |
| 15 switch (type) { | 14 switch (type) { |
| 16 case cc::SELECTION_BOUND_LEFT: | 15 case SelectionBound::LEFT: |
| 17 return TOUCH_HANDLE_LEFT; | 16 return TOUCH_HANDLE_LEFT; |
| 18 case cc::SELECTION_BOUND_RIGHT: | 17 case SelectionBound::RIGHT: |
| 19 return TOUCH_HANDLE_RIGHT; | 18 return TOUCH_HANDLE_RIGHT; |
| 20 case cc::SELECTION_BOUND_CENTER: | 19 case SelectionBound::CENTER: |
| 21 return TOUCH_HANDLE_CENTER; | 20 return TOUCH_HANDLE_CENTER; |
| 22 case cc::SELECTION_BOUND_EMPTY: | 21 case SelectionBound::EMPTY: |
| 23 return TOUCH_HANDLE_ORIENTATION_UNDEFINED; | 22 return TOUCH_HANDLE_ORIENTATION_UNDEFINED; |
| 24 } | 23 } |
| 25 NOTREACHED() << "Invalid selection bound type: " << type; | 24 NOTREACHED() << "Invalid selection bound type: " << type; |
| 26 return TOUCH_HANDLE_ORIENTATION_UNDEFINED; | 25 return TOUCH_HANDLE_ORIENTATION_UNDEFINED; |
| 27 } | 26 } |
| 28 | 27 |
| 29 } // namespace | 28 } // namespace |
| 30 | 29 |
| 31 TouchSelectionController::TouchSelectionController( | 30 TouchSelectionController::TouchSelectionController( |
| 32 TouchSelectionControllerClient* client, | 31 TouchSelectionControllerClient* client, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 46 selection_editable_(false), | 45 selection_editable_(false), |
| 47 temporarily_hidden_(false) { | 46 temporarily_hidden_(false) { |
| 48 DCHECK(client_); | 47 DCHECK(client_); |
| 49 HideAndDisallowShowingAutomatically(); | 48 HideAndDisallowShowingAutomatically(); |
| 50 } | 49 } |
| 51 | 50 |
| 52 TouchSelectionController::~TouchSelectionController() { | 51 TouchSelectionController::~TouchSelectionController() { |
| 53 } | 52 } |
| 54 | 53 |
| 55 void TouchSelectionController::OnSelectionBoundsChanged( | 54 void TouchSelectionController::OnSelectionBoundsChanged( |
| 56 const cc::ViewportSelectionBound& start, | 55 const SelectionBound& start, |
| 57 const cc::ViewportSelectionBound& end) { | 56 const SelectionBound& end) { |
| 58 if (start == start_ && end_ == end) | 57 if (start == start_ && end_ == end) |
| 59 return; | 58 return; |
| 60 | 59 |
| 61 start_ = start; | 60 start_ = start; |
| 62 end_ = end; | 61 end_ = end; |
| 63 start_orientation_ = ToTouchHandleOrientation(start_.type); | 62 start_orientation_ = ToTouchHandleOrientation(start_.type()); |
| 64 end_orientation_ = ToTouchHandleOrientation(end_.type); | 63 end_orientation_ = ToTouchHandleOrientation(end_.type()); |
| 65 | 64 |
| 66 if (!activate_selection_automatically_ && | 65 if (!activate_selection_automatically_ && |
| 67 !activate_insertion_automatically_) { | 66 !activate_insertion_automatically_) { |
| 68 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); | 67 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); |
| 69 return; | 68 return; |
| 70 } | 69 } |
| 71 | 70 |
| 72 // Ensure that |response_pending_input_event_| is cleared after the method | 71 // Ensure that |response_pending_input_event_| is cleared after the method |
| 73 // completes, while also making its current value available for the duration | 72 // completes, while also making its current value available for the duration |
| 74 // of the call. | 73 // of the call. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 103 } | 102 } |
| 104 | 103 |
| 105 if (start_orientation_ == TOUCH_HANDLE_CENTER && selection_editable_) { | 104 if (start_orientation_ == TOUCH_HANDLE_CENTER && selection_editable_) { |
| 106 OnInsertionChanged(); | 105 OnInsertionChanged(); |
| 107 return; | 106 return; |
| 108 } | 107 } |
| 109 | 108 |
| 110 HideAndDisallowShowingAutomatically(); | 109 HideAndDisallowShowingAutomatically(); |
| 111 } | 110 } |
| 112 | 111 |
| 113 bool TouchSelectionController::WillHandleTouchEvent( | 112 bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) { |
| 114 const ui::MotionEvent& event) { | |
| 115 if (is_insertion_active_) { | 113 if (is_insertion_active_) { |
| 116 DCHECK(insertion_handle_); | 114 DCHECK(insertion_handle_); |
| 117 return insertion_handle_->WillHandleTouchEvent(event); | 115 return insertion_handle_->WillHandleTouchEvent(event); |
| 118 } | 116 } |
| 119 | 117 |
| 120 if (is_selection_active_) { | 118 if (is_selection_active_) { |
| 121 DCHECK(start_selection_handle_); | 119 DCHECK(start_selection_handle_); |
| 122 DCHECK(end_selection_handle_); | 120 DCHECK(end_selection_handle_); |
| 123 if (start_selection_handle_->is_dragging()) | 121 if (start_selection_handle_->is_dragging()) |
| 124 return start_selection_handle_->WillHandleTouchEvent(event); | 122 return start_selection_handle_->WillHandleTouchEvent(event); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 DCHECK(end_selection_handle_); | 386 DCHECK(end_selection_handle_); |
| 389 start_selection_handle_->SetEnabled(false); | 387 start_selection_handle_->SetEnabled(false); |
| 390 end_selection_handle_->SetEnabled(false); | 388 end_selection_handle_->SetEnabled(false); |
| 391 is_selection_active_ = false; | 389 is_selection_active_ = false; |
| 392 client_->OnSelectionEvent(SELECTION_CLEARED, gfx::PointF()); | 390 client_->OnSelectionEvent(SELECTION_CLEARED, gfx::PointF()); |
| 393 } | 391 } |
| 394 | 392 |
| 395 void TouchSelectionController::ResetCachedValuesIfInactive() { | 393 void TouchSelectionController::ResetCachedValuesIfInactive() { |
| 396 if (is_selection_active_ || is_insertion_active_) | 394 if (is_selection_active_ || is_insertion_active_) |
| 397 return; | 395 return; |
| 398 start_ = cc::ViewportSelectionBound(); | 396 start_ = SelectionBound(); |
| 399 end_ = cc::ViewportSelectionBound(); | 397 end_ = SelectionBound(); |
| 400 start_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; | 398 start_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; |
| 401 end_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; | 399 end_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; |
| 402 } | 400 } |
| 403 | 401 |
| 404 const gfx::PointF& TouchSelectionController::GetStartPosition() const { | 402 const gfx::PointF& TouchSelectionController::GetStartPosition() const { |
| 405 return start_.edge_bottom; | 403 return start_.edge_bottom(); |
| 406 } | 404 } |
| 407 | 405 |
| 408 const gfx::PointF& TouchSelectionController::GetEndPosition() const { | 406 const gfx::PointF& TouchSelectionController::GetEndPosition() const { |
| 409 return end_.edge_bottom; | 407 return end_.edge_bottom(); |
| 410 } | 408 } |
| 411 | 409 |
| 412 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { | 410 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { |
| 413 return gfx::ScaleVector2d(start_.edge_top - start_.edge_bottom, 0.5f); | 411 return gfx::ScaleVector2d(start_.edge_top() - start_.edge_bottom(), 0.5f); |
| 414 } | 412 } |
| 415 | 413 |
| 416 gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const { | 414 gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const { |
| 417 return gfx::ScaleVector2d(end_.edge_top - end_.edge_bottom, 0.5f); | 415 return gfx::ScaleVector2d(end_.edge_top() - end_.edge_bottom(), 0.5f); |
| 418 } | 416 } |
| 419 | 417 |
| 420 bool TouchSelectionController::GetStartVisible() const { | 418 bool TouchSelectionController::GetStartVisible() const { |
| 421 return start_.visible && !temporarily_hidden_; | 419 return start_.visible() && !temporarily_hidden_; |
| 422 } | 420 } |
| 423 | 421 |
| 424 bool TouchSelectionController::GetEndVisible() const { | 422 bool TouchSelectionController::GetEndVisible() const { |
| 425 return end_.visible && !temporarily_hidden_; | 423 return end_.visible() && !temporarily_hidden_; |
| 426 } | 424 } |
| 427 | 425 |
| 428 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( | 426 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( |
| 429 bool was_active) const { | 427 bool was_active) const { |
| 430 return was_active && client_->SupportsAnimation() | 428 return was_active && client_->SupportsAnimation() |
| 431 ? TouchHandle::ANIMATION_SMOOTH | 429 ? TouchHandle::ANIMATION_SMOOTH |
| 432 : TouchHandle::ANIMATION_NONE; | 430 : TouchHandle::ANIMATION_NONE; |
| 433 } | 431 } |
| 434 | 432 |
| 435 } // namespace content | 433 } // namespace ui |
| OLD | NEW |