diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /editor/spellchecker/FilteredContentIterator.h | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'editor/spellchecker/FilteredContentIterator.h')
-rw-r--r-- | editor/spellchecker/FilteredContentIterator.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/editor/spellchecker/FilteredContentIterator.h b/editor/spellchecker/FilteredContentIterator.h new file mode 100644 index 0000000000..a6fee6c150 --- /dev/null +++ b/editor/spellchecker/FilteredContentIterator.h @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef FilteredContentIterator_h +#define FilteredContentIterator_h + +#include "nsComposeTxtSrvFilter.h" +#include "nsCOMPtr.h" +#include "nsCycleCollectionParticipant.h" +#include "nsISupportsImpl.h" +#include "nscore.h" +#include "mozilla/ContentIterator.h" +#include "mozilla/UniquePtr.h" + +class nsAtom; +class nsINode; +class nsRange; + +namespace mozilla { + +namespace dom { +class AbstractRange; +} + +class FilteredContentIterator final { + public: + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(FilteredContentIterator) + NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(FilteredContentIterator) + + explicit FilteredContentIterator(UniquePtr<nsComposeTxtSrvFilter> aFilter); + + nsresult Init(nsINode* aRoot); + nsresult Init(const dom::AbstractRange* aAbstractRange); + nsresult Init(nsINode* aStartContainer, uint32_t aStartOffset, + nsINode* aEndContainer, uint32_t aEndOffset); + nsresult Init(const RawRangeBoundary& aStartBoundary, + const RawRangeBoundary& aEndBoundary); + void First(); + void Last(); + void Next(); + void Prev(); + nsINode* GetCurrentNode(); + bool IsDone(); + nsresult PositionAt(nsINode* aCurNode); + + /* Helpers */ + bool DidSkip() { return mDidSkip; } + void ClearDidSkip() { mDidSkip = false; } + + protected: + FilteredContentIterator() + : mDidSkip(false), mIsOutOfRange(false), mDirection{eDirNotSet} {} + + virtual ~FilteredContentIterator(); + + /** + * Callers must guarantee that mRange isn't nullptr and it's positioned. + */ + nsresult InitWithRange(); + + // enum to give us the direction + typedef enum { eDirNotSet, eForward, eBackward } eDirectionType; + nsresult AdvanceNode(nsINode* aNode, nsINode*& aNewNode, eDirectionType aDir); + void CheckAdvNode(nsINode* aNode, bool& aDidSkip, eDirectionType aDir); + nsresult SwitchDirections(bool aChangeToForward); + + SafeContentIteratorBase* MOZ_NON_OWNING_REF mCurrentIterator; + PostContentIterator mPostIterator; + PreContentIterator mPreIterator; + + UniquePtr<nsComposeTxtSrvFilter> mFilter; + RefPtr<nsRange> mRange; + bool mDidSkip; + bool mIsOutOfRange; + eDirectionType mDirection; +}; + +} // namespace mozilla + +#endif // #ifndef FilteredContentIterator_h |