Bug 495390 - If a link has a non-breaking space as screen text, try to fall back to other means like @title, marcoz, davidb

This commit is contained in:
Alexander Surkov 2009-06-13 09:06:02 +08:00
Родитель 1f7a6fb844
Коммит b9a0cd6c6c
3 изменённых файлов: 41 добавлений и 1 удалений

Просмотреть файл

@ -75,7 +75,8 @@ nsTextEquivUtils::GetNameFromSubtree(nsIAccessible *aAccessible,
nsAutoString name;
AppendFromAccessibleChildren(aAccessible, &name);
name.CompressWhitespace();
aName = name;
if (!IsWhitespaceString(name))
aName = name;
}
}
@ -419,6 +420,27 @@ nsTextEquivUtils::AppendString(nsAString *aString,
return PR_TRUE;
}
PRBool
nsTextEquivUtils::IsWhitespaceString(const nsSubstring& aString)
{
nsSubstring::const_char_iterator iterBegin, iterEnd;
aString.BeginReading(iterBegin);
aString.EndReading(iterEnd);
while (iterBegin != iterEnd && IsWhitespace(*iterBegin))
++iterBegin;
return iterBegin == iterEnd;
}
PRBool
nsTextEquivUtils::IsWhitespace(PRUnichar aChar)
{
return aChar == ' ' || aChar == '\n' ||
aChar == '\r' || aChar == '\t' || aChar == 0xa0;
}
////////////////////////////////////////////////////////////////////////////////
// Name rules to role map.

Просмотреть файл

@ -159,6 +159,18 @@ private:
static PRBool AppendString(nsAString *aString,
const nsAString& aTextEquivalent);
/**
* Returns true if the given string is empty or contains whitespace symbols
* only. In contrast to nsWhitespaceTokenizer class it takes into account
* non-breaking space (0xa0).
*/
static PRBool IsWhitespaceString(const nsSubstring& aString);
/**
* Returns true if the given character is whitespace symbol.
*/
static PRBool IsWhitespace(PRUnichar aChar);
/**
* Map array from roles to name rules (constants of ETextEquivRule).
*/

Просмотреть файл

@ -92,6 +92,9 @@
// Gets the name from html:input value, ignore @title attribute on input
testName("from_input_ignoretitle", "Custom country");
// Gets the name from @title, ignore whitespace content
testName("from_label_ignore_ws_subtree", "about");
//////////////////////////////////////////////////////////////////////////
// label element
@ -303,6 +306,9 @@
value="Custom country"
title="Input your country of origin"/ >
<!-- no name from subtree because it holds whitespaces only -->
<a id="from_label_ignore_ws_subtree" href="about:" title="about">&nbsp;&nbsp; </a>
<!-- label element, label contains the button -->
<label>text<button id="btn_label_inside">10</button>text</label>
<br/>