如何在GeckoFX中访问nsIHTMLEditor界面? [英] How to access nsIHTMLEditor interface in GeckoFX?

查看:144
本文介绍了如何在GeckoFX中访问nsIHTMLEditor界面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过将GeckoFX嵌入VB.NET的Windows窗体应用程序中来制作所见即所得的HTML编辑器.

I am trying to make a WYSIWYG HTML-editor by embedding GeckoFX in a Windows Forms application in VB.NET.

代码如下:

Dim Gbrowser As New GeckoWebBrowser
Gbrowser.Navigate("about:blank")
...
Gbrowser.Navigate("javascript:void(document.body.contentEditable='true')")

如何从我的应用程序中激活和访问nsIHTMLEditor界面?

How can I activate and access the nsIHTMLEditor interface from within my application?

谢谢.

更新
此代码不起作用:

UPDATE
This code does not work:

Dim hEditor As nsIHTMLEditor
hEditor = Xpcom.GetService(Of nsIHTMLEditor)("@mozilla.org/editor/htmleditor;1")
hEditor = Xpcom.QueryInterface(Of nsIHTMLEditor)(hEditor)
hEditor.DecreaseFontSize()

最后一行错误:对COM组件的调用已返回HRESULT E_FAIL.

Error in the last line: HRESULT E_FAIL has been returned from a call to a COM component.

推荐答案

nsIHTMLEditor可能是每个浏览器实例,而不是全局实例(例如Xpcom.GetService返回的内容)

nsIHTMLEditor is likely a per browser instance rather than a global instance (like things returned by Xpcom.GetService)

通过提供一个Window实例,可以得到这样的nsIEditor

One can get a nsIEditor like this by (by supplying a Window instance)

var editingSession = Xpcom.CreateInstance<nsIEditingSession>("@mozilla.org/editor/editingsession;1");
nsIEditor editor = editingSession.GetEditorForWindow((nsIDOMWindow)Window.DomWindow);
Marshal.ReleaseComObject(editingSession);

(或者您可以只调用nsIEditor GeckoWebBrowser.Editor属性.)

(or you can just call the nsIEditor GeckoWebBrowser.Editor property.)

您也许可以将此nsIEditor强制转换为nsIHtmlEditor(尽管我尚未尝试过)

You may be able to cast this nsIEditor to a nsIHtmlEditor (although I have yet to try it)

GeckoWebBrowser browser = .....;
// Untested code
nsIHTMLEditor htmlEditor = (nsIHTMLEditor)browser.Editor;

更新: @GreenBear的VB代码

Update: The VB code from @GreenBear

Dim gEditor As nsIHTMLEditor: 
gEditor = Gbrowser.Editor: 
gEditor.DecreaseFontSize() 

这篇关于如何在GeckoFX中访问nsIHTMLEditor界面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆