| 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 | 6 |
| 7 #include "ui/events/test/cocoa_test_event_utils.h" | 7 #include "ui/events/test/cocoa_test_event_utils.h" |
| 8 | 8 |
| 9 ScopedClassSwizzler::ScopedClassSwizzler(Class target, Class source, | |
| 10 SEL selector) { | |
| 11 old_selector_impl_ = class_getInstanceMethod(target, selector); | |
| 12 new_selector_impl_ = class_getInstanceMethod(source, selector); | |
| 13 if (!old_selector_impl_ && !new_selector_impl_) { | |
| 14 // Try class methods. | |
| 15 old_selector_impl_ = class_getClassMethod(target, selector); | |
| 16 new_selector_impl_ = class_getClassMethod(source, selector); | |
| 17 } | |
| 18 method_exchangeImplementations(old_selector_impl_, new_selector_impl_); | |
| 19 } | |
| 20 | |
| 21 ScopedClassSwizzler::~ScopedClassSwizzler() { | |
| 22 method_exchangeImplementations(old_selector_impl_, new_selector_impl_); | |
| 23 } | |
| 24 | |
| 25 namespace cocoa_test_event_utils { | 9 namespace cocoa_test_event_utils { |
| 26 | 10 |
| 27 NSEvent* MouseEventAtPoint(NSPoint point, NSEventType type, | 11 NSEvent* MouseEventAtPoint(NSPoint point, NSEventType type, |
| 28 NSUInteger modifiers) { | 12 NSUInteger modifiers) { |
| 29 if (type == NSOtherMouseUp) { | 13 if (type == NSOtherMouseUp) { |
| 30 // To synthesize middle clicks we need to create a CGEvent with the | 14 // To synthesize middle clicks we need to create a CGEvent with the |
| 31 // "center" button flags so that our resulting NSEvent will have the | 15 // "center" button flags so that our resulting NSEvent will have the |
| 32 // appropriate buttonNumber field. NSEvent provides no way to create a | 16 // appropriate buttonNumber field. NSEvent provides no way to create a |
| 33 // mouse event with a buttonNumber directly. | 17 // mouse event with a buttonNumber directly. |
| 34 CGPoint location = { point.x, point.y }; | 18 CGPoint location = { point.x, point.y }; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 modifierFlags:0 | 126 modifierFlags:0 |
| 143 timestamp:0 | 127 timestamp:0 |
| 144 windowNumber:0 | 128 windowNumber:0 |
| 145 context:nil | 129 context:nil |
| 146 subtype:0 | 130 subtype:0 |
| 147 data1:0 | 131 data1:0 |
| 148 data2:0]; | 132 data2:0]; |
| 149 } | 133 } |
| 150 | 134 |
| 151 } // namespace cocoa_test_event_utils | 135 } // namespace cocoa_test_event_utils |
| OLD | NEW |