/* -*- 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/intl/BidiEmbeddingLevel.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/EditorForwards.h" #include "mozilla/EventForwards.h" // for InputEventTargetRanges #include "mozilla/Likely.h" // for MOZ_UNLIKELY, MOZ_LIKELY #include "mozilla/Maybe.h" // for Maybe #include "mozilla/OwningNonNull.h" // for OwningNonNull #include "mozilla/PendingStyles.h" // for PendingStyle, PendingStyleCache #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 "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. #include // for std::tuple class mozInlineSpellChecker; class nsAtom; class nsCaret; class nsIContent; class nsIDocumentEncoder; class nsIDocumentStateListener; class nsIEditActionListener; class nsINode; class nsIPrincipal; class nsISupports; class nsITransferable; class nsITransaction; class nsIWidget; class nsRange; namespace mozilla { class AlignStateAtSelection; class AutoTransactionsConserveSelection; class AutoUpdateViewBatch; class ErrorResult; class IMEContentObserver; class ListElementSelectionState; class ListItemElementSelectionState; class ParagraphStateAtSelection; class PresShell; class TextComposition; class TextInputListener; class TextServicesDocument; 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. ****************************************************************************/ using Document = dom::Document; using Element = dom::Element; using InterlinePosition = dom::Selection::InterlinePosition; using Selection = dom::Selection; using Text = dom::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. */ explicit EditorBase(EditorType aEditorType); 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