Hi,

I was working on making editor users use concrete classes rather than interface classes in a couple of weeks.

As I posted 2 months ago, editor concrete classes are now mozilla::EditorBase, mozilla::TextEditor and mozilla::HTMLEditor (old names are nsEditor, nsPlaintextEditor and nsHTMLEditor). Their header files were already exposed. However, some users kept treating editors with nsIEditor, nsIPlaintextEditor and nsIHTMLEditor interfaces because they can be implemented with JS. Fortunately, we succeeded to make them to builtinclasses [1]. So, you don't need to treat editors with interfaces anymore in native code.

So, please do not use nsI*Editor anymore in new code. Please use EditorBase, TextEditor or HTMLEditor classes directly. Then, you can call non-virtual methods of editors and get the result as return value instead of out param.

However, there is an exception. If you need to write scriptable method which gets/sets editor from/to JS, you still need to use nsI*Editor. When type of pointer is nsIEditor, you can retrieve pointer to concrete classes easily and safely:

NS_IMETHODIMP
Foo::DoSomething(nsIEditor* aEditor)
{
  // EditorBase is base class of any type of editors.
  // However, perhaps, you don't need to use this type.
  EditorBase* editorBase = aEditor->AsEditorBase();

  // TextEditor is plaintext editor class and super class of
  // HTMLEditor.  This won't be nullptr.
  TextEditor* textEditor = aEditor->AsTextEditor();

  // HTMLEditor is a subclass of TextEditor.  If the instance
  // is an HTMLEditor, this returns non-nullptr.  Otherwise, i.e.,
  // it's a TextEditor instance, returns nullptr.
  HTMLEditor* htmlEditor = aEditor->AsHTMLEditor();
  ...
}

If type of pointer is nsIPlaintextEditor or nsIHTMLEditor, you need to QI to nsIEditor first. So, if you need to add new scriptable method which treat editor, using nsIEditor is better than other editor interfaces since QI cost is not so cheap.

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1060051

--
Masayuki Nakano <masay...@d-toybox.com>
Software Engineer, Mozilla
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to