From b0435f2ffad50b07fd8f99e4c4da8395287787bf Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 26 Sep 2012 16:45:01 +0000 Subject: [PATCH] Merge revision 799 changes: - Mac: Trigger keydown events for single keystrokes (issue #664). git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1025@801 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/browser_webview_mac.h | 3 +++ libcef/browser_webview_mac.mm | 47 +++++++++++++++++++++++++++++++++-- libcef/webwidget_host.h | 3 +++ libcef/webwidget_host_mac.mm | 37 --------------------------- 4 files changed, 51 insertions(+), 39 deletions(-) diff --git a/libcef/browser_webview_mac.h b/libcef/browser_webview_mac.h index c219620dc..557d2e339 100644 --- a/libcef/browser_webview_mac.h +++ b/libcef/browser_webview_mac.h @@ -80,6 +80,9 @@ struct WebDropData; - (BOOL)isOpaque; - (void)setFrame:(NSRect)frameRect; +// Forward the keyboard event to the editor +- (void)forwardKeyEventToEditor: (NSEvent *)theEvent; + // Register this WebView as a drag/drop target. - (void)registerDragDrop; diff --git a/libcef/browser_webview_mac.mm b/libcef/browser_webview_mac.mm index f60368f33..35a4f9fa3 100644 --- a/libcef/browser_webview_mac.mm +++ b/libcef/browser_webview_mac.mm @@ -198,6 +198,9 @@ void ExtractUnderlines( // This code is mostly copied and adapted from // content/browser/renderer_host/render_widget_host_mac - (void)keyDown:(NSEvent *)theEvent { + if (browser_ && browser_->UIT_GetWebView()) + browser_->UIT_GetWebViewHost()->KeyEvent(theEvent); + // Records the current marked text state, so that we can know if the marked // text was deleted or not after handling the key down event. BOOL oldHasMarkedText = hasMarkedText_; @@ -208,7 +211,7 @@ void ExtractUnderlines( if (hasMarkedText_ && underlines_.size() <= 1) { // Check for backspace or delete. if ([theEvent keyCode] == 0x33 || [theEvent keyCode] == 0x75) - browser_->UIT_GetWebViewHost()->KeyEvent(theEvent); + [self forwardKeyEventToEditor: theEvent]; } textToBeInserted_.clear(); @@ -235,7 +238,7 @@ void ExtractUnderlines( keyboard_event.text[1] = 0; browser_->UIT_GetWebView()->handleInputEvent(keyboard_event); } else { - browser_->UIT_GetWebViewHost()->KeyEvent(theEvent); + [self forwardKeyEventToEditor: theEvent]; } } @@ -266,6 +269,46 @@ void ExtractUnderlines( } } +- (void)forwardKeyEventToEditor: (NSEvent *)theEvent { + if ([theEvent type] != NSKeyDown) + return; + + if ([theEvent modifierFlags] & (NSNumericPadKeyMask | NSFunctionKeyMask)) { + // Don't send a Char event for non-char keys like arrows, function keys and + // clear. + switch ([theEvent keyCode]) { + case 81: // = + case 75: // / + case 67: // * + case 78: // - + case 69: // + + case 76: // Enter + case 65: // . + case 82: // 0 + case 83: // 1 + case 84: // 2 + case 85: // 3 + case 86: // 4 + case 87: // 5 + case 88: // 6 + case 89: // 7 + case 91: // 8 + case 92: // 9 + break; + default: + return; + } + } + + if (browser_ && browser_->UIT_GetWebView()) { + WebKeyboardEvent keyboard_event( + WebInputEventFactory::keyboardEvent(theEvent)); + keyboard_event.type = WebInputEvent::Char; + browser_->UIT_GetWebViewHost()->SetLastKeyEvent(keyboard_event); + browser_->UIT_GetWebView()->handleInputEvent(keyboard_event); + } +} + - (void)keyUp:(NSEvent *)theEvent { if (browser_ && browser_->UIT_GetWebView()) browser_->UIT_GetWebViewHost()->KeyEvent(theEvent); diff --git a/libcef/webwidget_host.h b/libcef/webwidget_host.h index 74b3633fd..9934660da 100644 --- a/libcef/webwidget_host.h +++ b/libcef/webwidget_host.h @@ -106,6 +106,9 @@ class WebWidgetHost { WebKit::WebScreenInfo GetScreenInfo(); WebKit::WebKeyboardEvent GetLastKeyEvent() const { return last_key_event_; } + + void SetLastKeyEvent(WebKit::WebKeyboardEvent keyEvent) + { last_key_event_ = keyEvent; } void SetTooltipText(const CefString& tooltip_text); diff --git a/libcef/webwidget_host_mac.mm b/libcef/webwidget_host_mac.mm index 34271ed29..180c74fc9 100644 --- a/libcef/webwidget_host_mac.mm +++ b/libcef/webwidget_host_mac.mm @@ -318,43 +318,6 @@ void WebWidgetHost::KeyEvent(NSEvent *event) { WebKeyboardEvent keyboard_event(WebInputEventFactory::keyboardEvent(event)); last_key_event_ = keyboard_event; webwidget_->handleInputEvent(keyboard_event); - - if ([event type] != NSKeyDown) - return; - - if ([event modifierFlags] & (NSNumericPadKeyMask | NSFunctionKeyMask)) { - // Don't send a Char event for non-char keys like arrows, function keys and - // clear. - switch ([event keyCode]) { - case 81: // = - case 75: // / - case 67: // * - case 78: // - - case 69: // + - case 76: // Enter - case 65: // . - case 82: // 0 - case 83: // 1 - case 84: // 2 - case 85: // 3 - case 86: // 4 - case 87: // 5 - case 88: // 6 - case 89: // 7 - case 91: // 8 - case 92: // 9 - break; - default: - return; - } - } - - // Send a Char event here to emulate the keyboard events. - // TODO(hbono): Bug 20852 implement the NSTextInput - // protocol and remove this code. - keyboard_event.type = WebInputEvent::Char; - last_key_event_ = keyboard_event; - webwidget_->handleInputEvent(keyboard_event); } void WebWidgetHost::SetFocus(bool enable) {