Chromium Code Reviews| 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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 NSEvent* ns_event = cocoa_test_event_utils::SynthesizeKeyEvent( | 394 NSEvent* ns_event = cocoa_test_event_utils::SynthesizeKeyEvent( |
| 395 window_, event->type() == ui::ET_KEY_PRESSED, event->key_code(), | 395 window_, event->type() == ui::ET_KEY_PRESSED, event->key_code(), |
| 396 modifiers, event->is_char() ? event->GetDomKey() : ui::DomKey::NONE); | 396 modifiers, event->is_char() ? event->GetDomKey() : ui::DomKey::NONE); |
| 397 | 397 |
| 398 using Target = ui::test::EventGenerator::Target; | 398 using Target = ui::test::EventGenerator::Target; |
| 399 switch (owner_->target()) { | 399 switch (owner_->target()) { |
| 400 case Target::APPLICATION: | 400 case Target::APPLICATION: |
| 401 [NSApp sendEvent:ns_event]; | 401 [NSApp sendEvent:ns_event]; |
| 402 break; | 402 break; |
| 403 case Target::WINDOW: | 403 case Target::WINDOW: |
| 404 // -[NSApp sendEvent:] sends -performKeyEquivalent: if Command or Control | |
| 405 // modifiers are pressed. Emulate that behavior. | |
| 406 if ([ns_event type] == NSKeyDown && | |
| 407 [ns_event modifierFlags] & (NSControlKeyMask | NSCommandKeyMask) && | |
|
tapted
2016/11/28 08:14:18
nit: extra parens around the bitwise operation
themblsha
2016/11/30 12:35:33
Done. I think performKeyEquivalent: emulation is a
tapted
2016/11/30 23:52:03
I agree - I like it too :)
| |
| 408 [window_ performKeyEquivalent:ns_event]) | |
| 409 break; // Handled by performKeyEquivalent:. | |
| 410 | |
| 404 [window_ sendEvent:ns_event]; | 411 [window_ sendEvent:ns_event]; |
| 405 break; | 412 break; |
| 406 case Target::WIDGET: | 413 case Target::WIDGET: |
| 407 if ([fake_menu_ performKeyEquivalent:ns_event]) | 414 if ([fake_menu_ performKeyEquivalent:ns_event]) |
| 408 return; | 415 return; |
| 409 | 416 |
| 410 EmulateSendEvent(window_, ns_event); | 417 EmulateSendEvent(window_, ns_event); |
| 411 break; | 418 break; |
| 412 } | 419 } |
| 413 } | 420 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 - (NSEvent*)currentEvent { | 616 - (NSEvent*)currentEvent { |
| 610 if (g_current_event) | 617 if (g_current_event) |
| 611 return g_current_event; | 618 return g_current_event; |
| 612 | 619 |
| 613 // Find the original implementation and invoke it. | 620 // Find the original implementation and invoke it. |
| 614 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod(); | 621 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod(); |
| 615 return original(self, _cmd); | 622 return original(self, _cmd); |
| 616 } | 623 } |
| 617 | 624 |
| 618 @end | 625 @end |
| OLD | NEW |