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

Unified Diff: ui/views/test/event_generator_delegate_mac.mm

Issue 793003004: MacViews: Implement event monitoring for a specific window (Reland) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Created 6 years 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 | « ui/views/mouse_watcher.cc ('k') | ui/views/views.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/test/event_generator_delegate_mac.mm
diff --git a/ui/views/test/event_generator_delegate_mac.mm b/ui/views/test/event_generator_delegate_mac.mm
index d156aa5d4af42f9381c6e21c5329ec1a1861814c..db9b627313cdc6d0cdba47af66c9fa0dfd295ef9 100644
--- a/ui/views/test/event_generator_delegate_mac.mm
+++ b/ui/views/test/event_generator_delegate_mac.mm
@@ -28,6 +28,9 @@ ui::test::EventGenerator* g_active_generator = NULL;
// Donate +[NSEvent pressedMouseButtons] by retrieving the flags from the
// active generator.
+ (NSUInteger)pressedMouseButtons {
+ if (!g_active_generator)
+ return [NSEventDonor pressedMouseButtons]; // Call original implementation.
+
int flags = g_active_generator->flags();
NSUInteger bitmask = 0;
if (flags & ui::EF_LEFT_MOUSE_BUTTON)
@@ -197,10 +200,10 @@ void EmulateSendEvent(NSWindow* window, NSEvent* event) {
}
}
-void DispatchMouseEventInWindow(NSWindow* window,
- ui::EventType event_type,
- const gfx::Point& point_in_root,
- int flags) {
+NSEvent* CreateMouseEventInWindow(NSWindow* window,
+ ui::EventType event_type,
+ const gfx::Point& point_in_root,
+ int flags) {
NSUInteger click_count = 0;
if (event_type == ui::ET_MOUSE_PRESSED ||
event_type == ui::ET_MOUSE_RELEASED) {
@@ -214,19 +217,15 @@ void DispatchMouseEventInWindow(NSWindow* window,
NSPoint point = ConvertRootPointToTarget(window, point_in_root);
NSUInteger modifiers = 0;
NSEventType type = EventTypeToNative(event_type, flags, &modifiers);
- NSEvent* event = [NSEvent mouseEventWithType:type
- location:point
- modifierFlags:modifiers
- timestamp:0
- windowNumber:[window windowNumber]
- context:nil
- eventNumber:0
- clickCount:click_count
- pressure:1.0];
-
- // Typically events go through NSApplication. For tests, dispatch the event
- // directly to make things more predicatble.
- EmulateSendEvent(window, event);
+ return [NSEvent mouseEventWithType:type
+ location:point
+ modifierFlags:modifiers
+ timestamp:0
+ windowNumber:[window windowNumber]
+ context:nil
+ eventNumber:0
+ clickCount:click_count
+ pressure:1.0];
}
// Implementation of ui::test::EventGeneratorDelegate for Mac. Everything
@@ -319,10 +318,14 @@ EventGeneratorDelegateMac::GetChildIterator() const {
void EventGeneratorDelegateMac::OnMouseEvent(ui::MouseEvent* event) {
// For mouse drag events, ensure the swizzled methods return the right flags.
base::AutoReset<ui::test::EventGenerator*> reset(&g_active_generator, owner_);
- DispatchMouseEventInWindow(window_,
- event->type(),
- event->location(),
- event->changed_button_flags());
+ NSEvent* ns_event = CreateMouseEventInWindow(window_,
+ event->type(),
+ event->location(),
+ event->changed_button_flags());
+ if (owner_->targeting_application())
+ [NSApp sendEvent:ns_event];
+ else
+ EmulateSendEvent(window_, ns_event);
}
void EventGeneratorDelegateMac::SetContext(ui::test::EventGenerator* owner,
« no previous file with comments | « ui/views/mouse_watcher.cc ('k') | ui/views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698