From 1b5c98d62e32fb3b442ba431e749503cd2d6ad5f Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Fri, 17 Feb 2012 16:21:26 +0900 Subject: [PATCH] Bug 499093 - Fix discrepancy between tr count and row count in nsHTMLTableAccessible::IsProbablyForLayout, r=marcoz --- accessible/src/html/nsHTMLTableAccessible.cpp | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/accessible/src/html/nsHTMLTableAccessible.cpp b/accessible/src/html/nsHTMLTableAccessible.cpp index 88010995909f..b8a62a6a234c 100644 --- a/accessible/src/html/nsHTMLTableAccessible.cpp +++ b/accessible/src/html/nsHTMLTableAccessible.cpp @@ -1494,28 +1494,24 @@ nsHTMLTableAccessible::IsProbablyForLayout(bool *aIsProbablyForLayout) * Rules for non-bordered tables with 2-4 columns and 2+ rows from here on forward */ - // Check for styled background color across the row - // Alternating background color is a common way - nsCOMPtr nodeList; - nsCOMPtr tableElt(do_QueryInterface(mContent)); - tableElt->GetElementsByTagName(NS_LITERAL_STRING("tr"), getter_AddRefs(nodeList)); - NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE); - PRUint32 length; - nodeList->GetLength(&length); - nsAutoString color, lastRowColor; - for (PRUint32 rowCount = 0; rowCount < length; rowCount ++) { - nsCOMPtr rowNode; - nodeList->Item(rowCount, getter_AddRefs(rowNode)); - nsCOMPtr rowContent(do_QueryInterface(rowNode)); - - nsCOMPtr styleDecl = - nsCoreUtils::GetComputedStyleDeclaration(EmptyString(), rowContent); - NS_ENSURE_TRUE(styleDecl, NS_ERROR_FAILURE); - - lastRowColor = color; - styleDecl->GetPropertyValue(NS_LITERAL_STRING("background-color"), color); - if (rowCount > 0 && false == lastRowColor.Equals(color)) { - RETURN_LAYOUT_ANSWER(false, "2 styles of row background color, non-bordered"); + // Check for styled background color across rows (alternating background + // color is a common feature for data tables). + PRUint32 childCount = GetChildCount(); + nsAutoString rowColor, prevRowColor; + for (PRUint32 childIdx = 0; childIdx < childCount; childIdx++) { + nsAccessible* child = GetChildAt(childIdx); + if (child->Role() == roles::ROW) { + nsCOMPtr styleDecl = + nsCoreUtils::GetComputedStyleDeclaration(EmptyString(), + child->GetContent()); + if (styleDecl) { + prevRowColor = rowColor; + styleDecl->GetPropertyValue(NS_LITERAL_STRING("background-color"), + rowColor); + if (childIdx > 0 && !prevRowColor.Equals(rowColor)) { + RETURN_LAYOUT_ANSWER(false, "2 styles of row background color, non-bordered"); + } + } } }