| 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 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" | 9 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" |
| 10 #include "ui/events/test/cocoa_test_event_utils.h" | 10 #include "ui/events/test/cocoa_test_event_utils.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 data2:0]; | 183 data2:0]; |
| 184 } | 184 } |
| 185 | 185 |
| 186 NSTimeInterval TimeIntervalSinceSystemStartup() { | 186 NSTimeInterval TimeIntervalSinceSystemStartup() { |
| 187 return UpTimeInNanoseconds() / 1000000000.0; | 187 return UpTimeInNanoseconds() / 1000000000.0; |
| 188 } | 188 } |
| 189 | 189 |
| 190 NSEvent* SynthesizeKeyEvent(NSWindow* window, | 190 NSEvent* SynthesizeKeyEvent(NSWindow* window, |
| 191 bool keyDown, | 191 bool keyDown, |
| 192 ui::KeyboardCode keycode, | 192 ui::KeyboardCode keycode, |
| 193 NSUInteger flags) { | 193 NSUInteger flags, |
| 194 ui::DomKey dom_key) { |
| 194 // If caps lock is set for an alpha keycode, treat it as if shift was pressed. | 195 // If caps lock is set for an alpha keycode, treat it as if shift was pressed. |
| 195 // Note on Mac (unlike other platforms) shift while caps is down does not go | 196 // Note on Mac (unlike other platforms) shift while caps is down does not go |
| 196 // back to lowercase. | 197 // back to lowercase. |
| 197 if (keycode >= ui::VKEY_A && keycode <= ui::VKEY_Z && | 198 if (keycode >= ui::VKEY_A && keycode <= ui::VKEY_Z && |
| 198 (flags & NSAlphaShiftKeyMask)) | 199 (flags & NSAlphaShiftKeyMask)) |
| 199 flags |= NSShiftKeyMask; | 200 flags |= NSShiftKeyMask; |
| 200 | 201 |
| 201 // Clear caps regardless -- MacKeyCodeForWindowsKeyCode doesn't implement | 202 // Clear caps regardless -- MacKeyCodeForWindowsKeyCode doesn't implement |
| 202 // logic to support it. | 203 // logic to support it. |
| 203 flags &= ~NSAlphaShiftKeyMask; | 204 flags &= ~NSAlphaShiftKeyMask; |
| 204 | 205 |
| 205 unichar character; | 206 unichar character; |
| 206 unichar shifted_character; | 207 unichar shifted_character; |
| 207 int macKeycode = ui::MacKeyCodeForWindowsKeyCode( | 208 int macKeycode = ui::MacKeyCodeForWindowsKeyCode( |
| 208 keycode, flags, &shifted_character, &character); | 209 keycode, flags, &shifted_character, &character); |
| 209 | 210 |
| 210 if (macKeycode < 0) | 211 if (macKeycode < 0) |
| 211 return nil; | 212 return nil; |
| 212 | 213 |
| 214 // If an explicit unicode character is provided, use that instead of the one |
| 215 // derived from the keycode. |
| 216 if (dom_key.IsCharacter()) |
| 217 shifted_character = dom_key.ToCharacter(); |
| 218 |
| 213 // Note that, in line with AppKit's documentation (and tracing "real" events), | 219 // Note that, in line with AppKit's documentation (and tracing "real" events), |
| 214 // -[NSEvent charactersIngoringModifiers]" are "the characters generated by | 220 // -[NSEvent charactersIngoringModifiers]" are "the characters generated by |
| 215 // the receiving key event as if no modifier key (except for Shift)". | 221 // the receiving key event as if no modifier key (except for Shift)". |
| 216 // So |charactersIgnoringModifiers| uses |shifted_character|. | 222 // So |charactersIgnoringModifiers| uses |shifted_character|. |
| 217 NSString* charactersIgnoringModifiers = | 223 NSString* charactersIgnoringModifiers = |
| 218 [[[NSString alloc] initWithCharacters:&shifted_character | 224 [[[NSString alloc] initWithCharacters:&shifted_character |
| 219 length:1] autorelease]; | 225 length:1] autorelease]; |
| 220 NSString* characters; | 226 NSString* characters; |
| 221 // The following were determined empirically on OSX 10.9. | 227 // The following were determined empirically on OSX 10.9. |
| 222 if (flags & NSControlKeyMask) { | 228 if (flags & NSControlKeyMask) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 context:nil | 262 context:nil |
| 257 characters:characters | 263 characters:characters |
| 258 charactersIgnoringModifiers:charactersIgnoringModifiers | 264 charactersIgnoringModifiers:charactersIgnoringModifiers |
| 259 isARepeat:NO | 265 isARepeat:NO |
| 260 keyCode:(unsigned short)macKeycode]; | 266 keyCode:(unsigned short)macKeycode]; |
| 261 | 267 |
| 262 return event; | 268 return event; |
| 263 } | 269 } |
| 264 | 270 |
| 265 } // namespace cocoa_test_event_utils | 271 } // namespace cocoa_test_event_utils |
| OLD | NEW |