From cb1584d112fe208d12888cd21c563135e1383414 Mon Sep 17 00:00:00 2001 From: kocienda Date: Tue, 20 Jul 2004 23:32:08 +0000 Subject: [PATCH] WebCore: Reviewed by Richard * khtml/xml/dom_elementimpl.cpp: (ElementImpl::defaultEventHandler): No longer check whether the command key is modifying the key event. This check is now done elsewhere in the code. See the WebKit checkin that added the _web_keyBindingManagerHasBinding method to WebNSEventExtras. WebKit: Reviewed by Richard * Misc.subproj/WebNSEventExtras.h: Added helper that returns whether a key event has a binding in the key binding manager. * Misc.subproj/WebNSEventExtras.m: (-[NSEvent _web_keyBindingManagerHasBinding]): New helper mentioned above. * Plugins.subproj/npruntime.h: * WebView.subproj/WebHTMLView.m: (-[WebHTMLView performKeyEquivalent:]): Add a check of whether the key event has a binding in the key binding manager. This works around the fact that NSResponder's interpretKeyEvents does not return a value telling whether or not the key was handled. This now makes it possible for us to trap modified key events we know we can handle (like those command-key + arrow events used for text navigation), while letting all others pass. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@7077 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog-2005-08-23 | 11 +++++++++++ WebCore/khtml/xml/dom_elementimpl.cpp | 3 +-- WebKit/ChangeLog | 17 +++++++++++++++++ WebKit/Misc.subproj/WebNSEventExtras.h | 2 ++ WebKit/Misc.subproj/WebNSEventExtras.m | 8 ++++++++ WebKit/WebView.subproj/WebHTMLView.m | 11 ++++------- 6 files changed, 43 insertions(+), 9 deletions(-) diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23 index e325879..c0c0360 100644 --- a/WebCore/ChangeLog-2005-08-23 +++ b/WebCore/ChangeLog-2005-08-23 @@ -1,3 +1,14 @@ +2004-07-20 Ken Kocienda + + Reviewed by Richard + + * khtml/xml/dom_elementimpl.cpp: + (ElementImpl::defaultEventHandler): No longer check whether + the command key is modifying the key event. This check is + now done elsewhere in the code. See the WebKit checkin that + added the _web_keyBindingManagerHasBinding method to + WebNSEventExtras. + 2004-07-20 Chris Blumenberg Fixed: diff --git a/WebCore/khtml/xml/dom_elementimpl.cpp b/WebCore/khtml/xml/dom_elementimpl.cpp index 1521287..359ccfa 100644 --- a/WebCore/khtml/xml/dom_elementimpl.cpp +++ b/WebCore/khtml/xml/dom_elementimpl.cpp @@ -378,8 +378,7 @@ void ElementImpl::defaultEventHandler(EventImpl *evt) #if APPLE_CHANGES if (evt->id() == EventImpl::KEYPRESS_EVENT && isContentEditable()) { KHTMLPart *part = getDocument()->part(); - // Don't treat command-key combos as editing key events - if (part && !static_cast(evt)->metaKey() && KWQ(part)->interceptEditingKeyEvent()) + if (part && KWQ(part)->interceptEditingKeyEvent()) evt->setDefaultHandled(); } #endif diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog index 54e3d7a..a0b18b5 100644 --- a/WebKit/ChangeLog +++ b/WebKit/ChangeLog @@ -1,3 +1,20 @@ +2004-07-20 Ken Kocienda + + Reviewed by Richard + + * Misc.subproj/WebNSEventExtras.h: Added helper that returns whether + a key event has a binding in the key binding manager. + * Misc.subproj/WebNSEventExtras.m: + (-[NSEvent _web_keyBindingManagerHasBinding]): New helper mentioned above. + * Plugins.subproj/npruntime.h: + * WebView.subproj/WebHTMLView.m: + (-[WebHTMLView performKeyEquivalent:]): Add a check of whether the key event + has a binding in the key binding manager. This works around the fact that + NSResponder's interpretKeyEvents does not return a value telling whether + or not the key was handled. This now makes it possible for us to trap + modified key events we know we can handle (like those command-key + arrow events + used for text navigation), while letting all others pass. + 2004-07-20 Chris Blumenberg Fixed: diff --git a/WebKit/Misc.subproj/WebNSEventExtras.h b/WebKit/Misc.subproj/WebNSEventExtras.h index 600d534..b90cb61 100644 --- a/WebKit/Misc.subproj/WebNSEventExtras.h +++ b/WebKit/Misc.subproj/WebNSEventExtras.h @@ -15,4 +15,6 @@ -(BOOL)_web_isReturnOrEnterKeyEvent; -(BOOL)_web_isTabKeyEvent; +- (BOOL)_web_keyBindingManagerHasBinding; + @end diff --git a/WebKit/Misc.subproj/WebNSEventExtras.m b/WebKit/Misc.subproj/WebNSEventExtras.m index f9c0881..2743dfe 100644 --- a/WebKit/Misc.subproj/WebNSEventExtras.m +++ b/WebKit/Misc.subproj/WebNSEventExtras.m @@ -5,6 +5,8 @@ #import +#import + @implementation NSEvent (WebExtras) -(BOOL)_web_isKeyEvent:(unichar)key @@ -56,4 +58,10 @@ return [self _web_isKeyEvent:tabKey] || [self _web_isKeyEvent:shiftTabKey]; } +- (BOOL)_web_keyBindingManagerHasBinding +{ + NSDictionary *keyBindings = [[NSKeyBindingManager sharedKeyBindingManager] dictionary]; + return [keyBindings objectForKey:[self characters]] != nil; +} + @end diff --git a/WebKit/WebView.subproj/WebHTMLView.m b/WebKit/WebView.subproj/WebHTMLView.m index 8d7509d..e1822693 100644 --- a/WebKit/WebView.subproj/WebHTMLView.m +++ b/WebKit/WebView.subproj/WebHTMLView.m @@ -2271,15 +2271,12 @@ static WebHTMLView *lastHitView = nil; - (BOOL)performKeyEquivalent:(NSEvent *)event { - // Pass command-key combos through WebCore so Command-return on an active link is treated - // as a modified activation rather than ignored. Note that this means web pages have a crack - // at intercepting command-modified keypresses now. If this turns out to cause havoc we - // can restrict this to only send the event through WebCore if it contains the Return or - // Enter key. - if ([self firstResponderIsSelfOrDescendantView] && [[self _bridge] interceptKeyEvent:event toView:self]) { + // Pass command-key combos through WebCore if there is a key binding available for + // this event. This lets web pages have a crack at intercepting command-modified keypresses. + if ([self firstResponderIsSelfOrDescendantView] && [event _web_keyBindingManagerHasBinding]) { + [[self _bridge] interceptKeyEvent:event toView:self]; return YES; } - return [super performKeyEquivalent:event]; } -- 1.8.3.1