| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 | 7 |
| 8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 9 #import "base/mac/scoped_objc_class_swizzler.h" | 9 #import "base/mac/scoped_objc_class_swizzler.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 @interface NSEventDonor : NSObject | 29 @interface NSEventDonor : NSObject |
| 30 @end | 30 @end |
| 31 | 31 |
| 32 @interface NSApplicationDonor : NSObject | 32 @interface NSApplicationDonor : NSObject |
| 33 @end | 33 @end |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 NSPoint ConvertRootPointToTarget(NSWindow* target, | 37 NSPoint ConvertRootPointToTarget(NSWindow* target, |
| 38 const gfx::Point& point_in_root) { | 38 const gfx::Point& point_in_root) { |
| 39 // Normally this would do ui::ConvertPointFromScreenToWindow. However, Cocoa | 39 // For Mac, assume the root window equates to the primary screen. |
| 40 // can reposition the window on screen and make things flaky. Initially, just | 40 return ui::ConvertPointFromScreenToWindow( |
| 41 // assume that the contentRect of |target| is at the top-left corner of the | 41 target, gfx::ScreenPointToNSPoint(point_in_root)); |
| 42 // screen. | |
| 43 NSRect content_rect = [target contentRectForFrameRect:[target frame]]; | |
| 44 return NSMakePoint(point_in_root.x(), | |
| 45 NSHeight(content_rect) - point_in_root.y()); | |
| 46 } | 42 } |
| 47 | 43 |
| 48 // Inverse of ui::EventFlagsFromModifiers(). | 44 // Inverse of ui::EventFlagsFromModifiers(). |
| 49 NSUInteger EventFlagsToModifiers(int flags) { | 45 NSUInteger EventFlagsToModifiers(int flags) { |
| 50 NSUInteger modifiers = 0; | 46 NSUInteger modifiers = 0; |
| 51 modifiers |= (flags & ui::EF_SHIFT_DOWN) ? NSShiftKeyMask : 0; | 47 modifiers |= (flags & ui::EF_SHIFT_DOWN) ? NSShiftKeyMask : 0; |
| 52 modifiers |= (flags & ui::EF_CONTROL_DOWN) ? NSControlKeyMask : 0; | 48 modifiers |= (flags & ui::EF_CONTROL_DOWN) ? NSControlKeyMask : 0; |
| 53 modifiers |= (flags & ui::EF_ALT_DOWN) ? NSAlternateKeyMask : 0; | 49 modifiers |= (flags & ui::EF_ALT_DOWN) ? NSAlternateKeyMask : 0; |
| 54 modifiers |= (flags & ui::EF_COMMAND_DOWN) ? NSCommandKeyMask : 0; | 50 modifiers |= (flags & ui::EF_COMMAND_DOWN) ? NSCommandKeyMask : 0; |
| 55 modifiers |= (flags & ui::EF_CAPS_LOCK_ON) ? NSAlphaShiftKeyMask : 0; | 51 modifiers |= (flags & ui::EF_CAPS_LOCK_ON) ? NSAlphaShiftKeyMask : 0; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 ui::test::EventGenerator::default_delegate = nullptr; | 338 ui::test::EventGenerator::default_delegate = nullptr; |
| 343 } | 339 } |
| 344 | 340 |
| 345 scoped_ptr<ui::EventTargetIterator> | 341 scoped_ptr<ui::EventTargetIterator> |
| 346 EventGeneratorDelegateMac::GetChildIterator() const { | 342 EventGeneratorDelegateMac::GetChildIterator() const { |
| 347 // Return nullptr to dispatch all events to the result of GetRootTarget(). | 343 // Return nullptr to dispatch all events to the result of GetRootTarget(). |
| 348 return nullptr; | 344 return nullptr; |
| 349 } | 345 } |
| 350 | 346 |
| 351 void EventGeneratorDelegateMac::OnMouseEvent(ui::MouseEvent* event) { | 347 void EventGeneratorDelegateMac::OnMouseEvent(ui::MouseEvent* event) { |
| 352 NSEvent* ns_event = CreateMouseEventInWindow(window_, | 348 NSEvent* ns_event = CreateMouseEventInWindow( |
| 353 event->type(), | 349 window_, event->type(), event->location(), event->flags()); |
| 354 event->location(), | |
| 355 event->changed_button_flags()); | |
| 356 if (owner_->targeting_application()) | 350 if (owner_->targeting_application()) |
| 357 [NSApp sendEvent:ns_event]; | 351 [NSApp sendEvent:ns_event]; |
| 358 else | 352 else |
| 359 EmulateSendEvent(window_, ns_event); | 353 EmulateSendEvent(window_, ns_event); |
| 360 } | 354 } |
| 361 | 355 |
| 362 void EventGeneratorDelegateMac::OnKeyEvent(ui::KeyEvent* event) { | 356 void EventGeneratorDelegateMac::OnKeyEvent(ui::KeyEvent* event) { |
| 363 NSUInteger modifiers = EventFlagsToModifiers(event->flags()); | 357 NSUInteger modifiers = EventFlagsToModifiers(event->flags()); |
| 364 NSEvent* ns_event = cocoa_test_event_utils::SynthesizeKeyEvent( | 358 NSEvent* ns_event = cocoa_test_event_utils::SynthesizeKeyEvent( |
| 365 window_, event->type() == ui::ET_KEY_PRESSED, event->key_code(), | 359 window_, event->type() == ui::ET_KEY_PRESSED, event->key_code(), |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 - (NSEvent*)currentEvent { | 478 - (NSEvent*)currentEvent { |
| 485 if (g_current_event) | 479 if (g_current_event) |
| 486 return g_current_event; | 480 return g_current_event; |
| 487 | 481 |
| 488 // Find the original implementation and invoke it. | 482 // Find the original implementation and invoke it. |
| 489 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod(); | 483 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod(); |
| 490 return original(self, _cmd); | 484 return original(self, _cmd); |
| 491 } | 485 } |
| 492 | 486 |
| 493 @end | 487 @end |
| OLD | NEW |