Hi,
I've rewritten the editor module a lot in a half of decade, and I reach
a big milestone now. That is, `HTMLEditor` will stop being derived from
`TextEditor`, instead, will be directly derived from `EditorBase`.
Currently, the image is:
`HTMLEditor` <- `TextEditor` <- `EditorBase` <- `nsIEditor`
<- `nsIHTMLEditor` etc.
But this will be:
`HTMLEditor` <- `EditorBase` <- `nsIEditor`
<- `nsIHTMLEditor` etc.
`TextEditor` <- `EditorBase` <- `nsIEditor`
The code shared by both `HTMLEditor` and `TextEditor` have already been
moved to `EditorBase` and `EditorUtils`.
One of the big change is, `nsIEditor::AsTextEditor()` and
`nsIEditor::AsHTMLEditor()` will be unsafe like `nsINode::AsContent()`.
Currently, they check its type and returns `nullptr` if `AsHTMLEditor()`
is called with `TextEditor` instance. But new utility methods will take
same form as DOM nodes' ones.
`nsIEditor::IsTextEditor()` and `nsIEditor::IsHTMLEditor()` check
whether the instance is `TextEditor` or `HTMLEditor` (they are same as
current `EditorBase`'s API).
`nsIEditor::GetAsTextEditor()` and `nsIEditor::GetAsHTMLEditor()` will
check whether the instance is `TextEditor` or `HTMLEditor` and iif it
matches, returns its pointer, and otherwise, `nullptr`.
`nsIEditor::AsTextEditor()` and `nsIEditor::AsHTMLEditor()` will just
cast its pointer without the type check. So, they are faster, but must
be used after `Is*Editor()` check.
For making the code working with `nsIEditor` simpler, there will be new
static methods `TextEditor::GetFrom(nsIEditor*)` and
`HTMLEditor::GetFrom(nsIEditor*)`, and their const versions. They return
non-nullptr if and only if the instance type matches the class.
I hope this changes will help you to read editor code easier!
The former change is handled in bug 1713760
https://bugzilla.mozilla.org/show_bug.cgi?id=1713760
And the latter change is handled in bug 1714918
https://bugzilla.mozilla.org/show_bug.cgi?id=1714918
Thank you Makoto-san for your a lot of review about this kind of changes!
--
Masayuki Nakano <
masa...@d-toybox.com>
Working on DOM, Events, editor and IME handling for Gecko