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

Side by Side Diff: ui/events/test/cocoa_test_event_utils.mm

Issue 345243007: Add ScopedObjCClassSwizzler in base/mac, absorbs objc_method_swizzle and ScopedClassSwizzler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Inlude in shiny new gn base_unittests target Created 6 years, 4 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/events/test/cocoa_test_event_utils.h ('k') | ui/views/test/event_generator_delegate_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « ui/events/test/cocoa_test_event_utils.h ('k') | ui/views/test/event_generator_delegate_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698