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"
27 class FilteredContentIterator final
{
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
);
44 nsINode
* GetCurrentNode();
46 nsresult
PositionAt(nsINode
* aCurNode
);
49 bool DidSkip() { return mDidSkip
; }
50 void ClearDidSkip() { mDidSkip
= false; }
53 FilteredContentIterator()
54 : mDidSkip(false), mIsOutOfRange(false), mDirection
{eDirNotSet
} {}
56 virtual ~FilteredContentIterator();
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
;
77 eDirectionType mDirection
;
80 } // namespace mozilla
82 #endif // #ifndef FilteredContentIterator_h