简体   繁体   English

Mac OSX,NPAPI中的Cocoa事件模型,NSView和进程外插件

[英]Mac OSX, Cocoa event model in NPAPI , NSView, and Out of process plugins

Well, currently chrome has out of process plugins. 好吧,目前chrome的进程插件已停用。 and firefox 4 will use same model. 和Firefox 4将使用相同的模型。

That means plugin process is now seperated from browser process. 这意味着插件过程现在与浏览器过程分开了。 Plugin process might NOT have window at all. 插件过程可能根本没有窗口。

My plugin is based on NSView . 我的插件基于NSView

Before cocoa event model, when I can access NSWindow in browser process, All I have to do is just add my_view as a subview of the contentView in the window. 在可可事件模型之前,当我可以在浏览器过程中访问NSWindow时,我要做的就是将my_view添加为窗口中contentView的子视图。

[[the_window contentView] addSubview:my_view] 

I do NOT need to process events myself. 我不需要自己处理事件。 It worked itself. 它本身起作用。

But now, I convert NPCocoaEvents into NSEvents in event process code. 但现在,我转换NPCocoaEventsNSEvents在事件处理代码。

Do I have to change it myself? 我需要自己更改吗?

Also some instance of NSEvents , I can not make them for example, wheel mouse events. 还有NSEvents某些实例,例如,滚轮鼠标事件,我无法使它们成为NSEvents

What should do I do? 我该怎么办?

Did I approach a wrong way? 我的做法是否错误?

Please enlighten me. 请赐教。

Do I have to change it myself? 我需要自己更改吗?

If you plan to use the approach of forwarding NSEvents to your existing NSView then yes; 如果您打算使用将NSEvents转发到现有NSView的方法,则可以; there's no way to get access to the original NSEvents. 无法访问原始NSEvent。 They don't exist in the plugin process. 它们在插件过程中不存在。

Another option would be to move away from trying to use native controls, and do your own drawing and event handling. 另一种选择是远离尝试使用本机控件,而进行自己的绘制和事件处理。 This is the way most NPAPI plugins work. 这是大多数NPAPI插件的工作方式。

A third possibility would be to open a separate window for your plugin content, and put your view in that window. 第三种可能性是为插件内容打开一个单独的窗口,然后将视图放在该窗口中。 This isn't technically supported by NPAPI, and it won't be perfect, but it might be a short-term way to get your plugin working while you explore long-term options. NPAPI在技术上不支持此方法,它也不是完美的方法,但这可能是在探索长期选择时使插件正常工作的短期方法。

Did I approach a wrong way? 我的做法是否错误?

Yes, what you were doing before was an unsupported hack, and not how NPAPI was intended to be used. 是的,您之前所做的是不受支持的黑客攻击,而不是打算使用NPAPI的方式。 Adding a view to a browser's window assumes things about the browser's view hierarchy that are implementation details, and subject to change at any time. 将视图添加到浏览器的窗口时,假定有关浏览器视图层次结构的事情是实现细节,并且随时可能更改。

One option would be to use the FireBreath framework to create your plugin, as it already has a lot of the abstraction for negotiating the event and drawing models as well as an event abstraction. 一种选择是使用FireBreath框架来创建您的插件,因为它已经具有很多用于协商事件和绘制模型以及事件抽象的抽象。 It's pretty straightforward to get up and going. 站起来很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM