如何在GeckoFX中访问nsIHTMLEditor接口?

时间:2015-11-01 22:33:22

标签: vb.net winforms xpcom geckofx html-editor

我试图通过在VB.NET中的Windows窗体应用程序中嵌入GeckoFX来制作一个WYSIWYG HTML编辑器。

代码如下:

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

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

谢谢。

更新
此代码不起作用:

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

最后一行出错:HRESULT E_FAIL已从调用COM组件返回。

1 个答案:

答案 0 :(得分:1)

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

可以通过(通过提供Window实例)获得nsIEditor这样的var editingSession = Xpcom.CreateInstance<nsIEditingSession>("@mozilla.org/editor/editingsession;1"); nsIEditor editor = editingSession.GetEditorForWindow((nsIDOMWindow)Window.DomWindow); Marshal.ReleaseComObject(editingSession);

nsIEditor GeckoWebBrowser.Editor

(或者你可以调用GeckoWebBrowser browser = .....; // Untested code nsIHTMLEditor htmlEditor = (nsIHTMLEditor)browser.Editor; 属性。)

您可以将此nsIEditor强制转换为nsIHtmlEditor(虽然我还没有尝试过)

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

更新: 来自@GreenBear的VB代码

DISTINCT