Commit fafe7f85 authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Introduce HasHTMLTagName functor and use it with ElementTraversal

Introduce HasHTMLTagName functor and use it with ElementTraversal to simplify
the code a bit.

R=adamk@chromium.org

Review URL: https://codereview.chromium.org/471173003

git-svn-id: svn://svn.chromium.org/blink/trunk@180363 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b3ccc483
......@@ -149,6 +149,15 @@ inline bool Node::hasTagName(const HTMLQualifiedName& name) const
return isHTMLElement() && toHTMLElement(*this).hasTagName(name);
}
// Functor used to match HTMLElements with a specific HTML tag when using the ElementTraversal API.
class HasHTMLTagName {
public:
explicit HasHTMLTagName(const HTMLQualifiedName& tagName): m_tagName(tagName) { }
bool operator() (const HTMLElement& element) const { return element.hasTagName(m_tagName); }
private:
const HTMLQualifiedName& m_tagName;
};
// This requires isHTML*Element(const Element&) and isHTML*Element(const HTMLElement&).
// When the input element is an HTMLElement, we don't need to check the namespace URI, just the local name.
#define DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) \
......
......@@ -78,11 +78,7 @@ void HTMLTableElement::setCaption(PassRefPtrWillBeRawPtr<HTMLTableCaptionElement
HTMLTableSectionElement* HTMLTableElement::tHead() const
{
for (HTMLElement* child = Traversal<HTMLElement>::firstChild(*this); child; child = Traversal<HTMLElement>::nextSibling(*child)) {
if (child->hasTagName(theadTag))
return toHTMLTableSectionElement(child);
}
return 0;
return toHTMLTableSectionElement(Traversal<HTMLElement>::firstChild(*this, HasHTMLTagName(theadTag)));
}
void HTMLTableElement::setTHead(PassRefPtrWillBeRawPtr<HTMLTableSectionElement> newHead, ExceptionState& exceptionState)
......@@ -100,11 +96,7 @@ void HTMLTableElement::setTHead(PassRefPtrWillBeRawPtr<HTMLTableSectionElement>
HTMLTableSectionElement* HTMLTableElement::tFoot() const
{
for (HTMLElement* child = Traversal<HTMLElement>::firstChild(*this); child; child = Traversal<HTMLElement>::nextSibling(*child)) {
if (child->hasTagName(tfootTag))
return toHTMLTableSectionElement(child);
}
return 0;
return toHTMLTableSectionElement(Traversal<HTMLElement>::firstChild(*this, HasHTMLTagName(tfootTag)));
}
void HTMLTableElement::setTFoot(PassRefPtrWillBeRawPtr<HTMLTableSectionElement> newFoot, ExceptionState& exceptionState)
......@@ -173,11 +165,7 @@ void HTMLTableElement::deleteCaption()
HTMLTableSectionElement* HTMLTableElement::lastBody() const
{
for (HTMLElement* child = Traversal<HTMLElement>::lastChild(*this); child; child = Traversal<HTMLElement>::previousSibling(*child)) {
if (child->hasTagName(tbodyTag))
return toHTMLTableSectionElement(child);
}
return 0;
return toHTMLTableSectionElement(Traversal<HTMLElement>::lastChild(*this, HasHTMLTagName(tbodyTag)));
}
PassRefPtrWillBeRawPtr<HTMLElement> HTMLTableElement::insertRow(ExceptionState& exceptionState)
......
......@@ -81,16 +81,13 @@ int HTMLTableRowElement::rowIndex() const
}
}
for (HTMLElement* child = Traversal<HTMLElement>::firstChild(*table); child; child = Traversal<HTMLElement>::nextSibling(*child)) {
if (child->hasTagName(tbodyTag)) {
HTMLTableSectionElement* section = toHTMLTableSectionElement(child);
for (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::firstChild(*section); row; row = Traversal<HTMLTableRowElement>::nextSibling(*row)) {
for (HTMLElement* tbody = Traversal<HTMLElement>::firstChild(*table, HasHTMLTagName(tbodyTag)); tbody; tbody = Traversal<HTMLElement>::nextSibling(*tbody, HasHTMLTagName(tbodyTag))) {
for (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::firstChild(*tbody); row; row = Traversal<HTMLTableRowElement>::nextSibling(*row)) {
if (row == this)
return rIndex;
++rIndex;
}
}
}
if (HTMLTableSectionElement* foot = toHTMLTableElement(table)->tFoot()) {
for (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::firstChild(*foot); row; row = Traversal<HTMLTableRowElement>::nextSibling(*row)) {
......
......@@ -100,12 +100,10 @@ HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement& table,
HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement& table)
{
for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; child = Traversal<HTMLElement>::previousSibling(*child)) {
if (child->hasTagName(tfootTag)) {
if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::lastChild(*child))
for (HTMLElement* tfoot = Traversal<HTMLElement>::lastChild(table, HasHTMLTagName(tfootTag)); tfoot; tfoot = Traversal<HTMLElement>::previousSibling(*tfoot, HasHTMLTagName(tfootTag))) {
if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::lastChild(*tfoot))
return lastRow;
}
}
for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; child = Traversal<HTMLElement>::previousSibling(*child)) {
if (isHTMLTableRowElement(child))
......@@ -116,12 +114,10 @@ HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement& table)
}
}
for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; child = Traversal<HTMLElement>::previousSibling(*child)) {
if (child->hasTagName(theadTag)) {
if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::lastChild(*child))
for (HTMLElement* thead = Traversal<HTMLElement>::lastChild(table, HasHTMLTagName(theadTag)); thead; thead = Traversal<HTMLElement>::previousSibling(*thead, HasHTMLTagName(theadTag))) {
if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::lastChild(*thead))
return lastRow;
}
}
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment