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

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

Powered by Google App Engine
This is Rietveld 408576698