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_handle.h" | 5 #include "ui/touch_selection/touch_handle.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 namespace ui { | 9 namespace ui { |
10 | 10 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 return false; | 153 return false; |
154 | 154 |
155 switch (event.GetAction()) { | 155 switch (event.GetAction()) { |
156 case MotionEvent::ACTION_DOWN: { | 156 case MotionEvent::ACTION_DOWN: { |
157 if (!is_visible_) | 157 if (!is_visible_) |
158 return false; | 158 return false; |
159 const gfx::PointF touch_point(event.GetX(), event.GetY()); | 159 const gfx::PointF touch_point(event.GetX(), event.GetY()); |
160 const float touch_radius = std::max( | 160 const float touch_radius = std::max( |
161 kMinTouchMajorForHitTesting, | 161 kMinTouchMajorForHitTesting, |
162 std::min(kMaxTouchMajorForHitTesting, event.GetTouchMajor())) * 0.5f; | 162 std::min(kMaxTouchMajorForHitTesting, event.GetTouchMajor())) * 0.5f; |
163 if (!RectIntersectsCircle(drawable_->GetVisibleBounds(), | 163 const gfx::RectF drawable_bounds = drawable_->GetVisibleBounds(); |
164 touch_point, | 164 // Only use the touch radius for targetting if the touch is at or below |
165 touch_radius)) { | 165 // the drawable area. This makes it easier to interact with the line of |
| 166 // text above the drawable. |
| 167 if (touch_point.y() < drawable_bounds.y() || |
| 168 !RectIntersectsCircle(drawable_bounds, touch_point, touch_radius)) { |
166 EndDrag(); | 169 EndDrag(); |
167 return false; | 170 return false; |
168 } | 171 } |
169 touch_down_position_ = touch_point; | 172 touch_down_position_ = touch_point; |
170 touch_drag_offset_ = position_ - touch_down_position_; | 173 touch_drag_offset_ = position_ - touch_down_position_; |
171 touch_down_time_ = event.GetEventTime(); | 174 touch_down_time_ = event.GetEventTime(); |
172 BeginDrag(); | 175 BeginDrag(); |
173 } break; | 176 } break; |
174 | 177 |
175 case MotionEvent::ACTION_MOVE: { | 178 case MotionEvent::ACTION_MOVE: { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 297 |
295 void TouchHandle::SetAlpha(float alpha) { | 298 void TouchHandle::SetAlpha(float alpha) { |
296 alpha = std::max(0.f, std::min(1.f, alpha)); | 299 alpha = std::max(0.f, std::min(1.f, alpha)); |
297 if (alpha_ == alpha) | 300 if (alpha_ == alpha) |
298 return; | 301 return; |
299 alpha_ = alpha; | 302 alpha_ = alpha; |
300 drawable_->SetAlpha(alpha); | 303 drawable_->SetAlpha(alpha); |
301 } | 304 } |
302 | 305 |
303 } // namespace ui | 306 } // namespace ui |
OLD | NEW |