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

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

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

Powered by Google App Engine
This is Rietveld 408576698