Bug 849438 - Searches in ListControlFrames should ignore  . r=bz

This commit is contained in:
Mounir Lamouri 2013-03-22 17:52:52 +00:00
parent 8135a7145c
commit d15e867cca
7 changed files with 89 additions and 20 deletions

View File

@ -334,6 +334,12 @@ public:
*/
static bool IsHTMLWhitespace(PRUnichar aChar);
/*
* Returns whether the character is an HTML whitespace (see IsHTMLWhitespace)
* or a nbsp character (U+00A0).
*/
static bool IsHTMLWhitespaceOrNBSP(PRUnichar aChar);
/**
* Is the HTML local name a block element?
*/

View File

@ -1199,6 +1199,13 @@ nsContentUtils::IsHTMLWhitespace(PRUnichar aChar)
aChar == PRUnichar(0x0020);
}
/* static */
bool
nsContentUtils::IsHTMLWhitespaceOrNBSP(PRUnichar aChar)
{
return IsHTMLWhitespace(aChar) || aChar == PRUnichar(0xA0);
}
/* static */
bool
nsContentUtils::IsHTMLBlock(nsIAtom* aLocalName)
@ -2158,6 +2165,9 @@ nsContentUtils::TrimWhitespace<nsCRT::IsAsciiSpace>(const nsAString&, bool);
template
const nsDependentSubstring
nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespace>(const nsAString&, bool);
template
const nsDependentSubstring
nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespaceOrNBSP>(const nsAString&, bool);
static inline void KeyAppendSep(nsACString& aKey)
{

View File

@ -2465,28 +2465,32 @@ nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent)
startIndex++;
}
uint32_t i;
for (i = 0; i < numOptions; i++) {
for (uint32_t i = 0; i < numOptions; ++i) {
uint32_t index = (i + startIndex) % numOptions;
nsCOMPtr<nsIDOMHTMLOptionElement> optionElement =
GetOption(options, index);
if (optionElement) {
nsAutoString text;
if (NS_OK == optionElement->GetText(text)) {
if (StringBeginsWith(text, incrementalString,
nsCaseInsensitiveStringComparator())) {
bool wasChanged = PerformSelection(index, isShift, isControl);
if (wasChanged) {
// dispatch event, update combobox, etc.
if (!UpdateSelection()) {
return NS_OK;
}
}
break;
}
}
nsCOMPtr<nsIDOMHTMLOptionElement> optionElement = GetOption(options, index);
if (!optionElement) {
continue;
}
} // for
nsAutoString text;
if (NS_FAILED(optionElement->GetText(text)) ||
!StringBeginsWith(nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespaceOrNBSP>(text, false),
incrementalString,
nsCaseInsensitiveStringComparator())) {
continue;
}
if (!PerformSelection(index, isShift, isControl)) {
break;
}
// If UpdateSelection() returns false, that means the frame is no longer
// alive. We should stop doing anything.
if (!UpdateSelection()) {
return NS_OK;
}
break;
}
} break;//case
} // switch

View File

@ -44,6 +44,7 @@ MOCHITEST_FILES = test_bug231389.html \
test_bug644542.html \
test_bug672810.html \
test_bug704049.html \
test_listcontrol_search.html \
$(NULL)
MOCHITEST_CHROME_FILES = \

View File

@ -0,0 +1,46 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=849438
-->
<head>
<meta charset="utf-8">
<title>Test for &lt;select&gt; list control search</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** This test will focus a select element and press a key that matches the
first non-space character of an entry. **/
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
var select = document.getElementsByTagName('select')[0];
select.focus();
synthesizeKey('a', {});
is(select.options[0].selected, false, "the first option isn't selected");
is(select.options[1].selected, true, "the second option is selected");
select.blur();
SimpleTest.finish();
});
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=849438">Mozilla Bug 849438</a>
<p id="display"></p>
<div id="content">
<select>
<option>Please select an entry</option>
<option>&nbsp;a</option>
<option>&nbsp;b</option>
</select>
</div>
<pre id="test">
</pre>
</body>
</html>

View File

@ -268,6 +268,7 @@
"layout/forms/test/test_bug644542.html": "TIMED_OUT",
"layout/forms/test/test_bug672810.html": "",
"layout/forms/test/test_textarea_resize.html": "",
"layout/forms/test/test_listcontrol_search.html": "select elements don't use an in-page popup on Android",
"layout/generic/test/test_bug496275.html": "CRASH_DUMP",
"layout/generic/test/test_bug503813.html": "CRASH_DUMP",
"layout/generic/test/test_bug514732.html": "CRASH_DUMP",

View File

@ -468,6 +468,7 @@
"layout/forms/test/test_bug644542.html" : "",
"layout/forms/test/test_bug672810.html" : "",
"layout/forms/test/test_bug704049.html" : "",
"layout/forms/test/test_listcontrol_search.html" : "select elements don't use an in-page popup in B2G",
"layout/generic/test/test_bug240933.html" : "",
"layout/generic/test/test_bug263683.html" : "",
"layout/generic/test/test_bug290397.html" : "",