Bug 670317, add a focus manager flag to restrict tab navigation to the same frame, r=smaug

This commit is contained in:
Neil Deakin 2012-02-13 14:24:28 -05:00
Родитель 461d95548f
Коммит 6321188cf8
6 изменённых файлов: 58 добавлений и 5 удалений

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

@ -188,7 +188,8 @@ nsHTMLLegendElement::Focus()
return NS_OK;
nsCOMPtr<nsIDOMElement> result;
return fm->MoveFocus(nsnull, this, nsIFocusManager::MOVEFOCUS_FORWARD, 0,
return fm->MoveFocus(nsnull, this, nsIFocusManager::MOVEFOCUS_FORWARD,
nsIFocusManager::FLAG_NOPARENTFRAME,
getter_AddRefs(result));
}

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

@ -527,8 +527,9 @@ nsFocusManager::MoveFocus(nsIDOMWindow* aWindow, nsIDOMElement* aStartElement,
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
bool noParentTraversal = aFlags & FLAG_NOPARENTFRAME;
nsCOMPtr<nsIContent> newFocus;
nsresult rv = DetermineElementToMoveFocus(window, startContent, aType,
nsresult rv = DetermineElementToMoveFocus(window, startContent, aType, noParentTraversal,
getter_AddRefs(newFocus));
NS_ENSURE_SUCCESS(rv, rv);
@ -2332,7 +2333,7 @@ nsFocusManager::GetSelectionLocation(nsIDocument* aDocument,
nsresult
nsFocusManager::DetermineElementToMoveFocus(nsPIDOMWindow* aWindow,
nsIContent* aStartContent,
PRInt32 aType,
PRInt32 aType, bool aNoParentTraversal,
nsIContent** aNextContent)
{
*aNextContent = nsnull;
@ -2562,6 +2563,12 @@ nsFocusManager::DetermineElementToMoveFocus(nsPIDOMWindow* aWindow,
skipOriginalContentCheck = false;
ignoreTabIndex = false;
if (aNoParentTraversal) {
startContent = rootContent;
tabIndex = forward ? 1 : 0;
continue;
}
// reached the beginning or end of the document. Traverse up to the parent
// document and try again.
nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(docShell);

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

@ -347,11 +347,13 @@ protected:
* the element to start navigation from. For tab key navigation,
* this should be the currently focused element.
*
* aType is the type passed to MoveFocus.
* aType is the type passed to MoveFocus. If aNoParentTraversal is set,
* navigation is not done to parent documents and iteration returns to the
* beginning (or end) of the starting document.
*/
nsresult DetermineElementToMoveFocus(nsPIDOMWindow* aWindow,
nsIContent* aStart,
PRInt32 aType,
PRInt32 aType, bool aNoParentTraversal,
nsIContent** aNextContent);
/**

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

@ -190,6 +190,14 @@ interface nsIFocusManager : nsISupports
*/
const unsigned long FLAG_NOSWITCHFRAME = 4;
/**
* This flag is only used when passed to moveFocus. If set, focus is never
* moved to the parent frame of the starting element's document, instead
* iterating around to the beginning of that document again. Child frames
* are navigated as normal.
*/
const unsigned long FLAG_NOPARENTFRAME = 8;
/**
* Focus is changing due to a mouse operation, for instance the mouse was
* clicked on an element.

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

@ -80,6 +80,7 @@ _TEST_FILES = \
test_browserFrame5.html \
test_browserFrame6.html \
test_for_of.html \
test_focus_legend_noparent.html \
$(NULL)
_CHROME_FILES = \

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

@ -0,0 +1,34 @@
<html>
<head>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
<script type="text/javascript">
SimpleTest.waitForExplicitFinish();
function runTest()
{
window.focus();
var g = document.createElementNS("http://www.w3.org/1999/xhtml", "legend");
document.body.appendChild(g);
setTimeout(g.focus.bind(g), 0);
setTimeout(done, 10);
}
function done()
{
ok(document.hasFocus(), "document is still focused");
is(document.activeElement, document.body, "document has no focused element")
SimpleTest.finish();
}
SimpleTest.waitForFocus(runTest);
</script>
</head>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<body onblur="dump('blurred window!\n')"></body>
</html>