OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import <Cocoa/Cocoa.h> |
| 6 |
| 7 #include "chrome/browser/cocoa/test_event_utils.h" |
| 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 method_exchangeImplementations(old_selector_impl_, new_selector_impl_); |
| 14 } |
| 15 |
| 16 ScopedClassSwizzler::~ScopedClassSwizzler() { |
| 17 method_exchangeImplementations(old_selector_impl_, new_selector_impl_); |
| 18 } |
| 19 |
| 20 namespace test_event_utils { |
| 21 |
| 22 NSEvent* MakeMouseEvent(NSEventType type, NSUInteger modifiers) { |
| 23 if (type == NSOtherMouseUp) { |
| 24 // To synthesize middle clicks we need to create a CGEvent with the |
| 25 // "center" button flags so that our resulting NSEvent will have the |
| 26 // appropriate buttonNumber field. NSEvent provides no way to create a |
| 27 // mouse event with a buttonNumber directly. |
| 28 CGPoint location = { 0, 0 }; |
| 29 CGEventRef event = CGEventCreateMouseEvent(NULL, kCGEventOtherMouseUp, |
| 30 location, |
| 31 kCGMouseButtonCenter); |
| 32 return [NSEvent eventWithCGEvent:event]; |
| 33 } |
| 34 return [NSEvent mouseEventWithType:type |
| 35 location:NSMakePoint(0, 0) |
| 36 modifierFlags:modifiers |
| 37 timestamp:0 |
| 38 windowNumber:0 |
| 39 context:nil |
| 40 eventNumber:0 |
| 41 clickCount:1 |
| 42 pressure:1.0]; |
| 43 } |
| 44 |
| 45 } // namespace test_event_utils |
OLD | NEW |