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

Unified Diff: ui/events/test/cocoa_test_event_utils.mm

Issue 2486643002: Mac: Offset test scroll events when attaching them to an NSWindow. (Closed)
Patch Set: not needed Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/test/cocoa_test_event_utils.mm
diff --git a/ui/events/test/cocoa_test_event_utils.mm b/ui/events/test/cocoa_test_event_utils.mm
index 8bf1837edb4506a4e8ccec873494be411f5a5382..9bd42df4ef83bdd4800800ca2f25ab94715dfb79 100644
--- a/ui/events/test/cocoa_test_event_utils.mm
+++ b/ui/events/test/cocoa_test_event_utils.mm
@@ -25,6 +25,21 @@ CGPoint ScreenPointFromWindow(NSPoint window_point, NSWindow* window) {
}
NSEvent* AttachWindowToCGEvent(CGEventRef event, NSWindow* window) {
+ // -[NSEvent locationInWindow] changes from screen coordinates to window
+ // coordinates when a window is attached to the mouse event. -[NSEvent
+ // eventWithCGEvent:] handles the Quartz -> AppKit coordinate flipping, but
+ // not the offset. Unfortunately -eventWithCGEvent: uses the *screen* height
+ // to flip, not the window height (it doesn't know about the window yet). So
+ // to get the correct -[NSEvent locationInWindow], anticipate the bogus screen
+ // flip that eventWithCGEvent: will do. This is yuck, but NSEvent does not
+ // provide a way to generate test scrolling events any other way. Fortunately,
+ // once you do all the algebra, all we need to do here is offset by the window
+ // origin, but in different directions for x/y.
Avi (use Gerrit) 2016/11/08 16:20:47 o_O Is there a bug filed? This is surprising. (Th
tapted 2016/11/08 23:05:52 No bug.. It's annoying, but I think it's reasonabl
tapted 2016/11/08 23:54:20 Filed http://crbug.com/663553 that collects my cur
+ CGPoint location = CGEventGetLocation(event);
+ location.y += NSMinY([window frame]);
+ location.x -= NSMinX([window frame]);
+ CGEventSetLocation(event, location);
+
// These CGEventFields were made public in the 10.7 SDK, but don't help to
// populate the -[NSEvent window] pointer when creating an event with
// +[NSEvent eventWithCGEvent:]. Set that separately, using reflection.
@@ -207,6 +222,8 @@ NSEvent* TestScrollEvent(NSPoint window_point,
DCHECK_EQ(has_precise_deltas, [event hasPreciseScrollingDeltas]);
DCHECK_EQ(event_phase, [event phase]);
DCHECK_EQ(momentum_phase, [event momentumPhase]);
+ DCHECK_EQ(window_point.x, [event locationInWindow].x);
+ DCHECK_EQ(window_point.y, [event locationInWindow].y);
return event;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698