/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef mozilla_EditorBase_h #define mozilla_EditorBase_h #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc. #include "mozilla/EditAction.h" // for EditAction and EditSubAction #include "mozilla/EditorDOMPoint.h" // for EditorDOMPoint #include "mozilla/Maybe.h" // for Maybe #include "mozilla/OwningNonNull.h" // for OwningNonNull #include "mozilla/PresShell.h" // for PresShell #include "mozilla/TypeInState.h" // for PropItem, StyleCache #include "mozilla/RangeBoundary.h" // for RawRangeBoundary, RangeBoundary #include "mozilla/SelectionState.h" // for RangeUpdater, etc. #include "mozilla/StyleSheet.h" // for StyleSheet #include "mozilla/TransactionManager.h" // for TransactionManager #include "mozilla/WeakPtr.h" // for WeakPtr #include "mozilla/dom/DataTransfer.h" // for dom::DataTransfer #include "mozilla/dom/HTMLBRElement.h" // for dom::HTMLBRElement #include "mozilla/dom/Selection.h" #include "mozilla/dom/Text.h" #include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr #include "nsCycleCollectionParticipant.h" #include "nsGkAtoms.h" #include "mozilla/dom/Document.h" #include "nsIContentInlines.h" // for nsINode::IsEditable() #include "nsIEditor.h" // for nsIEditor, etc. #include "nsIObserver.h" // for NS_DECL_NSIOBSERVER, etc. #include "nsIPlaintextEditor.h" // for nsIPlaintextEditor, etc. #include "nsISelectionController.h" // for nsISelectionController constants #include "nsISelectionListener.h" // for nsISelectionListener #include "nsISupportsImpl.h" // for EditorBase::Release, etc. #include "nsIWeakReferenceUtils.h" // for nsWeakPtr #include "nsLiteralString.h" // for NS_LITERAL_STRING #include "nsPIDOMWindow.h" // for nsPIDOMWindowInner, etc. #include "nsString.h" // for nsCString #include "nsTArray.h" // for nsTArray and nsAutoTArray #include "nsWeakReference.h" // for nsSupportsWeakReference #include "nscore.h" // for nsresult, nsAString, etc. class mozInlineSpellChecker; class nsAtom; class nsCaret; class nsIContent; class nsIDocumentStateListener; class nsIEditActionListener; class nsIEditorObserver; class nsINode; class nsIPrincipal; class nsISupports; class nsITransferable; class nsITransaction; class nsITransactionListener; class nsIWidget; class nsRange; namespace mozilla { class AutoSelectionRestorer; class AutoTopLevelEditSubActionNotifier; class AutoTransactionBatch; class AutoTransactionsConserveSelection; class AutoUpdateViewBatch; class ChangeAttributeTransaction; class CompositionTransaction; class CreateElementTransaction; class CSSEditUtils; class DeleteNodeTransaction; class DeleteRangeTransaction; class DeleteTextTransaction; class EditAggregateTransaction; class EditorEventListener; class EditTransactionBase; class ErrorResult; class HTMLEditor; class HTMLEditUtils; class IMEContentObserver; class InsertNodeTransaction; class InsertTextTransaction; class JoinNodeTransaction; class PlaceholderTransaction; class PresShell; class SplitNodeResult; class SplitNodeTransaction; class TextComposition; class TextEditor; class TextEditRules; class TextInputListener; class TextServicesDocument; class TypeInState; class WSRunObject; template class CreateNodeResultBase; typedef CreateNodeResultBase CreateElementResult; namespace dom { class AbstractRange; class DataTransfer; class DragEvent; class Element; class EventTarget; class HTMLBRElement; } // namespace dom namespace widget { struct IMEState; } // namespace widget /** * SplitAtEdges is for EditorBase::SplitNodeDeepWithTransaction(), * HTMLEditor::InsertNodeAtPoint() */ enum class SplitAtEdges { // EditorBase::SplitNodeDeepWithTransaction() won't split container element // nodes at their edges. I.e., when split point is start or end of // container, it won't be split. eDoNotCreateEmptyContainer, // EditorBase::SplitNodeDeepWithTransaction() always splits containers even // if the split point is at edge of a container. E.g., if split point is // start of an inline element, empty inline element is created as a new left // node. eAllowToCreateEmptyContainer, }; /** * Implementation of an editor object. it will be the controller/focal point * for the main editor services. i.e. the GUIManager, publishing, transaction * manager, event interfaces. the idea for the event interfaces is to have them * delegate the actual commands to the editor independent of the XPFE * implementation. */ class EditorBase : public nsIEditor, public nsISelectionListener, public nsSupportsWeakReference { public: /**************************************************************************** * NOTE: DO NOT MAKE YOUR NEW METHODS PUBLIC IF they are called by other * classes under libeditor except EditorEventListener and * HTMLEditorEventListener because each public method which may fire * eEditorInput event will need to instantiate new stack class for * managing input type value of eEditorInput and cache some objects * for smarter handling. In other words, when you add new root * method to edit the DOM tree, you can make your new method public. ****************************************************************************/ typedef dom::Document Document; typedef dom::Element Element; typedef dom::Selection Selection; typedef dom::Text Text; NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(EditorBase, nsIEditor) // nsIEditor methods NS_DECL_NSIEDITOR // nsISelectionListener method NS_DECL_NSISELECTIONLISTENER /** * The default constructor. This should suffice. the setting of the * interfaces is done after the construction of the editor class. */ EditorBase(); /** * Init is to tell the implementation of nsIEditor to begin its services * @param aDoc The dom document interface being observed * @param aRoot This is the root of the editable section of this * document. If it is null then we get root * from document body. * @param aSelCon this should be used to get the selection location * (will be null for HTML editors) * @param aFlags A bitmask of flags for specifying the behavior * of the editor. */ MOZ_CAN_RUN_SCRIPT virtual nsresult Init(Document& doc, Element* aRoot, nsISelectionController* aSelCon, uint32_t aFlags, const nsAString& aInitialValue); /** * PostCreate should be called after Init, and is the time that the editor * tells its documentStateObservers that the document has been created. */ MOZ_CAN_RUN_SCRIPT nsresult PostCreate(); /** * PreDestroy is called before the editor goes away, and gives the editor a * chance to tell its documentStateObservers that the document is going away. * @param aDestroyingFrames set to true when the frames being edited * are being destroyed (so there is no need to modify any nsISelections, * nor is it safe to do so) */ MOZ_CAN_RUN_SCRIPT virtual void PreDestroy(bool aDestroyingFrames); bool IsInitialized() const { return !!mDocument; } bool Destroyed() const { return mDidPreDestroy; } Document* GetDocument() const { return mDocument; } nsPIDOMWindowOuter* GetWindow() const { return mDocument ? mDocument->GetWindow() : nullptr; } nsPIDOMWindowInner* GetInnerWindow() const { return mDocument ? mDocument->GetInnerWindow() : nullptr; } bool HasMutationEventListeners( uint32_t aMutationEventType = 0xFFFFFFFF) const { if (!mIsHTMLEditorClass) { // DOM mutation event listeners cannot catch the changes of // nor