Bug 1037990 - AccessLabelKey is now accessible event if the element is detached. r=bzbarsky

This commit is contained in:
Akshendra Pratap Singh 2014-10-15 07:42:00 +02:00
Родитель f5092e255e
Коммит cd19a8d6b0
5 изменённых файлов: 77 добавлений и 15 удалений

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

@ -291,16 +291,11 @@ static const nsAttrValue::EnumTable kDirTable[] = {
void
nsGenericHTMLElement::GetAccessKeyLabel(nsString& aLabel)
{
//XXXsmaug We shouldn't need PresContext for this.
nsPresContext *presContext = GetPresContext(eForComposedDoc);
if (presContext) {
nsAutoString suffix;
GetAccessKey(suffix);
if (!suffix.IsEmpty() &&
presContext->EventStateManager()->GetAccessKeyLabelPrefix(aLabel)) {
aLabel.Append(suffix);
}
nsAutoString suffix;
GetAccessKey(suffix);
if (!suffix.IsEmpty()) {
EventStateManager::GetAccessKeyLabelPrefix(this, aLabel);
aLabel.Append(suffix);
}
}

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

@ -944,16 +944,21 @@ EventStateManager::ExecuteAccessKey(nsTArray<uint32_t>& aAccessCharCodes,
return false;
}
bool
EventStateManager::GetAccessKeyLabelPrefix(nsAString& aPrefix)
// static
void
EventStateManager::GetAccessKeyLabelPrefix(Element* aElement, nsAString& aPrefix)
{
aPrefix.Truncate();
nsAutoString separator, modifierText;
nsContentUtils::GetModifierSeparatorText(separator);
nsCOMPtr<nsISupports> container = mPresContext->GetContainerWeak();
nsCOMPtr<nsISupports> container = aElement->OwnerDoc()->GetDocShell();
int32_t modifierMask = GetAccessModifierMaskFor(container);
if (modifierMask == -1) {
return;
}
if (modifierMask & NS_MODIFIER_CONTROL) {
nsContentUtils::GetControlText(modifierText);
aPrefix.Append(modifierText + separator);
@ -974,7 +979,6 @@ EventStateManager::GetAccessKeyLabelPrefix(nsAString& aPrefix)
nsContentUtils::GetShiftText(modifierText);
aPrefix.Append(modifierText + separator);
}
return !aPrefix.IsEmpty();
}
void

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

@ -40,6 +40,7 @@ class WheelTransaction;
namespace dom {
class DataTransfer;
class Element;
class TabParent;
} // namespace dom
@ -169,7 +170,7 @@ public:
*/
uint32_t GetRegisteredAccessKey(nsIContent* aContent);
bool GetAccessKeyLabelPrefix(nsAString& aPrefix);
static void GetAccessKeyLabelPrefix(dom::Element* aElement, nsAString& aPrefix);
nsresult SetCursor(int32_t aCursor, imgIContainer* aContainer,
bool aHaveHotspot, float aHotspotX, float aHotspotY,

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

@ -22,6 +22,7 @@ skip-if = buildapp == 'b2g'
skip-if = buildapp == 'b2g'
[test_bug288392.html]
[test_bug299673-1.html]
[test_bug1037990.html]
[test_bug299673-2.html]
[test_bug322588.html]
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') || e10s #Bug 931116, b2g desktop specific, initial triage

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

@ -0,0 +1,61 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1037990
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1037990</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=1037990">Mozilla Bug 1037990</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<script type="application/javascript">
/** Test for Bug 1037990 **/
var pre, node, detachedAccess, attachedAcess;
node = document.createElement('a');
node.href = 'http://example.org';
node.accessKey = 'e';
detachedAccess = node.accessKeyLabel;
info('[window.document] detached: ' + detachedAccess);
document.body.appendChild(node);
attachedAcess = node.accessKeyLabel;
info('[window.document] attached: ' + attachedAcess);
is(detachedAccess, attachedAcess, "Both values are same for the window.document");
var parser=new DOMParser();
var xmlDoc=parser.parseFromString("<root></root>","text/xml");
var nn = xmlDoc.createElementNS('http://www.w3.org/1999/xhtml','a');
nn.setAttribute('accesskey','t')
detachedAccess = nn.accessKeyLabel;
info('[xmlDoc] detached: ' + detachedAccess);
var root = xmlDoc.getElementsByTagName('root')[0];
root.appendChild(nn);
attachedAcess = nn.accessKeyLabel;
info('[xmlDoc] attached: ' + attachedAcess);
is(detachedAccess, attachedAcess, "Both values are same for the xmlDoc");
var myDoc = new Document();
var newnode = myDoc.createElementNS('http://www.w3.org/1999/xhtml','a');
newnode.href = 'http://example.org';
newnode.accessKey = 'f';
detachedAccess = newnode.accessKeyLabel;
info('[new document] detached: ' + detachedAccess);
myDoc.appendChild(newnode);
attachedAcess = newnode.accessKeyLabel;
info('[new document] attached: ' + attachedAcess);
is(detachedAccess, attachedAcess, "Both values are same for the new Document()");
</script>
</body>
</html>