Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: Source/core/html/HTMLTableRowsCollection.cpp

Issue 166093004: Avoid some code duplication in HTMLTableRowsCollection::rowAfter() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 for (Element* child = ElementTraversal::firstWithin(current); child; child = ElementTraversal::nextSibling(*child)) {
59 if (child->hasTagName(trTag))
60 return toHTMLTableRowElement(child);
61 }
62 return 0;
63 }
64
56 HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table, HTMLTableRowElement* previous) 65 HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table, HTMLTableRowElement* previous)
57 { 66 {
58 Element* child = 0; 67 Element* child = 0;
59 68
60 // Start by looking for the next row in this section. 69 // Start by looking for the next row in this section.
61 // Continue only if there is none. 70 // Continue only if there is none.
62 if (previous && previous->parentNode() != table) { 71 if (previous && previous->parentNode() != table) {
63 for (child = ElementTraversal::nextSibling(*previous); child; child = El ementTraversal::nextSibling(*child)) { 72 for (child = ElementTraversal::nextSibling(*previous); child; child = El ementTraversal::nextSibling(*child)) {
64 if (child->hasTagName(trTag)) 73 if (child->hasTagName(trTag))
65 return toHTMLTableRowElement(child); 74 return toHTMLTableRowElement(child);
66 } 75 }
67 } 76 }
68 77
69 // If still looking at head sections, find the first row in the next head se ction. 78 // If still looking at head sections, find the first row in the next head se ction.
70 if (!previous) 79 if (!previous)
71 child = ElementTraversal::firstWithin(*table); 80 child = ElementTraversal::firstWithin(*table);
72 else if (isInHead(previous)) 81 else if (isInHead(previous))
73 child = ElementTraversal::nextSibling(*previous->parentNode()); 82 child = ElementTraversal::nextSibling(*previous->parentNode());
74 for (; child; child = ElementTraversal::nextSibling(*child)) { 83 for (; child; child = ElementTraversal::nextSibling(*child)) {
75 if (child->hasTagName(theadTag)) { 84 if (child->hasTagName(theadTag)) {
76 for (Element* grandchild = ElementTraversal::firstWithin(*child); gr andchild; grandchild = ElementTraversal::nextSibling(*grandchild)) { 85 if (HTMLTableRowElement* row = findTableRowElementInChildren(*child) )
77 if (grandchild->hasTagName(trTag)) 86 return row;
78 return toHTMLTableRowElement(grandchild);
79 }
80 } 87 }
81 } 88 }
82 89
83 // If still looking at top level and bodies, find the next row in top level or the first in the next body section. 90 // If still looking at top level and bodies, find the next row in top level or the first in the next body section.
84 if (!previous || isInHead(previous)) 91 if (!previous || isInHead(previous))
85 child = ElementTraversal::firstWithin(*table); 92 child = ElementTraversal::firstWithin(*table);
86 else if (previous->parentNode() == table) 93 else if (previous->parentNode() == table)
87 child = ElementTraversal::nextSibling(*previous); 94 child = ElementTraversal::nextSibling(*previous);
88 else if (isInBody(previous)) 95 else if (isInBody(previous))
89 child = ElementTraversal::nextSibling(*previous->parentNode()); 96 child = ElementTraversal::nextSibling(*previous->parentNode());
90 for (; child; child = ElementTraversal::nextSibling(*child)) { 97 for (; child; child = ElementTraversal::nextSibling(*child)) {
91 if (child->hasTagName(trTag)) 98 if (child->hasTagName(trTag))
92 return toHTMLTableRowElement(child); 99 return toHTMLTableRowElement(child);
93 if (child->hasTagName(tbodyTag)) { 100 if (child->hasTagName(tbodyTag)) {
94 for (Element* grandchild = ElementTraversal::firstWithin(*child); gr andchild; grandchild = ElementTraversal::nextSibling(*grandchild)) { 101 if (HTMLTableRowElement* row = findTableRowElementInChildren(*child) )
95 if (grandchild->hasTagName(trTag)) 102 return row;
96 return toHTMLTableRowElement(grandchild);
97 }
98 } 103 }
99 } 104 }
100 105
101 // Find the first row in the next foot section. 106 // Find the first row in the next foot section.
102 if (!previous || !isInFoot(previous)) 107 if (!previous || !isInFoot(previous))
103 child = ElementTraversal::firstWithin(*table); 108 child = ElementTraversal::firstWithin(*table);
104 else 109 else
105 child = ElementTraversal::nextSibling(*previous->parentNode()); 110 child = ElementTraversal::nextSibling(*previous->parentNode());
106 for (; child; child = ElementTraversal::nextSibling(*child)) { 111 for (; child; child = ElementTraversal::nextSibling(*child)) {
107 if (child->hasTagName(tfootTag)) { 112 if (child->hasTagName(tfootTag)) {
108 for (Element* grandchild = ElementTraversal::firstWithin(*child); gr andchild; grandchild = ElementTraversal::nextSibling(*grandchild)) { 113 if (HTMLTableRowElement* row = findTableRowElementInChildren(*child) )
109 if (grandchild->hasTagName(trTag)) 114 return row;
110 return toHTMLTableRowElement(grandchild);
111 }
112 } 115 }
113 } 116 }
114 117
115 return 0; 118 return 0;
116 } 119 }
117 120
118 HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement* table) 121 HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement* table)
119 { 122 {
120 for (Node* child = table->lastChild(); child; child = child->previousSibling ()) { 123 for (Node* child = table->lastChild(); child; child = child->previousSibling ()) {
121 if (child->hasTagName(tfootTag)) { 124 if (child->hasTagName(tfootTag)) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 { 165 {
163 return adoptRef(new HTMLTableRowsCollection(table)); 166 return adoptRef(new HTMLTableRowsCollection(table));
164 } 167 }
165 168
166 Element* HTMLTableRowsCollection::virtualItemAfter(Element* previous) const 169 Element* HTMLTableRowsCollection::virtualItemAfter(Element* previous) const
167 { 170 {
168 return rowAfter(toHTMLTableElement(ownerNode()), toHTMLTableRowElement(previ ous)); 171 return rowAfter(toHTMLTableElement(ownerNode()), toHTMLTableRowElement(previ ous));
169 } 172 }
170 173
171 } 174 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698