diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-16 18:36:54 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-16 18:36:54 +0000 |
commit | 4f5f5b4569383133679901212efac1326e4be1e1 (patch) | |
tree | 16d49682d8a3b3abcaedb85e18624a1b57fb0474 /webkit/glue | |
parent | ebbb4cb63575cab7623a9e2aa60a6f995684ae6a (diff) | |
download | chromium_src-4f5f5b4569383133679901212efac1326e4be1e1.zip chromium_src-4f5f5b4569383133679901212efac1326e4be1e1.tar.gz chromium_src-4f5f5b4569383133679901212efac1326e4be1e1.tar.bz2 |
Infer caps lock state to set for Mac plugin events
BUG=38098
TEST=Plugins should know when caps lock is active.
Review URL: http://codereview.chromium.org/989002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41737 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_impl_mac.mm | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm index 8b484b6..19815b9 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm +++ b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm @@ -799,6 +799,26 @@ static bool WebInputEventIsWebKeyboardEvent(const WebInputEvent& event) { } } +// Returns true if the caps lock flag should be set for the given event. +// TODO: Ideally the event itself would know about the caps lock key; see +// <http://crbug.com/38226>. This function is only a temporary workaround that +// guesses based on live state. +static bool CapsLockIsActive(const WebInputEvent& event) { + NSUInteger current_flags = [[NSApp currentEvent] modifierFlags]; + bool caps_lock_on = (current_flags & NSAlphaShiftKeyMask) ? true : false; + // If this a caps lock keypress, then the event stream state can be wrong. + // Luckily, the weird event stream for caps lock makes it easy to tell whether + // caps lock is being turned on or off. + if (event.type == WebInputEvent::KeyDown || + event.type == WebInputEvent::KeyUp) { + const WebKeyboardEvent* key_event = + static_cast<const WebKeyboardEvent*>(&event); + if (key_event->nativeKeyCode == 57) + caps_lock_on = (event.type == WebInputEvent::KeyDown); + } + return caps_lock_on; +} + #ifndef NP_NO_CARBON static NSInteger CarbonModifiersFromWebEvent(const WebInputEvent& event) { NSInteger modifiers = 0; @@ -810,6 +830,8 @@ static NSInteger CarbonModifiersFromWebEvent(const WebInputEvent& event) { modifiers |= optionKey; if (event.modifiers & WebInputEvent::MetaKey) modifiers |= cmdKey; + if (CapsLockIsActive(event)) + modifiers |= alphaLock; return modifiers; } @@ -906,6 +928,8 @@ static NSInteger CocoaModifiersFromWebEvent(const WebInputEvent& event) { modifiers |= NSAlternateKeyMask; if (event.modifiers & WebInputEvent::MetaKey) modifiers |= NSCommandKeyMask; + if (CapsLockIsActive(event)) + modifiers |= NSAlphaShiftKeyMask; return modifiers; } |