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_handle.h" | 5 #include "content/browser/renderer_host/input/touch_handle.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 namespace content { | 9 namespace content { |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 // Maximum duration of a fade sequence. | 13 // Maximum duration of a fade sequence. |
14 const double kFadeDurationMs = 200; | 14 const double kFadeDurationMs = 200; |
15 | 15 |
16 // Maximum amount of travel for a fade sequence. This avoids handle "ghosting" | 16 // Maximum amount of travel for a fade sequence. This avoids handle "ghosting" |
17 // when the handle is moving rapidly while the fade is active. | 17 // when the handle is moving rapidly while the fade is active. |
18 const double kFadeDistanceSquared = 20.f * 20.f; | 18 const double kFadeDistanceSquared = 20.f * 20.f; |
19 | 19 |
| 20 // Avoid using an empty touch rect, as it may fail the intersection test event |
| 21 // if it lies within the other rect's bounds. |
| 22 const float kMinTouchMajorForHitTesting = 1.f; |
| 23 |
20 // The maximum touch size to use when computing whether a touch point is | 24 // The maximum touch size to use when computing whether a touch point is |
21 // targetting a touch handle. This is necessary for devices that misreport | 25 // targetting a touch handle. This is necessary for devices that misreport |
22 // touch radii, preventing inappropriately largely touch sizes from completely | 26 // touch radii, preventing inappropriately largely touch sizes from completely |
23 // breaking handle dragging behavior. | 27 // breaking handle dragging behavior. |
24 const float kMaxTouchMajorForHitTesting = 48.f; | 28 const float kMaxTouchMajorForHitTesting = 36.f; |
25 | 29 |
26 } // namespace | 30 } // namespace |
27 | 31 |
28 // Responsible for rendering a selection or insertion handle for text editing. | 32 // Responsible for rendering a selection or insertion handle for text editing. |
29 TouchHandle::TouchHandle(TouchHandleClient* client, | 33 TouchHandle::TouchHandle(TouchHandleClient* client, |
30 TouchHandleOrientation orientation) | 34 TouchHandleOrientation orientation) |
31 : drawable_(client->CreateDrawable()), | 35 : drawable_(client->CreateDrawable()), |
32 client_(client), | 36 client_(client), |
33 orientation_(orientation), | 37 orientation_(orientation), |
34 deferred_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), | 38 deferred_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 if (!enabled_) | 117 if (!enabled_) |
114 return false; | 118 return false; |
115 | 119 |
116 if (!is_dragging_ && event.GetAction() != ui::MotionEvent::ACTION_DOWN) | 120 if (!is_dragging_ && event.GetAction() != ui::MotionEvent::ACTION_DOWN) |
117 return false; | 121 return false; |
118 | 122 |
119 switch (event.GetAction()) { | 123 switch (event.GetAction()) { |
120 case ui::MotionEvent::ACTION_DOWN: { | 124 case ui::MotionEvent::ACTION_DOWN: { |
121 if (!is_visible_) | 125 if (!is_visible_) |
122 return false; | 126 return false; |
123 const float touch_size = | 127 const float touch_size = std::max( |
124 std::min(event.GetTouchMajor(), kMaxTouchMajorForHitTesting); | 128 kMinTouchMajorForHitTesting, |
| 129 std::min(kMaxTouchMajorForHitTesting, event.GetTouchMajor())); |
125 const gfx::RectF touch_rect(event.GetX() - touch_size * .5f, | 130 const gfx::RectF touch_rect(event.GetX() - touch_size * .5f, |
126 event.GetY() - touch_size * .5f, | 131 event.GetY() - touch_size * .5f, |
127 touch_size, | 132 touch_size, |
128 touch_size); | 133 touch_size); |
129 if (!drawable_->IntersectsWith(touch_rect)) | 134 if (!drawable_->IntersectsWith(touch_rect)) |
130 return false; | 135 return false; |
131 touch_down_position_ = gfx::PointF(event.GetX(), event.GetY()); | 136 touch_down_position_ = gfx::PointF(event.GetX(), event.GetY()); |
132 touch_to_focus_offset_ = position_ - touch_down_position_; | 137 touch_to_focus_offset_ = position_ - touch_down_position_; |
133 touch_down_time_ = event.GetEventTime(); | 138 touch_down_time_ = event.GetEventTime(); |
134 BeginDrag(); | 139 BeginDrag(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 246 |
242 void TouchHandle::SetAlpha(float alpha) { | 247 void TouchHandle::SetAlpha(float alpha) { |
243 alpha = std::max(0.f, std::min(1.f, alpha)); | 248 alpha = std::max(0.f, std::min(1.f, alpha)); |
244 if (alpha_ == alpha) | 249 if (alpha_ == alpha) |
245 return; | 250 return; |
246 alpha_ = alpha; | 251 alpha_ = alpha; |
247 drawable_->SetAlpha(alpha); | 252 drawable_->SetAlpha(alpha); |
248 } | 253 } |
249 | 254 |
250 } // namespace content | 255 } // namespace content |
OLD | NEW |