| Index: Source/core/dom/ElementTraversal.h
|
| diff --git a/Source/core/dom/ElementTraversal.h b/Source/core/dom/ElementTraversal.h
|
| index 6705f04efcd20b8bf281258b366a92797c59998a..e6d7e924ed65168990537f355f2588727990de9f 100644
|
| --- a/Source/core/dom/ElementTraversal.h
|
| +++ b/Source/core/dom/ElementTraversal.h
|
| @@ -40,6 +40,11 @@ public:
|
| static ElementType* lastChild(const ContainerNode& current) { return lastChildTemplate(current); }
|
| static ElementType* lastChild(const Node& current) { return lastChildTemplate(current); }
|
|
|
| + // First ElementType ancestor of the node.
|
| + static ElementType* firstAncestor(const Node& current);
|
| + static ElementType* firstAncestorOrSelf(Node& current) { return firstAncestorOrSelfTemplate(current); }
|
| + static ElementType* firstAncestorOrSelf(Element& current) { return firstAncestorOrSelfTemplate(current); }
|
| +
|
| // First or last ElementType descendant of the node.
|
| // For Elements firstWithin() is always the same as firstChild().
|
| static ElementType* firstWithin(const ContainerNode& current) { return firstWithinTemplate(current); }
|
| @@ -81,6 +86,8 @@ private:
|
| template <class NodeType>
|
| static ElementType* lastChildTemplate(NodeType&);
|
| template <class NodeType>
|
| + static ElementType* firstAncestorOrSelfTemplate(NodeType&);
|
| + template <class NodeType>
|
| static ElementType* firstWithinTemplate(NodeType&);
|
| template <class NodeType>
|
| static ElementType* lastWithinTemplate(NodeType&);
|
| @@ -167,6 +174,24 @@ inline ElementType* Traversal<ElementType>::firstChildTemplate(NodeType& current
|
| }
|
|
|
| template <class ElementType>
|
| +inline ElementType* Traversal<ElementType>::firstAncestor(const Node& current)
|
| +{
|
| + ContainerNode* ancestor = current.parentNode();
|
| + while (ancestor && !isElementOfType<const ElementType>(*ancestor))
|
| + ancestor = ancestor->parentNode();
|
| + return toElement<ElementType>(ancestor);
|
| +}
|
| +
|
| +template <class ElementType>
|
| +template <class NodeType>
|
| +inline ElementType* Traversal<ElementType>::firstAncestorOrSelfTemplate(NodeType& current)
|
| +{
|
| + if (isElementOfType<const ElementType>(current))
|
| + return &toElement<ElementType>(current);
|
| + return firstAncestor(current);
|
| +}
|
| +
|
| +template <class ElementType>
|
| template <class NodeType>
|
| inline ElementType* Traversal<ElementType>::lastChildTemplate(NodeType& current)
|
| {
|
|
|