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

Unified Diff: content/browser/devtools/protocol/native_input_event_builder_mac.mm

Issue 2656903005: ChromeDriver: Handle key events properly on Mac (Closed)
Patch Set: changes Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/devtools/protocol/native_input_event_builder_mac.mm
diff --git a/content/browser/devtools/protocol/native_input_event_builder_mac.mm b/content/browser/devtools/protocol/native_input_event_builder_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..865556763d4ea692085b7579970f7394ddb9d4c8
--- /dev/null
+++ b/content/browser/devtools/protocol/native_input_event_builder_mac.mm
@@ -0,0 +1,48 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/strings/sys_string_conversions.h"
+#include "content/browser/devtools/protocol/native_input_event_builder.h"
+#include "third_party/WebKit/public/platform/WebInputEvent.h"
+#include <Cocoa/Cocoa.h>
+
+namespace content {
+namespace protocol {
+
+// Mac requires a native event to emulate key events. This method gives
+// only crude capabilities (see: crbug.com/667387).
+gfx::NativeEvent NativeInputEventBuilder::Build(
+ const NativeWebKeyboardEvent& event) {
+ NSEventType type = NSKeyUp;
+ if (event.type() == blink::WebInputEvent::RawKeyDown ||
+ event.type() == blink::WebInputEvent::KeyDown)
+ type = NSKeyDown;
+ const blink::WebUChar* textStartAddr = &event.text[0];
+ const int textLength =
+ std::find(textStartAddr,
+ textStartAddr + NativeWebKeyboardEvent::textLengthCap, '\0') -
erikchen 2017/02/15 22:21:16 What if '\0' isn't found? It looks like textLength
allada 2017/02/17 18:30:58 In this case it is what I want. event.text is a fi
erikchen 2017/02/17 19:15:50 My point was that if you don't find '\0', you prob
allada 2017/03/06 23:34:33 If we don't find \0 I think we do want to use all
+ textStartAddr;
+ NSString* character =
+ base::SysUTF16ToNSString(base::string16(textStartAddr, textLength));
erikchen 2017/02/15 22:21:16 This could be more than one character. Do you want
allada 2017/02/17 18:30:58 Yes it could be more than 1 character, from what I
+ int modifiers = event.modifiers();
+ NSUInteger flags =
+ (modifiers & blink::WebInputEvent::ShiftKey ? NSShiftKeyMask : 0) |
+ (modifiers & blink::WebInputEvent::ControlKey ? NSControlKeyMask : 0) |
+ (modifiers & blink::WebInputEvent::AltKey ? NSAlternateKeyMask : 0) |
+ (modifiers & blink::WebInputEvent::MetaKey ? NSCommandKeyMask : 0);
+
+ return [[NSEvent keyEventWithType:type
+ location:NSZeroPoint
+ modifierFlags:flags
+ timestamp:0
+ windowNumber:0
erikchen 2017/02/15 22:21:16 Is it okay to leave all these fields empty?
allada 2017/02/17 18:30:58 It was modeled mostly after this: https://cs.chrom
erikchen 2017/02/17 19:15:49 That event is just being used as a wrapper as a ca
allada 2017/03/06 23:34:33 I do not believe it does get passed to AppKit. The
+ context:nil
+ characters:character
+ charactersIgnoringModifiers:character
+ isARepeat:NO
+ keyCode:event.nativeKeyCode] retain];
erikchen 2017/02/15 22:21:16 This code *looks* like it will leak. That's dealt
allada 2017/02/17 18:30:58 Per our offline discussion, I made appropriate cha
+};
+
+} // namespace protocol
+} // namespace content
« 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