Bug 1523562 [wpt PR 14770] - Reland "[PE] Fix background-image on ::first-line",...
[gecko.git] / editor / spellchecker / FilteredContentIterator.h
blobd9313ee69e43d17bfad56f1ce1d5acf3694d302e
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 class FilteredContentIterator final {
24 public:
25 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(FilteredContentIterator)
26 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(FilteredContentIterator)
28 explicit FilteredContentIterator(UniquePtr<nsComposeTxtSrvFilter> aFilter);
30 nsresult Init(nsINode* aRoot);
31 nsresult Init(nsRange* aRange);
32 nsresult Init(nsINode* aStartContainer, uint32_t aStartOffset,
33 nsINode* aEndContainer, uint32_t aEndOffset);
34 nsresult Init(const RawRangeBoundary& aStart, const RawRangeBoundary& aEnd);
35 void First();
36 void Last();
37 void Next();
38 void Prev();
39 nsINode* GetCurrentNode();
40 bool IsDone();
41 nsresult PositionAt(nsINode* aCurNode);
43 /* Helpers */
44 bool DidSkip() { return mDidSkip; }
45 void ClearDidSkip() { mDidSkip = false; }
47 protected:
48 FilteredContentIterator()
49 : mDidSkip(false), mIsOutOfRange(false), mDirection{eDirNotSet} {}
51 virtual ~FilteredContentIterator();
53 /**
54 * Callers must guarantee that mRange isn't nullptr and it's positioned.
56 nsresult InitWithRange();
58 // enum to give us the direction
59 typedef enum { eDirNotSet, eForward, eBackward } eDirectionType;
60 nsresult AdvanceNode(nsINode* aNode, nsINode*& aNewNode, eDirectionType aDir);
61 void CheckAdvNode(nsINode* aNode, bool& aDidSkip, eDirectionType aDir);
62 nsresult SwitchDirections(bool aChangeToForward);
64 ContentIteratorBase* MOZ_NON_OWNING_REF mCurrentIterator;
65 PostContentIterator mPostIterator;
66 PreContentIterator mPreIterator;
68 RefPtr<nsAtom> mBlockQuoteAtom;
69 RefPtr<nsAtom> mScriptAtom;
70 RefPtr<nsAtom> mTextAreaAtom;
71 RefPtr<nsAtom> mSelectAreaAtom;
72 RefPtr<nsAtom> mMapAtom;
74 UniquePtr<nsComposeTxtSrvFilter> mFilter;
75 RefPtr<nsRange> mRange;
76 bool mDidSkip;
77 bool mIsOutOfRange;
78 eDirectionType mDirection;
81 } // namespace mozilla
83 #endif // #ifndef FilteredContentIterator_h