Chromium Code Reviews| 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..01b63e01671abb5a35cdcdac65b029758b0cd80d 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_); |
| } |
| @@ -118,8 +120,9 @@ void TouchHandle::SetVisible(bool visible, AnimationStyle animation_style) { |
| EndFade(); |
| } |
| -void TouchHandle::SetPosition(const gfx::PointF& position) { |
| - DCHECK(enabled_); |
| +void TouchHandle::UpdatePosition() { |
| + gfx::PointF position = mirror_vertical_ ? focus_top_ : focus_bottom_; |
| + |
| if (position_ == position) |
| return; |
| position_ = position; |
| @@ -130,6 +133,21 @@ void TouchHandle::SetPosition(const gfx::PointF& position) { |
| drawable_->SetFocus(position_); |
| } |
| +void TouchHandle::SetFocus(const gfx::PointF& top, const gfx::PointF& bottom) { |
| + if (focus_top_ == top && focus_bottom_ == bottom) |
| + return; |
| + |
| + focus_top_ = top; |
| + focus_bottom_ = bottom; |
|
jdduke (slow)
2015/04/24 21:42:25
OK, so there are 3 inputs here that can impact the
|
| +} |
| + |
| +void TouchHandle::SetViewportRect(const gfx::RectF viewport_rect) { |
| + if (viewport_rect_ == viewport_rect) |
| + return; |
| + |
| + viewport_rect_ = viewport_rect; |
| +} |
| + |
| void TouchHandle::SetOrientation(TouchHandleOrientation orientation) { |
| DCHECK(enabled_); |
| DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED); |
| @@ -138,11 +156,40 @@ void TouchHandle::SetOrientation(TouchHandleOrientation orientation) { |
| return; |
| } |
| DCHECK_EQ(deferred_orientation_, TouchHandleOrientation::UNDEFINED); |
| - if (orientation_ == orientation) |
| + |
| + bool mirror_state_changed = SetMirrorParameters(); |
| + if (orientation_ == orientation && !mirror_state_changed) |
| return; |
| orientation_ = orientation; |
| - drawable_->SetOrientation(orientation); |
| + drawable_->SetOrientation(orientation, mirror_vertical_, mirror_horizontal_); |
| +} |
| + |
| +bool TouchHandle::SetMirrorParameters() { |
| + bool mirror_vertical = false; |
| + bool mirror_horizontal = false; |
| + bool mirror_state_changed = false; |
| + gfx::RectF handle_bounds = drawable_->GetVisibleBounds(); |
| + |
| + if (focus_bottom_.y() + handle_bounds.height() > viewport_rect_.bottom()) { |
| + mirror_vertical = true; |
| + } |
| + |
| + if (orientation_ == TouchHandleOrientation::LEFT && |
| + focus_bottom_.x() - handle_bounds.width() < viewport_rect_.x()) { |
| + mirror_horizontal = true; |
| + } |
| + |
| + if (orientation_ == TouchHandleOrientation::RIGHT && |
| + focus_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) { |
| @@ -251,6 +298,7 @@ void TouchHandle::EndDrag() { |
| TouchHandleOrientation deferred_orientation = deferred_orientation_; |
| deferred_orientation_ = TouchHandleOrientation::UNDEFINED; |
| SetOrientation(deferred_orientation); |
| + UpdatePosition(); |
| } |
| if (animate_deferred_fade_) { |