#import <WebCore/Page.h>
#import <WebCore/SoftLinking.h>
#import <WebCore/WebCoreObjCExtras.h>
+#import <WebKit/nptextinput.h>
#import <WebKit/DOMPrivate.h>
#import <WebKit/WebUIDelegate.h>
#import <objc/objc-runtime.h>
AGLContext oldContext;
} PortState_GL;
+@class NSInputContext;
+@interface NSResponder (IMSecretsIKnowAbout)
+- (NSInputContext *)inputContext;
+@end
+
@interface WebPluginRequest : NSObject
{
NSURLRequest *_request;
// 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];
delete eventHandler;
eventHandler = 0;
+ textInputFuncs = 0;
+
if (drawingModel == NPDrawingModelOpenGL)
[self _destroyAGLContext];
}
[_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 <rdar://problem/4243463>
+#ifdef BUILDING_ON_TIGER
+- (long)conversationIdentifier
+{
+ return (long)self;
+}
+#else
+- (NSInteger)conversationIdentifier
+{
+ return (NSInteger)self;
+}
+#endif
+
@end
@implementation WebBaseNetscapePluginView (WebNPPCallbacks)
[[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) {
return NPERR_NO_ERROR;
}
+ case NPNVbrowserTextInputFuncs:
+ {
+ if (eventModel == NPEventModelCocoa) {
+ *(NPBrowserTextInputFuncs **)value = browserTextInputFuncs();
+ return NPERR_NO_ERROR;
+ }
+ }
default:
break;
}