Chromium Code Reviews| 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..284d2d581c9412d7230d87fe27bb963efc693d9b 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(HTMLCollection* rows, |
|
tkent
2016/10/27 02:31:28
nit: Because |rows| isn't nullptr and it isn't mod
|
| + const HTMLTableRowElement* target) { |
|
tkent
2016/10/27 02:31:28
nit: |target| isn't nullptr. The argument type sh
|
| + 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,21 @@ 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, |