LCOV - code coverage report
Current view: directory - editor/libeditor/text - nsPlaintextEditor.h (source / functions) Found Hit Coverage
Test: app.info Lines: 1 1 100.0 %
Date: 2012-06-02 Functions: 2 1 50.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Daniel Glazman <glazman@netscape.com>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef nsPlaintextEditor_h__
      40                 : #define nsPlaintextEditor_h__
      41                 : 
      42                 : #include "nsCOMPtr.h"
      43                 : 
      44                 : #include "nsIPlaintextEditor.h"
      45                 : #include "nsIEditorMailSupport.h"
      46                 : 
      47                 : #include "nsEditor.h"
      48                 : #include "nsIDOMElement.h"
      49                 : #include "nsIDOMEventListener.h"
      50                 : 
      51                 : #include "nsEditRules.h"
      52                 : #include "nsCycleCollectionParticipant.h"
      53                 :  
      54                 : class nsITransferable;
      55                 : class nsIDocumentEncoder;
      56                 : 
      57                 : /**
      58                 :  * The text editor implementation.
      59                 :  * Use to edit text document represented as a DOM tree. 
      60                 :  */
      61                 : class nsPlaintextEditor : public nsEditor,
      62                 :                           public nsIPlaintextEditor,
      63                 :                           public nsIEditorMailSupport
      64                 : {
      65                 : 
      66                 : public:
      67                 : 
      68                 : // Interfaces for addref and release and queryinterface
      69                 : // NOTE macro used is for classes that inherit from 
      70                 : // another class. Only the base class should use NS_DECL_ISUPPORTS
      71                 :   NS_DECL_ISUPPORTS_INHERITED
      72            2928 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsPlaintextEditor, nsEditor)
      73                 : 
      74                 :   /* below used by TypedText() */
      75                 :   enum {
      76                 :     eTypedText,  /* user typed text */
      77                 :     eTypedBR,    /* user typed shift-enter to get a br */
      78                 :     eTypedBreak  /* user typed enter */
      79                 :   };
      80                 : 
      81                 :            nsPlaintextEditor();
      82                 :   virtual  ~nsPlaintextEditor();
      83                 : 
      84                 :   /* ------------ nsIPlaintextEditor methods -------------- */
      85                 :   NS_DECL_NSIPLAINTEXTEDITOR
      86                 : 
      87                 :   /* ------------ nsIEditorMailSupport overrides -------------- */
      88                 :   NS_DECL_NSIEDITORMAILSUPPORT
      89                 : 
      90                 :   /* ------------ Overrides of nsEditor interface methods -------------- */
      91                 :   NS_IMETHOD SetAttributeOrEquivalent(nsIDOMElement * aElement,
      92                 :                                       const nsAString & aAttribute,
      93                 :                                       const nsAString & aValue,
      94                 :                                       bool aSuppressTransaction);
      95                 :   NS_IMETHOD RemoveAttributeOrEquivalent(nsIDOMElement * aElement,
      96                 :                                          const nsAString & aAttribute,
      97                 :                                          bool aSuppressTransaction);
      98                 : 
      99                 :   /** prepare the editor for use */
     100                 :   NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIContent *aRoot, nsISelectionController *aSelCon, PRUint32 aFlags);
     101                 :   
     102                 :   NS_IMETHOD GetDocumentIsEmpty(bool *aDocumentIsEmpty);
     103                 :   NS_IMETHOD GetIsDocumentEditable(bool *aIsDocumentEditable);
     104                 : 
     105                 :   NS_IMETHOD DeleteSelection(EDirection aAction);
     106                 : 
     107                 :   NS_IMETHOD SetDocumentCharacterSet(const nsACString & characterSet);
     108                 : 
     109                 :   NS_IMETHOD Undo(PRUint32 aCount);
     110                 :   NS_IMETHOD Redo(PRUint32 aCount);
     111                 : 
     112                 :   NS_IMETHOD Cut();
     113                 :   NS_IMETHOD CanCut(bool *aCanCut);
     114                 :   NS_IMETHOD Copy();
     115                 :   NS_IMETHOD CanCopy(bool *aCanCopy);
     116                 :   NS_IMETHOD Paste(PRInt32 aSelectionType);
     117                 :   NS_IMETHOD CanPaste(PRInt32 aSelectionType, bool *aCanPaste);
     118                 :   NS_IMETHOD PasteTransferable(nsITransferable *aTransferable);
     119                 :   NS_IMETHOD CanPasteTransferable(nsITransferable *aTransferable, bool *aCanPaste);
     120                 : 
     121                 :   NS_IMETHOD OutputToString(const nsAString& aFormatType,
     122                 :                             PRUint32 aFlags,
     123                 :                             nsAString& aOutputString);
     124                 :                             
     125                 :   NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
     126                 :                             const nsAString& aFormatType,
     127                 :                             const nsACString& aCharsetOverride,
     128                 :                             PRUint32 aFlags);
     129                 : 
     130                 : 
     131                 :   /** All editor operations which alter the doc should be prefaced
     132                 :    *  with a call to StartOperation, naming the action and direction */
     133                 :   NS_IMETHOD StartOperation(PRInt32 opID, nsIEditor::EDirection aDirection);
     134                 : 
     135                 :   /** All editor operations which alter the doc should be followed
     136                 :    *  with a call to EndOperation */
     137                 :   NS_IMETHOD EndOperation();
     138                 : 
     139                 :   /** make the given selection span the entire document */
     140                 :   NS_IMETHOD SelectEntireDocument(nsISelection *aSelection);
     141                 : 
     142                 :   virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
     143                 : 
     144                 :   virtual already_AddRefed<nsIDOMEventTarget> GetDOMEventTarget();
     145                 : 
     146                 :   virtual nsresult BeginIMEComposition();
     147                 :   virtual nsresult UpdateIMEComposition(const nsAString &aCompositionString,
     148                 :                                         nsIPrivateTextRangeList *aTextRange);
     149                 : 
     150                 :   /* ------------ Utility Routines, not part of public API -------------- */
     151                 :   NS_IMETHOD TypedText(const nsAString& aString, PRInt32 aAction);
     152                 : 
     153                 :   /** Returns the absolute position of the end points of aSelection
     154                 :    * in the document as a text stream.
     155                 :    * Invariant: aStartOffset <= aEndOffset.
     156                 :    */
     157                 :   nsresult GetTextSelectionOffsets(nsISelection *aSelection,
     158                 :                                    PRUint32 &aStartOffset, 
     159                 :                                    PRUint32 &aEndOffset);
     160                 : 
     161                 :   nsresult InsertTextAt(const nsAString &aStringToInsert,
     162                 :                         nsIDOMNode *aDestinationNode,
     163                 :                         PRInt32 aDestOffset,
     164                 :                         bool aDoDeleteSelection);
     165                 : 
     166                 :   virtual nsresult InsertFromDataTransfer(nsIDOMDataTransfer *aDataTransfer,
     167                 :                                           PRInt32 aIndex,
     168                 :                                           nsIDOMDocument *aSourceDoc,
     169                 :                                           nsIDOMNode *aDestinationNode,
     170                 :                                           PRInt32 aDestOffset,
     171                 :                                           bool aDoDeleteSelection);
     172                 : 
     173                 :   virtual nsresult InsertFromDrop(nsIDOMEvent* aDropEvent);
     174                 : 
     175                 :   /**
     176                 :    * Extends the selection for given deletion operation
     177                 :    * If done, also update aAction to what's actually left to do after the
     178                 :    * extension.
     179                 :    */
     180                 :   nsresult ExtendSelectionForDelete(nsISelection* aSelection,
     181                 :                                     nsIEditor::EDirection *aAction);
     182                 : 
     183                 :   static void GetDefaultEditorPrefs(PRInt32 &aNewLineHandling,
     184                 :                                     PRInt32 &aCaretStyle);
     185                 : 
     186                 : protected:
     187                 : 
     188                 :   NS_IMETHOD  InitRules();
     189                 :   void        BeginEditorInit();
     190                 :   nsresult    EndEditorInit();
     191                 : 
     192                 :   // Helpers for output routines
     193                 :   NS_IMETHOD GetAndInitDocEncoder(const nsAString& aFormatType,
     194                 :                                   PRUint32 aFlags,
     195                 :                                   const nsACString& aCharset,
     196                 :                                   nsIDocumentEncoder** encoder);
     197                 : 
     198                 :   // key event helpers
     199                 :   NS_IMETHOD CreateBR(nsIDOMNode *aNode, PRInt32 aOffset, 
     200                 :                       nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect = eNone);
     201                 :   nsresult CreateBRImpl(nsCOMPtr<nsIDOMNode>* aInOutParent,
     202                 :                         PRInt32* aInOutOffset,
     203                 :                         nsCOMPtr<nsIDOMNode>* outBRNode,
     204                 :                         EDirection aSelect);
     205                 :   nsresult InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode);
     206                 : 
     207                 :   // factored methods for handling insertion of data from transferables (drag&drop or clipboard)
     208                 :   NS_IMETHOD PrepareTransferable(nsITransferable **transferable);
     209                 :   NS_IMETHOD InsertTextFromTransferable(nsITransferable *transferable,
     210                 :                                         nsIDOMNode *aDestinationNode,
     211                 :                                         PRInt32 aDestOffset,
     212                 :                                         bool aDoDeleteSelection);
     213                 : 
     214                 :   /** shared outputstring; returns whether selection is collapsed and resulting string */
     215                 :   nsresult SharedOutputString(PRUint32 aFlags, bool* aIsCollapsed, nsAString& aResult);
     216                 : 
     217                 :   /* small utility routine to test the eEditorReadonly bit */
     218                 :   bool IsModifiable();
     219                 : 
     220                 :   bool CanCutOrCopy();
     221                 :   bool FireClipboardEvent(PRInt32 aType);
     222                 : 
     223                 :   bool UpdateMetaCharset(nsIDOMDocument* aDocument,
     224                 :                          const nsACString& aCharacterSet);
     225                 : 
     226                 : // Data members
     227                 : protected:
     228                 : 
     229                 :   nsCOMPtr<nsIEditRules>        mRules;
     230                 :   bool    mWrapToWindow;
     231                 :   PRInt32 mWrapColumn;
     232                 :   PRInt32 mMaxTextLength;
     233                 :   PRInt32 mInitTriggerCounter;
     234                 :   PRInt32 mNewlineHandling;
     235                 :   PRInt32 mCaretStyle;
     236                 : 
     237                 : // friends
     238                 : friend class nsHTMLEditRules;
     239                 : friend class nsTextEditRules;
     240                 : friend class nsAutoEditInitRulesTrigger;
     241                 : 
     242                 : };
     243                 : 
     244                 : #endif //nsPlaintextEditor_h__
     245                 : 

Generated by: LCOV version 1.7