summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/HTMLTableRowsCollection.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/html/HTMLTableRowsCollection.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/html/HTMLTableRowsCollection.cpp')
-rw-r--r--Source/WebCore/html/HTMLTableRowsCollection.cpp73
1 files changed, 36 insertions, 37 deletions
diff --git a/Source/WebCore/html/HTMLTableRowsCollection.cpp b/Source/WebCore/html/HTMLTableRowsCollection.cpp
index 0e4ac0830..2d91d9d48 100644
--- a/Source/WebCore/html/HTMLTableRowsCollection.cpp
+++ b/Source/WebCore/html/HTMLTableRowsCollection.cpp
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -38,7 +38,7 @@ namespace WebCore {
using namespace HTMLNames;
-static inline void assertRowIsInTable(HTMLTableElement* table, HTMLTableRowElement* row)
+static inline void assertRowIsInTable(HTMLTableElement& table, HTMLTableRowElement* row)
{
#if !ASSERT_DISABLED
UNUSED_PARAM(table);
@@ -46,30 +46,29 @@ static inline void assertRowIsInTable(HTMLTableElement* table, HTMLTableRowEleme
#else
if (!row)
return;
- if (row->parentNode() == table)
+ if (row->parentNode() == &table)
return;
ASSERT(row->parentNode());
ASSERT(row->parentNode()->hasTagName(theadTag) || row->parentNode()->hasTagName(tbodyTag) || row->parentNode()->hasTagName(tfootTag));
- ASSERT(row->parentNode()->parentNode() == table);
+ ASSERT(row->parentNode()->parentNode() == &table);
#endif
}
-static inline bool isInSection(HTMLTableRowElement* row, const QualifiedName& sectionTag)
+static inline bool isInSection(HTMLTableRowElement& row, const HTMLQualifiedName& sectionTag)
{
- // Because we know that the parent is a table or a section, all of which are in the HTML
- // namespace, it's OK to do the faster hasLocalName here instead of the more typical hasTagName,
- // since we don't need the check for the HTML namespace.
- return toElement(row->parentNode())->hasLocalName(sectionTag);
+ // Because we know that the parent is a table or a section, it's safe to cast it to an HTMLElement
+ // giving us access to the faster hasTagName overload from that class.
+ return downcast<HTMLElement>(*row.parentNode()).hasTagName(sectionTag);
}
-HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table, HTMLTableRowElement* previous)
+HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement& table, HTMLTableRowElement* previous)
{
// The HTMLCollection caching mechanism, along with the code in this class, will guarantee that the previous row
// is an immediate child of either the table, or a table section that is itself an immediate child of the table.
assertRowIsInTable(table, previous);
// Start by looking for the next row in this section. Continue only if there is none.
- if (previous && previous->parentNode() != table) {
+ if (previous && previous->parentNode() != &table) {
auto childRows = childrenOfType<HTMLTableRowElement>(*previous->parentNode());
auto row = childRows.beginAt(*previous);
if (++row != childRows.end())
@@ -81,9 +80,9 @@ HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table,
// If still looking at head sections, find the first row in the next head section.
if (!previous)
child = ElementTraversal::firstChild(table);
- else if (isInSection(previous, theadTag))
- child = ElementTraversal::nextSibling(previous->parentNode());
- for (; child; child = ElementTraversal::nextSibling(child)) {
+ else if (isInSection(*previous, theadTag))
+ child = ElementTraversal::nextSibling(*previous->parentNode());
+ for (; child; child = ElementTraversal::nextSibling(*child)) {
if (child->hasTagName(theadTag)) {
if (auto row = childrenOfType<HTMLTableRowElement>(*child).first())
return row;
@@ -91,15 +90,15 @@ HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table,
}
// If still looking at top level and bodies, find the next row in top level or the first in the next body section.
- if (!previous || isInSection(previous, theadTag))
+ if (!previous || isInSection(*previous, theadTag))
child = ElementTraversal::firstChild(table);
- else if (previous->parentNode() == table)
- child = ElementTraversal::nextSibling(previous);
- else if (isInSection(previous, tbodyTag))
- child = ElementTraversal::nextSibling(previous->parentNode());
- for (; child; child = ElementTraversal::nextSibling(child)) {
- if (isHTMLTableRowElement(child))
- return toHTMLTableRowElement(child);
+ else if (previous->parentNode() == &table)
+ child = ElementTraversal::nextSibling(*previous);
+ else if (isInSection(*previous, tbodyTag))
+ child = ElementTraversal::nextSibling(*previous->parentNode());
+ for (; child; child = ElementTraversal::nextSibling(*child)) {
+ if (is<HTMLTableRowElement>(*child))
+ return downcast<HTMLTableRowElement>(child);
if (child->hasTagName(tbodyTag)) {
if (auto row = childrenOfType<HTMLTableRowElement>(*child).first())
return row;
@@ -107,11 +106,11 @@ HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table,
}
// Find the first row in the next foot section.
- if (!previous || !isInSection(previous, tfootTag))
+ if (!previous || !isInSection(*previous, tfootTag))
child = ElementTraversal::firstChild(table);
else
- child = ElementTraversal::nextSibling(previous->parentNode());
- for (; child; child = ElementTraversal::nextSibling(child)) {
+ child = ElementTraversal::nextSibling(*previous->parentNode());
+ for (; child; child = ElementTraversal::nextSibling(*child)) {
if (child->hasTagName(tfootTag)) {
if (auto row = childrenOfType<HTMLTableRowElement>(*child).first())
return row;
@@ -121,27 +120,27 @@ HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table,
return nullptr;
}
-HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement* table)
+HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement& table)
{
- for (auto child = ElementTraversal::lastChild(table); child; child = ElementTraversal::previousSibling(child)) {
+ for (auto* child = ElementTraversal::lastChild(table); child; child = ElementTraversal::previousSibling(*child)) {
if (child->hasTagName(tfootTag)) {
- if (auto row = childrenOfType<HTMLTableRowElement>(*child).last())
+ if (auto* row = childrenOfType<HTMLTableRowElement>(*child).last())
return row;
}
}
- for (auto child = ElementTraversal::lastChild(table); child; child = ElementTraversal::previousSibling(child)) {
- if (isHTMLTableRowElement(child))
- return toHTMLTableRowElement(child);
+ for (auto* child = ElementTraversal::lastChild(table); child; child = ElementTraversal::previousSibling(*child)) {
+ if (is<HTMLTableRowElement>(*child))
+ return downcast<HTMLTableRowElement>(child);
if (child->hasTagName(tbodyTag)) {
- if (auto row = childrenOfType<HTMLTableRowElement>(*child).last())
+ if (auto* row = childrenOfType<HTMLTableRowElement>(*child).last())
return row;
}
}
- for (auto child = ElementTraversal::lastChild(table); child; child = ElementTraversal::previousSibling(child)) {
+ for (auto* child = ElementTraversal::lastChild(table); child; child = ElementTraversal::previousSibling(*child)) {
if (child->hasTagName(theadTag)) {
- if (auto row = childrenOfType<HTMLTableRowElement>(*child).last())
+ if (auto* row = childrenOfType<HTMLTableRowElement>(*child).last())
return row;
}
}
@@ -150,11 +149,11 @@ HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement* table)
}
HTMLTableRowsCollection::HTMLTableRowsCollection(HTMLTableElement& table)
- : HTMLCollection(table, TableRows, CustomForwardOnlyTraversal)
+ : CachedHTMLCollection<HTMLTableRowsCollection, CollectionTypeTraits<TableRows>::traversalType>(table, TableRows)
{
}
-PassRef<HTMLTableRowsCollection> HTMLTableRowsCollection::create(HTMLTableElement& table, CollectionType type)
+Ref<HTMLTableRowsCollection> HTMLTableRowsCollection::create(HTMLTableElement& table, CollectionType type)
{
ASSERT_UNUSED(type, type == TableRows);
return adoptRef(*new HTMLTableRowsCollection(table));
@@ -162,7 +161,7 @@ PassRef<HTMLTableRowsCollection> HTMLTableRowsCollection::create(HTMLTableElemen
Element* HTMLTableRowsCollection::customElementAfter(Element* previous) const
{
- return rowAfter(const_cast<HTMLTableElement*>(&tableElement()), toHTMLTableRowElement(previous));
+ return rowAfter(const_cast<HTMLTableElement&>(tableElement()), downcast<HTMLTableRowElement>(previous));
}
}