Fix for bug 386996 (Can't tab past disabled inputs or textareas). r/sr=sicking.

This commit is contained in:
peterv@propagandism.org 2007-07-13 07:17:35 -07:00
parent c7d42f48f8
commit a8f0fd523f
4 changed files with 58 additions and 38 deletions

View File

@ -3316,8 +3316,12 @@ nsGenericHTMLElement::IsFocusable(PRInt32 *aTabIndex)
PRBool disabled;
if (IsEditableRoot()) {
// Ignore the disabled attribute in editable contentEditable/designMode
// roots.
disabled = PR_FALSE;
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex)) {
// The default value for tabindex should be 0 for editable
// contentEditable roots.
tabIndex = 0;
}
}
@ -3951,7 +3955,7 @@ nsGenericHTMLElement::IsEditableRoot() const
return this == document->GetRootContent();
}
if (!HasFlag(NODE_IS_EDITABLE)) {
if (GetContentEditableValue() != eTrue) {
return PR_FALSE;
}
@ -3960,30 +3964,6 @@ nsGenericHTMLElement::IsEditableRoot() const
return !parent || !parent->HasFlag(NODE_IS_EDITABLE);
}
nsIContent*
nsGenericHTMLElement::FindEditableRoot()
{
nsIDocument *document = GetCurrentDoc();
if (!document) {
return nsnull;
}
if (document->HasFlag(NODE_IS_EDITABLE)) {
return document->GetRootContent();
}
if (!HasFlag(NODE_IS_EDITABLE)) {
return nsnull;
}
nsIContent *parent, *content = this;
while ((parent = content->GetParent()) && parent->HasFlag(NODE_IS_EDITABLE)) {
content = parent;
}
return content;
}
static void
MakeContentDescendantsEditable(nsIContent *aContent, nsIDocument *aDocument)
{

View File

@ -810,22 +810,17 @@ protected:
private:
/**
* Returns whether this element is an editable root. An editable root is
* defined as an element that is editable and whose parent is either a
* non-editable element or an editable document (so if the whole document is
* editable, then there is only one editable root, namely the
* documentElement).
* Returns whether this element is an editable root. There are two types of
* editable roots:
* 1) the documentElement if the whole document is editable (for example for
* desginMode=on)
* 2) an element that is marked editable with contentEditable=true and that
* doesn't have a parent or whose parent is not editable.
* Note that this doesn't return input and textarea elements that haven't been
* made editable through contentEditable or designMode.
*/
PRBool IsEditableRoot() const;
/**
* Returns the first node amongst this node and its ancestors that is an
* editable root.
*
* @see IsEditableRoot for a definition of an editable root.
*/
nsIContent* FindEditableRoot();
void ChangeEditableState(PRInt32 aChange);
};

View File

@ -78,6 +78,7 @@ _TEST_FILES = test_bug589.html \
test_bug384419.html \
test_bug386496.html \
test_bug386728.html \
test_bug386996.html \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,44 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=386996
-->
<head>
<title>Test for Bug 386996</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=386996">Mozilla Bug 386996</a>
<p id="display"></p>
<div id="content">
<input id="input1"><input disabled><input id="input2">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 386996 **/
var frame = document.getElementById("testIframe");
function testContentEditable() {
var focusedElement;
document.getElementById("input1").onfocus = function() { focusedElement = this };
document.getElementById("input2").onfocus = function() { focusedElement = this };
document.getElementById("input1").focus();
synthesizeKey("VK_TAB", {});
is(focusedElement.id, "input2");
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(testContentEditable);
addLoadEvent(SimpleTest.finish);
</script>
</pre>
</body>
</html>