/* -*- 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/EventForwards.h" // for InputEventTargetRanges #include "mozilla/Maybe.h" // for Maybe #include "mozilla/OwningNonNull.h" // for OwningNonNull #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 "nsAtom.h" // for nsAtom, nsStaticAtom #include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr #include "nsCycleCollectionParticipant.h" #include "nsGkAtoms.h" #include "nsIContentInlines.h" // for nsINode::IsEditable() #include "nsIEditor.h" // for nsIEditor, etc. #include "nsIFrame.h" // for nsBidiLevel #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 AlignStateAtSelection; class AutoRangeArray; 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 EditActionResult; class EditAggregateTransaction; class EditorEventListener; class EditTransactionBase; class ErrorResult; class HTMLEditor; class HTMLEditUtils; class IMEContentObserver; class InsertNodeTransaction; class InsertTextTransaction; class JoinNodeTransaction; class ListElementSelectionState; class ListItemElementSelectionState; class ParagraphStateAtSelection; class PlaceholderTransaction; class PresShell; class ReplaceTextTransaction; class SplitNodeResult; class SplitNodeTransaction; class TextComposition; class TextEditor; class TextInputListener; class TextServicesDocument; class TypeInState; class WhiteSpaceVisibilityKeeper; template class CreateNodeResultBase; typedef CreateNodeResultBase CreateElementResult; namespace dom { class AbstractRange; class DataTransfer; class Document; class DragEvent; class Element; class EventTarget; class HTMLBRElement; } // namespace dom namespace widget { struct IMEState; } // namespace widget /** * 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; enum class EditorType { Text, HTML }; 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(); bool IsTextEditor() const { return !mIsHTMLEditorClass; } bool IsHTMLEditor() const { return mIsHTMLEditorClass; } /** * 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; nsPIDOMWindowInner* GetInnerWindow() const; /** * MayHaveMutationEventListeners() returns true when the window may have * mutation event listeners. * * @param aMutationEventType One or multiple of NS_EVENT_BITS_MUTATION_*. * @return true if the editor is an HTMLEditor instance, * and at least one of NS_EVENT_BITS_MUTATION_* is * set to the window or in debug build. */ bool MayHaveMutationEventListeners( uint32_t aMutationEventType = 0xFFFFFFFF) const { if (IsTextEditor()) { // DOM mutation event listeners cannot catch the changes of // nor