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

Side by Side Diff: content/browser/renderer_host/input/synthetic_gesture_target_mac.mm

Issue 1349813002: Enable pinch-zoom telemetry on Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@telemetry
Patch Set: feedback Created 5 years, 2 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
(Empty)
1 // Copyright 2015 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_gesture_target_mac.h"
6
7 #include "base/mac/scoped_nsautorelease_pool.h"
8 #include "content/browser/renderer_host/render_widget_host_impl.h"
9
10 // Unlike some event APIs, Apple does not provide a way to programmatically
11 // build a zoom event. To work around this, we leverage ObjectiveC's flexible
12 // typing and build up an object with the right interface to provide a zoom
13 // event.
14 @interface SyntheticPinchEvent : NSObject
15
16 // Populated based on desired zoom level.
17 @property CGFloat magnification;
18 @property NSPoint locationInWindow;
19 @property NSEventType type;
20
21 // Filled with default values.
22 @property(readonly) CGFloat deltaX;
23 @property(readonly) CGFloat deltaY;
24 @property(readonly) NSEventModifierFlags modifierFlags;
25 @property(readonly) NSTimeInterval timestamp;
26
27 @end
28
29 @implementation SyntheticPinchEvent
30
31 @synthesize magnification = magnification_;
32 @synthesize locationInWindow = locationInWindow_;
33 @synthesize type = type_;
34 @synthesize deltaX = deltaX_;
35 @synthesize deltaY = deltaY_;
36 @synthesize modifierFlags = modifierFlags_;
37 @synthesize timestamp = timestamp_;
38
39 - (id)initWithMagnification:(float)magnification
40 locationInWindow:(NSPoint)location {
41 self = [super init];
42 if (self) {
43 type_ = NSEventTypeMagnify;
44 magnification_ = magnification;
45 locationInWindow_ = location;
46
47 deltaX_ = 0;
48 deltaY_ = 0;
49 modifierFlags_ = 0;
50
51 // Default timestamp to current time.
52 timestamp_ = [[NSDate date] timeIntervalSince1970];
53 }
54
55 return self;
56 }
57
58 + (id)eventWithMagnification:(float)magnification
59 locationInWindow:(NSPoint)location {
60 SyntheticPinchEvent* event =
61 [[SyntheticPinchEvent alloc] initWithMagnification:magnification
62 locationInWindow:location];
63 return [event autorelease];
64 }
65
66 @end
67
68 using blink::WebInputEvent;
69 using blink::WebGestureEvent;
70
71 namespace content {
72
73 SyntheticGestureTargetMac::SyntheticGestureTargetMac(
74 RenderWidgetHostImpl* host,
75 RenderWidgetHostViewCocoa* cocoa_view)
76 : SyntheticGestureTargetBase(host), cocoa_view_(cocoa_view) {}
77
78 void SyntheticGestureTargetMac::DispatchInputEventToPlatform(
79 const WebInputEvent& event) {
80 if (WebInputEvent::isGestureEventType(event.type)) {
81 // Create an autorelease pool so that we clean up any synthetic events we
82 // generate.
83 base::mac::ScopedNSAutoreleasePool pool;
84
85 const WebGestureEvent* gesture_event =
86 static_cast<const WebGestureEvent*>(&event);
87
88 switch (event.type) {
89 case WebInputEvent::GesturePinchBegin: {
90 id event = [SyntheticPinchEvent
91 eventWithMagnification:0.0f
92 locationInWindow:NSMakePoint(gesture_event->x,
93 gesture_event->y)];
94 [cocoa_view_ beginGestureWithEvent:event];
95 return;
96 }
97 case WebInputEvent::GesturePinchEnd: {
98 id event = [SyntheticPinchEvent
99 eventWithMagnification:0.0f
100 locationInWindow:NSMakePoint(gesture_event->x,
101 gesture_event->y)];
102 [cocoa_view_ endGestureWithEvent:event];
103 return;
104 }
105 case WebInputEvent::GesturePinchUpdate: {
106 id event = [SyntheticPinchEvent
107 eventWithMagnification:gesture_event->data.pinchUpdate.scale - 1.0f
108 locationInWindow:NSMakePoint(gesture_event->x,
109 gesture_event->y)];
110 [cocoa_view_ magnifyWithEvent:event];
111 return;
112 }
113 default:
114 break;
115 }
116 }
117
118 // This event wasn't handled yet, forward to the base class.
119 SyntheticGestureTargetBase::DispatchInputEventToPlatform(event);
120 }
121
122 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698