OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2008, 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2011, 2012 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 static bool isInBody(Element* row) | 46 static bool isInBody(Element* row) |
47 { | 47 { |
48 return row->parentNode() && toElement(row->parentNode())->hasLocalName(tbody Tag); | 48 return row->parentNode() && toElement(row->parentNode())->hasLocalName(tbody Tag); |
49 } | 49 } |
50 | 50 |
51 static bool isInFoot(Element* row) | 51 static bool isInFoot(Element* row) |
52 { | 52 { |
53 return row->parentNode() && toElement(row->parentNode())->hasLocalName(tfoot Tag); | 53 return row->parentNode() && toElement(row->parentNode())->hasLocalName(tfoot Tag); |
54 } | 54 } |
55 | 55 |
56 static inline HTMLTableRowElement* findTableRowElementInChildren(Element& curren t) | |
57 { | |
58 return Traversal<HTMLTableRowElement>::firstChild(current); | |
59 } | |
60 | |
61 HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement& table, HTMLTableRowElement* previous) | 56 HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement& table, HTMLTableRowElement* previous) |
62 { | 57 { |
63 Element* child = 0; | |
64 | |
65 // Start by looking for the next row in this section. | 58 // Start by looking for the next row in this section. |
66 // Continue only if there is none. | 59 // Continue only if there is none. |
67 if (previous && previous->parentNode() != table) { | 60 if (previous && previous->parentNode() != table) { |
68 if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::nextSibli ng(*previous)) | 61 if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::nextSibli ng(*previous)) |
69 return row; | 62 return row; |
70 } | 63 } |
71 | 64 |
72 // If still looking at head sections, find the first row in the next head se ction. | 65 // If still looking at head sections, find the first row in the next head se ction. |
66 HTMLElement* child = 0; | |
73 if (!previous) | 67 if (!previous) |
74 child = ElementTraversal::firstWithin(table); | 68 child = Traversal<HTMLElement>::firstChild(table); |
75 else if (isInHead(previous)) | 69 else if (isInHead(previous)) |
76 child = ElementTraversal::nextSibling(*previous->parentNode()); | 70 child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); |
77 for (; child; child = ElementTraversal::nextSibling(*child)) { | 71 for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { |
78 if (child->hasTagName(theadTag)) { | 72 if (child->hasLocalName(theadTag)) { |
79 if (HTMLTableRowElement* row = findTableRowElementInChildren(*child) ) | 73 if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::first Child(*child)) |
80 return row; | 74 return row; |
81 } | 75 } |
82 } | 76 } |
83 | 77 |
84 // If still looking at top level and bodies, find the next row in top level or the first in the next body section. | 78 // If still looking at top level and bodies, find the next row in top level or the first in the next body section. |
85 if (!previous || isInHead(previous)) | 79 if (!previous || isInHead(previous)) |
86 child = ElementTraversal::firstWithin(table); | 80 child = Traversal<HTMLElement>::firstChild(table); |
87 else if (previous->parentNode() == table) | 81 else if (previous->parentNode() == table) |
88 child = ElementTraversal::nextSibling(*previous); | 82 child = Traversal<HTMLElement>::nextSibling(*previous); |
89 else if (isInBody(previous)) | 83 else if (isInBody(previous)) |
90 child = ElementTraversal::nextSibling(*previous->parentNode()); | 84 child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); |
91 for (; child; child = ElementTraversal::nextSibling(*child)) { | 85 for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { |
esprehn
2014/03/27 13:35:49
This isn't equivalent to the original code. If you
Inactive
2014/03/27 13:57:58
Arg, you are right, I caused a slight behavior cha
Inactive
2014/03/27 14:39:54
Actually, the new code returns 2 as well since I a
| |
92 if (isHTMLTableRowElement(child)) | 86 if (isHTMLTableRowElement(child)) |
93 return toHTMLTableRowElement(child); | 87 return toHTMLTableRowElement(child); |
94 if (child->hasTagName(tbodyTag)) { | 88 if (child->hasLocalName(tbodyTag)) { |
95 if (HTMLTableRowElement* row = findTableRowElementInChildren(*child) ) | 89 if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::first Child(*child)) |
96 return row; | 90 return row; |
97 } | 91 } |
98 } | 92 } |
99 | 93 |
100 // Find the first row in the next foot section. | 94 // Find the first row in the next foot section. |
101 if (!previous || !isInFoot(previous)) | 95 if (!previous || !isInFoot(previous)) |
102 child = ElementTraversal::firstWithin(table); | 96 child = Traversal<HTMLElement>::firstChild(table); |
103 else | 97 else |
104 child = ElementTraversal::nextSibling(*previous->parentNode()); | 98 child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); |
105 for (; child; child = ElementTraversal::nextSibling(*child)) { | 99 for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { |
106 if (child->hasTagName(tfootTag)) { | 100 if (child->hasLocalName(tfootTag)) { |
107 if (HTMLTableRowElement* row = findTableRowElementInChildren(*child) ) | 101 if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::first Child(*child)) |
108 return row; | 102 return row; |
109 } | 103 } |
110 } | 104 } |
111 | 105 |
112 return 0; | 106 return 0; |
113 } | 107 } |
114 | 108 |
115 HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement& table) | 109 HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement& table) |
116 { | 110 { |
117 for (Node* child = table.lastChild(); child; child = child->previousSibling( )) { | 111 for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; c hild = Traversal<HTMLElement>::previousSibling(*child)) { |
118 if (child->hasTagName(tfootTag)) { | 112 if (child->hasLocalName(tfootTag)) { |
119 if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::l astChild(*child)) | 113 if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::l astChild(*child)) |
120 return lastRow; | 114 return lastRow; |
121 } | 115 } |
122 } | 116 } |
123 | 117 |
124 for (Node* child = table.lastChild(); child; child = child->previousSibling( )) { | 118 for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; c hild = Traversal<HTMLElement>::previousSibling(*child)) { |
125 if (isHTMLTableRowElement(child)) | 119 if (isHTMLTableRowElement(child)) |
126 return toHTMLTableRowElement(child); | 120 return toHTMLTableRowElement(child); |
127 if (child->hasTagName(tbodyTag)) { | 121 if (child->hasLocalName(tbodyTag)) { |
128 if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::l astChild(*child)) | 122 if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::l astChild(*child)) |
129 return lastRow; | 123 return lastRow; |
130 } | 124 } |
131 } | 125 } |
132 | 126 |
133 for (Node* child = table.lastChild(); child; child = child->previousSibling( )) { | 127 for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; c hild = Traversal<HTMLElement>::previousSibling(*child)) { |
esprehn
2014/03/27 13:35:49
Why not use Traversal<HTMLTableSectionElement> ?
Inactive
2014/03/27 13:57:58
We are only interested in thead elements so using
| |
134 if (child->hasTagName(theadTag)) { | 128 if (child->hasLocalName(theadTag)) { |
135 if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::l astChild(*child)) | 129 if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::l astChild(*child)) |
136 return lastRow; | 130 return lastRow; |
137 } | 131 } |
138 } | 132 } |
139 | 133 |
140 return 0; | 134 return 0; |
141 } | 135 } |
142 | 136 |
143 // Must call get() on the table in case that argument is compiled before derefer encing the | 137 // Must call get() on the table in case that argument is compiled before derefer encing the |
144 // table to get at the collection cache. Order of argument evaluation is undefin ed and can | 138 // table to get at the collection cache. Order of argument evaluation is undefin ed and can |
145 // differ between compilers. | 139 // differ between compilers. |
146 HTMLTableRowsCollection::HTMLTableRowsCollection(ContainerNode& table) | 140 HTMLTableRowsCollection::HTMLTableRowsCollection(ContainerNode& table) |
147 : HTMLCollection(table, TableRows, OverridesItemAfter) | 141 : HTMLCollection(table, TableRows, OverridesItemAfter) |
148 { | 142 { |
149 ASSERT(isHTMLTableElement(table)); | 143 ASSERT(isHTMLTableElement(table)); |
150 } | 144 } |
151 | 145 |
152 PassRefPtr<HTMLTableRowsCollection> HTMLTableRowsCollection::create(ContainerNod e& table, CollectionType) | 146 PassRefPtr<HTMLTableRowsCollection> HTMLTableRowsCollection::create(ContainerNod e& table, CollectionType) |
153 { | 147 { |
154 return adoptRef(new HTMLTableRowsCollection(table)); | 148 return adoptRef(new HTMLTableRowsCollection(table)); |
155 } | 149 } |
156 | 150 |
157 Element* HTMLTableRowsCollection::virtualItemAfter(Element* previous) const | 151 Element* HTMLTableRowsCollection::virtualItemAfter(Element* previous) const |
158 { | 152 { |
159 return rowAfter(toHTMLTableElement(ownerNode()), toHTMLTableRowElement(previ ous)); | 153 return rowAfter(toHTMLTableElement(ownerNode()), toHTMLTableRowElement(previ ous)); |
160 } | 154 } |
161 | 155 |
162 } | 156 } |
OLD | NEW |