Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: ui/touch_selection/touch_handle.cc

Issue 1087893003: Support longpress drag selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Factor out logic Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (!RectIntersectsCircle(drawable_->GetVisibleBounds(),
164 touch_point, 164 touch_point,
165 touch_radius)) { 165 touch_radius)) {
166 EndDrag(); 166 EndDrag();
167 return false; 167 return false;
168 } 168 }
169 touch_down_position_ = touch_point; 169 touch_down_position_ = touch_point;
170 touch_to_focus_offset_ = position_ - touch_down_position_; 170 touch_drag_offset_ = position_ - touch_down_position_;
171 touch_down_time_ = event.GetEventTime(); 171 touch_down_time_ = event.GetEventTime();
172 BeginDrag(); 172 BeginDrag();
173 } break; 173 } break;
174 174
175 case MotionEvent::ACTION_MOVE: { 175 case MotionEvent::ACTION_MOVE: {
176 gfx::PointF touch_move_position(event.GetX(), event.GetY()); 176 gfx::PointF touch_move_position(event.GetX(), event.GetY());
177 if (is_drag_within_tap_region_) { 177 if (is_drag_within_tap_region_) {
178 const float tap_slop = client_->GetTapSlop(); 178 const float tap_slop = client_->GetTapSlop();
179 is_drag_within_tap_region_ = 179 is_drag_within_tap_region_ =
180 (touch_move_position - touch_down_position_).LengthSquared() < 180 (touch_move_position - touch_down_position_).LengthSquared() <
181 tap_slop * tap_slop; 181 tap_slop * tap_slop;
182 } 182 }
183 183
184 // Note that we signal drag update even if we're inside the tap region, 184 // Note that we signal drag update even if we're inside the tap region,
185 // as there are cases where characters are narrower than the slop length. 185 // as there are cases where characters are narrower than the slop length.
186 client_->OnHandleDragUpdate(*this, 186 client_->OnDragUpdate(*this, touch_move_position + touch_drag_offset_);
187 touch_move_position + touch_to_focus_offset_);
188 } break; 187 } break;
189 188
190 case MotionEvent::ACTION_UP: { 189 case MotionEvent::ACTION_UP: {
191 if (is_drag_within_tap_region_ && 190 if (is_drag_within_tap_region_ &&
192 (event.GetEventTime() - touch_down_time_) < 191 (event.GetEventTime() - touch_down_time_) <
193 client_->GetTapTimeout()) { 192 client_->GetTapTimeout()) {
194 client_->OnHandleTapped(*this); 193 client_->OnHandleTapped(*this);
195 } 194 }
196 195
197 EndDrag(); 196 EndDrag();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 return drawable_->GetVisibleBounds(); 234 return drawable_->GetVisibleBounds();
236 } 235 }
237 236
238 void TouchHandle::BeginDrag() { 237 void TouchHandle::BeginDrag() {
239 DCHECK(enabled_); 238 DCHECK(enabled_);
240 if (is_dragging_) 239 if (is_dragging_)
241 return; 240 return;
242 EndFade(); 241 EndFade();
243 is_dragging_ = true; 242 is_dragging_ = true;
244 is_drag_within_tap_region_ = true; 243 is_drag_within_tap_region_ = true;
245 client_->OnHandleDragBegin(*this); 244 client_->OnDragBegin(*this, position());
246 } 245 }
247 246
248 void TouchHandle::EndDrag() { 247 void TouchHandle::EndDrag() {
249 DCHECK(enabled_); 248 DCHECK(enabled_);
250 if (!is_dragging_) 249 if (!is_dragging_)
251 return; 250 return;
252 251
253 is_dragging_ = false; 252 is_dragging_ = false;
254 is_drag_within_tap_region_ = false; 253 is_drag_within_tap_region_ = false;
255 client_->OnHandleDragEnd(*this); 254 client_->OnDragEnd(*this);
256 255
257 if (deferred_orientation_ != TouchHandleOrientation::UNDEFINED) { 256 if (deferred_orientation_ != TouchHandleOrientation::UNDEFINED) {
258 TouchHandleOrientation deferred_orientation = deferred_orientation_; 257 TouchHandleOrientation deferred_orientation = deferred_orientation_;
259 deferred_orientation_ = TouchHandleOrientation::UNDEFINED; 258 deferred_orientation_ = TouchHandleOrientation::UNDEFINED;
260 SetOrientation(deferred_orientation); 259 SetOrientation(deferred_orientation);
261 } 260 }
262 261
263 if (animate_deferred_fade_) { 262 if (animate_deferred_fade_) {
264 BeginFade(); 263 BeginFade();
265 } else { 264 } else {
(...skipping 29 matching lines...) Expand all
295 294
296 void TouchHandle::SetAlpha(float alpha) { 295 void TouchHandle::SetAlpha(float alpha) {
297 alpha = std::max(0.f, std::min(1.f, alpha)); 296 alpha = std::max(0.f, std::min(1.f, alpha));
298 if (alpha_ == alpha) 297 if (alpha_ == alpha)
299 return; 298 return;
300 alpha_ = alpha; 299 alpha_ = alpha;
301 drawable_->SetAlpha(alpha); 300 drawable_->SetAlpha(alpha);
302 } 301 }
303 302
304 } // namespace ui 303 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698