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

Side by Side 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, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1997 Martin Jones (mjones@kde.org) 2 * Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 * (C) 1997 Torben Weis (weis@kde.org) 3 * (C) 1997 Torben Weis (weis@kde.org)
4 * (C) 1998 Waldo Bastian (bastian@kde.org) 4 * (C) 1998 Waldo Bastian (bastian@kde.org)
5 * (C) 1999 Lars Knoll (knoll@kde.org) 5 * (C) 1999 Lars Knoll (knoll@kde.org)
6 * (C) 1999 Antti Koivisto (koivisto@kde.org) 6 * (C) 1999 Antti Koivisto (koivisto@kde.org)
7 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights 7 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights
8 * reserved. 8 * reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 bool HTMLTableRowElement::hasLegalLinkAttribute( 48 bool HTMLTableRowElement::hasLegalLinkAttribute(
49 const QualifiedName& name) const { 49 const QualifiedName& name) const {
50 return name == backgroundAttr || 50 return name == backgroundAttr ||
51 HTMLTablePartElement::hasLegalLinkAttribute(name); 51 HTMLTablePartElement::hasLegalLinkAttribute(name);
52 } 52 }
53 53
54 const QualifiedName& HTMLTableRowElement::subResourceAttributeName() const { 54 const QualifiedName& HTMLTableRowElement::subResourceAttributeName() const {
55 return backgroundAttr; 55 return backgroundAttr;
56 } 56 }
57 57
58 static int findIndexInRowCollection(const HTMLCollection& rows,
59 const HTMLTableRowElement& target) {
60 Element* candidate = rows.item(0);
61 for (int i = 0; candidate; i++, candidate = rows.item(i)) {
62 if (target == candidate)
63 return i;
64 }
65 return -1;
66 }
67
58 int HTMLTableRowElement::rowIndex() const { 68 int HTMLTableRowElement::rowIndex() const {
59 ContainerNode* maybeTable = parentNode(); 69 ContainerNode* maybeTable = parentNode();
60 if (maybeTable && isHTMLTableSectionElement(maybeTable)) { 70 if (maybeTable && isHTMLTableSectionElement(maybeTable)) {
61 // Skip THEAD, TBODY and TFOOT. 71 // Skip THEAD, TBODY and TFOOT.
62 maybeTable = maybeTable->parentNode(); 72 maybeTable = maybeTable->parentNode();
63 } 73 }
64 if (!(maybeTable && isHTMLTableElement(maybeTable))) 74 if (!(maybeTable && isHTMLTableElement(maybeTable)))
65 return -1; 75 return -1;
66 76 return findIndexInRowCollection(*toHTMLTableElement(maybeTable)->rows(),
67 HTMLTableRowsCollection* rows = toHTMLTableElement(maybeTable)->rows(); 77 *this);
68 HTMLTableRowElement* candidate = rows->item(0);
69 for (int i = 0; candidate; i++, candidate = rows->item(i)) {
70 if (this == candidate)
71 return i;
72 }
73
74 return -1;
75 } 78 }
76 79
77 int HTMLTableRowElement::sectionRowIndex() const { 80 int HTMLTableRowElement::sectionRowIndex() const {
78 ContainerNode* maybeTable = parentNode(); 81 ContainerNode* maybeTable = parentNode();
79 if (!(maybeTable && (isHTMLTableSectionElement(maybeTable) || 82 if (!maybeTable)
80 isHTMLTableElement(maybeTable))))
81 return -1; 83 return -1;
82 int rIndex = 0; 84 HTMLCollection* rows = nullptr;
83 const Node* n = this; 85 if (isHTMLTableSectionElement(maybeTable))
84 do { 86 rows = toHTMLTableSectionElement(maybeTable)->rows();
85 n = n->previousSibling(); 87 else if (isHTMLTableElement(maybeTable))
86 if (n && isHTMLTableRowElement(*n)) 88 rows = toHTMLTableElement(maybeTable)->rows();
87 ++rIndex; 89 if (!rows)
88 } while (n); 90 return -1;
89 91 return findIndexInRowCollection(*rows, *this);
90 return rIndex;
91 } 92 }
92 93
93 HTMLElement* HTMLTableRowElement::insertCell(int index, 94 HTMLElement* HTMLTableRowElement::insertCell(int index,
94 ExceptionState& exceptionState) { 95 ExceptionState& exceptionState) {
95 HTMLCollection* children = cells(); 96 HTMLCollection* children = cells();
96 int numCells = children ? children->length() : 0; 97 int numCells = children ? children->length() : 0;
97 if (index < -1 || index > numCells) { 98 if (index < -1 || index > numCells) {
98 exceptionState.throwDOMException( 99 exceptionState.throwDOMException(
99 IndexSizeError, "The value provided (" + String::number(index) + 100 IndexSizeError, "The value provided (" + String::number(index) +
100 ") is outside the range [-1, " + 101 ") is outside the range [-1, " +
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // 3. Remove the indexth element in the cells collection from its parent. 134 // 3. Remove the indexth element in the cells collection from its parent.
134 Element* cell = children->item(index); 135 Element* cell = children->item(index);
135 HTMLElement::removeChild(cell, exceptionState); 136 HTMLElement::removeChild(cell, exceptionState);
136 } 137 }
137 138
138 HTMLCollection* HTMLTableRowElement::cells() { 139 HTMLCollection* HTMLTableRowElement::cells() {
139 return ensureCachedCollection<HTMLCollection>(TRCells); 140 return ensureCachedCollection<HTMLCollection>(TRCells);
140 } 141 }
141 142
142 } // namespace blink 143 } // namespace blink
OLDNEW
« 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