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 71dcce80c0807b1262b2429d5d67912e1ce3140c..4362f5474a6f5f18ee9f5ccc14488b8acb091a60 100644 |
| --- a/ui/touch_selection/touch_selection_controller.cc |
| +++ b/ui/touch_selection/touch_selection_controller.cc |
| @@ -68,14 +68,22 @@ TouchSelectionController::~TouchSelectionController() { |
| void TouchSelectionController::OnSelectionBoundsChanged( |
| const SelectionBound& start, |
| - const SelectionBound& end) { |
| - if (start == start_ && end_ == end) |
| + const SelectionBound& end, |
| + const gfx::SizeF& root_layer_size, |
|
jdduke (slow)
2015/03/16 22:01:45
The size/offet should probably be in a separate me
AviD
2015/03/19 13:13:33
Done.
|
| + const gfx::Vector2dF& offset) { |
| + if (start == start_ && end_ == end && root_layer_size != root_layer_size_ && |
| + offset != content_offset_) |
| return; |
| start_ = start; |
| end_ = end; |
| + root_layer_size_ = root_layer_size; |
| + content_offset_ = offset; |
| + viewport_rect_.SetRect(offset.x(), offset.y(), root_layer_size.width(), |
| + root_layer_size.height()); |
| start_orientation_ = ToTouchHandleOrientation(start_.type()); |
| end_orientation_ = ToTouchHandleOrientation(end_.type()); |
| + SetInvertedOrientation(); |
| if (!activate_selection_automatically_ && |
| !activate_insertion_automatically_) { |
| @@ -429,13 +437,70 @@ void TouchSelectionController::ResetCachedValuesIfInactive() { |
| } |
| const gfx::PointF& TouchSelectionController::GetStartPosition() const { |
| + bool top_handle = |
| + start_orientation_ == TouchHandleOrientation::LEFT_INVERTED || |
| + start_orientation_ == TouchHandleOrientation::LEFT_FLIPPED_INVERTED; |
| + if (top_handle) |
| + return start_.edge_top(); |
| return start_.edge_bottom(); |
| } |
| const gfx::PointF& TouchSelectionController::GetEndPosition() const { |
| + bool top_handle = |
| + end_orientation_ == TouchHandleOrientation::RIGHT_INVERTED || |
| + end_orientation_ == TouchHandleOrientation::RIGHT_FLIPPED_INVERTED; |
| + if (top_handle) |
| + return end_.edge_top(); |
| return end_.edge_bottom(); |
| } |
| +void TouchSelectionController::SetInvertedOrientation() { |
| + if (!start_selection_handle_ || !end_selection_handle_) |
| + return; |
| + |
| + TouchHandleOrientation old_start_orientation = start_orientation_; |
| + TouchHandleOrientation old_end_orientation = end_orientation_; |
| + |
| + gfx::RectF start_size = start_selection_handle_->GetHandleBounds(); |
| + gfx::RectF end_size = end_selection_handle_->GetHandleBounds(); |
| + |
| + int start_handle_state = 0; |
| + int end_handle_state = 0; |
| + |
| + if (start_.edge_bottom().y() + start_size.height() > |
| + viewport_rect_.height()) { |
| + start_orientation_ = TouchHandleOrientation::LEFT_INVERTED; |
| + start_handle_state++; |
| + } |
| + |
| + if (end_.edge_bottom().y() + end_size.height() > viewport_rect_.height()) { |
| + end_orientation_ = TouchHandleOrientation::RIGHT_INVERTED; |
| + end_handle_state++; |
| + } |
| + |
| + if (start_.edge_top().x() - end_size.width() < viewport_rect_.x()) { |
| + start_orientation_ = TouchHandleOrientation::LEFT_FLIPPED; |
| + start_handle_state++; |
| + } |
| + |
| + if (end_.edge_top().x() + start_size.width() > viewport_rect_.width()) { |
| + end_orientation_ = TouchHandleOrientation::RIGHT_FLIPPED; |
| + end_handle_state++; |
| + } |
| + |
| + if (start_handle_state == 2) { |
| + start_orientation_ = TouchHandleOrientation::LEFT_FLIPPED_INVERTED; |
| + } else if (start_handle_state == 0) { |
| + start_orientation_ = old_start_orientation; |
| + } |
| + |
| + if (end_handle_state == 2) { |
| + end_orientation_ = TouchHandleOrientation::RIGHT_FLIPPED_INVERTED; |
| + } else if (end_handle_state == 0) { |
| + end_orientation_ = old_end_orientation; |
| + } |
| +} |
| + |
| gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { |
| return ComputeLineOffsetFromBottom(start_); |
| } |