OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights
reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights
reserved. |
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
(...skipping 30 matching lines...) Expand all Loading... |
41 public: | 41 public: |
42 static bool isFirstChild(Element&); | 42 static bool isFirstChild(Element&); |
43 static bool isLastChild(Element&); | 43 static bool isLastChild(Element&); |
44 static bool isFirstOfType(Element&, const QualifiedName&); | 44 static bool isFirstOfType(Element&, const QualifiedName&); |
45 static bool isLastOfType(Element&, const QualifiedName&); | 45 static bool isLastOfType(Element&, const QualifiedName&); |
46 | 46 |
47 static int countElementsBefore(Element&); | 47 static int countElementsBefore(Element&); |
48 static int countElementsAfter(Element&); | 48 static int countElementsAfter(Element&); |
49 static int countElementsOfTypeBefore(Element&, const QualifiedName&); | 49 static int countElementsOfTypeBefore(Element&, const QualifiedName&); |
50 static int countElementsOfTypeAfter(Element&, const QualifiedName&); | 50 static int countElementsOfTypeAfter(Element&, const QualifiedName&); |
51 | |
52 private: | |
53 class HasTagName { | |
54 public: | |
55 explicit HasTagName(const QualifiedName& tagName) : m_tagName(tagName) {
} | |
56 bool operator() (const Element& element) const { return element.hasTagNa
me(m_tagName); } | |
57 private: | |
58 const QualifiedName& m_tagName; | |
59 }; | |
60 }; | 51 }; |
61 | 52 |
62 inline bool DOMSiblingTraversalStrategy::isFirstChild(Element& element) | 53 inline bool DOMSiblingTraversalStrategy::isFirstChild(Element& element) |
63 { | 54 { |
64 return !ElementTraversal::previousSibling(element); | 55 return !ElementTraversal::previousSibling(element); |
65 } | 56 } |
66 | 57 |
67 inline bool DOMSiblingTraversalStrategy::isLastChild(Element& element) | 58 inline bool DOMSiblingTraversalStrategy::isLastChild(Element& element) |
68 { | 59 { |
69 return !ElementTraversal::nextSibling(element); | 60 return !ElementTraversal::nextSibling(element); |
(...skipping 16 matching lines...) Expand all Loading... |
86 | 77 |
87 int count = 0; | 78 int count = 0; |
88 for (const Element* sibling = ElementTraversal::previousSibling(element); si
bling; sibling = ElementTraversal::previousSibling(*sibling)) | 79 for (const Element* sibling = ElementTraversal::previousSibling(element); si
bling; sibling = ElementTraversal::previousSibling(*sibling)) |
89 count++; | 80 count++; |
90 | 81 |
91 return count; | 82 return count; |
92 } | 83 } |
93 | 84 |
94 inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element& eleme
nt, const QualifiedName& type) | 85 inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element& eleme
nt, const QualifiedName& type) |
95 { | 86 { |
| 87 if (NthIndexCache* nthIndexCache = element.document().nthIndexCache()) |
| 88 return nthIndexCache->nthChildIndexOfType(element, type) - 1; |
96 int count = 0; | 89 int count = 0; |
97 for (const Element* sibling = ElementTraversal::previousSibling(element, Has
TagName(type)); sibling; sibling = ElementTraversal::previousSibling(*sibling, H
asTagName(type))) | 90 for (const Element* sibling = ElementTraversal::previousSibling(element, Has
TagName(type)); sibling; sibling = ElementTraversal::previousSibling(*sibling, H
asTagName(type))) |
98 ++count; | 91 ++count; |
99 return count; | 92 return count; |
100 } | 93 } |
101 | 94 |
102 inline int DOMSiblingTraversalStrategy::countElementsAfter(Element& element) | 95 inline int DOMSiblingTraversalStrategy::countElementsAfter(Element& element) |
103 { | 96 { |
104 if (NthIndexCache* nthIndexCache = element.document().nthIndexCache()) | 97 if (NthIndexCache* nthIndexCache = element.document().nthIndexCache()) |
105 return nthIndexCache->nthLastChildIndex(element) - 1; | 98 return nthIndexCache->nthLastChildIndex(element) - 1; |
106 | 99 |
107 int count = 0; | 100 int count = 0; |
108 for (const Element* sibling = ElementTraversal::nextSibling(element); siblin
g; sibling = ElementTraversal::nextSibling(*sibling)) | 101 for (const Element* sibling = ElementTraversal::nextSibling(element); siblin
g; sibling = ElementTraversal::nextSibling(*sibling)) |
109 ++count; | 102 ++count; |
110 return count; | 103 return count; |
111 } | 104 } |
112 | 105 |
113 inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element& elemen
t, const QualifiedName& type) | 106 inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element& elemen
t, const QualifiedName& type) |
114 { | 107 { |
| 108 if (NthIndexCache* nthIndexCache = element.document().nthIndexCache()) |
| 109 return nthIndexCache->nthLastChildIndexOfType(element, type) - 1; |
| 110 |
115 int count = 0; | 111 int count = 0; |
116 for (const Element* sibling = ElementTraversal::nextSibling(element, HasTagN
ame(type)); sibling; sibling = ElementTraversal::nextSibling(*sibling, HasTagNam
e(type))) | 112 for (const Element* sibling = ElementTraversal::nextSibling(element, HasTagN
ame(type)); sibling; sibling = ElementTraversal::nextSibling(*sibling, HasTagNam
e(type))) |
117 ++count; | 113 ++count; |
118 return count; | 114 return count; |
119 } | 115 } |
120 | 116 |
121 } | 117 } |
122 | 118 |
123 #endif | 119 #endif |
OLD | NEW |