X-Git-Url: http://git.webkit.org/?p=WebKit-https.git;a=blobdiff_plain;f=WebKit%2Fmac%2FPlugins%2FWebBaseNetscapePluginView.mm;h=30d3782e366131128fbd444df867d67271ac344a;hp=7794b070d6190ffb8d393be28a18132b6a474817;hb=0f8ecf1ef91ff02c1aaa2bfb79074c322b593d29;hpb=6fe5aac0fca5473cd506521e930c560dbb960c8c diff --git a/WebKit/mac/Plugins/WebBaseNetscapePluginView.mm b/WebKit/mac/Plugins/WebBaseNetscapePluginView.mm index 7794b07..30d3782 100644 --- a/WebKit/mac/Plugins/WebBaseNetscapePluginView.mm +++ b/WebKit/mac/Plugins/WebBaseNetscapePluginView.mm @@ -63,6 +63,7 @@ #import #import #import +#import #import #import #import @@ -181,6 +182,11 @@ typedef struct { AGLContext oldContext; } PortState_GL; +@class NSInputContext; +@interface NSResponder (IMSecretsIKnowAbout) +- (NSInputContext *)inputContext; +@end + @interface WebPluginRequest : NSObject { NSURLRequest *_request; @@ -1233,6 +1239,18 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) // Create the event handler eventHandler = WebNetscapePluginEventHandler::create(self); + // Get the text input vtable + if (eventModel == NPEventModelCocoa) { + [self willCallPlugInFunction]; + { + KJS::JSLock::DropAllLocks dropAllLocks; + NPPluginTextInputFuncs *value; + if (NPP_GetValue(plugin, NPPVpluginTextInputFuncs, &value) == NPERR_NO_ERROR && value) + textInputFuncs = value; + } + [self didCallPlugInFunction]; + } + isStarted = YES; [self updateAndSetWindow]; @@ -1293,6 +1311,8 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) delete eventHandler; eventHandler = 0; + textInputFuncs = 0; + if (drawingModel == NPDrawingModelOpenGL) [self _destroyAGLContext]; } @@ -1850,6 +1870,158 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) [_manualStream finishedLoading]; } +#pragma mark NSTextInput implementation + +- (NSInputContext *)inputContext +{ + if ([self isStarted] && eventModel == NPEventModelCarbon) + return nil; + + return [super inputContext]; +} + +- (BOOL)hasMarkedText +{ + ASSERT(eventModel == NPEventModelCocoa); + ASSERT([self isStarted]); + + if (textInputFuncs && textInputFuncs->hasMarkedText) + return textInputFuncs->hasMarkedText(plugin); + + return NO; +} + +- (void)insertText:(id)aString +{ + ASSERT(eventModel == NPEventModelCocoa); + ASSERT([self isStarted]); + + if (textInputFuncs && textInputFuncs->insertText) + textInputFuncs->insertText(plugin, aString); +} + +- (NSRange)markedRange +{ + ASSERT(eventModel == NPEventModelCocoa); + ASSERT([self isStarted]); + + if (textInputFuncs && textInputFuncs->markedRange) + return textInputFuncs->markedRange(plugin); + + return NSMakeRange(NSNotFound, 0); +} + +- (NSRange)selectedRange +{ + ASSERT(eventModel == NPEventModelCocoa); + ASSERT([self isStarted]); + + if (textInputFuncs && textInputFuncs->selectedRange) + return textInputFuncs->selectedRange(plugin); + + return NSMakeRange(NSNotFound, 0); +} + +- (void)setMarkedText:(id)aString selectedRange:(NSRange)selRange +{ + ASSERT(eventModel == NPEventModelCocoa); + ASSERT([self isStarted]); + + if (textInputFuncs && textInputFuncs->setMarkedText) + textInputFuncs->setMarkedText(plugin, aString, selRange); +} + +- (void)unmarkText +{ + ASSERT(eventModel == NPEventModelCocoa); + ASSERT([self isStarted]); + + if (textInputFuncs && textInputFuncs->unmarkText) + textInputFuncs->unmarkText(plugin); +} + +- (NSArray *)validAttributesForMarkedText +{ + ASSERT(eventModel == NPEventModelCocoa); + ASSERT([self isStarted]); + + if (textInputFuncs && textInputFuncs->validAttributesForMarkedText) + return textInputFuncs->validAttributesForMarkedText(plugin); + + return [NSArray array]; +} + +- (NSAttributedString *)attributedSubstringFromRange:(NSRange)theRange +{ + ASSERT(eventModel == NPEventModelCocoa); + ASSERT([self isStarted]); + + if (textInputFuncs && textInputFuncs->attributedSubstringFromRange) + return textInputFuncs->attributedSubstringFromRange(plugin, theRange); + + return nil; +} + +- (NSUInteger)characterIndexForPoint:(NSPoint)thePoint +{ + ASSERT(eventModel == NPEventModelCocoa); + ASSERT([self isStarted]); + + if (textInputFuncs && textInputFuncs->characterIndexForPoint) { + // Convert the point to window coordinates + NSPoint point = [[self window] convertScreenToBase:thePoint]; + + // And view coordinates + point = [self convertPoint:point fromView:nil]; + + return textInputFuncs->characterIndexForPoint(plugin, point); + } + + return NSNotFound; +} + +- (void)doCommandBySelector:(SEL)aSelector +{ + ASSERT(eventModel == NPEventModelCocoa); + ASSERT([self isStarted]); + + if (textInputFuncs && textInputFuncs->doCommandBySelector) + textInputFuncs->doCommandBySelector(plugin, aSelector); +} + +- (NSRect)firstRectForCharacterRange:(NSRange)theRange +{ + ASSERT(eventModel == NPEventModelCocoa); + ASSERT([self isStarted]); + + if (textInputFuncs && textInputFuncs->firstRectForCharacterRange) { + NSRect rect = textInputFuncs->firstRectForCharacterRange(plugin, theRange); + + // Convert the rect to window coordinates + rect = [self convertRect:rect toView:nil]; + + // Convert the rect location to screen coordinates + rect.origin = [[self window] convertBaseToScreen:rect.origin]; + + return rect; + } + + return NSZeroRect; +} + +// test for 10.4 because of +#ifdef BUILDING_ON_TIGER +- (long)conversationIdentifier +{ + return (long)self; +} +#else +- (NSInteger)conversationIdentifier +{ + return (NSInteger)self; +} +#endif + @end @implementation WebBaseNetscapePluginView (WebNPPCallbacks) @@ -2311,6 +2483,18 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) [[self window] displayIfNeeded]; } +static NPBrowserTextInputFuncs *browserTextInputFuncs() +{ + static NPBrowserTextInputFuncs inputFuncs = { + 0, + sizeof(NPBrowserTextInputFuncs), + NPN_MarkedTextAbandoned, + NPN_MarkedTextSelectionChanged + }; + + return &inputFuncs; +} + - (NPError)getVariable:(NPNVariable)variable value:(void *)value { switch (variable) { @@ -2392,6 +2576,13 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) return NPERR_NO_ERROR; } + case NPNVbrowserTextInputFuncs: + { + if (eventModel == NPEventModelCocoa) { + *(NPBrowserTextInputFuncs **)value = browserTextInputFuncs(); + return NPERR_NO_ERROR; + } + } default: break; }