• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 #ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_MAC_H_
6 #define UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_MAC_H_
7 
8 #import <Cocoa/Cocoa.h>
9 
10 #include "base/basictypes.h"
11 #include "ui/events/events_base_export.h"
12 #include "ui/events/keycodes/keyboard_codes_posix.h"
13 
14 namespace ui {
15 
16 // We use windows virtual keycodes throughout our keyboard event related code,
17 // including unit tests. But Mac uses a different set of virtual keycodes.
18 // This function converts a windows virtual keycode into Mac's virtual key code
19 // and corresponding unicode character. |flags| is the modifiers mask such
20 // as NSControlKeyMask, NSShiftKeyMask, etc.
21 // When success, the corresponding Mac's virtual key code will be returned.
22 // The corresponding unicode character will be stored in |character|, and the
23 // corresponding unicode character ignoring the modifiers will be stored in
24 // |characterIgnoringModifiers|.
25 // -1 will be returned if the keycode can't be converted.
26 // This function is mainly for simulating keyboard events in unit tests.
27 // See |KeyboardCodeFromNSEvent| for reverse conversion.
28 EVENTS_BASE_EXPORT int MacKeyCodeForWindowsKeyCode(
29     KeyboardCode keycode,
30     NSUInteger flags,
31     unichar* character,
32     unichar* characterIgnoringModifiers);
33 
34 // This implementation cribbed from:
35 //   third_party/WebKit/Source/web/mac/WebInputEventFactory.mm
36 // Converts |event| into a |KeyboardCode|.  The mapping is not direct as the Mac
37 // has a different notion of key codes.
38 EVENTS_BASE_EXPORT KeyboardCode KeyboardCodeFromNSEvent(NSEvent* event);
39 
40 EVENTS_BASE_EXPORT const char* CodeFromNSEvent(NSEvent* event);
41 
42 } // namespace ui
43 
44 #endif  // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_MAC_H_
45