Hi All,
We currently fudge our keyboard handling on OSX, we interpret command key
shortcuts ourselves and thus miss out on quite a few Cocoa text handling
niceities.  We also don't support IMEs.

Relevant bugs:
http://crbug.com/10862 - OS X: Can't use command-key shortcuts with foreign
keyboard layouts
http://crbug.com/12698 - standard macintosh text editing keyboard shortcuts
are missing
http://crbug.com/11981 - Deadkeys do not work
http://crbug.com/11952 - IME support (Chinese input method doesnt work)
We also don't handle activation/deactivation of edit menu items correctly
(select all is always disabled).

I've done a little digging in WebKit's keyboard handling and what follows is
a proposal on how we can more closely match the OSX keyboard handling code
and [hopefully] do things the right way.  I don't purport to understand this
all and there may be simpler ways to achieve this so feel free to comment.

Standard commands (Copy/Paste/Select-all):

WebKit handles these through the regular obj-c selectors in WebHTMLView, see
the WEBCORE_COMMAND macro.

We could do the same thing and add these selectors
to BrowserWindowController which would then send an IPC message over to the
renderer process to execute the appropriate command.

The tricky bit is updating the menus, the model in Cocoa is for the OS to
call you for each menu item before displaying a menu.  We can't block the
browser process on the renderer process so the browser process would always
need to know if there is an active selection.  WebCore appears to already
have a mechanism to do this via notifyAccessibilityForSelectionChange() - we
could use the same or a similar mechanism to send an IPC message back to the
browser process each time the selection changes.

Emacs keyboard commands and IMEs:

The IME part of the title may be nonsense, but looking at the code it
appears the code path and issues are the same.

I've attached the stack trace for hitting cntrl-t to the end of this email.
 The tricky bit here is that WebCore is first given a shot at handling the
event and then passes it back to WebHTMLView to take another look at the
event which is where it's actually parsed.  I assume this is to give JS code
a chance to listen on these events.

Since we can't serialize an NSEvent, we can't replicate this code solely in
the renderer.

A possible solution to this would be to store a queue of the last N NSEvents
per renderer matched with an ID.  the event would then be serialized and
sent to the renderer which could then send it's own IPC message back to the
browser process to get Cocoa to handle the message, we could pick the
NSEvent out of the queue by ID and send back the relevant edit command to
the renderer.

Since the events belong to a specific renderer a malicious renderer process
can't access events not targeted at them.

Best regards,
Jeremy

Stack trace of hitting cntrl-t (transpose) in a text view, Cocoa
[browser-process] stuff marked in bold.

#0 WebCore::executeTranspose (frame=0x70b9800) at
/Users/Shared/playmobil/work/git.WebKit/WebCore/editing/EditorCommand.cpp:961
#1 0x03702f0f in WebCore::Editor::Command::execute (this=0xbfffe2f4,
paramet...@0xbfffe2ac, triggeringEvent=0x24178380) at
/Users/Shared/playmobil/work/git.WebKit/WebCore/editing/EditorCommand.cpp:1450
#2 0x037052ad in WebCore::Editor::Command::execute (this=0xbfffe2f4,
triggeringEvent=0x24178380) at
/Users/Shared/playmobil/work/git.WebKit/WebCore/editing/EditorCommand.cpp:1455
*#3 0x0031d3da in -[WebHTMLView(WebNSTextInputSupport) doCommandBySelector:]
(self=0x6cefe90, _cmd=0x943edca4, selector=0x94423fa4) at
/Users/Shared/playmobil/work/git.WebKit/WebKit/mac/WebView/WebHTMLView.mm:5337
#4 0x0031c238 in -[WebHTMLView(WebInternal)
_interceptEditingKeyEvent:shouldSaveCommand:] (self=0x6cefe90,
_cmd=0x3a405c, event=0x24178380, shouldSave=0 '\000') at
/Users/Shared/playmobil/work/git.WebKit/WebKit/mac/WebView/WebHTMLView.mm:4966
*#5 0x002eb19b in WebEditorClient::handleKeyboardEvent (this=0x6c31aa0,
event=0x24178380) at
/Users/Shared/playmobil/work/git.WebKit/WebKit/mac/WebCoreSupport/WebEditorClient.mm:440
#6 0x036f8875 in WebCore::Editor::handleKeyboardEvent (this=0x70b9cd4,
event=0x24178380) at
/Users/Shared/playmobil/work/git.WebKit/WebCore/editing/Editor.cpp:105
#7 0x037156fb in WebCore::EventHandler::defaultKeyboardEventHandler
(this=0x70b9d00, event=0x24178380) at
/Users/Shared/playmobil/work/git.WebKit/WebCore/page/EventHandler.cpp:1907
#8 0x03a7876e in WebCore::Node::defaultEventHandler (this=0x1c23f430,
event=0x24178380) at
/Users/Shared/playmobil/work/git.WebKit/WebCore/dom/Node.cpp:2812
#9 0x037c7d17 in WebCore::HTMLInputElement::defaultEventHandler
(this=0x1c23f430, evt=0x24178380) at
/Users/Shared/playmobil/work/git.WebKit/WebCore/html/HTMLInputElement.cpp:1120
#10 0x03a70c27 in WebCore::Node::dispatchGenericEvent (this=0x1c23f430,
prpeve...@0xbfffe63c) at
/Users/Shared/playmobil/work/git.WebKit/WebCore/dom/Node.cpp:2439
#11 0x03a70f0f in WebCore::Node::dispatchEvent (this=0x1c23f430,
e...@0xbfffe6e8, e...@0xbfffe6cc) at
/Users/Shared/playmobil/work/git.WebKit/WebCore/dom/Node.cpp:2336
#12 0x03718720 in WebCore::EventHandler::keyEvent (this=0x70b9d00,
initialkeyeve...@0xbfffe74c) at
/Users/Shared/playmobil/work/git.WebKit/WebCore/page/EventHandler.cpp:1848
#13 0x0371da3b in WebCore::EventHandler::keyEvent (this=0x70b9d00,
event=0x2416ded0) at
/Users/Shared/playmobil/work/git.WebKit/WebCore/page/mac/EventHandlerMac.mm:172
*#14 0x003138ce in -[WebHTMLView performKeyEquivalent:] (self=0x6cefe90,
_cmd=0x94421a60, event=0x2416ded0) at
/Users/Shared/playmobil/work/git.WebKit/WebKit/mac/WebView/WebHTMLView.mm:4013
#15 0x959398b6 in -[NSControl _performKeyEquivalent:conditionally:] ()
#16 0x95939782 in -[NSView performKeyEquivalent:] ()
#17 0x95939782 in -[NSView performKeyEquivalent:] ()
#18 0x95939782 in -[NSView performKeyEquivalent:] ()
#19 0x95939782 in -[NSView performKeyEquivalent:] ()
#20 0x95939782 in -[NSView performKeyEquivalent:] ()
#21 0x95939782 in -[NSView performKeyEquivalent:] ()
#22 0x95939782 in -[NSView performKeyEquivalent:] ()
#23 0x95939782 in -[NSView performKeyEquivalent:] ()
#24 0x959394eb in -[NSWindow performKeyEquivalent:] ()
#25 0x0004dbc1 in ?? ()
#26 0x959391af in -[NSApplication _handleKeyEquivalent:] ()
#27 0x958560fb in -[NSApplication sendEvent:] ()
#28 0x0003918a in ?? ()
#29 0x957b362f in -[NSApplication run] ()
#30 0x95780834 in NSApplicationMain ()
#31 0x00003296 in ?? ()*

--~--~---------~--~----~------------~-------~--~----~
Chromium Developers mailing list: chromium-dev@googlegroups.com 
View archives, change email options, or unsubscribe: 
    http://groups.google.com/group/chromium-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to