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"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsISupportsImpl.h"
14 #include "mozilla/ContentIterator.h"
15 #include "mozilla/UniquePtr.h"
23 class FilteredContentIterator final
{
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
);
39 nsINode
* GetCurrentNode();
41 nsresult
PositionAt(nsINode
* aCurNode
);
44 bool DidSkip() { return mDidSkip
; }
45 void ClearDidSkip() { mDidSkip
= false; }
48 FilteredContentIterator()
49 : mDidSkip(false), mIsOutOfRange(false), mDirection
{eDirNotSet
} {}
51 virtual ~FilteredContentIterator();
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
;
78 eDirectionType mDirection
;
81 } // namespace mozilla
83 #endif // #ifndef FilteredContentIterator_h