editor/libeditor/text/nsPlaintextEditor.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef nsPlaintextEditor_h__
     7 #define nsPlaintextEditor_h__
     9 #include "nsCOMPtr.h"
    10 #include "nsCycleCollectionParticipant.h"
    11 #include "nsEditor.h"
    12 #include "nsIEditor.h"
    13 #include "nsIEditorMailSupport.h"
    14 #include "nsIPlaintextEditor.h"
    15 #include "nsISupportsImpl.h"
    16 #include "nscore.h"
    18 class nsIContent;
    19 class nsIDOMDataTransfer;
    20 class nsIDOMDocument;
    21 class nsIDOMElement;
    22 class nsIDOMEvent;
    23 class nsIDOMEventTarget;
    24 class nsIDOMKeyEvent;
    25 class nsIDOMNode;
    26 class nsIDocumentEncoder;
    27 class nsIEditRules;
    28 class nsIOutputStream;
    29 class nsISelection;
    30 class nsISelectionController;
    31 class nsITransferable;
    33 /**
    34  * The text editor implementation.
    35  * Use to edit text document represented as a DOM tree. 
    36  */
    37 class nsPlaintextEditor : public nsEditor,
    38                           public nsIPlaintextEditor,
    39                           public nsIEditorMailSupport
    40 {
    42 public:
    44 // Interfaces for addref and release and queryinterface
    45 // NOTE macro used is for classes that inherit from 
    46 // another class. Only the base class should use NS_DECL_ISUPPORTS
    47   NS_DECL_ISUPPORTS_INHERITED
    48   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsPlaintextEditor, nsEditor)
    50   /* below used by TypedText() */
    51   enum ETypingAction {
    52     eTypedText,  /* user typed text */
    53     eTypedBR,    /* user typed shift-enter to get a br */
    54     eTypedBreak  /* user typed enter */
    55   };
    57            nsPlaintextEditor();
    58   virtual  ~nsPlaintextEditor();
    60   /* ------------ nsIPlaintextEditor methods -------------- */
    61   NS_DECL_NSIPLAINTEXTEDITOR
    63   /* ------------ nsIEditorMailSupport overrides -------------- */
    64   NS_DECL_NSIEDITORMAILSUPPORT
    66   /* ------------ Overrides of nsEditor interface methods -------------- */
    67   NS_IMETHOD SetAttributeOrEquivalent(nsIDOMElement * aElement,
    68                                       const nsAString & aAttribute,
    69                                       const nsAString & aValue,
    70                                       bool aSuppressTransaction);
    71   NS_IMETHOD RemoveAttributeOrEquivalent(nsIDOMElement * aElement,
    72                                          const nsAString & aAttribute,
    73                                          bool aSuppressTransaction);
    75   /** prepare the editor for use */
    76   NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIContent *aRoot,
    77                   nsISelectionController *aSelCon, uint32_t aFlags,
    78                   const nsAString& aValue);
    80   NS_IMETHOD GetDocumentIsEmpty(bool *aDocumentIsEmpty);
    81   NS_IMETHOD GetIsDocumentEditable(bool *aIsDocumentEditable);
    83   NS_IMETHOD DeleteSelection(EDirection aAction,
    84                              EStripWrappers aStripWrappers);
    86   NS_IMETHOD SetDocumentCharacterSet(const nsACString & characterSet);
    88   NS_IMETHOD Undo(uint32_t aCount);
    89   NS_IMETHOD Redo(uint32_t aCount);
    91   NS_IMETHOD Cut();
    92   NS_IMETHOD CanCut(bool *aCanCut);
    93   NS_IMETHOD Copy();
    94   NS_IMETHOD CanCopy(bool *aCanCopy);
    95   NS_IMETHOD Paste(int32_t aSelectionType);
    96   NS_IMETHOD CanPaste(int32_t aSelectionType, bool *aCanPaste);
    97   NS_IMETHOD PasteTransferable(nsITransferable *aTransferable);
    98   NS_IMETHOD CanPasteTransferable(nsITransferable *aTransferable, bool *aCanPaste);
   100   NS_IMETHOD OutputToString(const nsAString& aFormatType,
   101                             uint32_t aFlags,
   102                             nsAString& aOutputString);
   104   NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
   105                             const nsAString& aFormatType,
   106                             const nsACString& aCharsetOverride,
   107                             uint32_t aFlags);
   110   /** All editor operations which alter the doc should be prefaced
   111    *  with a call to StartOperation, naming the action and direction */
   112   NS_IMETHOD StartOperation(EditAction opID,
   113                             nsIEditor::EDirection aDirection);
   115   /** All editor operations which alter the doc should be followed
   116    *  with a call to EndOperation */
   117   NS_IMETHOD EndOperation();
   119   /** make the given selection span the entire document */
   120   NS_IMETHOD SelectEntireDocument(nsISelection *aSelection);
   122   virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
   124   virtual already_AddRefed<mozilla::dom::EventTarget> GetDOMEventTarget();
   126   virtual nsresult BeginIMEComposition(mozilla::WidgetCompositionEvent* aEvent);
   127   virtual nsresult UpdateIMEComposition(nsIDOMEvent* aTextEvent) MOZ_OVERRIDE;
   129   virtual already_AddRefed<nsIContent> GetInputEventTargetContent();
   131   /* ------------ Utility Routines, not part of public API -------------- */
   132   NS_IMETHOD TypedText(const nsAString& aString, ETypingAction aAction);
   134   nsresult InsertTextAt(const nsAString &aStringToInsert,
   135                         nsIDOMNode *aDestinationNode,
   136                         int32_t aDestOffset,
   137                         bool aDoDeleteSelection);
   139   virtual nsresult InsertFromDataTransfer(mozilla::dom::DataTransfer *aDataTransfer,
   140                                           int32_t aIndex,
   141                                           nsIDOMDocument *aSourceDoc,
   142                                           nsIDOMNode *aDestinationNode,
   143                                           int32_t aDestOffset,
   144                                           bool aDoDeleteSelection);
   146   virtual nsresult InsertFromDrop(nsIDOMEvent* aDropEvent);
   148   /**
   149    * Extends the selection for given deletion operation
   150    * If done, also update aAction to what's actually left to do after the
   151    * extension.
   152    */
   153   nsresult ExtendSelectionForDelete(nsISelection* aSelection,
   154                                     nsIEditor::EDirection *aAction);
   156   // Return true if the data is safe to insert as the source and destination
   157   // principals match, or we are in a editor context where this doesn't matter.
   158   // Otherwise, the data must be sanitized first.
   159   bool IsSafeToInsertData(nsIDOMDocument* aSourceDoc);
   161   static void GetDefaultEditorPrefs(int32_t &aNewLineHandling,
   162                                     int32_t &aCaretStyle);
   164 protected:
   166   NS_IMETHOD  InitRules();
   167   void        BeginEditorInit();
   168   nsresult    EndEditorInit();
   170   // Helpers for output routines
   171   NS_IMETHOD GetAndInitDocEncoder(const nsAString& aFormatType,
   172                                   uint32_t aFlags,
   173                                   const nsACString& aCharset,
   174                                   nsIDocumentEncoder** encoder);
   176   // key event helpers
   177   NS_IMETHOD CreateBR(nsIDOMNode *aNode, int32_t aOffset, 
   178                       nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect = eNone);
   179   nsresult CreateBRImpl(nsCOMPtr<nsIDOMNode>* aInOutParent,
   180                         int32_t* aInOutOffset,
   181                         nsCOMPtr<nsIDOMNode>* outBRNode,
   182                         EDirection aSelect);
   183   nsresult InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode);
   185   // factored methods for handling insertion of data from transferables (drag&drop or clipboard)
   186   NS_IMETHOD PrepareTransferable(nsITransferable **transferable);
   187   NS_IMETHOD InsertTextFromTransferable(nsITransferable *transferable,
   188                                         nsIDOMNode *aDestinationNode,
   189                                         int32_t aDestOffset,
   190                                         bool aDoDeleteSelection);
   192   /** shared outputstring; returns whether selection is collapsed and resulting string */
   193   nsresult SharedOutputString(uint32_t aFlags, bool* aIsCollapsed, nsAString& aResult);
   195   /* small utility routine to test the eEditorReadonly bit */
   196   bool IsModifiable();
   198   bool CanCutOrCopy();
   199   bool FireClipboardEvent(int32_t aType, int32_t aSelectionType);
   201   bool UpdateMetaCharset(nsIDOMDocument* aDocument,
   202                          const nsACString& aCharacterSet);
   204 // Data members
   205 protected:
   207   nsCOMPtr<nsIEditRules>        mRules;
   208   bool    mWrapToWindow;
   209   int32_t mWrapColumn;
   210   int32_t mMaxTextLength;
   211   int32_t mInitTriggerCounter;
   212   int32_t mNewlineHandling;
   213   int32_t mCaretStyle;
   215 // friends
   216 friend class nsHTMLEditRules;
   217 friend class nsTextEditRules;
   218 friend class nsAutoEditInitRulesTrigger;
   220 };
   222 #endif //nsPlaintextEditor_h__

mercurial