diff options
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac.mm | 25 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_mac.mm | 10 |
2 files changed, 19 insertions, 16 deletions
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm index 881a0b3..8317479 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -703,9 +703,9 @@ void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) { lastKeyPressedEvent_.get() != theEvent && [[theEvent characters] length] > 0 && renderWidgetHostView_->render_widget_host_) { - NativeWebKeyboardEvent event([[theEvent characters] characterAtIndex:0], - ToWebKitModifiers([theEvent modifierFlags]), - base::Time::Now().ToDoubleT()); + // Just fabricate a Char event by changing the type of the RawKeyDown + // event, to retain all necessary informations, such as unmodifiedText. + event.type = WebKit::WebInputEvent::Char; // We fire menu items on keydown, we don't want to activate menu items // twice. event.skip_in_browser = true; @@ -1352,8 +1352,13 @@ extern NSString *NSTextInputReplacementRangeAttributeName; // TODO(hbono): need to handle more commands? if (selector == @selector(insertNewline:)) { lastKeyPressedEvent_.reset([[NSApp currentEvent] retain]); - NativeWebKeyboardEvent event('\r', renderWidgetHostView_->im_modifiers_, - base::Time::Now().ToDoubleT()); + // Create the Char event from the NSEvent object, so that we can retain + // necessary informations, especially unmodifiedText. + NativeWebKeyboardEvent event(lastKeyPressedEvent_.get()); + event.type = WebKit::WebInputEvent::Char; + event.text[0] = '\r'; + event.text[1] = 0; + event.skip_in_browser = true; renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); } } @@ -1373,9 +1378,13 @@ extern NSString *NSTextInputReplacementRangeAttributeName; NSString* im_text = isAttributedString ? [string string] : string; if (!renderWidgetHostView_->im_composing_ && [im_text length] == 1) { lastKeyPressedEvent_.reset([[NSApp currentEvent] retain]); - NativeWebKeyboardEvent event([im_text characterAtIndex:0], - renderWidgetHostView_->im_modifiers_, - base::Time::Now().ToDoubleT()); + // Create the Char event from the NSEvent object, so that we can retain + // necessary informations, especially unmodifiedText. + NativeWebKeyboardEvent event(lastKeyPressedEvent_.get()); + event.type = WebKit::WebInputEvent::Char; + event.text[0] = [im_text characterAtIndex:0]; + event.text[1] = 0; + event.skip_in_browser = true; renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); } else { renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index 60bc43a..763aa3b 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -356,17 +356,11 @@ void TabContentsViewMac::Observe(NotificationType type, } - (BOOL)processKeyboardEvent:(NativeWebKeyboardEvent*)wkEvent { - if (wkEvent->skip_in_browser) + if (wkEvent->skip_in_browser || wkEvent->type == WebKit::WebInputEvent::Char) return NO; NSEvent* event = wkEvent->os_event; - - if (!event) { - // Char events are synthesized and do not contain a real event. We are not - // interested in them anyway. - DCHECK(wkEvent->type == WebKit::WebInputEvent::Char); - return NO; - } + DCHECK(event != NULL); // If this tab is no longer active, its window will be |nil|. In that case, // best ignore the event. |