我已經從夜間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