| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2011, 2012 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 |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 #include "core/HTMLNames.h" | 32 #include "core/HTMLNames.h" |
| 33 #include "core/dom/ElementTraversal.h" | 33 #include "core/dom/ElementTraversal.h" |
| 34 #include "core/html/HTMLTableElement.h" | 34 #include "core/html/HTMLTableElement.h" |
| 35 #include "core/html/HTMLTableRowElement.h" | 35 #include "core/html/HTMLTableRowElement.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 using namespace HTMLNames; | 39 using namespace HTMLNames; |
| 40 | 40 |
| 41 static bool isInHead(Element* row) | 41 static inline bool isInSection(HTMLTableRowElement& row, const HTMLQualifiedName
& sectionTag) |
| 42 { | 42 { |
| 43 return row->parentNode() && toElement(row->parentNode())->hasLocalName(thead
Tag); | 43 // Because we know that the parent is a table or a section, it's safe to cas
t it to an HTMLElement |
| 44 } | 44 // giving us access to the faster hasTagName overload from that class. |
| 45 | 45 return toHTMLElement(row.parentNode())->hasTagName(sectionTag); |
| 46 static bool isInBody(Element* row) | |
| 47 { | |
| 48 return row->parentNode() && toElement(row->parentNode())->hasLocalName(tbody
Tag); | |
| 49 } | |
| 50 | |
| 51 static bool isInFoot(Element* row) | |
| 52 { | |
| 53 return row->parentNode() && toElement(row->parentNode())->hasLocalName(tfoot
Tag); | |
| 54 } | 46 } |
| 55 | 47 |
| 56 HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement& table,
HTMLTableRowElement* previous) | 48 HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement& table,
HTMLTableRowElement* previous) |
| 57 { | 49 { |
| 58 // Start by looking for the next row in this section. | 50 // Start by looking for the next row in this section. |
| 59 // Continue only if there is none. | 51 // Continue only if there is none. |
| 60 if (previous && previous->parentNode() != table) { | 52 if (previous && previous->parentNode() != table) { |
| 61 if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::nextSibli
ng(*previous)) | 53 if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::nextSibli
ng(*previous)) |
| 62 return row; | 54 return row; |
| 63 } | 55 } |
| 64 | 56 |
| 65 // If still looking at head sections, find the first row in the next head se
ction. | 57 // If still looking at head sections, find the first row in the next head se
ction. |
| 66 HTMLElement* child = 0; | 58 HTMLElement* child = 0; |
| 67 if (!previous) | 59 if (!previous) |
| 68 child = Traversal<HTMLElement>::firstChild(table); | 60 child = Traversal<HTMLElement>::firstChild(table); |
| 69 else if (isInHead(previous)) | 61 else if (isInSection(*previous, theadTag)) |
| 70 child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); | 62 child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); |
| 71 for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { | 63 for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { |
| 72 if (child->hasLocalName(theadTag)) { | 64 if (child->hasTagName(theadTag)) { |
| 73 if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::first
Child(*child)) | 65 if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::first
Child(*child)) |
| 74 return row; | 66 return row; |
| 75 } | 67 } |
| 76 } | 68 } |
| 77 | 69 |
| 78 // If still looking at top level and bodies, find the next row in top level
or the first in the next body section. | 70 // If still looking at top level and bodies, find the next row in top level
or the first in the next body section. |
| 79 if (!previous || isInHead(previous)) | 71 if (!previous || isInSection(*previous, theadTag)) |
| 80 child = Traversal<HTMLElement>::firstChild(table); | 72 child = Traversal<HTMLElement>::firstChild(table); |
| 81 else if (previous->parentNode() == table) | 73 else if (previous->parentNode() == table) |
| 82 child = Traversal<HTMLElement>::nextSibling(*previous); | 74 child = Traversal<HTMLElement>::nextSibling(*previous); |
| 83 else if (isInBody(previous)) | 75 else if (isInSection(*previous, tbodyTag)) |
| 84 child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); | 76 child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); |
| 85 for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { | 77 for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { |
| 86 if (isHTMLTableRowElement(child)) | 78 if (isHTMLTableRowElement(child)) |
| 87 return toHTMLTableRowElement(child); | 79 return toHTMLTableRowElement(child); |
| 88 if (child->hasLocalName(tbodyTag)) { | 80 if (child->hasTagName(tbodyTag)) { |
| 89 if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::first
Child(*child)) | 81 if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::first
Child(*child)) |
| 90 return row; | 82 return row; |
| 91 } | 83 } |
| 92 } | 84 } |
| 93 | 85 |
| 94 // Find the first row in the next foot section. | 86 // Find the first row in the next foot section. |
| 95 if (!previous || !isInFoot(previous)) | 87 if (!previous || !isInSection(*previous, tfootTag)) |
| 96 child = Traversal<HTMLElement>::firstChild(table); | 88 child = Traversal<HTMLElement>::firstChild(table); |
| 97 else | 89 else |
| 98 child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); | 90 child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); |
| 99 for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { | 91 for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { |
| 100 if (child->hasLocalName(tfootTag)) { | 92 if (child->hasTagName(tfootTag)) { |
| 101 if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::first
Child(*child)) | 93 if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::first
Child(*child)) |
| 102 return row; | 94 return row; |
| 103 } | 95 } |
| 104 } | 96 } |
| 105 | 97 |
| 106 return 0; | 98 return 0; |
| 107 } | 99 } |
| 108 | 100 |
| 109 HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement& table) | 101 HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement& table) |
| 110 { | 102 { |
| 111 for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; c
hild = Traversal<HTMLElement>::previousSibling(*child)) { | 103 for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; c
hild = Traversal<HTMLElement>::previousSibling(*child)) { |
| 112 if (child->hasLocalName(tfootTag)) { | 104 if (child->hasTagName(tfootTag)) { |
| 113 if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::l
astChild(*child)) | 105 if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::l
astChild(*child)) |
| 114 return lastRow; | 106 return lastRow; |
| 115 } | 107 } |
| 116 } | 108 } |
| 117 | 109 |
| 118 for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; c
hild = Traversal<HTMLElement>::previousSibling(*child)) { | 110 for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; c
hild = Traversal<HTMLElement>::previousSibling(*child)) { |
| 119 if (isHTMLTableRowElement(child)) | 111 if (isHTMLTableRowElement(child)) |
| 120 return toHTMLTableRowElement(child); | 112 return toHTMLTableRowElement(child); |
| 121 if (child->hasLocalName(tbodyTag)) { | 113 if (child->hasTagName(tbodyTag)) { |
| 122 if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::l
astChild(*child)) | 114 if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::l
astChild(*child)) |
| 123 return lastRow; | 115 return lastRow; |
| 124 } | 116 } |
| 125 } | 117 } |
| 126 | 118 |
| 127 for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; c
hild = Traversal<HTMLElement>::previousSibling(*child)) { | 119 for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; c
hild = Traversal<HTMLElement>::previousSibling(*child)) { |
| 128 if (child->hasLocalName(theadTag)) { | 120 if (child->hasTagName(theadTag)) { |
| 129 if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::l
astChild(*child)) | 121 if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::l
astChild(*child)) |
| 130 return lastRow; | 122 return lastRow; |
| 131 } | 123 } |
| 132 } | 124 } |
| 133 | 125 |
| 134 return 0; | 126 return 0; |
| 135 } | 127 } |
| 136 | 128 |
| 137 // Must call get() on the table in case that argument is compiled before derefer
encing the | 129 // Must call get() on the table in case that argument is compiled before derefer
encing the |
| 138 // table to get at the collection cache. Order of argument evaluation is undefin
ed and can | 130 // table to get at the collection cache. Order of argument evaluation is undefin
ed and can |
| 139 // differ between compilers. | 131 // differ between compilers. |
| 140 HTMLTableRowsCollection::HTMLTableRowsCollection(ContainerNode& table) | 132 HTMLTableRowsCollection::HTMLTableRowsCollection(ContainerNode& table) |
| 141 : HTMLCollection(table, TableRows, OverridesItemAfter) | 133 : HTMLCollection(table, TableRows, OverridesItemAfter) |
| 142 { | 134 { |
| 143 ASSERT(isHTMLTableElement(table)); | 135 ASSERT(isHTMLTableElement(table)); |
| 144 } | 136 } |
| 145 | 137 |
| 146 PassRefPtrWillBeRawPtr<HTMLTableRowsCollection> HTMLTableRowsCollection::create(
ContainerNode& table, CollectionType type) | 138 PassRefPtrWillBeRawPtr<HTMLTableRowsCollection> HTMLTableRowsCollection::create(
ContainerNode& table, CollectionType type) |
| 147 { | 139 { |
| 148 ASSERT_UNUSED(type, type == TableRows); | 140 ASSERT_UNUSED(type, type == TableRows); |
| 149 return adoptRefWillBeNoop(new HTMLTableRowsCollection(table)); | 141 return adoptRefWillBeNoop(new HTMLTableRowsCollection(table)); |
| 150 } | 142 } |
| 151 | 143 |
| 152 Element* HTMLTableRowsCollection::virtualItemAfter(Element* previous) const | 144 Element* HTMLTableRowsCollection::virtualItemAfter(Element* previous) const |
| 153 { | 145 { |
| 154 return rowAfter(toHTMLTableElement(ownerNode()), toHTMLTableRowElement(previ
ous)); | 146 return rowAfter(toHTMLTableElement(ownerNode()), toHTMLTableRowElement(previ
ous)); |
| 155 } | 147 } |
| 156 | 148 |
| 157 } | 149 } |
| OLD | NEW |