Chromium Code Reviews| Index: Source/core/dom/ElementTraversal.h |
| diff --git a/Source/core/dom/ElementTraversal.h b/Source/core/dom/ElementTraversal.h |
| index 6705f04efcd20b8bf281258b366a92797c59998a..4c9f2adef8894f48a5ab56d7eaf5b6641f3dc51f 100644 |
| --- a/Source/core/dom/ElementTraversal.h |
| +++ b/Source/core/dom/ElementTraversal.h |
| @@ -40,6 +40,9 @@ 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. |
|
esprehn
2014/03/21 07:58:33
The comment doesn't add anything.
Inactive
2014/03/21 14:37:24
Each set of ElementTraversal functions is grouped
|
| + static ElementType* firstAncestor(const Node& 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); } |
| @@ -167,6 +170,15 @@ inline ElementType* Traversal<ElementType>::firstChildTemplate(NodeType& current |
| } |
| template <class ElementType> |
| +inline ElementType* Traversal<ElementType>::firstAncestor(const Node& current) |
| +{ |
| + ContainerNode* ancestor = current.parentNode(); |
|
Inactive
2014/03/15 23:50:18
One idea that came to mind, we could potentially o
|
| + while (ancestor && !isElementOfType<const ElementType>(*ancestor)) |
| + ancestor = ancestor->parentNode(); |
| + return toElement<ElementType>(ancestor); |
| +} |
| + |
| +template <class ElementType> |
| template <class NodeType> |
| inline ElementType* Traversal<ElementType>::lastChildTemplate(NodeType& current) |
| { |