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

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

Issue 166093004: Avoid some code duplication in HTMLTableRowsCollection::rowAfter() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLTableRowsCollection.cpp
diff --git a/Source/core/html/HTMLTableRowsCollection.cpp b/Source/core/html/HTMLTableRowsCollection.cpp
index f2aa4d4f2a8c74c13ae0c18088ffcbe202fde7e0..ae67c03a695ed3db9812a0909f173683f5b37772 100644
--- a/Source/core/html/HTMLTableRowsCollection.cpp
+++ b/Source/core/html/HTMLTableRowsCollection.cpp
@@ -53,6 +53,15 @@ static bool isInFoot(Element* row)
return row->parentNode() && toElement(row->parentNode())->hasLocalName(tfootTag);
}
+static inline HTMLTableRowElement* findTableRowElementInChildren(Element& current)
+{
+ for (Element* child = ElementTraversal::firstWithin(current); child; child = ElementTraversal::nextSibling(*child)) {
+ if (child->hasTagName(trTag))
+ return toHTMLTableRowElement(child);
+ }
+ return 0;
+}
+
HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table, HTMLTableRowElement* previous)
{
Element* child = 0;
@@ -73,10 +82,8 @@ HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table,
child = ElementTraversal::nextSibling(*previous->parentNode());
for (; child; child = ElementTraversal::nextSibling(*child)) {
if (child->hasTagName(theadTag)) {
- for (Element* grandchild = ElementTraversal::firstWithin(*child); grandchild; grandchild = ElementTraversal::nextSibling(*grandchild)) {
- if (grandchild->hasTagName(trTag))
- return toHTMLTableRowElement(grandchild);
- }
+ if (HTMLTableRowElement* row = findTableRowElementInChildren(*child))
+ return row;
}
}
@@ -91,10 +98,8 @@ HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table,
if (child->hasTagName(trTag))
return toHTMLTableRowElement(child);
if (child->hasTagName(tbodyTag)) {
- for (Element* grandchild = ElementTraversal::firstWithin(*child); grandchild; grandchild = ElementTraversal::nextSibling(*grandchild)) {
- if (grandchild->hasTagName(trTag))
- return toHTMLTableRowElement(grandchild);
- }
+ if (HTMLTableRowElement* row = findTableRowElementInChildren(*child))
+ return row;
}
}
@@ -105,10 +110,8 @@ HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table,
child = ElementTraversal::nextSibling(*previous->parentNode());
for (; child; child = ElementTraversal::nextSibling(*child)) {
if (child->hasTagName(tfootTag)) {
- for (Element* grandchild = ElementTraversal::firstWithin(*child); grandchild; grandchild = ElementTraversal::nextSibling(*grandchild)) {
- if (grandchild->hasTagName(trTag))
- return toHTMLTableRowElement(grandchild);
- }
+ if (HTMLTableRowElement* row = findTableRowElementInChildren(*child))
+ return row;
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698