tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FilteredContentIterator.h (2455B)


      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 FilteredContentIterator_h
      7 #define FilteredContentIterator_h
      8 
      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"
     16 
     17 class nsAtom;
     18 class nsINode;
     19 class nsRange;
     20 
     21 namespace mozilla {
     22 
     23 namespace dom {
     24 class AbstractRange;
     25 }
     26 
     27 class FilteredContentIterator final {
     28 public:
     29  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(FilteredContentIterator)
     30  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(FilteredContentIterator)
     31 
     32  explicit FilteredContentIterator(UniquePtr<nsComposeTxtSrvFilter> aFilter);
     33 
     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);
     40  void First();
     41  void Last();
     42  void Next();
     43  void Prev();
     44  nsINode* GetCurrentNode();
     45  bool IsDone();
     46  nsresult PositionAt(nsINode* aCurNode);
     47 
     48  /* Helpers */
     49  bool DidSkip() { return mDidSkip; }
     50  void ClearDidSkip() { mDidSkip = false; }
     51 
     52 protected:
     53  FilteredContentIterator()
     54      : mDidSkip(false), mIsOutOfRange(false), mDirection{eDirNotSet} {}
     55 
     56  virtual ~FilteredContentIterator();
     57 
     58  /**
     59   * Callers must guarantee that mRange isn't nullptr and it's positioned.
     60   */
     61  nsresult InitWithRange();
     62 
     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);
     68 
     69  SafeContentIteratorBase* MOZ_NON_OWNING_REF mCurrentIterator;
     70  PostContentIterator mPostIterator;
     71  PreContentIterator mPreIterator;
     72 
     73  UniquePtr<nsComposeTxtSrvFilter> mFilter;
     74  RefPtr<nsRange> mRange;
     75  bool mDidSkip;
     76  bool mIsOutOfRange;
     77  eDirectionType mDirection;
     78 };
     79 
     80 }  // namespace mozilla
     81 
     82 #endif  // #ifndef FilteredContentIterator_h