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

Side by Side Diff: content/browser/devtools/protocol/native_input_event_builder_mac.mm

Issue 2656903005: ChromeDriver: Handle key events properly on Mac (Closed)
Patch Set: fixes Created 3 years, 5 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
OLDNEW
(Empty)
1 // Copyright 2017 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 #include <Cocoa/Cocoa.h>
6 #include "base/strings/sys_string_conversions.h"
7 #include "content/browser/devtools/protocol/native_input_event_builder.h"
8 #include "third_party/WebKit/public/platform/WebInputEvent.h"
9
10 namespace content {
11 namespace protocol {
12
13 // Mac requires a native event to emulate key events. This method gives
14 // only crude capabilities (see: crbug.com/667387).
15 // The returned object has a retain count of 1.
16 gfx::NativeEvent NativeInputEventBuilder::CreateEvent(
17 const NativeWebKeyboardEvent& event) {
18 NSEventType type = NSKeyUp;
19 if (event.GetType() == blink::WebInputEvent::kRawKeyDown ||
20 event.GetType() == blink::WebInputEvent::kKeyDown)
21 type = NSKeyDown;
22 const blink::WebUChar* textStartAddr = &event.text[0];
23 const int textLength =
24 std::find(textStartAddr,
25 textStartAddr + NativeWebKeyboardEvent::kTextLengthCap, '\0') -
26 textStartAddr;
27 NSString* character =
28 base::SysUTF16ToNSString(base::string16(textStartAddr, textLength));
29 int modifiers = event.GetModifiers();
30 NSUInteger flags =
31 (modifiers & blink::WebInputEvent::kShiftKey ? NSShiftKeyMask : 0) |
32 (modifiers & blink::WebInputEvent::kControlKey ? NSControlKeyMask : 0) |
33 (modifiers & blink::WebInputEvent::kAltKey ? NSAlternateKeyMask : 0) |
34 (modifiers & blink::WebInputEvent::kMetaKey ? NSCommandKeyMask : 0);
35
36 return [[NSEvent keyEventWithType:type
37 location:NSZeroPoint
38 modifierFlags:flags
39 timestamp:0
40 windowNumber:0
41 context:nil
42 characters:character
43 charactersIgnoringModifiers:character
44 isARepeat:NO
45 keyCode:event.native_key_code] retain];
46 };
47
48 } // namespace protocol
49 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/protocol/native_input_event_builder.h ('k') | third_party/WebKit/Source/devtools/front_end/Tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698