Index: ui/touch_selection/touch_handle.cc |
diff --git a/ui/touch_selection/touch_handle.cc b/ui/touch_selection/touch_handle.cc |
index 0f28c3fedf8d69068acba4969db54e13cbd60bda..9d54423030b8bc1da6dd1fd9e587feb9979dd970 100644 |
--- a/ui/touch_selection/touch_handle.cc |
+++ b/ui/touch_selection/touch_handle.cc |
@@ -73,10 +73,12 @@ TouchHandle::TouchHandle(TouchHandleClient* client, |
enabled_(true), |
is_visible_(false), |
is_dragging_(false), |
- is_drag_within_tap_region_(false) { |
+ is_drag_within_tap_region_(false), |
+ mirror_vertical_(false), |
+ mirror_horizontal_(false) { |
DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED); |
drawable_->SetEnabled(enabled_); |
- drawable_->SetOrientation(orientation_); |
+ drawable_->SetOrientation(orientation_, false, false); |
drawable_->SetAlpha(alpha_); |
drawable_->SetFocus(position_); |
} |
@@ -130,19 +132,55 @@ void TouchHandle::SetPosition(const gfx::PointF& position) { |
drawable_->SetFocus(position_); |
} |
-void TouchHandle::SetOrientation(TouchHandleOrientation orientation) { |
+void TouchHandle::SetOrientation(TouchHandleOrientation orientation, |
+ const gfx::RectF viewport_rect, |
+ const gfx::PointF handle_bottom) { |
DCHECK(enabled_); |
DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED); |
if (is_dragging_) { |
deferred_orientation_ = orientation; |
+ deferred_viewport_rect_ = viewport_rect; |
+ deferred_handle_bottom_ = handle_bottom; |
return; |
} |
DCHECK_EQ(deferred_orientation_, TouchHandleOrientation::UNDEFINED); |
- if (orientation_ == orientation) |
+ |
+ bool mirror_state_changed = |
+ SetInvertHandleParameters(viewport_rect, handle_bottom); |
+ if (orientation_ == orientation && !mirror_state_changed) |
return; |
orientation_ = orientation; |
- drawable_->SetOrientation(orientation); |
+ drawable_->SetOrientation(orientation, mirror_vertical_, mirror_horizontal_); |
+} |
+ |
+bool TouchHandle::SetInvertHandleParameters(const gfx::RectF viewport_rect, |
+ const gfx::PointF handle_bottom) { |
+ bool mirror_vertical = false; |
+ bool mirror_horizontal = false; |
+ bool mirror_state_changed = false; |
+ gfx::RectF handle_bounds = drawable_->GetVisibleBounds(); |
+ |
+ if (handle_bottom.y() + handle_bounds.height() > viewport_rect.bottom()) { |
+ mirror_vertical = true; |
+ } |
+ |
+ if (orientation_ == TouchHandleOrientation::LEFT && |
+ handle_bottom.x() - handle_bounds.width() < viewport_rect.x()) { |
+ mirror_horizontal = true; |
+ } |
+ |
+ if (orientation_ == TouchHandleOrientation::RIGHT && |
+ handle_bottom.x() + handle_bounds.width() > viewport_rect.right()) { |
+ mirror_horizontal = true; |
+ } |
+ |
+ mirror_state_changed = mirror_vertical_ != mirror_vertical || |
+ mirror_horizontal_ != mirror_horizontal; |
+ mirror_vertical_ = mirror_vertical; |
+ mirror_horizontal_ = mirror_horizontal; |
+ |
+ return mirror_state_changed; |
} |
bool TouchHandle::WillHandleTouchEvent(const MotionEvent& event) { |
@@ -250,7 +288,8 @@ void TouchHandle::EndDrag() { |
if (deferred_orientation_ != TouchHandleOrientation::UNDEFINED) { |
TouchHandleOrientation deferred_orientation = deferred_orientation_; |
deferred_orientation_ = TouchHandleOrientation::UNDEFINED; |
- SetOrientation(deferred_orientation); |
+ SetOrientation(deferred_orientation, deferred_viewport_rect_, |
+ deferred_handle_bottom_); |
} |
if (animate_deferred_fade_) { |
@@ -294,4 +333,8 @@ void TouchHandle::SetAlpha(float alpha) { |
drawable_->SetAlpha(alpha); |
} |
+gfx::RectF TouchHandle::GetHandleBounds() { |
+ return drawable_->GetVisibleBounds(); |
+} |
+ |
} // namespace ui |