Bug 1835710 - Cancel off-thread JIT compilation before changing nursery allocation...
[gecko.git] / dom / base / NodeIterator.h
blob0f20734685737eacd969613d69a109eb9169a783
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /*
8 * Implementation of DOM Traversal's NodeIterator
9 */
11 #ifndef mozilla_dom_NodeIterator_h
12 #define mozilla_dom_NodeIterator_h
14 #include "nsTraversal.h"
15 #include "nsCycleCollectionParticipant.h"
16 #include "nsStubMutationObserver.h"
18 class nsINode;
20 namespace mozilla::dom {
22 class NodeIterator final : public nsStubMutationObserver, public nsTraversal {
23 public:
24 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
26 NodeIterator(nsINode* aRoot, uint32_t aWhatToShow, NodeFilter* aFilter);
28 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
30 NS_DECL_CYCLE_COLLECTION_CLASS(NodeIterator)
32 // WebIDL API
33 nsINode* Root() const { return mRoot; }
34 nsINode* GetReferenceNode() const { return mPointer.mNode; }
35 bool PointerBeforeReferenceNode() const { return mPointer.mBeforeNode; }
36 uint32_t WhatToShow() const { return mWhatToShow; }
37 NodeFilter* GetFilter() { return mFilter; }
38 already_AddRefed<nsINode> NextNode(ErrorResult& aResult) {
39 return NextOrPrevNode(&NodePointer::MoveToNext, aResult);
41 already_AddRefed<nsINode> PreviousNode(ErrorResult& aResult) {
42 return NextOrPrevNode(&NodePointer::MoveToPrevious, aResult);
44 void Detach();
46 bool WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto,
47 JS::MutableHandle<JSObject*> aReflector);
49 private:
50 virtual ~NodeIterator();
52 struct NodePointer {
53 NodePointer() : mNode(nullptr), mBeforeNode(false) {}
54 NodePointer(nsINode* aNode, bool aBeforeNode);
56 typedef bool (NodePointer::*MoveToMethodType)(nsINode*);
57 bool MoveToNext(nsINode* aRoot);
58 bool MoveToPrevious(nsINode* aRoot);
60 bool MoveForward(nsINode* aRoot, nsINode* aNode);
61 void MoveBackward(nsINode* aParent, nsINode* aNode);
63 void AdjustAfterRemoval(nsINode* aRoot, nsINode* aContainer,
64 nsIContent* aChild, nsIContent* aPreviousSibling);
66 void Clear() { mNode = nullptr; }
68 nsINode* mNode;
69 bool mBeforeNode;
72 // Have to return a strong ref, because the act of testing the node can
73 // remove it from the DOM so we're holding the only ref to it.
74 already_AddRefed<nsINode> NextOrPrevNode(NodePointer::MoveToMethodType aMove,
75 ErrorResult& aResult);
77 NodePointer mPointer;
78 NodePointer mWorkingPointer;
81 } // namespace mozilla::dom
83 #endif // mozilla_dom_NodeIterator_h