Bug 1852754: part 9) Add tests for dynamically loading <link rel="prefetch"> elements...
[gecko.git] / dom / base / TreeWalker.h
blob4580a44b1f61011e9285b44e2d9cca47d2e396af
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=4 et sw=2 tw=80: */
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 TreeWalker
9 */
11 #ifndef mozilla_dom_TreeWalker_h
12 #define mozilla_dom_TreeWalker_h
14 #include "nsISupports.h"
15 #include "nsTraversal.h"
16 #include "nsCOMPtr.h"
17 #include "nsTArray.h"
18 #include "nsCycleCollectionParticipant.h"
20 class nsINode;
22 namespace mozilla::dom {
24 class TreeWalker final : public nsISupports, public nsTraversal {
25 virtual ~TreeWalker();
27 public:
28 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
30 TreeWalker(nsINode* aRoot, uint32_t aWhatToShow, NodeFilter* aFilter);
32 NS_DECL_CYCLE_COLLECTION_CLASS(TreeWalker)
34 // WebIDL API
35 nsINode* Root() const { return mRoot; }
36 uint32_t WhatToShow() const { return mWhatToShow; }
37 NodeFilter* GetFilter() { return mFilter; }
38 nsINode* CurrentNode() const { return mCurrentNode; }
39 void SetCurrentNode(nsINode& aNode, ErrorResult& aResult);
40 // All our traversal methods return strong refs because filtering can
41 // remove nodes from the tree.
42 already_AddRefed<nsINode> ParentNode(ErrorResult& aResult);
43 already_AddRefed<nsINode> FirstChild(ErrorResult& aResult);
44 already_AddRefed<nsINode> LastChild(ErrorResult& aResult);
45 already_AddRefed<nsINode> PreviousSibling(ErrorResult& aResult);
46 already_AddRefed<nsINode> NextSibling(ErrorResult& aResult);
47 already_AddRefed<nsINode> PreviousNode(ErrorResult& aResult);
48 already_AddRefed<nsINode> NextNode(ErrorResult& aResult);
50 bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto,
51 JS::MutableHandle<JSObject*> aReflector);
53 private:
54 nsCOMPtr<nsINode> mCurrentNode;
57 * Implements FirstChild and LastChild which only vary in which direction
58 * they search.
59 * @param aReversed Controls whether we search forwards or backwards
60 * @param aResult Whether we threw or not.
61 * @returns The desired node. Null if no child is found
63 already_AddRefed<nsINode> FirstChildInternal(bool aReversed,
64 ErrorResult& aResult);
67 * Implements NextSibling and PreviousSibling which only vary in which
68 * direction they search.
69 * @param aReversed Controls whether we search forwards or backwards
70 * @param aResult Whether we threw or not.
71 * @returns The desired node. Null if no child is found
73 already_AddRefed<nsINode> NextSiblingInternal(bool aReversed,
74 ErrorResult& aResult);
77 } // namespace mozilla::dom
79 #endif // mozilla_dom_TreeWalker_h