Add element ancestor iterator
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Sep 2013 10:33:08 +0000 (10:33 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Sep 2013 10:33:08 +0000 (10:33 +0000)
commita0d51a8092907be555dd1afb70d488c0f119f1bb
treefa345305574ba8baa93da0785030561284fddf65
parentdf57a6de0edcd55a9a018c3424c8c8fb7ecc179d
Add element ancestor iterator
https://bugs.webkit.org/show_bug.cgi?id=120563

Reviewed by Andreas Kling.

This patch adds ancestor iterators. They iterate over elements parent chain up to the root.

To iterate over Element ancestors:

auto ancestors = elementAncestors(this);
for (auto it = ancestors.begin(), end = ancestors.end(); it != end; ++it) {
    Element& element = *it;
    ...

To iterate over Element ancestors including the current element:

auto lineage = elementLineage(this);
for (auto it = lineage.begin(), end = lineage.end(); it != end; ++it) {
    Element& element = *it;
    ...

To iterate over ancestors of a specific Element subclass:

auto htmlAncestors = ancestorsOfType<HTMLElement>(this);
for (auto it = htmlAncestors.begin(), end = htmlAncestors.end(); it != end; ++it) {
    HTMLElement& htmlElement = *it;
    ...

To iterate over ancestors of a specific Element subclass including the current element:

auto htmlLineage = lineageOfType<HTMLElement>(this);
for (auto it = htmlLineage.begin(), end = htmlLineage.end(); it != end; ++it) {
    HTMLElement& htmlElement = *it;
    ...

The patch also uses the new types in a few places.

* WebCore.xcodeproj/project.pbxproj:
* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::mouseButtonListener):
(WebCore::AccessibilityNodeObject::labelForElement):
* dom/ElementAncestorIterator.h: Added.
(WebCore::::ElementAncestorIterator):
(WebCore::::operator):
(WebCore::::ElementAncestorConstIterator):
(WebCore::::ElementAncestorIteratorAdapter):
(WebCore::::begin):
(WebCore::::end):
(WebCore::::ElementAncestorConstIteratorAdapter):
(WebCore::elementLineage):
(WebCore::elementAncestors):
(WebCore::ancestorsOfType):
* dom/ElementIterator.h:
(WebCore::findElementAncestorOfType):
(WebCore::::traverseAncestor):
(WebCore::=):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::adjustDirectionalityIfNeededAfterChildAttributeChanged):
* html/HTMLFieldSetElement.h:
(WebCore::isHTMLFieldSetElement):
(WebCore::HTMLFieldSetElement):
* html/HTMLFrameSetElement.cpp:
(WebCore::HTMLFrameSetElement::findContaining):
* html/HTMLFrameSetElement.h:
(WebCore::HTMLFrameSetElement):
* html/HTMLInputElement.h:
(WebCore::isHTMLInputElement):
(WebCore::toHTMLInputElement):
* html/HTMLLegendElement.cpp:
(WebCore::HTMLLegendElement::associatedControl):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154940 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/accessibility/AccessibilityNodeObject.cpp
Source/WebCore/dom/ElementAncestorIterator.h [new file with mode: 0644]
Source/WebCore/dom/ElementIterator.h
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLFieldSetElement.h
Source/WebCore/html/HTMLFrameSetElement.cpp
Source/WebCore/html/HTMLFrameSetElement.h
Source/WebCore/html/HTMLInputElement.h
Source/WebCore/html/HTMLLegendElement.cpp