Line data Source code
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/. */
5 :
6 : #ifndef nsFilteredContentIterator_h__
7 : #define nsFilteredContentIterator_h__
8 :
9 : #include "nsCOMPtr.h"
10 : #include "nsCycleCollectionParticipant.h"
11 : #include "nsIContentIterator.h"
12 : #include "nsISupportsImpl.h"
13 : #include "nscore.h"
14 :
15 : class nsIAtom;
16 : class nsIDOMNode;
17 : class nsIDOMRange;
18 : class nsINode;
19 : class nsITextServicesFilter;
20 : class nsRange;
21 :
22 : class nsFilteredContentIterator final : public nsIContentIterator
23 : {
24 : public:
25 :
26 : // nsISupports interface...
27 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
28 0 : NS_DECL_CYCLE_COLLECTION_CLASS(nsFilteredContentIterator)
29 :
30 : explicit nsFilteredContentIterator(nsITextServicesFilter* aFilter);
31 :
32 : /* nsIContentIterator */
33 : virtual nsresult Init(nsINode* aRoot) override;
34 : virtual nsresult Init(nsIDOMRange* aRange) override;
35 : virtual void First() override;
36 : virtual void Last() override;
37 : virtual void Next() override;
38 : virtual void Prev() override;
39 : virtual nsINode *GetCurrentNode() override;
40 : virtual bool IsDone() override;
41 : virtual nsresult PositionAt(nsINode* aCurNode) override;
42 :
43 : /* Helpers */
44 0 : bool DidSkip() { return mDidSkip; }
45 0 : void ClearDidSkip() { mDidSkip = false; }
46 :
47 : protected:
48 : nsFilteredContentIterator() : mDidSkip(false), mIsOutOfRange(false) { }
49 :
50 : virtual ~nsFilteredContentIterator();
51 :
52 : // enum to give us the direction
53 : typedef enum {eDirNotSet, eForward, eBackward} eDirectionType;
54 : nsresult AdvanceNode(nsIDOMNode* aNode, nsIDOMNode*& aNewNode, eDirectionType aDir);
55 : void CheckAdvNode(nsIDOMNode* aNode, bool& aDidSkip, eDirectionType aDir);
56 : nsresult SwitchDirections(bool aChangeToForward);
57 :
58 : nsCOMPtr<nsIContentIterator> mCurrentIterator;
59 : nsCOMPtr<nsIContentIterator> mIterator;
60 : nsCOMPtr<nsIContentIterator> mPreIterator;
61 :
62 : nsCOMPtr<nsIAtom> mBlockQuoteAtom;
63 : nsCOMPtr<nsIAtom> mScriptAtom;
64 : nsCOMPtr<nsIAtom> mTextAreaAtom;
65 : nsCOMPtr<nsIAtom> mSelectAreaAtom;
66 : nsCOMPtr<nsIAtom> mMapAtom;
67 :
68 : nsCOMPtr<nsITextServicesFilter> mFilter;
69 : RefPtr<nsRange> mRange;
70 : bool mDidSkip;
71 : bool mIsOutOfRange;
72 : eDirectionType mDirection;
73 : };
74 :
75 : #endif
|