OLD | NEW |
---|---|
(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 "base/strings/sys_string_conversions.h" | |
6 #include "content/browser/devtools/protocol/native_input_event_builder.h" | |
7 #include "third_party/WebKit/public/platform/WebInputEvent.h" | |
8 #include <Cocoa/Cocoa.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 gfx::NativeEvent NativeInputEventBuilder::Build( | |
16 const NativeWebKeyboardEvent& event) { | |
17 NSEventType type = NSKeyUp; | |
18 if (event.type() == blink::WebInputEvent::RawKeyDown || | |
19 event.type() == blink::WebInputEvent::KeyDown) | |
20 type = NSKeyDown; | |
21 const blink::WebUChar* textStartAddr = &event.text[0]; | |
22 const int textLength = | |
23 std::find(textStartAddr, | |
24 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
| |
25 textStartAddr; | |
26 NSString* character = | |
27 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
| |
28 int modifiers = event.modifiers(); | |
29 NSUInteger flags = | |
30 (modifiers & blink::WebInputEvent::ShiftKey ? NSShiftKeyMask : 0) | | |
31 (modifiers & blink::WebInputEvent::ControlKey ? NSControlKeyMask : 0) | | |
32 (modifiers & blink::WebInputEvent::AltKey ? NSAlternateKeyMask : 0) | | |
33 (modifiers & blink::WebInputEvent::MetaKey ? NSCommandKeyMask : 0); | |
34 | |
35 return [[NSEvent keyEventWithType:type | |
36 location:NSZeroPoint | |
37 modifierFlags:flags | |
38 timestamp:0 | |
39 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
| |
40 context:nil | |
41 characters:character | |
42 charactersIgnoringModifiers:character | |
43 isARepeat:NO | |
44 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
| |
45 }; | |
46 | |
47 } // namespace protocol | |
48 } // namespace content | |
OLD | NEW |