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

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

Issue 62443007: Replace old with new synthetic gesture framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: opt_mouse_move_event_x/y -> opt_start_x/y Created 7 years, 1 month 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 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_new.h" 5 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h"
6 6
7 #include "content/common/input/input_event.h" 7 #include "content/common/input/input_event.h"
8 #include "ui/events/latency_info.h" 8 #include "ui/events/latency_info.h"
9 9
10 namespace content { 10 namespace content {
11 namespace { 11 namespace {
12 12
13 // TODO(dominikg): Use touch slop to compute this value. 13 // TODO(dominikg): Use touch slop to compute this value.
14 const float kMinPointerDistance = 40.0f; 14 const float kMinPointerDistance = 40.0f;
15 15
16 } 16 }
17 17
18 SyntheticPinchGestureNew::SyntheticPinchGestureNew( 18 SyntheticPinchGesture::SyntheticPinchGesture(
19 const SyntheticPinchGestureParams& params) 19 const SyntheticPinchGestureParams& params)
20 : params_(params), started_(false) { 20 : params_(params), started_(false) {
21 DCHECK_GE(params_.total_num_pixels_covered, 0); 21 DCHECK_GE(params_.total_num_pixels_covered, 0);
22 22
23 float inner_distance_to_anchor = kMinPointerDistance / 2; 23 float inner_distance_to_anchor = kMinPointerDistance / 2;
24 float outer_distance_to_anchor = 24 float outer_distance_to_anchor =
25 inner_distance_to_anchor + params_.total_num_pixels_covered / 2; 25 inner_distance_to_anchor + params_.total_num_pixels_covered / 2;
26 26
27 // Move pointers away from each other to zoom in 27 // Move pointers away from each other to zoom in
28 // or towards each other to zoom out. 28 // or towards each other to zoom out.
29 if (params_.zoom_in) { 29 if (params_.zoom_in) {
30 current_y_0_ = params_.anchor.y() - inner_distance_to_anchor; 30 current_y_0_ = params_.anchor.y() - inner_distance_to_anchor;
31 current_y_1_ = params_.anchor.y() + inner_distance_to_anchor; 31 current_y_1_ = params_.anchor.y() + inner_distance_to_anchor;
32 target_y_0_ = params_.anchor.y() - outer_distance_to_anchor; 32 target_y_0_ = params_.anchor.y() - outer_distance_to_anchor;
33 target_y_1_ = params_.anchor.y() + outer_distance_to_anchor; 33 target_y_1_ = params_.anchor.y() + outer_distance_to_anchor;
34 } else { 34 } else {
35 current_y_0_ = params_.anchor.y() - outer_distance_to_anchor; 35 current_y_0_ = params_.anchor.y() - outer_distance_to_anchor;
36 current_y_1_ = params_.anchor.y() + outer_distance_to_anchor; 36 current_y_1_ = params_.anchor.y() + outer_distance_to_anchor;
37 target_y_0_ = params_.anchor.y() - inner_distance_to_anchor; 37 target_y_0_ = params_.anchor.y() - inner_distance_to_anchor;
38 target_y_1_ = params_.anchor.y() + inner_distance_to_anchor; 38 target_y_1_ = params_.anchor.y() + inner_distance_to_anchor;
39 } 39 }
40 } 40 }
41 41
42 SyntheticPinchGestureNew::~SyntheticPinchGestureNew() {} 42 SyntheticPinchGesture::~SyntheticPinchGesture() {}
43 43
44 SyntheticGestureNew::Result SyntheticPinchGestureNew::ForwardInputEvents( 44 SyntheticGesture::Result SyntheticPinchGesture::ForwardInputEvents(
45 const base::TimeDelta& interval, SyntheticGestureTarget* target) { 45 const base::TimeDelta& interval, SyntheticGestureTarget* target) {
46 46
47 SyntheticGestureParams::GestureSourceType source = 47 SyntheticGestureParams::GestureSourceType source =
48 params_.gesture_source_type; 48 params_.gesture_source_type;
49 if (source == SyntheticGestureParams::DEFAULT_INPUT) 49 if (source == SyntheticGestureParams::DEFAULT_INPUT)
50 source = target->GetDefaultSyntheticGestureSourceType(); 50 source = target->GetDefaultSyntheticGestureSourceType();
51 51
52 if (!target->SupportsSyntheticGestureSourceType(source)) 52 if (!target->SupportsSyntheticGestureSourceType(source))
53 return SyntheticGestureNew::GESTURE_SOURCE_TYPE_NOT_SUPPORTED_BY_PLATFORM; 53 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_SUPPORTED_BY_PLATFORM;
54 54
55 if (source == SyntheticGestureParams::TOUCH_INPUT) 55 if (source == SyntheticGestureParams::TOUCH_INPUT)
56 return ForwardTouchInputEvents(interval, target); 56 return ForwardTouchInputEvents(interval, target);
57 else 57 else
58 return SyntheticGestureNew::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; 58 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED;
59 } 59 }
60 60
61 SyntheticGestureNew::Result SyntheticPinchGestureNew::ForwardTouchInputEvents( 61 SyntheticGesture::Result SyntheticPinchGesture::ForwardTouchInputEvents(
62 const base::TimeDelta& interval, SyntheticGestureTarget* target) { 62 const base::TimeDelta& interval, SyntheticGestureTarget* target) {
63 if (HasFinished()) 63 if (HasFinished())
64 return SyntheticGestureNew::GESTURE_FINISHED; 64 return SyntheticGesture::GESTURE_FINISHED;
65 65
66 if (!started_) { 66 if (!started_) {
67 touch_event_.PressPoint(params_.anchor.x(), current_y_0_); 67 touch_event_.PressPoint(params_.anchor.x(), current_y_0_);
68 touch_event_.PressPoint(params_.anchor.x(), current_y_1_); 68 touch_event_.PressPoint(params_.anchor.x(), current_y_1_);
69 ForwardTouchEvent(target); 69 ForwardTouchEvent(target);
70 started_ = true; 70 started_ = true;
71 } 71 }
72 72
73 float delta = GetPositionDelta(interval) / 2; 73 float delta = GetPositionDelta(interval) / 2;
74 if (params_.zoom_in) { 74 if (params_.zoom_in) {
75 current_y_0_ -= delta; 75 current_y_0_ -= delta;
76 current_y_1_ += delta; 76 current_y_1_ += delta;
77 } else { 77 } else {
78 current_y_0_ += delta; 78 current_y_0_ += delta;
79 current_y_1_ -= delta; 79 current_y_1_ -= delta;
80 } 80 }
81 touch_event_.MovePoint(0, params_.anchor.x(), current_y_0_); 81 touch_event_.MovePoint(0, params_.anchor.x(), current_y_0_);
82 touch_event_.MovePoint(1, params_.anchor.x(), current_y_1_); 82 touch_event_.MovePoint(1, params_.anchor.x(), current_y_1_);
83 ForwardTouchEvent(target); 83 ForwardTouchEvent(target);
84 84
85 if (HasFinished()) { 85 if (HasFinished()) {
86 touch_event_.ReleasePoint(0); 86 touch_event_.ReleasePoint(0);
87 touch_event_.ReleasePoint(1); 87 touch_event_.ReleasePoint(1);
88 ForwardTouchEvent(target); 88 ForwardTouchEvent(target);
89 return SyntheticGestureNew::GESTURE_FINISHED; 89 return SyntheticGesture::GESTURE_FINISHED;
90 } 90 }
91 91
92 return SyntheticGestureNew::GESTURE_RUNNING; 92 return SyntheticGesture::GESTURE_RUNNING;
93 } 93 }
94 94
95 void SyntheticPinchGestureNew::ForwardTouchEvent( 95 void SyntheticPinchGesture::ForwardTouchEvent(SyntheticGestureTarget* target) {
96 SyntheticGestureTarget* target) {
97 target->DispatchInputEventToPlatform( 96 target->DispatchInputEventToPlatform(
98 InputEvent(touch_event_, ui::LatencyInfo(), false)); 97 InputEvent(touch_event_, ui::LatencyInfo(), false));
99 } 98 }
100 99
101 float SyntheticPinchGestureNew::GetPositionDelta( 100 float SyntheticPinchGesture::GetPositionDelta(const base::TimeDelta& interval) {
102 const base::TimeDelta& interval) {
103 return params_.relative_pointer_speed_in_pixels_s * interval.InSecondsF(); 101 return params_.relative_pointer_speed_in_pixels_s * interval.InSecondsF();
104 } 102 }
105 103
106 bool SyntheticPinchGestureNew::HasFinished() { 104 bool SyntheticPinchGesture::HasFinished() {
107 return params_.zoom_in ? (current_y_0_ <= target_y_0_) 105 return params_.zoom_in ? (current_y_0_ <= target_y_0_)
108 : (current_y_0_ >= target_y_0_); 106 : (current_y_0_ >= target_y_0_);
109 } 107 }
110 108
111 } // namespace content 109 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698