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 12 matching lines...) Expand all Loading... |
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 #include "core/html/HTMLTableRowsCollection.h" | 30 #include "core/html/HTMLTableRowsCollection.h" |
31 | 31 |
32 #include "HTMLNames.h" | 32 #include "HTMLNames.h" |
| 33 #include "core/dom/ElementTraversal.h" |
33 #include "core/html/HTMLTableElement.h" | 34 #include "core/html/HTMLTableElement.h" |
34 #include "core/html/HTMLTableRowElement.h" | 35 #include "core/html/HTMLTableRowElement.h" |
35 | 36 |
36 namespace WebCore { | 37 namespace WebCore { |
37 | 38 |
38 using namespace HTMLNames; | 39 using namespace HTMLNames; |
39 | 40 |
40 static bool isInHead(Element* row) | 41 static bool isInHead(Element* row) |
41 { | 42 { |
42 return row->parentNode() && toElement(row->parentNode())->hasLocalName(thead
Tag); | 43 return row->parentNode() && toElement(row->parentNode())->hasLocalName(thead
Tag); |
43 } | 44 } |
44 | 45 |
45 static bool isInBody(Element* row) | 46 static bool isInBody(Element* row) |
46 { | 47 { |
47 return row->parentNode() && toElement(row->parentNode())->hasLocalName(tbody
Tag); | 48 return row->parentNode() && toElement(row->parentNode())->hasLocalName(tbody
Tag); |
48 } | 49 } |
49 | 50 |
50 static bool isInFoot(Element* row) | 51 static bool isInFoot(Element* row) |
51 { | 52 { |
52 return row->parentNode() && toElement(row->parentNode())->hasLocalName(tfoot
Tag); | 53 return row->parentNode() && toElement(row->parentNode())->hasLocalName(tfoot
Tag); |
53 } | 54 } |
54 | 55 |
55 HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table,
HTMLTableRowElement* previous) | 56 HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table,
HTMLTableRowElement* previous) |
56 { | 57 { |
57 Node* child = 0; | 58 Element* child = 0; |
58 | 59 |
59 // Start by looking for the next row in this section. | 60 // Start by looking for the next row in this section. |
60 // Continue only if there is none. | 61 // Continue only if there is none. |
61 if (previous && previous->parentNode() != table) { | 62 if (previous && previous->parentNode() != table) { |
62 for (child = previous->nextSibling(); child; child = child->nextSibling(
)) { | 63 for (child = ElementTraversal::nextSibling(*previous); child; child = El
ementTraversal::nextSibling(*child)) { |
63 if (child->hasTagName(trTag)) | 64 if (child->hasTagName(trTag)) |
64 return toHTMLTableRowElement(child); | 65 return toHTMLTableRowElement(child); |
65 } | 66 } |
66 } | 67 } |
67 | 68 |
68 // If still looking at head sections, find the first row in the next head se
ction. | 69 // If still looking at head sections, find the first row in the next head se
ction. |
69 if (!previous) | 70 if (!previous) |
70 child = table->firstChild(); | 71 child = ElementTraversal::firstWithin(*table); |
71 else if (isInHead(previous)) | 72 else if (isInHead(previous)) |
72 child = previous->parentNode()->nextSibling(); | 73 child = ElementTraversal::nextSibling(*previous->parentNode()); |
73 for (; child; child = child->nextSibling()) { | 74 for (; child; child = ElementTraversal::nextSibling(*child)) { |
74 if (child->hasTagName(theadTag)) { | 75 if (child->hasTagName(theadTag)) { |
75 for (Node* grandchild = child->firstChild(); grandchild; grandchild
= grandchild->nextSibling()) { | 76 for (Element* grandchild = ElementTraversal::firstWithin(*child); gr
andchild; grandchild = ElementTraversal::nextSibling(*grandchild)) { |
76 if (grandchild->hasTagName(trTag)) | 77 if (grandchild->hasTagName(trTag)) |
77 return toHTMLTableRowElement(grandchild); | 78 return toHTMLTableRowElement(grandchild); |
78 } | 79 } |
79 } | 80 } |
80 } | 81 } |
81 | 82 |
82 // If still looking at top level and bodies, find the next row in top level
or the first in the next body section. | 83 // If still looking at top level and bodies, find the next row in top level
or the first in the next body section. |
83 if (!previous || isInHead(previous)) | 84 if (!previous || isInHead(previous)) |
84 child = table->firstChild(); | 85 child = ElementTraversal::firstWithin(*table); |
85 else if (previous->parentNode() == table) | 86 else if (previous->parentNode() == table) |
86 child = previous->nextSibling(); | 87 child = ElementTraversal::nextSibling(*previous); |
87 else if (isInBody(previous)) | 88 else if (isInBody(previous)) |
88 child = previous->parentNode()->nextSibling(); | 89 child = ElementTraversal::nextSibling(*previous->parentNode()); |
89 for (; child; child = child->nextSibling()) { | 90 for (; child; child = ElementTraversal::nextSibling(*child)) { |
90 if (child->hasTagName(trTag)) | 91 if (child->hasTagName(trTag)) |
91 return toHTMLTableRowElement(child); | 92 return toHTMLTableRowElement(child); |
92 if (child->hasTagName(tbodyTag)) { | 93 if (child->hasTagName(tbodyTag)) { |
93 for (Node* grandchild = child->firstChild(); grandchild; grandchild
= grandchild->nextSibling()) { | 94 for (Element* grandchild = ElementTraversal::firstWithin(*child); gr
andchild; grandchild = ElementTraversal::nextSibling(*grandchild)) { |
94 if (grandchild->hasTagName(trTag)) | 95 if (grandchild->hasTagName(trTag)) |
95 return toHTMLTableRowElement(grandchild); | 96 return toHTMLTableRowElement(grandchild); |
96 } | 97 } |
97 } | 98 } |
98 } | 99 } |
99 | 100 |
100 // Find the first row in the next foot section. | 101 // Find the first row in the next foot section. |
101 if (!previous || !isInFoot(previous)) | 102 if (!previous || !isInFoot(previous)) |
102 child = table->firstChild(); | 103 child = ElementTraversal::firstWithin(*table); |
103 else | 104 else |
104 child = previous->parentNode()->nextSibling(); | 105 child = ElementTraversal::nextSibling(*previous->parentNode()); |
105 for (; child; child = child->nextSibling()) { | 106 for (; child; child = ElementTraversal::nextSibling(*child)) { |
106 if (child->hasTagName(tfootTag)) { | 107 if (child->hasTagName(tfootTag)) { |
107 for (Node* grandchild = child->firstChild(); grandchild; grandchild
= grandchild->nextSibling()) { | 108 for (Element* grandchild = ElementTraversal::firstWithin(*child); gr
andchild; grandchild = ElementTraversal::nextSibling(*grandchild)) { |
108 if (grandchild->hasTagName(trTag)) | 109 if (grandchild->hasTagName(trTag)) |
109 return toHTMLTableRowElement(grandchild); | 110 return toHTMLTableRowElement(grandchild); |
110 } | 111 } |
111 } | 112 } |
112 } | 113 } |
113 | 114 |
114 return 0; | 115 return 0; |
115 } | 116 } |
116 | 117 |
117 HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement* table) | 118 HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement* table) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 { | 162 { |
162 return adoptRef(new HTMLTableRowsCollection(table)); | 163 return adoptRef(new HTMLTableRowsCollection(table)); |
163 } | 164 } |
164 | 165 |
165 Element* HTMLTableRowsCollection::virtualItemAfter(Element* previous) const | 166 Element* HTMLTableRowsCollection::virtualItemAfter(Element* previous) const |
166 { | 167 { |
167 return rowAfter(toHTMLTableElement(ownerNode()), toHTMLTableRowElement(previ
ous)); | 168 return rowAfter(toHTMLTableElement(ownerNode()), toHTMLTableRowElement(previ
ous)); |
168 } | 169 } |
169 | 170 |
170 } | 171 } |
OLD | NEW |