| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2011, 2012, 2014 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2011, 2012, 2014 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "core/dom/ElementTraversal.h" | 32 #include "core/dom/ElementTraversal.h" |
| 33 #include "core/html/HTMLTableElement.h" | 33 #include "core/html/HTMLTableElement.h" |
| 34 #include "core/html/HTMLTableRowElement.h" | 34 #include "core/html/HTMLTableRowElement.h" |
| 35 | 35 |
| 36 namespace blink { | 36 namespace blink { |
| 37 | 37 |
| 38 using namespace HTMLNames; | 38 using namespace HTMLNames; |
| 39 | 39 |
| 40 static inline bool isInSection(HTMLTableRowElement& row, | 40 static inline bool isInSection(HTMLTableRowElement& row, |
| 41 const HTMLQualifiedName& sectionTag) { | 41 const HTMLQualifiedName& sectionTag) { |
| 42 // Because we know that the parent is a table or a section, it's safe to cast
it to an HTMLElement | 42 // Because we know that the parent is a table or a section, it's safe to cast |
| 43 // giving us access to the faster hasTagName overload from that class. | 43 // it to an HTMLElement giving us access to the faster hasTagName overload |
| 44 // from that class. |
| 44 return toHTMLElement(row.parentNode())->hasTagName(sectionTag); | 45 return toHTMLElement(row.parentNode())->hasTagName(sectionTag); |
| 45 } | 46 } |
| 46 | 47 |
| 47 HTMLTableRowElement* HTMLTableRowsCollection::rowAfter( | 48 HTMLTableRowElement* HTMLTableRowsCollection::rowAfter( |
| 48 HTMLTableElement& table, | 49 HTMLTableElement& table, |
| 49 HTMLTableRowElement* previous) { | 50 HTMLTableRowElement* previous) { |
| 50 // Start by looking for the next row in this section. | 51 // Start by looking for the next row in this section. |
| 51 // Continue only if there is none. | 52 // Continue only if there is none. |
| 52 if (previous && previous->parentNode() != table) { | 53 if (previous && previous->parentNode() != table) { |
| 53 if (HTMLTableRowElement* row = | 54 if (HTMLTableRowElement* row = |
| 54 Traversal<HTMLTableRowElement>::nextSibling(*previous)) | 55 Traversal<HTMLTableRowElement>::nextSibling(*previous)) |
| 55 return row; | 56 return row; |
| 56 } | 57 } |
| 57 | 58 |
| 58 // If still looking at head sections, find the first row in the next head sect
ion. | 59 // If still looking at head sections, find the first row in the next head |
| 60 // section. |
| 59 HTMLElement* child = 0; | 61 HTMLElement* child = 0; |
| 60 if (!previous) | 62 if (!previous) |
| 61 child = Traversal<HTMLElement>::firstChild(table); | 63 child = Traversal<HTMLElement>::firstChild(table); |
| 62 else if (isInSection(*previous, theadTag)) | 64 else if (isInSection(*previous, theadTag)) |
| 63 child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); | 65 child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); |
| 64 for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { | 66 for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { |
| 65 if (child->hasTagName(theadTag)) { | 67 if (child->hasTagName(theadTag)) { |
| 66 if (HTMLTableRowElement* row = | 68 if (HTMLTableRowElement* row = |
| 67 Traversal<HTMLTableRowElement>::firstChild(*child)) | 69 Traversal<HTMLTableRowElement>::firstChild(*child)) |
| 68 return row; | 70 return row; |
| 69 } | 71 } |
| 70 } | 72 } |
| 71 | 73 |
| 72 // If still looking at top level and bodies, find the next row in top level or
the first in the next body section. | 74 // If still looking at top level and bodies, find the next row in top level or |
| 75 // the first in the next body section. |
| 73 if (!previous || isInSection(*previous, theadTag)) | 76 if (!previous || isInSection(*previous, theadTag)) |
| 74 child = Traversal<HTMLElement>::firstChild(table); | 77 child = Traversal<HTMLElement>::firstChild(table); |
| 75 else if (previous->parentNode() == table) | 78 else if (previous->parentNode() == table) |
| 76 child = Traversal<HTMLElement>::nextSibling(*previous); | 79 child = Traversal<HTMLElement>::nextSibling(*previous); |
| 77 else if (isInSection(*previous, tbodyTag)) | 80 else if (isInSection(*previous, tbodyTag)) |
| 78 child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); | 81 child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); |
| 79 for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { | 82 for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { |
| 80 if (isHTMLTableRowElement(child)) | 83 if (isHTMLTableRowElement(child)) |
| 81 return toHTMLTableRowElement(child); | 84 return toHTMLTableRowElement(child); |
| 82 if (child->hasTagName(tbodyTag)) { | 85 if (child->hasTagName(tbodyTag)) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 thead; thead = Traversal<HTMLElement>::previousSibling( | 131 thead; thead = Traversal<HTMLElement>::previousSibling( |
| 129 *thead, HasHTMLTagName(theadTag))) { | 132 *thead, HasHTMLTagName(theadTag))) { |
| 130 if (HTMLTableRowElement* lastRow = | 133 if (HTMLTableRowElement* lastRow = |
| 131 Traversal<HTMLTableRowElement>::lastChild(*thead)) | 134 Traversal<HTMLTableRowElement>::lastChild(*thead)) |
| 132 return lastRow; | 135 return lastRow; |
| 133 } | 136 } |
| 134 | 137 |
| 135 return nullptr; | 138 return nullptr; |
| 136 } | 139 } |
| 137 | 140 |
| 138 // Must call get() on the table in case that argument is compiled before derefer
encing the | 141 // Must call get() on the table in case that argument is compiled before |
| 139 // table to get at the collection cache. Order of argument evaluation is undefin
ed and can | 142 // dereferencing the table to get at the collection cache. Order of argument |
| 140 // differ between compilers. | 143 // evaluation is undefined and can differ between compilers. |
| 141 HTMLTableRowsCollection::HTMLTableRowsCollection(ContainerNode& table) | 144 HTMLTableRowsCollection::HTMLTableRowsCollection(ContainerNode& table) |
| 142 : HTMLCollection(table, TableRows, OverridesItemAfter) { | 145 : HTMLCollection(table, TableRows, OverridesItemAfter) { |
| 143 DCHECK(isHTMLTableElement(table)); | 146 DCHECK(isHTMLTableElement(table)); |
| 144 } | 147 } |
| 145 | 148 |
| 146 HTMLTableRowsCollection* HTMLTableRowsCollection::create(ContainerNode& table, | 149 HTMLTableRowsCollection* HTMLTableRowsCollection::create(ContainerNode& table, |
| 147 CollectionType type) { | 150 CollectionType type) { |
| 148 DCHECK_EQ(type, TableRows); | 151 DCHECK_EQ(type, TableRows); |
| 149 return new HTMLTableRowsCollection(table); | 152 return new HTMLTableRowsCollection(table); |
| 150 } | 153 } |
| 151 | 154 |
| 152 Element* HTMLTableRowsCollection::virtualItemAfter(Element* previous) const { | 155 Element* HTMLTableRowsCollection::virtualItemAfter(Element* previous) const { |
| 153 return rowAfter(toHTMLTableElement(ownerNode()), | 156 return rowAfter(toHTMLTableElement(ownerNode()), |
| 154 toHTMLTableRowElement(previous)); | 157 toHTMLTableRowElement(previous)); |
| 155 } | 158 } |
| 156 | 159 |
| 157 } // namespace blink | 160 } // namespace blink |
| OLD | NEW |