我遵循了夜间 Webkit 构建中的 NetscapeCocoaPlugin 示例,并且能够构建使用 Cocoa 事件模型的 NPAPI 样式插件。
我现在的问题是如何在 NPP_SetWindow 中获取 NSView。
此线程中的一张海报说,可以使用 [NSView focusView],但我无法让它工作
我当前的功能如下所示:
NPError NPP_SetWindow(NPP instance, NPWindow* window)
{
PluginObject *obj = instance->pdata;
obj->window = *window;
NSLog(@"Set Window called");
NSView* currentView = [NSView focusView];
[[NSColor redColor] set]; // Sets current drawing color.
NSRectFill(NSMakeRect(10, 10, 2, 20)); // Defines a rectangle and then fills it with the current drawing color.
[[NSColor colorWithCalibratedRed:0.7 green:0.9 blue:0.3 alpha:1.0] set]; // Sets a new color.
[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(5, 0, 10, 10)] fill]; // Draws a circle in the new color.
[currentView setNeedsDisplay:YES];
return NPERR_NO_ERROR;
}