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 17 matching lines...) Expand all Loading... | |
28 | 28 |
29 #ifndef SiblingTraversalStrategies_h | 29 #ifndef SiblingTraversalStrategies_h |
30 #define SiblingTraversalStrategies_h | 30 #define SiblingTraversalStrategies_h |
31 | 31 |
32 #include "core/dom/Element.h" | 32 #include "core/dom/Element.h" |
33 #include "core/dom/ElementTraversal.h" | 33 #include "core/dom/ElementTraversal.h" |
34 #include "core/rendering/style/RenderStyle.h" | 34 #include "core/rendering/style/RenderStyle.h" |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 struct DOMSiblingTraversalStrategy { | 38 class DOMSiblingTraversalStrategy { |
39 public: | |
39 bool isFirstChild(Element&) const; | 40 bool isFirstChild(Element&) const; |
40 bool isLastChild(Element&) const; | 41 bool isLastChild(Element&) const; |
41 bool isFirstOfType(Element&, const QualifiedName&) const; | 42 bool isFirstOfType(Element&, const QualifiedName&) const; |
42 bool isLastOfType(Element&, const QualifiedName&) const; | 43 bool isLastOfType(Element&, const QualifiedName&) const; |
43 | 44 |
44 int countElementsBefore(Element&) const; | 45 int countElementsBefore(Element&) const; |
45 int countElementsAfter(Element&) const; | 46 int countElementsAfter(Element&) const; |
46 int countElementsOfTypeBefore(Element&, const QualifiedName&) const; | 47 int countElementsOfTypeBefore(Element&, const QualifiedName&) const; |
47 int countElementsOfTypeAfter(Element&, const QualifiedName&) const; | 48 int countElementsOfTypeAfter(Element&, const QualifiedName&) const; |
49 | |
50 private: | |
51 class HasTagName { | |
Inactive
2014/08/14 18:48:50
We could move this to Element.h if it is used in m
| |
52 public: | |
53 explicit HasTagName(const QualifiedName& tagName) : m_tagName(tagName) { } | |
54 bool operator() (const Element& element) const { return element.hasTagNa me(m_tagName); } | |
55 private: | |
56 const QualifiedName& m_tagName; | |
57 }; | |
48 }; | 58 }; |
49 | 59 |
50 inline bool DOMSiblingTraversalStrategy::isFirstChild(Element& element) const | 60 inline bool DOMSiblingTraversalStrategy::isFirstChild(Element& element) const |
51 { | 61 { |
52 return !ElementTraversal::previousSibling(element); | 62 return !ElementTraversal::previousSibling(element); |
53 } | 63 } |
54 | 64 |
55 inline bool DOMSiblingTraversalStrategy::isLastChild(Element& element) const | 65 inline bool DOMSiblingTraversalStrategy::isLastChild(Element& element) const |
56 { | 66 { |
57 return !ElementTraversal::nextSibling(element); | 67 return !ElementTraversal::nextSibling(element); |
58 } | 68 } |
59 | 69 |
60 inline bool DOMSiblingTraversalStrategy::isFirstOfType(Element& element, const Q ualifiedName& type) const | 70 inline bool DOMSiblingTraversalStrategy::isFirstOfType(Element& element, const Q ualifiedName& type) const |
61 { | 71 { |
62 for (const Element* sibling = ElementTraversal::previousSibling(element); si bling; sibling = ElementTraversal::previousSibling(*sibling)) { | 72 return !ElementTraversal::previousSibling(element, HasTagName(type)); |
63 if (sibling->hasTagName(type)) | |
64 return false; | |
65 } | |
66 return true; | |
67 } | 73 } |
68 | 74 |
69 inline bool DOMSiblingTraversalStrategy::isLastOfType(Element& element, const Qu alifiedName& type) const | 75 inline bool DOMSiblingTraversalStrategy::isLastOfType(Element& element, const Qu alifiedName& type) const |
70 { | 76 { |
71 for (const Element* sibling = ElementTraversal::nextSibling(element); siblin g; sibling = ElementTraversal::nextSibling(*sibling)) { | 77 return !ElementTraversal::nextSibling(element, HasTagName(type)); |
72 if (sibling->hasTagName(type)) | |
73 return false; | |
74 } | |
75 return true; | |
76 } | 78 } |
77 | 79 |
78 inline int DOMSiblingTraversalStrategy::countElementsBefore(Element& element) co nst | 80 inline int DOMSiblingTraversalStrategy::countElementsBefore(Element& element) co nst |
79 { | 81 { |
80 int count = 0; | 82 int count = 0; |
81 for (const Element* sibling = ElementTraversal::previousSibling(element); si bling; sibling = ElementTraversal::previousSibling(*sibling)) | 83 for (const Element* sibling = ElementTraversal::previousSibling(element); si bling; sibling = ElementTraversal::previousSibling(*sibling)) |
82 count++; | 84 count++; |
83 | 85 |
84 return count; | 86 return count; |
85 } | 87 } |
86 | 88 |
87 inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element& eleme nt, const QualifiedName& type) const | 89 inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element& eleme nt, const QualifiedName& type) const |
88 { | 90 { |
89 int count = 0; | 91 int count = 0; |
90 for (const Element* sibling = ElementTraversal::previousSibling(element); si bling; sibling = ElementTraversal::previousSibling(*sibling)) { | 92 for (const Element* sibling = ElementTraversal::previousSibling(element, Has TagName(type)); sibling; sibling = ElementTraversal::previousSibling(*sibling, H asTagName(type))) |
91 if (sibling->hasTagName(type)) | 93 ++count; |
92 ++count; | |
93 } | |
94 | |
95 return count; | 94 return count; |
96 } | 95 } |
97 | 96 |
98 inline int DOMSiblingTraversalStrategy::countElementsAfter(Element& element) con st | 97 inline int DOMSiblingTraversalStrategy::countElementsAfter(Element& element) con st |
99 { | 98 { |
100 int count = 0; | 99 int count = 0; |
101 for (const Element* sibling = ElementTraversal::nextSibling(element); siblin g; sibling = ElementTraversal::nextSibling(*sibling)) | 100 for (const Element* sibling = ElementTraversal::nextSibling(element); siblin g; sibling = ElementTraversal::nextSibling(*sibling)) |
102 ++count; | 101 ++count; |
103 | |
104 return count; | 102 return count; |
105 } | 103 } |
106 | 104 |
107 inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element& elemen t, const QualifiedName& type) const | 105 inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element& elemen t, const QualifiedName& type) const |
108 { | 106 { |
109 int count = 0; | 107 int count = 0; |
110 for (const Element* sibling = ElementTraversal::nextSibling(element); siblin g; sibling = ElementTraversal::nextSibling(*sibling)) { | 108 for (const Element* sibling = ElementTraversal::nextSibling(element, HasTagN ame(type)); sibling; sibling = ElementTraversal::nextSibling(*sibling, HasTagNam e(type))) |
111 if (sibling->hasTagName(type)) | 109 ++count; |
112 ++count; | |
113 } | |
114 | |
115 return count; | 110 return count; |
116 } | 111 } |
117 | 112 |
118 class ShadowDOMSiblingTraversalStrategy FINAL { | 113 class ShadowDOMSiblingTraversalStrategy FINAL { |
119 STACK_ALLOCATED(); | 114 STACK_ALLOCATED(); |
120 public: | 115 public: |
121 ShadowDOMSiblingTraversalStrategy(const WillBeHeapVector<RawPtrWillBeMember< Node>, 32>& siblings, int nth) | 116 ShadowDOMSiblingTraversalStrategy(const WillBeHeapVector<RawPtrWillBeMember< Node>, 32>& siblings, int nth) |
122 : m_siblings(siblings) | 117 : m_siblings(siblings) |
123 , m_nth(nth) | 118 , m_nth(nth) |
124 { | 119 { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 if (m_siblings[i]->isElementNode() && toElement(m_siblings[i])->hasTagNa me(type)) | 230 if (m_siblings[i]->isElementNode() && toElement(m_siblings[i])->hasTagNa me(type)) |
236 return ++count; | 231 return ++count; |
237 } | 232 } |
238 | 233 |
239 return count; | 234 return count; |
240 } | 235 } |
241 | 236 |
242 } | 237 } |
243 | 238 |
244 #endif | 239 #endif |
OLD | NEW |