Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(685)

Unified Diff: Source/core/html/HTMLFormControlElement.cpp

Issue 201293002: Add Traversal<*Element>::firstAncestor() API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Slight clean up Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/HTMLFormControlElement.cpp
diff --git a/Source/core/html/HTMLFormControlElement.cpp b/Source/core/html/HTMLFormControlElement.cpp
index 6d32513c5af5256724ab13feef1a7162f017a6d3..7b9c1d91cc06ce88eac834ff845fd8417ccdaf7a 100644
--- a/Source/core/html/HTMLFormControlElement.cpp
+++ b/Source/core/html/HTMLFormControlElement.cpp
@@ -28,6 +28,7 @@
#include "core/dom/PostAttachCallbacks.h"
#include "core/events/Event.h"
#include "core/events/ThreadLocalEventNames.h"
+#include "core/html/HTMLDataListElement.h"
#include "core/html/HTMLFieldSetElement.h"
#include "core/html/HTMLFormElement.h"
#include "core/html/HTMLInputElement.h"
@@ -103,7 +104,7 @@ void HTMLFormControlElement::updateAncestorDisabledState() const
{
HTMLFieldSetElement* fieldSetAncestor = 0;
ContainerNode* legendAncestor = 0;
- for (ContainerNode* ancestor = parentNode(); ancestor; ancestor = ancestor->parentNode()) {
+ for (HTMLElement* ancestor = Traversal<HTMLElement>::firstAncestor(*this); ancestor; ancestor = Traversal<HTMLElement>::firstAncestor(*ancestor)) {
if (!legendAncestor && isHTMLLegendElement(*ancestor))
legendAncestor = ancestor;
if (isHTMLFieldSetElement(*ancestor)) {
@@ -357,13 +358,9 @@ short HTMLFormControlElement::tabIndex() const
bool HTMLFormControlElement::recalcWillValidate() const
{
if (m_dataListAncestorState == Unknown) {
- for (ContainerNode* ancestor = parentNode(); ancestor; ancestor = ancestor->parentNode()) {
- if (isHTMLDataListElement(*ancestor)) {
- m_dataListAncestorState = InsideDataList;
- break;
- }
- }
- if (m_dataListAncestorState == Unknown)
+ if (Traversal<HTMLDataListElement>::firstAncestor(*this))
+ m_dataListAncestorState = InsideDataList;
+ else
m_dataListAncestorState = NotInsideDataList;
}
return m_dataListAncestorState == NotInsideDataList && !isDisabledOrReadOnly();
@@ -484,11 +481,9 @@ bool HTMLFormControlElement::isDefaultButtonForForm() const
HTMLFormControlElement* HTMLFormControlElement::enclosingFormControlElement(Node* node)
{
- for (; node; node = node->parentNode()) {
- if (node->isElementNode() && toElement(node)->isFormControlElement())
- return toHTMLFormControlElement(node);
- }
- return 0;
+ if (!node || isHTMLFormControlElement(*node))
+ return toHTMLFormControlElement(node);
+ return Traversal<HTMLFormControlElement>::firstAncestor(*node);
}
String HTMLFormControlElement::nameForAutofill() const

Powered by Google App Engine
This is Rietveld 408576698