我已经从夜间Webkit构建中跟踪了NetscapeCocoaPlugin示例,并且我能够构建使用Cocoa事件模型的NPAPI样式插件。我如何在可可事件模型中获得NSView NPAPI插件
我现在的问题是,我可以如何获得NPP_SetWindow内的NSView。
在此thread海报,说,这是可能使用[的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;
}
呵呵,有意思!如果我想获得CGContextRef,我可以通过调用:NP_CGContext * npContext =(NP_CGContext *)window-> window; npContext->上下文? – CambridgeMike
这取决于很多事情。首先,您需要选择CoreGraphics作为您的绘图模型(https://wiki.mozilla.org/NPAPI:Models和https://wiki.mozilla.org/NPAPI:CoreGraphicsDrawing)。然后,如果您协商了可能可行的Carbon事件模型,但如果您使用Cocoa(请参阅https://wiki.mozilla.org/NPAPI:CocoaEventModel),则无法保存CGContextRef,但需要从事件数据每次从NPAPI获得一个CocoaEvent。这些链接应该帮助你开始,或帮助你制定一个新的问题。 – taxilian
如果这是答案,请将其标记为这样 – taxilian