Bug 723833 - IAccessibleText::setCaretOffset on location or search bar causes focus to jump, r=tbsaunde, marcoz

--HG--
rename : accessible/tests/mochitest/test_text_caret.html => accessible/tests/mochitest/textcaret/test_general.html
This commit is contained in:
Alexander Surkov 2012-02-08 13:31:18 +09:00
parent 6996cab07d
commit 613fe0d75a
6 changed files with 170 additions and 51 deletions

View File

@ -1560,12 +1560,17 @@ nsHyperTextAccessible::GetAssociatedEditor(nsIEditor **aEditor)
nsresult
nsHyperTextAccessible::SetSelectionRange(PRInt32 aStartPos, PRInt32 aEndPos)
{
nsresult rv = TakeFocus();
NS_ENSURE_SUCCESS(rv, rv);
bool isFocusable = State() & states::FOCUSABLE;
// If accessible is focusable then focus it before setting the selection to
// neglect control's selection changes on focus if any (for example, inputs
// that do select all on focus).
// some input controls
if (isFocusable)
TakeFocus();
// Set the selection
SetSelectionBounds(0, aStartPos, aEndPos);
NS_ENSURE_SUCCESS(rv, rv);
// If range 0 was successfully set, clear any additional selection
// ranges remaining from previous selection
@ -1585,7 +1590,12 @@ nsHyperTextAccessible::SetSelectionRange(PRInt32 aStartPos, PRInt32 aEndPos)
domSel->RemoveRange(range);
}
// Now that selection is done, move the focus to the selection.
// When selection is done, move the focus to the selection if accessible is
// not focusable. That happens when selection is set within hypertext
// accessible.
if (isFocusable)
return NS_OK;
nsFocusManager* DOMFocusManager = nsFocusManager::GetFocusManager();
if (DOMFocusManager) {
nsCOMPtr<nsIPresShell> shell = GetPresShell();

View File

@ -58,6 +58,7 @@ DIRS = \
states \
table \
text \
textcaret \
textselection \
tree \
treeupdate \
@ -103,7 +104,6 @@ _TEST_FILES =\
test_nsIAccessNode_utils.html \
test_nsOuterDocAccessible.html \
test_role_nsHyperTextAcc.html \
test_text_caret.html \
test_textboxes.html \
test_textboxes.xul \
testTextboxes.js \

View File

@ -1221,6 +1221,33 @@ function synthSelectAll(aNodeOrID, aCheckerOrEventSeq)
}
}
/**
* Set caret offset in text accessible.
*/
function setCaretOffset(aID, aOffset, aFocusTargetID)
{
this.target = getAccessible(aID, [nsIAccessibleText]);
this.offset = aOffset == -1 ? this.target.characterCount: aOffset;
this.focus = aFocusTargetID ? getAccessible(aFocusTargetID) : null;
this.invoke = function setCaretOffset_invoke()
{
this.target.caretOffset = this.offset;
}
this.getID = function setCaretOffset_getID()
{
return "Set caretOffset on " + prettyName(aID) + " at " + this.offset;
}
this.eventSeq = [
new caretMoveChecker(this.offset, this.target)
];
if (this.focus)
this.eventSeq.push(new asyncInvokerChecker(EVENT_FOCUS, this.focus));
}
////////////////////////////////////////////////////////////////////////////////
// Event queue checkers

View File

@ -0,0 +1,54 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2012
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Alexander Surkov <surkov.alexander@gmail.com> (original author)
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = accessible/textcaret
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = \
test_browserui.xul \
test_general.html \
$(NULL)
libs:: $(_TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)

View File

@ -0,0 +1,69 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="Accessibility Caret Offset Test.">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../role.js"></script>
<script type="application/javascript"
src="../states.js"></script>
<script type="application/javascript"
src="../events.js"></script>
<script type="application/javascript"
src="../browser.js"></script>
<script type="application/javascript">
<![CDATA[
////////////////////////////////////////////////////////////////////////////
// Tests
//gA11yEventDumpID = "eventdump"; // debug stuff
//gA11yEventDumpToConsole = true; // debug
var gQueue = null;
function doTests()
{
gQueue = new eventQueue();
gQueue.push(new setCaretOffset(urlbarInput(), -1, urlbarInput()));
gQueue.push(new setCaretOffset(urlbarInput(), 0));
gQueue.onFinish = function()
{
closeBrowserWindow();
}
gQueue.invoke();
}
SimpleTest.waitForExplicitFinish();
openBrowserWindow(doTests, "about:");
]]>
</script>
<vbox flex="1" style="overflow: auto;">
<body xmlns="http://www.w3.org/1999/xhtml">
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=723833"
title="IAccessibleText::setCaretOffset on location or search bar causes focus to jump">
Mozilla Bug 723833
</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
<vbox id="eventdump"></vbox>
</vbox>
</window>

View File

@ -10,52 +10,11 @@
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="common.js"></script>
src="../common.js"></script>
<script type="application/javascript"
src="events.js"></script>
src="../events.js"></script>
<script type="application/javascript">
/**
* Checkers.
*/
function caretMovedChecker(aID, aOffset)
{
this.__proto__ = new invokerChecker(EVENT_TEXT_CARET_MOVED, aID);
this.check = function caretMovedChecker_check(aEvent)
{
is(aEvent.QueryInterface(nsIAccessibleCaretMoveEvent).caretOffset,
aOffset,
"Wrong caret offset for " + prettyName(aEvent.target));
}
}
/**
* Invokers.
*/
function setCaretOffsetInvoker(aID, aOffset, aFocusableContainerID)
{
this.target = getAccessible(aID, [nsIAccessibleText]);
this.focus = aFocusableContainerID ?
getAccessible(aFocusableContainerID) : this.target;
this.invoke = function setCaretOffsetInvoker_invoke()
{
this.target.caretOffset = aOffset;
}
this.getID = function setCaretOffsetInvoker_getID()
{
return "Set caretOffset on " + prettyName(aID) + " at " + aOffset;
}
this.eventSeq = [
new caretMovedChecker(this.target, aOffset),
new asyncInvokerChecker(EVENT_FOCUS, this.focus)
];
}
/**
* Turn on/off the caret browsing mode.
*/
@ -81,9 +40,9 @@
// test caret move events and caret offsets
gQueue = new eventQueue();
gQueue.push(new setCaretOffsetInvoker("textbox", 1));
gQueue.push(new setCaretOffsetInvoker("link", 1));
gQueue.push(new setCaretOffsetInvoker("heading", 1, document));
gQueue.push(new setCaretOffset("textbox", 1, "textbox"));
gQueue.push(new setCaretOffset("link", 1, "link"));
gQueue.push(new setCaretOffset("heading", 1, document));
gQueue.onFinish = function()
{
turnCaretBrowsing(false);