Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* vim: set ts=4 et sw=4 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* |
michael@0 | 8 | * Implementation of DOM Traversal's nsIDOMTreeWalker |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #ifndef mozilla_dom_TreeWalker_h |
michael@0 | 12 | #define mozilla_dom_TreeWalker_h |
michael@0 | 13 | |
michael@0 | 14 | #include "nsIDOMTreeWalker.h" |
michael@0 | 15 | #include "nsTraversal.h" |
michael@0 | 16 | #include "nsCOMPtr.h" |
michael@0 | 17 | #include "nsTArray.h" |
michael@0 | 18 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 19 | |
michael@0 | 20 | class nsINode; |
michael@0 | 21 | class nsIDOMNode; |
michael@0 | 22 | |
michael@0 | 23 | namespace mozilla { |
michael@0 | 24 | namespace dom { |
michael@0 | 25 | |
michael@0 | 26 | class TreeWalker MOZ_FINAL : public nsIDOMTreeWalker, public nsTraversal |
michael@0 | 27 | { |
michael@0 | 28 | public: |
michael@0 | 29 | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
michael@0 | 30 | NS_DECL_NSIDOMTREEWALKER |
michael@0 | 31 | |
michael@0 | 32 | TreeWalker(nsINode *aRoot, |
michael@0 | 33 | uint32_t aWhatToShow, |
michael@0 | 34 | const NodeFilterHolder &aFilter); |
michael@0 | 35 | virtual ~TreeWalker(); |
michael@0 | 36 | |
michael@0 | 37 | NS_DECL_CYCLE_COLLECTION_CLASS(TreeWalker) |
michael@0 | 38 | |
michael@0 | 39 | // WebIDL API |
michael@0 | 40 | nsINode* Root() const |
michael@0 | 41 | { |
michael@0 | 42 | return mRoot; |
michael@0 | 43 | } |
michael@0 | 44 | uint32_t WhatToShow() const |
michael@0 | 45 | { |
michael@0 | 46 | return mWhatToShow; |
michael@0 | 47 | } |
michael@0 | 48 | already_AddRefed<NodeFilter> GetFilter() |
michael@0 | 49 | { |
michael@0 | 50 | return mFilter.ToWebIDLCallback(); |
michael@0 | 51 | } |
michael@0 | 52 | nsINode* CurrentNode() const |
michael@0 | 53 | { |
michael@0 | 54 | return mCurrentNode; |
michael@0 | 55 | } |
michael@0 | 56 | void SetCurrentNode(nsINode& aNode, ErrorResult& aResult); |
michael@0 | 57 | // All our traversal methods return strong refs because filtering can |
michael@0 | 58 | // remove nodes from the tree. |
michael@0 | 59 | already_AddRefed<nsINode> ParentNode(ErrorResult& aResult); |
michael@0 | 60 | already_AddRefed<nsINode> FirstChild(ErrorResult& aResult); |
michael@0 | 61 | already_AddRefed<nsINode> LastChild(ErrorResult& aResult); |
michael@0 | 62 | already_AddRefed<nsINode> PreviousSibling(ErrorResult& aResult); |
michael@0 | 63 | already_AddRefed<nsINode> NextSibling(ErrorResult& aResult); |
michael@0 | 64 | already_AddRefed<nsINode> PreviousNode(ErrorResult& aResult); |
michael@0 | 65 | already_AddRefed<nsINode> NextNode(ErrorResult& aResult); |
michael@0 | 66 | |
michael@0 | 67 | JSObject* WrapObject(JSContext *cx); |
michael@0 | 68 | |
michael@0 | 69 | private: |
michael@0 | 70 | nsCOMPtr<nsINode> mCurrentNode; |
michael@0 | 71 | |
michael@0 | 72 | /* |
michael@0 | 73 | * Implements FirstChild and LastChild which only vary in which direction |
michael@0 | 74 | * they search. |
michael@0 | 75 | * @param aReversed Controls whether we search forwards or backwards |
michael@0 | 76 | * @param aResult Whether we threw or not. |
michael@0 | 77 | * @returns The desired node. Null if no child is found |
michael@0 | 78 | */ |
michael@0 | 79 | already_AddRefed<nsINode> FirstChildInternal(bool aReversed, |
michael@0 | 80 | ErrorResult& aResult); |
michael@0 | 81 | |
michael@0 | 82 | /* |
michael@0 | 83 | * Implements NextSibling and PreviousSibling which only vary in which |
michael@0 | 84 | * direction they search. |
michael@0 | 85 | * @param aReversed Controls whether we search forwards or backwards |
michael@0 | 86 | * @param aResult Whether we threw or not. |
michael@0 | 87 | * @returns The desired node. Null if no child is found |
michael@0 | 88 | */ |
michael@0 | 89 | already_AddRefed<nsINode> NextSiblingInternal(bool aReversed, |
michael@0 | 90 | ErrorResult& aResult); |
michael@0 | 91 | |
michael@0 | 92 | // Implementation for our various XPCOM getters |
michael@0 | 93 | typedef already_AddRefed<nsINode> (TreeWalker::*NodeGetter)(ErrorResult&); |
michael@0 | 94 | inline nsresult ImplNodeGetter(NodeGetter aGetter, nsIDOMNode** aRetval) |
michael@0 | 95 | { |
michael@0 | 96 | mozilla::ErrorResult rv; |
michael@0 | 97 | nsCOMPtr<nsINode> node = (this->*aGetter)(rv); |
michael@0 | 98 | if (rv.Failed()) { |
michael@0 | 99 | return rv.ErrorCode(); |
michael@0 | 100 | } |
michael@0 | 101 | *aRetval = node ? node.forget().take()->AsDOMNode() : nullptr; |
michael@0 | 102 | return NS_OK; |
michael@0 | 103 | } |
michael@0 | 104 | }; |
michael@0 | 105 | |
michael@0 | 106 | } // namespace dom |
michael@0 | 107 | } // namespace mozilla |
michael@0 | 108 | |
michael@0 | 109 | #endif // mozilla_dom_TreeWalker_h |
michael@0 | 110 |