Bug 1319340 - part1 Move AsTextEditor() and AsHTMLEditor() to nsIEditor r?m_kato
nsIEditor is still first contact with editor class for some modules. They should be accessible to the concrete classes without QI. Therefore, nsIEditor should have As*Editor() methods.
Additionally, this adds AsEditorBase(). That is always implemented but it might be necessary for some files for minimizing its include files.
MozReview-Commit-ID: 8WqkDJLiVDs
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -231,23 +231,16 @@ public:
};
/**
* The default constructor. This should suffice. the setting of the
* interfaces is done after the construction of the editor class.
*/
EditorBase();
- // Please include TextEditor.h.
- inline TextEditor* AsTextEditor();
- inline const TextEditor* AsTextEditor() const;
- // Please include HTMLEditor.h.
- inline HTMLEditor* AsHTMLEditor();
- inline const HTMLEditor* AsHTMLEditor() const;
-
protected:
/**
* The default destructor. This should suffice. Should this be pure virtual
* for someone to derive from the EditorBase later? I don't believe so.
*/
virtual ~EditorBase();
public:
@@ -1248,13 +1241,26 @@ protected:
// Whether we are an HTML editor class.
bool mIsHTMLEditorClass;
friend bool NSCanUnload(nsISupports* serviceMgr);
friend class AutoRules;
friend class AutoSelectionRestorer;
friend class AutoTransactionsConserveSelection;
friend class RangeUpdater;
+ friend class nsIEditor;
};
} // namespace mozilla
+mozilla::EditorBase*
+nsIEditor::AsEditorBase()
+{
+ return static_cast<mozilla::EditorBase*>(this);
+}
+
+const mozilla::EditorBase*
+nsIEditor::AsEditorBase() const
+{
+ return static_cast<const mozilla::EditorBase*>(this);
+}
+
#endif // #ifndef mozilla_EditorBase_h
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -1049,23 +1049,25 @@ private:
* element
*/
ManualNACPtr CreateAnonymousElement(nsIAtom* aTag,
nsIContent& aParentContent,
const nsAString& aAnonClass,
bool aIsCreatedHidden);
};
-HTMLEditor*
-EditorBase::AsHTMLEditor()
+} // namespace mozilla
+
+mozilla::HTMLEditor*
+nsIEditor::AsHTMLEditor()
{
- return mIsHTMLEditorClass ? static_cast<HTMLEditor*>(this) : nullptr;
+ return static_cast<mozilla::EditorBase*>(this)->mIsHTMLEditorClass ?
+ static_cast<mozilla::HTMLEditor*>(this) : nullptr;
}
-const HTMLEditor*
-EditorBase::AsHTMLEditor() const
+const mozilla::HTMLEditor*
+nsIEditor::AsHTMLEditor() const
{
- return mIsHTMLEditorClass ? static_cast<const HTMLEditor*>(this) : nullptr;
+ return static_cast<const mozilla::EditorBase*>(this)->mIsHTMLEditorClass ?
+ static_cast<const mozilla::HTMLEditor*>(this) : nullptr;
}
-} // namespace mozilla
-
#endif // #ifndef mozilla_HTMLEditor_h
--- a/editor/libeditor/TextEditor.h
+++ b/editor/libeditor/TextEditor.h
@@ -237,23 +237,23 @@ protected:
int32_t mNewlineHandling;
int32_t mCaretStyle;
friend class AutoEditInitRulesTrigger;
friend class HTMLEditRules;
friend class TextEditRules;
};
-TextEditor*
-EditorBase::AsTextEditor()
+} // namespace mozilla
+
+mozilla::TextEditor*
+nsIEditor::AsTextEditor()
{
- return static_cast<TextEditor*>(this);
+ return static_cast<mozilla::TextEditor*>(this);
}
-const TextEditor*
-EditorBase::AsTextEditor() const
+const mozilla::TextEditor*
+nsIEditor::AsTextEditor() const
{
- return static_cast<const TextEditor*>(this);
+ return static_cast<const mozilla::TextEditor*>(this);
}
-} // namespace mozilla
-
#endif // #ifndef mozilla_TextEditor_h
--- a/editor/nsIEditor.idl
+++ b/editor/nsIEditor.idl
@@ -18,16 +18,19 @@ interface nsITransactionManager;
interface nsITransaction;
interface nsIEditorObserver;
interface nsIEditActionListener;
interface nsIInlineSpellChecker;
interface nsITransferable;
%{C++
namespace mozilla {
+class EditorBase;
+class HTMLEditor;
+class TextEditor;
namespace widget {
struct IMEState;
} // namespace widget
} // namespace mozilla
%}
native IMEState(mozilla::widget::IMEState);
@@ -584,9 +587,38 @@ interface nsIEditor : nsISupports
* Get preferred IME status of current widget.
*/
[noscript] IMEState getPreferredIMEState();
/**
* whether this editor has active IME transaction
*/
readonly attribute boolean composing;
+
+%{C++
+ /**
+ * AsEditorBase() returns a pointer to EditorBase class.
+ *
+ * In order to avoid circular dependency issues, this method is defined
+ * in mozilla/EditorBase.h. Consumers need to #include that header.
+ */
+ inline mozilla::EditorBase* AsEditorBase();
+ inline const mozilla::EditorBase* AsEditorBase() const;
+
+ /**
+ * AsTextEditor() returns a pointer to TextEditor class.
+ *
+ * In order to avoid circular dependency issues, this method is defined
+ * in mozilla/TextEditor.h. Consumers need to #include that header.
+ */
+ inline mozilla::TextEditor* AsTextEditor();
+ inline const mozilla::TextEditor* AsTextEditor() const;
+
+ /**
+ * AsHTMLEditor() returns a pointer to HTMLEditor class.
+ *
+ * In order to avoid circular dependency issues, this method is defined
+ * in mozilla/HTMLEditor.h. Consumers need to #include that header.
+ */
+ inline mozilla::HTMLEditor* AsHTMLEditor();
+ inline const mozilla::HTMLEditor* AsHTMLEditor() const;
+%}
};