本文介绍了如何在可爱事件模型NPAPI插件中获取NSView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我已经从夜间Webkit构建中跟踪NetscapeCocoaPlugin示例,我可以构建一个使用Cocoa事件模型的NPAPI样式插件。 I've followed the NetscapeCocoaPlugin example from the nightly Webkit build, and I'm able to build a NPAPI style plugin that uses the Cocoa Event Model. 我现在的问题,是如何获得NSView内部的NPP_SetWindow。 My question now, is how I can get the NSView inside NPP_SetWindow. 此主题中的海报, 我的当前函数看起来像这样:My current function looks like this: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;} 推荐答案有一个时候,你可以得到NSView使用一个黑客,但它从来没有得到支持,从来没有一个好主意,不再可能,因为所有三个浏览器已经切换到使用过程外插件,这意味着你不能访问You can't. There was a time when you could get the NSView using a hack, but it was never supported, never a good idea, and no longer possible because all three browsers have switched to using out of process plugins, which means you can't get access to the NSView.您可以获得一个CGContextRef,然后创建自己的屏幕外NSWindow和NSView并将它们渲染到CGContextRef,但是你必须代理所有事件以及。 WebView封装在 FireBreath 这是实验性的,但这是相当痛苦。最后,我打算把它变成更通用的东西,所以一个NSView可以(kinda)在插件中使用,但没有本机的方式这样做。You can get a CGContextRef and then create your own offscreen NSWindow and NSView and render them into the CGContextRef, but then you'd have to proxy all events as well. There is a WebView wrapper in FireBreath that is experimental still that does this, but it is quite a pain. Eventually I plan to turn it into something more generic so that an NSView can (kinda) be used in a plugin, but there is no native way to do so.是一篇有关Mac绘图模型的优秀博文: http:// www.escapedthoughts.com/weblog/geek/P110308-mac-npapi-plugins.writeback There is an excellent blog post about mac drawing models here: http://www.escapedthoughts.com/weblog/geek/P110308-mac-npapi-plugins.writeback 这篇关于如何在可爱事件模型NPAPI插件中获取NSView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-16 20:04