no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / editor / spellchecker / FilteredContentIterator.h
bloba6fee6c1502ebffbd97d2a9daac66c5d7c7d1243
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 FilteredContentIterator_h
7 #define FilteredContentIterator_h
9 #include "nsComposeTxtSrvFilter.h"
10 #include "nsCOMPtr.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsISupportsImpl.h"
13 #include "nscore.h"
14 #include "mozilla/ContentIterator.h"
15 #include "mozilla/UniquePtr.h"
17 class nsAtom;
18 class nsINode;
19 class nsRange;
21 namespace mozilla {
23 namespace dom {
24 class AbstractRange;
27 class FilteredContentIterator final {
28 public:
29 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(FilteredContentIterator)
30 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(FilteredContentIterator)
32 explicit FilteredContentIterator(UniquePtr<nsComposeTxtSrvFilter> aFilter);
34 nsresult Init(nsINode* aRoot);
35 nsresult Init(const dom::AbstractRange* aAbstractRange);
36 nsresult Init(nsINode* aStartContainer, uint32_t aStartOffset,
37 nsINode* aEndContainer, uint32_t aEndOffset);
38 nsresult Init(const RawRangeBoundary& aStartBoundary,
39 const RawRangeBoundary& aEndBoundary);
40 void First();
41 void Last();
42 void Next();
43 void Prev();
44 nsINode* GetCurrentNode();
45 bool IsDone();
46 nsresult PositionAt(nsINode* aCurNode);
48 /* Helpers */
49 bool DidSkip() { return mDidSkip; }
50 void ClearDidSkip() { mDidSkip = false; }
52 protected:
53 FilteredContentIterator()
54 : mDidSkip(false), mIsOutOfRange(false), mDirection{eDirNotSet} {}
56 virtual ~FilteredContentIterator();
58 /**
59 * Callers must guarantee that mRange isn't nullptr and it's positioned.
61 nsresult InitWithRange();
63 // enum to give us the direction
64 typedef enum { eDirNotSet, eForward, eBackward } eDirectionType;
65 nsresult AdvanceNode(nsINode* aNode, nsINode*& aNewNode, eDirectionType aDir);
66 void CheckAdvNode(nsINode* aNode, bool& aDidSkip, eDirectionType aDir);
67 nsresult SwitchDirections(bool aChangeToForward);
69 SafeContentIteratorBase* MOZ_NON_OWNING_REF mCurrentIterator;
70 PostContentIterator mPostIterator;
71 PreContentIterator mPreIterator;
73 UniquePtr<nsComposeTxtSrvFilter> mFilter;
74 RefPtr<nsRange> mRange;
75 bool mDidSkip;
76 bool mIsOutOfRange;
77 eDirectionType mDirection;
80 } // namespace mozilla
82 #endif // #ifndef FilteredContentIterator_h