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

Side by Side Diff: content/browser/renderer_host/input/synthetic_pinch_gesture.cc

Issue 95153002: Make touch-based synthetic gesture take touch slop into account. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: undo pinch refactoring; get device scale factor from gfx::Screen Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/synthetic_pinch_gesture.h" 5 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "content/common/input/input_event.h" 9 #include "content/common/input/input_event.h"
10 #include "ui/events/latency_info.h" 10 #include "ui/events/latency_info.h"
11 11
12 namespace content { 12 namespace content {
13 namespace { 13 namespace {
14 14
15 // TODO(dominikg): Use touch slop to compute this value. 15 // TODO(dominikg): Use touch slop to compute this value.
16 const float kMinPointerDistance = 40.0f; 16 const float kMinPointerDistance = 40.0f;
17 17
18 } 18 }
19 19
20 SyntheticPinchGesture::SyntheticPinchGesture( 20 SyntheticPinchGesture::SyntheticPinchGesture(
21 const SyntheticPinchGestureParams& params) 21 const SyntheticPinchGestureParams& params)
22 : params_(params), started_(false) { 22 : params_(params),
23 current_y_0_(0),
24 current_y_1_(0),
25 target_y_0_(0),
26 target_y_1_(0),
27 started_(false) {
23 DCHECK_GE(params_.total_num_pixels_covered, 0); 28 DCHECK_GE(params_.total_num_pixels_covered, 0);
24
25 float inner_distance_to_anchor = kMinPointerDistance / 2.0f;
26 float outer_distance_to_anchor =
27 inner_distance_to_anchor + params_.total_num_pixels_covered / 2.0f;
28
29 // Move pointers away from each other to zoom in
30 // or towards each other to zoom out.
31 if (params_.zoom_in) {
32 current_y_0_ = params_.anchor.y() - inner_distance_to_anchor;
33 current_y_1_ = params_.anchor.y() + inner_distance_to_anchor;
34 target_y_0_ = params_.anchor.y() - outer_distance_to_anchor;
35 target_y_1_ = params_.anchor.y() + outer_distance_to_anchor;
36 } else {
37 current_y_0_ = params_.anchor.y() - outer_distance_to_anchor;
38 current_y_1_ = params_.anchor.y() + outer_distance_to_anchor;
39 target_y_0_ = params_.anchor.y() - inner_distance_to_anchor;
40 target_y_1_ = params_.anchor.y() + inner_distance_to_anchor;
41 }
42 } 29 }
43 30
44 SyntheticPinchGesture::~SyntheticPinchGesture() {} 31 SyntheticPinchGesture::~SyntheticPinchGesture() {}
45 32
46 SyntheticGesture::Result SyntheticPinchGesture::ForwardInputEvents( 33 SyntheticGesture::Result SyntheticPinchGesture::ForwardInputEvents(
47 const base::TimeDelta& interval, SyntheticGestureTarget* target) { 34 const base::TimeDelta& interval, SyntheticGestureTarget* target) {
48 35
49 SyntheticGestureParams::GestureSourceType source = 36 SyntheticGestureParams::GestureSourceType source =
50 params_.gesture_source_type; 37 params_.gesture_source_type;
51 if (source == SyntheticGestureParams::DEFAULT_INPUT) 38 if (source == SyntheticGestureParams::DEFAULT_INPUT)
52 source = target->GetDefaultSyntheticGestureSourceType(); 39 source = target->GetDefaultSyntheticGestureSourceType();
53 40
54 if (!target->SupportsSyntheticGestureSourceType(source)) 41 if (!target->SupportsSyntheticGestureSourceType(source))
55 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_SUPPORTED_BY_PLATFORM; 42 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_SUPPORTED_BY_PLATFORM;
56 43
57 if (source == SyntheticGestureParams::TOUCH_INPUT) 44 if (source == SyntheticGestureParams::TOUCH_INPUT)
58 return ForwardTouchInputEvents(interval, target); 45 return ForwardTouchInputEvents(interval, target);
59 else 46 else
60 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; 47 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED;
61 } 48 }
62 49
63 SyntheticGesture::Result SyntheticPinchGesture::ForwardTouchInputEvents( 50 SyntheticGesture::Result SyntheticPinchGesture::ForwardTouchInputEvents(
64 const base::TimeDelta& interval, SyntheticGestureTarget* target) { 51 const base::TimeDelta& interval, SyntheticGestureTarget* target) {
65 if (HasFinished()) 52 if (!started_) {
66 return SyntheticGesture::GESTURE_FINISHED; 53 SetupCoordinates(target);
67 54
68 if (!started_) { 55 if (HasFinished())
56 return SyntheticGesture::GESTURE_FINISHED;
57
69 touch_event_.PressPoint(params_.anchor.x(), current_y_0_); 58 touch_event_.PressPoint(params_.anchor.x(), current_y_0_);
70 touch_event_.PressPoint(params_.anchor.x(), current_y_1_); 59 touch_event_.PressPoint(params_.anchor.x(), current_y_1_);
71 ForwardTouchEvent(target); 60 ForwardTouchEvent(target);
72 started_ = true; 61 started_ = true;
73 } 62 }
74 63
75 // Compute the delta for the first pointer. The other one moves exactly 64 // Compute the delta for the first pointer. The other one moves exactly
76 // the same but in the opposite direction. 65 // the same but in the opposite direction.
77 float delta = GetDeltaForPointer0(interval); 66 float delta = GetDeltaForPointer0(interval);
78 current_y_0_ += delta; 67 current_y_0_ += delta;
(...skipping 10 matching lines...) Expand all
89 if (HasFinished()) { 78 if (HasFinished()) {
90 touch_event_.ReleasePoint(0); 79 touch_event_.ReleasePoint(0);
91 touch_event_.ReleasePoint(1); 80 touch_event_.ReleasePoint(1);
92 ForwardTouchEvent(target); 81 ForwardTouchEvent(target);
93 return SyntheticGesture::GESTURE_FINISHED; 82 return SyntheticGesture::GESTURE_FINISHED;
94 } 83 }
95 84
96 return SyntheticGesture::GESTURE_RUNNING; 85 return SyntheticGesture::GESTURE_RUNNING;
97 } 86 }
98 87
88 void SyntheticPinchGesture::SetupCoordinates(SyntheticGestureTarget* target) {
jdduke (slow) 2013/12/02 16:29:43 Nit: Move this below |ForwardTouchEvent()| for con
Dominik Grewe 2013/12/02 16:42:26 Done.
89 float inner_distance_to_anchor = 2 * target->GetTouchSlopInDips();
90 float outer_distance_to_anchor = inner_distance_to_anchor +
91 params_.total_num_pixels_covered / 2.0f +
92 target->GetTouchSlopInDips();
93
94 // Move pointers away from each other to zoom in
95 // or towards each other to zoom out.
96 if (params_.zoom_in) {
97 current_y_0_ = params_.anchor.y() - inner_distance_to_anchor;
98 current_y_1_ = params_.anchor.y() + inner_distance_to_anchor;
99 target_y_0_ = params_.anchor.y() - outer_distance_to_anchor;
100 target_y_1_ = params_.anchor.y() + outer_distance_to_anchor;
101 } else {
102 current_y_0_ = params_.anchor.y() - outer_distance_to_anchor;
103 current_y_1_ = params_.anchor.y() + outer_distance_to_anchor;
104 target_y_0_ = params_.anchor.y() - inner_distance_to_anchor;
105 target_y_1_ = params_.anchor.y() + inner_distance_to_anchor;
106 }
107 }
108
99 void SyntheticPinchGesture::ForwardTouchEvent(SyntheticGestureTarget* target) { 109 void SyntheticPinchGesture::ForwardTouchEvent(SyntheticGestureTarget* target) {
100 target->DispatchInputEventToPlatform( 110 target->DispatchInputEventToPlatform(
101 InputEvent(touch_event_, ui::LatencyInfo(), false)); 111 InputEvent(touch_event_, ui::LatencyInfo(), false));
102 } 112 }
103 113
104 float SyntheticPinchGesture::GetDeltaForPointer0( 114 float SyntheticPinchGesture::GetDeltaForPointer0(
105 const base::TimeDelta& interval) const { 115 const base::TimeDelta& interval) const {
106 float total_abs_delta = 116 float total_abs_delta =
107 params_.relative_pointer_speed_in_pixels_s * interval.InSecondsF(); 117 params_.relative_pointer_speed_in_pixels_s * interval.InSecondsF();
108 118
(...skipping 12 matching lines...) Expand all
121 131
122 // Both pointers move the same overall distance at the same speed. 132 // Both pointers move the same overall distance at the same speed.
123 return 2 * distance_0; 133 return 2 * distance_0;
124 } 134 }
125 135
126 bool SyntheticPinchGesture::HasFinished() const { 136 bool SyntheticPinchGesture::HasFinished() const {
127 return ComputeAbsoluteRemainingDistance() == 0; 137 return ComputeAbsoluteRemainingDistance() == 0;
128 } 138 }
129 139
130 } // namespace content 140 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698