darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 1 | /* |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 | * Copyright (C) 2000 Frederik Holljen (frederik.holljen@hig.no) |
| 4 | * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
| 5 | * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
darin@apple.com | e4f9a66 | 2008-02-08 10:35:20 +0000 | [diff] [blame] | 6 | * Copyright (C) 2004, 2008 Apple Inc. All rights reserved. |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Library General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Library General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Library General Public License |
| 19 | * along with this library; see the file COPYING.LIB. If not, write to |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 | * Boston, MA 02110-1301, USA. |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 22 | * |
| 23 | */ |
| 24 | |
| 25 | #ifndef NodeIterator_h |
| 26 | #define NodeIterator_h |
| 27 | |
dino@apple.com | 54b5cc1 | 2008-07-08 03:19:30 +0000 | [diff] [blame] | 28 | #include "NodeFilter.h" |
eric@webkit.org | 1373a74 | 2012-11-18 03:37:49 +0000 | [diff] [blame] | 29 | #include "ScriptWrappable.h" |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 30 | #include "Traversal.h" |
darin@apple.com | e4f9a66 | 2008-02-08 10:35:20 +0000 | [diff] [blame] | 31 | #include <wtf/PassRefPtr.h> |
darin@apple.com | 1edff43 | 2008-06-24 05:23:17 +0000 | [diff] [blame] | 32 | #include <wtf/RefCounted.h> |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 33 | |
| 34 | namespace WebCore { |
| 35 | |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 36 | typedef int ExceptionCode; |
| 37 | |
eric@webkit.org | 1373a74 | 2012-11-18 03:37:49 +0000 | [diff] [blame] | 38 | class NodeIterator : public ScriptWrappable, public RefCounted<NodeIterator>, public Traversal { |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 39 | public: |
andersca@apple.com | 0f509b1 | 2008-06-04 21:12:16 +0000 | [diff] [blame] | 40 | static PassRefPtr<NodeIterator> create(PassRefPtr<Node> rootNode, unsigned whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences) |
| 41 | { |
| 42 | return adoptRef(new NodeIterator(rootNode, whatToShow, filter, expandEntityReferences)); |
| 43 | } |
darin@apple.com | 1edff43 | 2008-06-24 05:23:17 +0000 | [diff] [blame] | 44 | ~NodeIterator(); |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 45 | |
eric@webkit.org | 406d642 | 2008-12-04 20:51:21 +0000 | [diff] [blame] | 46 | PassRefPtr<Node> nextNode(ScriptState*, ExceptionCode&); |
| 47 | PassRefPtr<Node> previousNode(ScriptState*, ExceptionCode&); |
andersca | c86bc24 | 2006-08-15 00:59:42 +0000 | [diff] [blame] | 48 | void detach(); |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 49 | |
darin@apple.com | e4f9a66 | 2008-02-08 10:35:20 +0000 | [diff] [blame] | 50 | Node* referenceNode() const { return m_referenceNode.node.get(); } |
| 51 | bool pointerBeforeReferenceNode() const { return m_referenceNode.isPointerBeforeNode; } |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 52 | |
darin@apple.com | e4f9a66 | 2008-02-08 10:35:20 +0000 | [diff] [blame] | 53 | // This function is called before any node is removed from the document tree. |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 54 | void nodeWillBeRemoved(Node*); |
darin@apple.com | e4f9a66 | 2008-02-08 10:35:20 +0000 | [diff] [blame] | 55 | |
barraclough@apple.com | 6539bbe | 2009-11-30 21:48:23 +0000 | [diff] [blame] | 56 | // Do not call these functions. They are just scaffolding to support the Objective-C bindings. |
| 57 | // They operate in the main thread normal world, and they swallow JS exceptions. |
| 58 | PassRefPtr<Node> nextNode(ExceptionCode& ec) { return nextNode(scriptStateFromNode(mainThreadNormalWorld(), referenceNode()), ec); } |
| 59 | PassRefPtr<Node> previousNode(ExceptionCode& ec) { return previousNode(scriptStateFromNode(mainThreadNormalWorld(), referenceNode()), ec); } |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 60 | |
| 61 | private: |
andersca@apple.com | 0f509b1 | 2008-06-04 21:12:16 +0000 | [diff] [blame] | 62 | NodeIterator(PassRefPtr<Node>, unsigned whatToShow, PassRefPtr<NodeFilter>, bool expandEntityReferences); |
| 63 | |
darin@apple.com | e4f9a66 | 2008-02-08 10:35:20 +0000 | [diff] [blame] | 64 | struct NodePointer { |
| 65 | RefPtr<Node> node; |
| 66 | bool isPointerBeforeNode; |
| 67 | NodePointer(); |
| 68 | NodePointer(PassRefPtr<Node>, bool); |
| 69 | void clear(); |
| 70 | bool moveToNext(Node* root); |
| 71 | bool moveToPrevious(Node* root); |
| 72 | }; |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 73 | |
darin@apple.com | e4f9a66 | 2008-02-08 10:35:20 +0000 | [diff] [blame] | 74 | void updateForNodeRemoval(Node* nodeToBeRemoved, NodePointer&) const; |
| 75 | |
| 76 | NodePointer m_referenceNode; |
| 77 | NodePointer m_candidateNode; |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 78 | bool m_detached; |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | } // namespace WebCore |
| 82 | |
| 83 | #endif // NodeIterator_h |