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 <mach/mach_time.h> | 6 #include <mach/mach_time.h> |
7 | 7 |
8 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" | 8 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" |
9 #include "ui/events/test/cocoa_test_event_utils.h" | 9 #include "ui/events/test/cocoa_test_event_utils.h" |
10 | 10 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 context:nil | 65 context:nil |
66 eventNumber:0 | 66 eventNumber:0 |
67 clickCount:1 | 67 clickCount:1 |
68 pressure:1.0]; | 68 pressure:1.0]; |
69 } | 69 } |
70 | 70 |
71 NSEvent* MouseEventWithType(NSEventType type, NSUInteger modifiers) { | 71 NSEvent* MouseEventWithType(NSEventType type, NSUInteger modifiers) { |
72 return MouseEventAtPoint(NSZeroPoint, type, modifiers); | 72 return MouseEventAtPoint(NSZeroPoint, type, modifiers); |
73 } | 73 } |
74 | 74 |
75 static NSEvent* MouseEventAtPointInWindow(NSPoint point, | 75 NSEvent* MouseEventAtPointInWindow(NSPoint point, |
76 NSEventType type, | 76 NSEventType type, |
77 NSWindow* window, | 77 NSWindow* window, |
78 NSUInteger clickCount) { | 78 NSUInteger clickCount) { |
79 return [NSEvent mouseEventWithType:type | 79 return [NSEvent mouseEventWithType:type |
80 location:point | 80 location:point |
81 modifierFlags:0 | 81 modifierFlags:0 |
82 timestamp:0 | 82 timestamp:0 |
83 windowNumber:[window windowNumber] | 83 windowNumber:[window windowNumber] |
84 context:nil | 84 context:nil |
85 eventNumber:0 | 85 eventNumber:0 |
86 clickCount:clickCount | 86 clickCount:clickCount |
87 pressure:1.0]; | 87 pressure:1.0]; |
88 } | 88 } |
(...skipping 18 matching lines...) Expand all Loading... |
107 NSUInteger clickCount) { | 107 NSUInteger clickCount) { |
108 const NSRect bounds = [view convertRect:[view bounds] toView:nil]; | 108 const NSRect bounds = [view convertRect:[view bounds] toView:nil]; |
109 const NSPoint mid_point = NSMakePoint(NSMidX(bounds), NSMidY(bounds)); | 109 const NSPoint mid_point = NSMakePoint(NSMidX(bounds), NSMidY(bounds)); |
110 NSEvent* down = MouseEventAtPointInWindow(mid_point, NSLeftMouseDown, | 110 NSEvent* down = MouseEventAtPointInWindow(mid_point, NSLeftMouseDown, |
111 [view window], clickCount); | 111 [view window], clickCount); |
112 NSEvent* up = MouseEventAtPointInWindow(mid_point, NSLeftMouseUp, | 112 NSEvent* up = MouseEventAtPointInWindow(mid_point, NSLeftMouseUp, |
113 [view window], clickCount); | 113 [view window], clickCount); |
114 return std::make_pair(down, up); | 114 return std::make_pair(down, up); |
115 } | 115 } |
116 | 116 |
| 117 std::pair<NSEvent*, NSEvent*> RightMouseClickInView(NSView* view, |
| 118 NSUInteger clickCount) { |
| 119 const NSRect bounds = [view convertRect:[view bounds] toView:nil]; |
| 120 const NSPoint mid_point = NSMakePoint(NSMidX(bounds), NSMidY(bounds)); |
| 121 NSEvent* down = MouseEventAtPointInWindow(mid_point, NSRightMouseDown, |
| 122 [view window], clickCount); |
| 123 NSEvent* up = MouseEventAtPointInWindow(mid_point, NSRightMouseUp, |
| 124 [view window], clickCount); |
| 125 return std::make_pair(down, up); |
| 126 } |
| 127 |
117 NSEvent* KeyEventWithCharacter(unichar c) { | 128 NSEvent* KeyEventWithCharacter(unichar c) { |
118 return KeyEventWithKeyCode(0, c, NSKeyDown, 0); | 129 return KeyEventWithKeyCode(0, c, NSKeyDown, 0); |
119 } | 130 } |
120 | 131 |
121 NSEvent* KeyEventWithType(NSEventType event_type, NSUInteger modifiers) { | 132 NSEvent* KeyEventWithType(NSEventType event_type, NSUInteger modifiers) { |
122 return KeyEventWithKeyCode(0x78, 'x', event_type, modifiers); | 133 return KeyEventWithKeyCode(0x78, 'x', event_type, modifiers); |
123 } | 134 } |
124 | 135 |
125 NSEvent* KeyEventWithKeyCode(unsigned short key_code, | 136 NSEvent* KeyEventWithKeyCode(unsigned short key_code, |
126 unichar c, | 137 unichar c, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 context:nil | 236 context:nil |
226 characters:characters | 237 characters:characters |
227 charactersIgnoringModifiers:charactersIgnoringModifiers | 238 charactersIgnoringModifiers:charactersIgnoringModifiers |
228 isARepeat:NO | 239 isARepeat:NO |
229 keyCode:(unsigned short)macKeycode]; | 240 keyCode:(unsigned short)macKeycode]; |
230 | 241 |
231 return event; | 242 return event; |
232 } | 243 } |
233 | 244 |
234 } // namespace cocoa_test_event_utils | 245 } // namespace cocoa_test_event_utils |
OLD | NEW |