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

Unified Diff: chrome/browser/renderer_host/render_widget_host_view_mac.mm

Issue 293019: Send keypress() events for ctrl-key and cmd-key in addition to keydown() (Closed)
Patch Set: rebase tot Created 11 years, 1 month 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
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/renderer_host/render_widget_host_view_mac.mm
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 28245926701416742320792de0552adc4345a289..6e14cbafbc33d99c272da0a6a3224170de7ccbd0 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
@@ -22,10 +22,20 @@
#include "webkit/api/public/WebInputEvent.h"
#include "webkit/glue/webmenurunner_mac.h"
+using WebKit::WebInputEvent;
using WebKit::WebInputEventFactory;
using WebKit::WebMouseEvent;
using WebKit::WebMouseWheelEvent;
+static inline int ToWebKitModifiers(NSUInteger flags) {
pink (ping after 24hrs) 2009/11/11 15:46:16 if this is a bitfield, should it be an unsigned in
Nico 2009/11/12 00:11:16 Technically yes, but the NativeWebKeyboardEvent co
+ int modifiers = 0;
+ if (flags & NSControlKeyMask) modifiers |= WebInputEvent::ControlKey;
+ if (flags & NSShiftKeyMask) modifiers |= WebInputEvent::ShiftKey;
+ if (flags & NSAlternateKeyMask) modifiers |= WebInputEvent::AltKey;
+ if (flags & NSCommandKeyMask) modifiers |= WebInputEvent::MetaKey;
+ return modifiers;
+}
+
@interface RenderWidgetHostViewCocoa (Private)
+ (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event;
- (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r;
@@ -652,9 +662,22 @@ void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) {
// closure. Were it not for that single reference, this object would
// already be deallocated. In that case, there's no point in calling
// -interpretKeyEvents:.
- if ([self retainCount] > 1 && [theEvent type] == NSKeyDown)
+ if ([self retainCount] > 1 && [theEvent type] == NSKeyDown) {
[self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
+ // We don't get insertText: calls if ctrl is down, so synthesize a keypress
+ // event for that case. Note that this makes our behavior deviate from the
+ // windows and linux versions of chrome (however, see http://crbug.com/13891
+ // ), but it makes us similar to how Safari behaves.
pink (ping after 24hrs) 2009/11/11 15:46:16 should you be specific about Mac Safari? Does Win
Nico 2009/11/12 00:11:16 Safari/win seems to be similar. At least for keys
+ if ([theEvent modifierFlags] & (NSControlKeyMask | NSCommandKeyMask) &&
pink (ping after 24hrs) 2009/11/11 15:46:16 the comment only mentions control, but this fires
Nico 2009/11/12 00:11:16 Updated the comment.
+ lastKeyPressedEvent_.get() != theEvent) {
+ NativeWebKeyboardEvent event([[theEvent characters] characterAtIndex:0],
+ ToWebKitModifiers([theEvent modifierFlags]),
+ base::Time::Now().ToDoubleT());
+ renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event);
+ }
+ }
+
// Possibly autohide the cursor.
if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent])
[NSCursor setHiddenUntilMouseMoves:YES];
@@ -1284,6 +1307,7 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
// character to onkeypress() event handlers.
// 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());
renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event);
@@ -1304,6 +1328,7 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]];
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());
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698