1/*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 *     * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *     * Neither the name of Google Inc. nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef NodeRenderingTraversal_h
29#define NodeRenderingTraversal_h
30
31#include "ContainerNode.h"
32
33namespace WebCore {
34
35namespace NodeRenderingTraversal {
36
37ContainerNode* parent(const Node*);
38Node* firstChild(const Node*);
39Node* nextSibling(const Node*);
40Node* previousSibling(const Node*);
41
42Node* nextInScope(const Node*);
43Node* previousInScope(const Node*);
44Node* parentInScope(const Node*);
45Node* lastChildInScope(const Node*);
46
47ContainerNode* parentSlow(const Node*);
48Node* firstChildSlow(const Node*);
49Node* nextSiblingSlow(const Node*);
50Node* previousSiblingSlow(const Node*);
51
52inline ContainerNode* parent(const Node* node)
53{
54    ASSERT(!node->isPseudoElement());
55    if (node->needsNodeRenderingTraversalSlowPath())
56        return parentSlow(node);
57
58    ASSERT(node->parentNode() == parentSlow(node));
59    return node->parentNodeGuaranteedHostFree();
60}
61
62inline Node* firstChild(const Node* node)
63{
64    ASSERT(!node->isPseudoElement());
65    if (node->needsNodeRenderingTraversalSlowPath())
66        return firstChildSlow(node);
67
68    ASSERT(nextSiblingSlow(node) == node->nextSibling());
69    return node->firstChild();
70}
71
72inline Node* nextSibling(const Node* node)
73{
74    ASSERT(!node->isPseudoElement());
75    if (node->needsNodeRenderingTraversalSlowPath())
76        return nextSiblingSlow(node);
77
78    ASSERT(nextSiblingSlow(node) == node->nextSibling());
79    return node->nextSibling();
80}
81
82inline Node* previousSibling(const Node* node)
83{
84    ASSERT(!node->isPseudoElement());
85    if (node->needsNodeRenderingTraversalSlowPath())
86        return previousSiblingSlow(node);
87
88    ASSERT(previousSiblingSlow(node) == node->previousSibling());
89    return node->previousSibling();
90}
91
92}
93
94} // namespace WebCore
95
96#endif
97