How to access nsIHTMLEditor interface in GeckoFX?

耗尽温柔 提交于 2019-12-08 00:27:11

问题


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

The code goes like this:

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

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

Thank you.

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()

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


回答1:


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

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);

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

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;

Update: The VB code from @GreenBear

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


来源:https://stackoverflow.com/questions/33467992/how-to-access-nsihtmleditor-interface-in-geckofx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!