editor/txtsvc/src/nsTextServicesDocument.h

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsTextServicesDocument_h__
michael@0 7 #define nsTextServicesDocument_h__
michael@0 8
michael@0 9 #include "nsCOMPtr.h"
michael@0 10 #include "nsCycleCollectionParticipant.h"
michael@0 11 #include "nsIEditActionListener.h"
michael@0 12 #include "nsISupportsImpl.h"
michael@0 13 #include "nsITextServicesDocument.h"
michael@0 14 #include "nsIWeakReferenceUtils.h"
michael@0 15 #include "nsTArray.h"
michael@0 16 #include "nscore.h"
michael@0 17
michael@0 18 class OffsetEntry;
michael@0 19 class nsIAtom;
michael@0 20 class nsIContent;
michael@0 21 class nsIContentIterator;
michael@0 22 class nsIDOMCharacterData;
michael@0 23 class nsIDOMDocument;
michael@0 24 class nsIDOMNode;
michael@0 25 class nsIDOMRange;
michael@0 26 class nsIEditor;
michael@0 27 class nsISelection;
michael@0 28 class nsISelectionController;
michael@0 29 class nsITextServicesFilter;
michael@0 30 class nsString;
michael@0 31
michael@0 32 /** implementation of a text services object.
michael@0 33 *
michael@0 34 */
michael@0 35 class nsTextServicesDocument : public nsITextServicesDocument,
michael@0 36 public nsIEditActionListener
michael@0 37 {
michael@0 38 private:
michael@0 39 static nsIAtom *sAAtom;
michael@0 40 static nsIAtom *sAddressAtom;
michael@0 41 static nsIAtom *sBigAtom;
michael@0 42 static nsIAtom *sBAtom;
michael@0 43 static nsIAtom *sCiteAtom;
michael@0 44 static nsIAtom *sCodeAtom;
michael@0 45 static nsIAtom *sDfnAtom;
michael@0 46 static nsIAtom *sEmAtom;
michael@0 47 static nsIAtom *sFontAtom;
michael@0 48 static nsIAtom *sIAtom;
michael@0 49 static nsIAtom *sKbdAtom;
michael@0 50 static nsIAtom *sKeygenAtom;
michael@0 51 static nsIAtom *sNobrAtom;
michael@0 52 static nsIAtom *sSAtom;
michael@0 53 static nsIAtom *sSampAtom;
michael@0 54 static nsIAtom *sSmallAtom;
michael@0 55 static nsIAtom *sSpacerAtom;
michael@0 56 static nsIAtom *sSpanAtom;
michael@0 57 static nsIAtom *sStrikeAtom;
michael@0 58 static nsIAtom *sStrongAtom;
michael@0 59 static nsIAtom *sSubAtom;
michael@0 60 static nsIAtom *sSupAtom;
michael@0 61 static nsIAtom *sTtAtom;
michael@0 62 static nsIAtom *sUAtom;
michael@0 63 static nsIAtom *sVarAtom;
michael@0 64 static nsIAtom *sWbrAtom;
michael@0 65
michael@0 66 typedef enum { eIsDone=0, // No iterator (I), or iterator doesn't point to anything valid.
michael@0 67 eValid, // I points to first text node (TN) in current block (CB).
michael@0 68 ePrev, // No TN in CB, I points to first TN in prev block.
michael@0 69 eNext // No TN in CB, I points to first TN in next block.
michael@0 70 } TSDIteratorStatus;
michael@0 71
michael@0 72 nsCOMPtr<nsIDOMDocument> mDOMDocument;
michael@0 73 nsCOMPtr<nsISelectionController>mSelCon;
michael@0 74 nsWeakPtr mEditor; // avoid a cycle with the spell checker and editor
michael@0 75 nsCOMPtr<nsIContentIterator> mIterator;
michael@0 76 TSDIteratorStatus mIteratorStatus;
michael@0 77 nsCOMPtr<nsIContent> mPrevTextBlock;
michael@0 78 nsCOMPtr<nsIContent> mNextTextBlock;
michael@0 79 nsTArray<OffsetEntry*> mOffsetTable;
michael@0 80
michael@0 81 int32_t mSelStartIndex;
michael@0 82 int32_t mSelStartOffset;
michael@0 83 int32_t mSelEndIndex;
michael@0 84 int32_t mSelEndOffset;
michael@0 85
michael@0 86 nsCOMPtr<nsIDOMRange> mExtent;
michael@0 87
michael@0 88 nsCOMPtr<nsITextServicesFilter> mTxtSvcFilter;
michael@0 89
michael@0 90 public:
michael@0 91
michael@0 92 /** The default constructor.
michael@0 93 */
michael@0 94 nsTextServicesDocument();
michael@0 95
michael@0 96 /** The default destructor.
michael@0 97 */
michael@0 98 virtual ~nsTextServicesDocument();
michael@0 99
michael@0 100 /** To be called at module init
michael@0 101 */
michael@0 102 static void RegisterAtoms();
michael@0 103
michael@0 104 /* Macro for AddRef(), Release(), and QueryInterface() */
michael@0 105 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 106 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsTextServicesDocument, nsITextServicesDocument)
michael@0 107
michael@0 108 /* nsITextServicesDocument method implementations. */
michael@0 109 NS_IMETHOD InitWithEditor(nsIEditor *aEditor);
michael@0 110 NS_IMETHOD GetDocument(nsIDOMDocument **aDoc);
michael@0 111 NS_IMETHOD SetExtent(nsIDOMRange* aDOMRange);
michael@0 112 NS_IMETHOD ExpandRangeToWordBoundaries(nsIDOMRange *aRange);
michael@0 113 NS_IMETHOD SetFilter(nsITextServicesFilter *aFilter);
michael@0 114 NS_IMETHOD GetCurrentTextBlock(nsString *aStr);
michael@0 115 NS_IMETHOD FirstBlock();
michael@0 116 NS_IMETHOD LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, int32_t *aSelOffset, int32_t *aSelLength);
michael@0 117 NS_IMETHOD PrevBlock();
michael@0 118 NS_IMETHOD NextBlock();
michael@0 119 NS_IMETHOD IsDone(bool *aIsDone);
michael@0 120 NS_IMETHOD SetSelection(int32_t aOffset, int32_t aLength);
michael@0 121 NS_IMETHOD ScrollSelectionIntoView();
michael@0 122 NS_IMETHOD DeleteSelection();
michael@0 123 NS_IMETHOD InsertText(const nsString *aText);
michael@0 124
michael@0 125 /* nsIEditActionListener method implementations. */
michael@0 126 NS_IMETHOD WillInsertNode(nsIDOMNode *aNode,
michael@0 127 nsIDOMNode *aParent,
michael@0 128 int32_t aPosition);
michael@0 129 NS_IMETHOD DidInsertNode(nsIDOMNode *aNode,
michael@0 130 nsIDOMNode *aParent,
michael@0 131 int32_t aPosition,
michael@0 132 nsresult aResult);
michael@0 133
michael@0 134 NS_IMETHOD WillDeleteNode(nsIDOMNode *aChild);
michael@0 135 NS_IMETHOD DidDeleteNode(nsIDOMNode *aChild, nsresult aResult);
michael@0 136
michael@0 137 NS_IMETHOD WillSplitNode(nsIDOMNode * aExistingRightNode,
michael@0 138 int32_t aOffset);
michael@0 139 NS_IMETHOD DidSplitNode(nsIDOMNode *aExistingRightNode,
michael@0 140 int32_t aOffset,
michael@0 141 nsIDOMNode *aNewLeftNode,
michael@0 142 nsresult aResult);
michael@0 143
michael@0 144 NS_IMETHOD WillJoinNodes(nsIDOMNode *aLeftNode,
michael@0 145 nsIDOMNode *aRightNode,
michael@0 146 nsIDOMNode *aParent);
michael@0 147 NS_IMETHOD DidJoinNodes(nsIDOMNode *aLeftNode,
michael@0 148 nsIDOMNode *aRightNode,
michael@0 149 nsIDOMNode *aParent,
michael@0 150 nsresult aResult);
michael@0 151 // these listen methods are unused:
michael@0 152 NS_IMETHOD WillCreateNode(const nsAString& aTag, nsIDOMNode *aParent, int32_t aPosition);
michael@0 153 NS_IMETHOD DidCreateNode(const nsAString& aTag, nsIDOMNode *aNode, nsIDOMNode *aParent, int32_t aPosition, nsresult aResult);
michael@0 154 NS_IMETHOD WillInsertText(nsIDOMCharacterData *aTextNode, int32_t aOffset, const nsAString &aString);
michael@0 155 NS_IMETHOD DidInsertText(nsIDOMCharacterData *aTextNode, int32_t aOffset, const nsAString &aString, nsresult aResult);
michael@0 156 NS_IMETHOD WillDeleteText(nsIDOMCharacterData *aTextNode, int32_t aOffset, int32_t aLength);
michael@0 157 NS_IMETHOD DidDeleteText(nsIDOMCharacterData *aTextNode, int32_t aOffset, int32_t aLength, nsresult aResult);
michael@0 158 NS_IMETHOD WillDeleteSelection(nsISelection *aSelection);
michael@0 159 NS_IMETHOD DidDeleteSelection(nsISelection *aSelection);
michael@0 160
michael@0 161 /* Helper functions */
michael@0 162 static nsresult GetRangeEndPoints(nsIDOMRange *aRange, nsIDOMNode **aParent1, int32_t *aOffset1, nsIDOMNode **aParent2, int32_t *aOffset2);
michael@0 163 static nsresult CreateRange(nsIDOMNode *aStartParent, int32_t aStartOffset, nsIDOMNode *aEndParent, int32_t aEndOffset, nsIDOMRange **aRange);
michael@0 164
michael@0 165 private:
michael@0 166 /* nsTextServicesDocument private methods. */
michael@0 167
michael@0 168 nsresult CreateContentIterator(nsIDOMRange *aRange, nsIContentIterator **aIterator);
michael@0 169
michael@0 170 nsresult GetDocumentContentRootNode(nsIDOMNode **aNode);
michael@0 171 nsresult CreateDocumentContentRange(nsIDOMRange **aRange);
michael@0 172 nsresult CreateDocumentContentRootToNodeOffsetRange(nsIDOMNode *aParent, int32_t aOffset, bool aToStart, nsIDOMRange **aRange);
michael@0 173 nsresult CreateDocumentContentIterator(nsIContentIterator **aIterator);
michael@0 174
michael@0 175 nsresult AdjustContentIterator();
michael@0 176
michael@0 177 static nsresult FirstTextNode(nsIContentIterator *aIterator, TSDIteratorStatus *IteratorStatus);
michael@0 178 static nsresult LastTextNode(nsIContentIterator *aIterator, TSDIteratorStatus *IteratorStatus);
michael@0 179
michael@0 180 static nsresult FirstTextNodeInCurrentBlock(nsIContentIterator *aIterator);
michael@0 181 static nsresult FirstTextNodeInPrevBlock(nsIContentIterator *aIterator);
michael@0 182 static nsresult FirstTextNodeInNextBlock(nsIContentIterator *aIterator);
michael@0 183
michael@0 184 nsresult GetFirstTextNodeInPrevBlock(nsIContent **aContent);
michael@0 185 nsresult GetFirstTextNodeInNextBlock(nsIContent **aContent);
michael@0 186
michael@0 187 static bool IsBlockNode(nsIContent *aContent);
michael@0 188 static bool IsTextNode(nsIContent *aContent);
michael@0 189 static bool IsTextNode(nsIDOMNode *aNode);
michael@0 190
michael@0 191 static bool DidSkip(nsIContentIterator* aFilteredIter);
michael@0 192 static void ClearDidSkip(nsIContentIterator* aFilteredIter);
michael@0 193
michael@0 194 static bool HasSameBlockNodeParent(nsIContent *aContent1, nsIContent *aContent2);
michael@0 195
michael@0 196 nsresult SetSelectionInternal(int32_t aOffset, int32_t aLength, bool aDoUpdate);
michael@0 197 nsresult GetSelection(TSDBlockSelectionStatus *aSelStatus, int32_t *aSelOffset, int32_t *aSelLength);
michael@0 198 nsresult GetCollapsedSelection(TSDBlockSelectionStatus *aSelStatus, int32_t *aSelOffset, int32_t *aSelLength);
michael@0 199 nsresult GetUncollapsedSelection(TSDBlockSelectionStatus *aSelStatus, int32_t *aSelOffset, int32_t *aSelLength);
michael@0 200
michael@0 201 bool SelectionIsCollapsed();
michael@0 202 bool SelectionIsValid();
michael@0 203
michael@0 204 static nsresult CreateOffsetTable(nsTArray<OffsetEntry*> *aOffsetTable,
michael@0 205 nsIContentIterator *aIterator,
michael@0 206 TSDIteratorStatus *aIteratorStatus,
michael@0 207 nsIDOMRange *aIterRange,
michael@0 208 nsString *aStr);
michael@0 209 static nsresult ClearOffsetTable(nsTArray<OffsetEntry*> *aOffsetTable);
michael@0 210
michael@0 211 static nsresult NodeHasOffsetEntry(nsTArray<OffsetEntry*> *aOffsetTable,
michael@0 212 nsIDOMNode *aNode,
michael@0 213 bool *aHasEntry,
michael@0 214 int32_t *aEntryIndex);
michael@0 215
michael@0 216 nsresult RemoveInvalidOffsetEntries();
michael@0 217 nsresult SplitOffsetEntry(int32_t aTableIndex, int32_t aOffsetIntoEntry);
michael@0 218
michael@0 219 static nsresult FindWordBounds(nsTArray<OffsetEntry*> *offsetTable,
michael@0 220 nsString *blockStr,
michael@0 221 nsIDOMNode *aNode, int32_t aNodeOffset,
michael@0 222 nsIDOMNode **aWordStartNode,
michael@0 223 int32_t *aWordStartOffset,
michael@0 224 nsIDOMNode **aWordEndNode,
michael@0 225 int32_t *aWordEndOffset);
michael@0 226
michael@0 227 #ifdef DEBUG_kin
michael@0 228 void PrintOffsetTable();
michael@0 229 void PrintContentNode(nsIContent *aContent);
michael@0 230 #endif
michael@0 231 };
michael@0 232
michael@0 233 #endif // nsTextServicesDocument_h__

mercurial