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 |
(...skipping 22 matching lines...) Expand all Loading... | |
33 TouchHandle::TouchHandle(TouchHandleClient* client, | 33 TouchHandle::TouchHandle(TouchHandleClient* client, |
34 TouchHandleOrientation orientation) | 34 TouchHandleOrientation orientation) |
35 : drawable_(client->CreateDrawable()), | 35 : drawable_(client->CreateDrawable()), |
36 client_(client), | 36 client_(client), |
37 orientation_(orientation), | 37 orientation_(orientation), |
38 deferred_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), | 38 deferred_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), |
39 alpha_(0.f), | 39 alpha_(0.f), |
40 animate_deferred_fade_(false), | 40 animate_deferred_fade_(false), |
41 enabled_(true), | 41 enabled_(true), |
42 is_visible_(false), | 42 is_visible_(false), |
43 is_dragging_(false) { | 43 is_dragging_(false), |
44 is_drag_within_tap_region_(false) { | |
44 DCHECK_NE(orientation, TOUCH_HANDLE_ORIENTATION_UNDEFINED); | 45 DCHECK_NE(orientation, TOUCH_HANDLE_ORIENTATION_UNDEFINED); |
45 drawable_->SetEnabled(enabled_); | 46 drawable_->SetEnabled(enabled_); |
46 drawable_->SetOrientation(orientation_); | 47 drawable_->SetOrientation(orientation_); |
47 drawable_->SetAlpha(alpha_); | 48 drawable_->SetAlpha(alpha_); |
48 drawable_->SetVisible(is_visible_); | 49 drawable_->SetVisible(is_visible_); |
49 drawable_->SetFocus(position_); | 50 drawable_->SetFocus(position_); |
50 } | 51 } |
51 | 52 |
52 TouchHandle::~TouchHandle() { | 53 TouchHandle::~TouchHandle() { |
53 } | 54 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 touch_size); | 134 touch_size); |
134 if (!drawable_->IntersectsWith(touch_rect)) | 135 if (!drawable_->IntersectsWith(touch_rect)) |
135 return false; | 136 return false; |
136 touch_down_position_ = gfx::PointF(event.GetX(), event.GetY()); | 137 touch_down_position_ = gfx::PointF(event.GetX(), event.GetY()); |
137 touch_to_focus_offset_ = position_ - touch_down_position_; | 138 touch_to_focus_offset_ = position_ - touch_down_position_; |
138 touch_down_time_ = event.GetEventTime(); | 139 touch_down_time_ = event.GetEventTime(); |
139 BeginDrag(); | 140 BeginDrag(); |
140 } break; | 141 } break; |
141 | 142 |
142 case ui::MotionEvent::ACTION_MOVE: { | 143 case ui::MotionEvent::ACTION_MOVE: { |
143 gfx::PointF new_position = | 144 gfx::PointF touch_move_position(event.GetX(), event.GetY()); |
144 gfx::PointF(event.GetX(), event.GetY()) + touch_to_focus_offset_; | 145 if (is_drag_within_tap_region_) { |
raghu
2014/08/28 03:00:33
Please correct me here if I am wrong. Do we need t
jdduke (slow)
2014/08/28 15:37:12
It will only be true until we exceed the slop regi
| |
145 client_->OnHandleDragUpdate(*this, new_position); | 146 const float tap_slop = client_->GetTapSlop(); |
147 is_drag_within_tap_region_ = | |
148 (touch_move_position - touch_down_position_).LengthSquared() < | |
149 tap_slop * tap_slop; | |
150 } | |
151 | |
152 // Note that we signal drag update even if we're inside the tap region, | |
153 // as there are cases where characters are narrower than the slop length. | |
154 client_->OnHandleDragUpdate(*this, | |
155 touch_move_position + touch_to_focus_offset_); | |
146 } break; | 156 } break; |
147 | 157 |
148 case ui::MotionEvent::ACTION_UP: { | 158 case ui::MotionEvent::ACTION_UP: { |
149 // TODO(jdduke): Use the platform touch slop distance and tap delay to | 159 if (is_drag_within_tap_region_ && |
150 // properly detect a tap, crbug.com/394093. | 160 (event.GetEventTime() - touch_down_time_) < |
151 base::TimeDelta delay = event.GetEventTime() - touch_down_time_; | 161 client_->GetTapTimeout()) { |
152 if (delay < base::TimeDelta::FromMilliseconds(180)) | |
153 client_->OnHandleTapped(*this); | 162 client_->OnHandleTapped(*this); |
163 } | |
154 | 164 |
155 EndDrag(); | 165 EndDrag(); |
156 } break; | 166 } break; |
157 | 167 |
158 case ui::MotionEvent::ACTION_CANCEL: | 168 case ui::MotionEvent::ACTION_CANCEL: |
159 EndDrag(); | 169 EndDrag(); |
160 break; | 170 break; |
161 | 171 |
162 default: | 172 default: |
163 break; | 173 break; |
(...skipping 21 matching lines...) Expand all Loading... | |
185 | 195 |
186 return true; | 196 return true; |
187 } | 197 } |
188 | 198 |
189 void TouchHandle::BeginDrag() { | 199 void TouchHandle::BeginDrag() { |
190 DCHECK(enabled_); | 200 DCHECK(enabled_); |
191 if (is_dragging_) | 201 if (is_dragging_) |
192 return; | 202 return; |
193 EndFade(); | 203 EndFade(); |
194 is_dragging_ = true; | 204 is_dragging_ = true; |
205 is_drag_within_tap_region_ = true; | |
195 client_->OnHandleDragBegin(*this); | 206 client_->OnHandleDragBegin(*this); |
196 } | 207 } |
197 | 208 |
198 void TouchHandle::EndDrag() { | 209 void TouchHandle::EndDrag() { |
199 DCHECK(enabled_); | 210 DCHECK(enabled_); |
200 if (!is_dragging_) | 211 if (!is_dragging_) |
201 return; | 212 return; |
202 | 213 |
203 is_dragging_ = false; | 214 is_dragging_ = false; |
215 is_drag_within_tap_region_ = false; | |
204 client_->OnHandleDragEnd(*this); | 216 client_->OnHandleDragEnd(*this); |
205 | 217 |
206 if (deferred_orientation_ != TOUCH_HANDLE_ORIENTATION_UNDEFINED) { | 218 if (deferred_orientation_ != TOUCH_HANDLE_ORIENTATION_UNDEFINED) { |
207 TouchHandleOrientation deferred_orientation = deferred_orientation_; | 219 TouchHandleOrientation deferred_orientation = deferred_orientation_; |
208 deferred_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; | 220 deferred_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; |
209 SetOrientation(deferred_orientation); | 221 SetOrientation(deferred_orientation); |
210 } | 222 } |
211 | 223 |
212 if (animate_deferred_fade_) { | 224 if (animate_deferred_fade_) { |
213 BeginFade(); | 225 BeginFade(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 | 258 |
247 void TouchHandle::SetAlpha(float alpha) { | 259 void TouchHandle::SetAlpha(float alpha) { |
248 alpha = std::max(0.f, std::min(1.f, alpha)); | 260 alpha = std::max(0.f, std::min(1.f, alpha)); |
249 if (alpha_ == alpha) | 261 if (alpha_ == alpha) |
250 return; | 262 return; |
251 alpha_ = alpha; | 263 alpha_ = alpha; |
252 drawable_->SetAlpha(alpha); | 264 drawable_->SetAlpha(alpha); |
253 } | 265 } |
254 | 266 |
255 } // namespace content | 267 } // namespace content |
OLD | NEW |