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

Unified Diff: third_party/WebKit/Source/core/html/HTMLTableRowElement.cpp

Issue 2455623003: Make sectionRowIndex be more conforming to spec (Closed)
Patch Set: Patch for landing Created 4 years, 2 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: third_party/WebKit/Source/core/html/HTMLTableRowElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLTableRowElement.cpp b/third_party/WebKit/Source/core/html/HTMLTableRowElement.cpp
index 1202573468891ae8b59ed578afd8816919d92ca1..3f61e1b6b45379943ee10c886deaf96e6e6c47d0 100644
--- a/third_party/WebKit/Source/core/html/HTMLTableRowElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLTableRowElement.cpp
@@ -55,6 +55,16 @@ const QualifiedName& HTMLTableRowElement::subResourceAttributeName() const {
return backgroundAttr;
}
+static int findIndexInRowCollection(const HTMLCollection& rows,
+ const HTMLTableRowElement& target) {
+ Element* candidate = rows.item(0);
+ for (int i = 0; candidate; i++, candidate = rows.item(i)) {
+ if (target == candidate)
+ return i;
+ }
+ return -1;
+}
+
int HTMLTableRowElement::rowIndex() const {
ContainerNode* maybeTable = parentNode();
if (maybeTable && isHTMLTableSectionElement(maybeTable)) {
@@ -63,31 +73,22 @@ int HTMLTableRowElement::rowIndex() const {
}
if (!(maybeTable && isHTMLTableElement(maybeTable)))
return -1;
-
- HTMLTableRowsCollection* rows = toHTMLTableElement(maybeTable)->rows();
- HTMLTableRowElement* candidate = rows->item(0);
- for (int i = 0; candidate; i++, candidate = rows->item(i)) {
- if (this == candidate)
- return i;
- }
-
- return -1;
+ return findIndexInRowCollection(*toHTMLTableElement(maybeTable)->rows(),
+ *this);
}
int HTMLTableRowElement::sectionRowIndex() const {
ContainerNode* maybeTable = parentNode();
- if (!(maybeTable && (isHTMLTableSectionElement(maybeTable) ||
- isHTMLTableElement(maybeTable))))
+ if (!maybeTable)
+ return -1;
+ HTMLCollection* rows = nullptr;
+ if (isHTMLTableSectionElement(maybeTable))
+ rows = toHTMLTableSectionElement(maybeTable)->rows();
+ else if (isHTMLTableElement(maybeTable))
+ rows = toHTMLTableElement(maybeTable)->rows();
+ if (!rows)
return -1;
- int rIndex = 0;
- const Node* n = this;
- do {
- n = n->previousSibling();
- if (n && isHTMLTableRowElement(*n))
- ++rIndex;
- } while (n);
-
- return rIndex;
+ return findIndexInRowCollection(*rows, *this);
}
HTMLElement* HTMLTableRowElement::insertCell(int index,
« 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