diff options
Diffstat (limited to 'WebKit/mac/Plugins/WebNetscapePluginEventHandlerCocoa.mm')
-rw-r--r-- | WebKit/mac/Plugins/WebNetscapePluginEventHandlerCocoa.mm | 82 |
1 files changed, 80 insertions, 2 deletions
diff --git a/WebKit/mac/Plugins/WebNetscapePluginEventHandlerCocoa.mm b/WebKit/mac/Plugins/WebNetscapePluginEventHandlerCocoa.mm index 288a356..e3fb362 100644 --- a/WebKit/mac/Plugins/WebNetscapePluginEventHandlerCocoa.mm +++ b/WebKit/mac/Plugins/WebNetscapePluginEventHandlerCocoa.mm @@ -27,10 +27,16 @@ #import "WebNetscapePluginEventHandlerCocoa.h" +#import "WebKitSystemInterface.h" #import "WebNetscapePluginView.h" +#import <wtf/UnusedParam.h> +#import <wtf/Vector.h> WebNetscapePluginEventHandlerCocoa::WebNetscapePluginEventHandlerCocoa(WebNetscapePluginView* pluginView) : WebNetscapePluginEventHandler(pluginView) +#ifndef __LP64__ + , m_keyEventHandler(0) +#endif { } @@ -117,9 +123,13 @@ void WebNetscapePluginEventHandlerCocoa::keyDown(NSEvent *event) { bool retval = sendKeyEvent(event, NPCocoaEventKeyDown); +#ifndef __LP64__ // If the plug-in did not handle the event, pass it on to the Input Manager. - if (!retval) - [m_pluginView interpretKeyEvents:[NSArray arrayWithObject:event]]; + if (retval) + WKSendKeyEventToTSM(event); +#else + UNUSED_PARAM(retval); +#endif } void WebNetscapePluginEventHandlerCocoa::keyUp(NSEvent *event) @@ -173,6 +183,11 @@ void WebNetscapePluginEventHandlerCocoa::focusChanged(bool hasFocus) event.data.focus.hasFocus = hasFocus; sendEvent(&event); + + if (hasFocus) + installKeyEventHandler(); + else + removeKeyEventHandler(); } void* WebNetscapePluginEventHandlerCocoa::platformWindow(NSWindow* window) @@ -202,4 +217,67 @@ bool WebNetscapePluginEventHandlerCocoa::sendEvent(NPCocoaEvent* event) return result; } +#ifndef __LP64__ + +void WebNetscapePluginEventHandlerCocoa::installKeyEventHandler() +{ + static const EventTypeSpec TSMEvents[] = + { + { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } + }; + + if (!m_keyEventHandler) + InstallEventHandler(GetWindowEventTarget((WindowRef)[[m_pluginView window] windowRef]), + NewEventHandlerUPP(TSMEventHandler), + GetEventTypeCount(TSMEvents), + TSMEvents, + this, + &m_keyEventHandler); +} + +void WebNetscapePluginEventHandlerCocoa::removeKeyEventHandler() +{ + if (m_keyEventHandler) { + RemoveEventHandler(m_keyEventHandler); + m_keyEventHandler = 0; + } +} + +OSStatus WebNetscapePluginEventHandlerCocoa::TSMEventHandler(EventHandlerCallRef inHandlerRef, EventRef event, void* eventHandler) +{ + return static_cast<WebNetscapePluginEventHandlerCocoa*>(eventHandler)->handleTSMEvent(event); +} + +OSStatus WebNetscapePluginEventHandlerCocoa::handleTSMEvent(EventRef eventRef) +{ + ASSERT(GetEventKind(eventRef) == kEventTextInputUnicodeForKeyEvent); + + // Get the text buffer size. + ByteCount size; + OSStatus result = GetEventParameter(eventRef, kEventParamTextInputSendText, typeUnicodeText, 0, 0, &size, 0); + if (result != noErr) + return result; + + unsigned length = size / sizeof(UniChar); + Vector<UniChar, 16> characters(length); + + // Now get the actual text. + result = GetEventParameter(eventRef, kEventParamTextInputSendText, typeUnicodeText, 0, size, 0, characters.data()); + if (result != noErr) + return result; + + RetainPtr<CFStringRef> text(AdoptCF, CFStringCreateWithCharacters(0, characters.data(), length)); + + NPCocoaEvent event; + + initializeEvent(&event, NPCocoaEventTextInput); + event.data.text.text = (NPNSString*)text.get(); + + sendEvent(&event); + + return noErr; +} + +#endif // __LP64__ + #endif // ENABLE(NETSCAPE_PLUGIN_API) |