OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return false; | 139 return false; |
140 | 140 |
141 // If there are at least 20 rows, we'll call it a data table. | 141 // If there are at least 20 rows, we'll call it a data table. |
142 if (numRows >= 20) | 142 if (numRows >= 20) |
143 return true; | 143 return true; |
144 | 144 |
145 // Store the background color of the table to check against cell's backgroun
d colors. | 145 // Store the background color of the table to check against cell's backgroun
d colors. |
146 RenderStyle* tableStyle = table->style(); | 146 RenderStyle* tableStyle = table->style(); |
147 if (!tableStyle) | 147 if (!tableStyle) |
148 return false; | 148 return false; |
149 Color tableBGColor = tableStyle->visitedDependentColor(CSSPropertyBackground
Color); | 149 StyleColor tableBGColor = tableStyle->visitedDependentColor(CSSPropertyBackg
roundColor); |
150 | 150 |
151 // check enough of the cells to find if the table matches our criteria | 151 // check enough of the cells to find if the table matches our criteria |
152 // Criteria: | 152 // Criteria: |
153 // 1) must have at least one valid cell (and) | 153 // 1) must have at least one valid cell (and) |
154 // 2) at least half of cells have borders (or) | 154 // 2) at least half of cells have borders (or) |
155 // 3) at least half of cells have different bg colors than the table, and
there is cell spacing | 155 // 3) at least half of cells have different bg colors than the table, and
there is cell spacing |
156 unsigned validCellCount = 0; | 156 unsigned validCellCount = 0; |
157 unsigned borderedCellCount = 0; | 157 unsigned borderedCellCount = 0; |
158 unsigned backgroundDifferenceCellCount = 0; | 158 unsigned backgroundDifferenceCellCount = 0; |
159 unsigned cellsWithTopBorder = 0; | 159 unsigned cellsWithTopBorder = 0; |
160 unsigned cellsWithBottomBorder = 0; | 160 unsigned cellsWithBottomBorder = 0; |
161 unsigned cellsWithLeftBorder = 0; | 161 unsigned cellsWithLeftBorder = 0; |
162 unsigned cellsWithRightBorder = 0; | 162 unsigned cellsWithRightBorder = 0; |
163 | 163 |
164 Color alternatingRowColors[5]; | 164 StyleColor alternatingRowColors[5]; |
165 int alternatingRowColorCount = 0; | 165 int alternatingRowColorCount = 0; |
166 | 166 |
167 int headersInFirstColumnCount = 0; | 167 int headersInFirstColumnCount = 0; |
168 for (int row = 0; row < numRows; ++row) { | 168 for (int row = 0; row < numRows; ++row) { |
169 | 169 |
170 int headersInFirstRowCount = 0; | 170 int headersInFirstRowCount = 0; |
171 for (int col = 0; col < numCols; ++col) { | 171 for (int col = 0; col < numCols; ++col) { |
172 RenderTableCell* cell = firstBody->primaryCellAt(row, col); | 172 RenderTableCell* cell = firstBody->primaryCellAt(row, col); |
173 if (!cell) | 173 if (!cell) |
174 continue; | 174 continue; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 cellsWithTopBorder++; | 216 cellsWithTopBorder++; |
217 if (cell->borderBottom() > 0) | 217 if (cell->borderBottom() > 0) |
218 cellsWithBottomBorder++; | 218 cellsWithBottomBorder++; |
219 if (cell->borderLeft() > 0) | 219 if (cell->borderLeft() > 0) |
220 cellsWithLeftBorder++; | 220 cellsWithLeftBorder++; |
221 if (cell->borderRight() > 0) | 221 if (cell->borderRight() > 0) |
222 cellsWithRightBorder++; | 222 cellsWithRightBorder++; |
223 | 223 |
224 // If the cell has a different color from the table and there is cel
l spacing, | 224 // If the cell has a different color from the table and there is cel
l spacing, |
225 // then it is probably a data table cell (spacing and colors take th
e place of borders). | 225 // then it is probably a data table cell (spacing and colors take th
e place of borders). |
226 Color cellColor = renderStyle->visitedDependentColor(CSSPropertyBack
groundColor); | 226 StyleColor cellColor = renderStyle->visitedDependentColor(CSSPropert
yBackgroundColor); |
227 if (table->hBorderSpacing() > 0 && table->vBorderSpacing() > 0 | 227 if (table->hBorderSpacing() > 0 && table->vBorderSpacing() > 0 |
228 && tableBGColor != cellColor && cellColor.alpha() != 1) | 228 && tableBGColor != cellColor && cellColor.alpha() != 1) |
229 backgroundDifferenceCellCount++; | 229 backgroundDifferenceCellCount++; |
230 | 230 |
231 // If we've found 10 "good" cells, we don't need to keep searching. | 231 // If we've found 10 "good" cells, we don't need to keep searching. |
232 if (borderedCellCount >= 10 || backgroundDifferenceCellCount >= 10) | 232 if (borderedCellCount >= 10 || backgroundDifferenceCellCount >= 10) |
233 return true; | 233 return true; |
234 | 234 |
235 // For the first 5 rows, cache the background color so we can check
if this table has zebra-striped rows. | 235 // For the first 5 rows, cache the background color so we can check
if this table has zebra-striped rows. |
236 if (row < 5 && row == alternatingRowColorCount) { | 236 if (row < 5 && row == alternatingRowColorCount) { |
237 RenderObject* renderRow = cell->parent(); | 237 RenderObject* renderRow = cell->parent(); |
238 if (!renderRow || !renderRow->isBoxModelObject() || !toRenderBox
ModelObject(renderRow)->isTableRow()) | 238 if (!renderRow || !renderRow->isBoxModelObject() || !toRenderBox
ModelObject(renderRow)->isTableRow()) |
239 continue; | 239 continue; |
240 RenderStyle* rowRenderStyle = renderRow->style(); | 240 RenderStyle* rowRenderStyle = renderRow->style(); |
241 if (!rowRenderStyle) | 241 if (!rowRenderStyle) |
242 continue; | 242 continue; |
243 Color rowColor = rowRenderStyle->visitedDependentColor(CSSProper
tyBackgroundColor); | 243 StyleColor rowColor = rowRenderStyle->visitedDependentColor(CSSP
ropertyBackgroundColor); |
244 alternatingRowColors[alternatingRowColorCount] = rowColor; | 244 alternatingRowColors[alternatingRowColorCount] = rowColor; |
245 alternatingRowColorCount++; | 245 alternatingRowColorCount++; |
246 } | 246 } |
247 } | 247 } |
248 | 248 |
249 if (!row && headersInFirstRowCount == numCols && numCols > 1) | 249 if (!row && headersInFirstRowCount == numCols && numCols > 1) |
250 return true; | 250 return true; |
251 } | 251 } |
252 | 252 |
253 if (headersInFirstColumnCount == numRows && numRows > 1) | 253 if (headersInFirstColumnCount == numRows && numRows > 1) |
(...skipping 11 matching lines...) Expand all Loading... |
265 || cellsWithLeftBorder >= neededCellCount | 265 || cellsWithLeftBorder >= neededCellCount |
266 || cellsWithRightBorder >= neededCellCount) | 266 || cellsWithRightBorder >= neededCellCount) |
267 return true; | 267 return true; |
268 | 268 |
269 // half had different background colors, it's a data table | 269 // half had different background colors, it's a data table |
270 if (backgroundDifferenceCellCount >= neededCellCount) | 270 if (backgroundDifferenceCellCount >= neededCellCount) |
271 return true; | 271 return true; |
272 | 272 |
273 // Check if there is an alternating row background color indicating a zebra
striped style pattern. | 273 // Check if there is an alternating row background color indicating a zebra
striped style pattern. |
274 if (alternatingRowColorCount > 2) { | 274 if (alternatingRowColorCount > 2) { |
275 Color firstColor = alternatingRowColors[0]; | 275 StyleColor firstColor = alternatingRowColors[0]; |
276 for (int k = 1; k < alternatingRowColorCount; k++) { | 276 for (int k = 1; k < alternatingRowColorCount; k++) { |
277 // If an odd row was the same color as the first row, its not altern
ating. | 277 // If an odd row was the same color as the first row, its not altern
ating. |
278 if (k % 2 == 1 && alternatingRowColors[k] == firstColor) | 278 if (k % 2 == 1 && alternatingRowColors[k] == firstColor) |
279 return false; | 279 return false; |
280 // If an even row is not the same as the first row, its not alternat
ing. | 280 // If an even row is not the same as the first row, its not alternat
ing. |
281 if (!(k % 2) && alternatingRowColors[k] != firstColor) | 281 if (!(k % 2) && alternatingRowColors[k] != firstColor) |
282 return false; | 282 return false; |
283 } | 283 } |
284 return true; | 284 return true; |
285 } | 285 } |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 } | 541 } |
542 | 542 |
543 // try the standard | 543 // try the standard |
544 if (title.isEmpty()) | 544 if (title.isEmpty()) |
545 title = AccessibilityRenderObject::title(); | 545 title = AccessibilityRenderObject::title(); |
546 | 546 |
547 return title; | 547 return title; |
548 } | 548 } |
549 | 549 |
550 } // namespace WebCore | 550 } // namespace WebCore |
OLD | NEW |