Merged after backing out leaking changeset b0d1180627db

This commit is contained in:
Daniel Holbert 2008-06-19 09:28:21 -07:00
commit d6a82d2266
8 changed files with 4 additions and 229 deletions

View File

@ -58,8 +58,8 @@ class nsIAtom;
class nsIPrincipal;
#define NS_IXBLSERVICE_IID \
{ 0x8d3b37f5, 0xde7e, 0x4595, \
{ 0xb8, 0x56, 0xf7, 0x11, 0xe8, 0xe7, 0xb5, 0x59 } }
{ 0x98b28f4e, 0x698f, 0x4f77, \
{ 0xa8, 0x9e, 0x65, 0xf5, 0xd0, 0xde, 0x6a, 0xbf } }
class nsIXBLService : public nsISupports
{
@ -90,7 +90,6 @@ public:
// Hooks up the global key event handlers to the document root.
NS_IMETHOD AttachGlobalKeyHandler(nsPIDOMEventTarget* aTarget)=0;
NS_IMETHOD DetachGlobalKeyHandler(nsPIDOMEventTarget* aTarget)=0;
};

View File

@ -673,10 +673,6 @@ nsXBLService::AttachGlobalKeyHandler(nsPIDOMEventTarget* aTarget)
if (!piTarget)
return NS_ERROR_FAILURE;
// the listener already exists, so skip this
if (contentNode && contentNode->GetProperty(nsGkAtoms::listener))
return NS_OK;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(contentNode));
@ -698,50 +694,8 @@ nsXBLService::AttachGlobalKeyHandler(nsPIDOMEventTarget* aTarget)
target->AddGroupedEventListener(NS_LITERAL_STRING("keypress"), handler,
PR_FALSE, systemGroup);
// the reference added in NS_NewXBLWindowKeyHandler will be taken by the property
if (contentNode)
return contentNode->SetProperty(nsGkAtoms::listener, handler,
nsPropertyTable::SupportsDtorFunc, PR_TRUE);
return NS_OK;
}
//
// DetachGlobalKeyHandler
//
// Removes a key handler added by DeatchGlobalKeyHandler.
//
NS_IMETHODIMP
nsXBLService::DetachGlobalKeyHandler(nsPIDOMEventTarget* aTarget)
{
nsCOMPtr<nsPIDOMEventTarget> piTarget = aTarget;
nsCOMPtr<nsIContent> contentNode(do_QueryInterface(aTarget));
if (!contentNode) // detaching is only supported for content nodes
return NS_ERROR_FAILURE;
// Only attach if we're really in a document
nsCOMPtr<nsIDocument> doc = contentNode->GetCurrentDoc();
if (doc)
piTarget = do_QueryInterface(doc);
if (!piTarget)
return NS_ERROR_FAILURE;
nsIDOMEventListener* handler =
static_cast<nsIDOMEventListener*>(contentNode->GetProperty(nsGkAtoms::listener));
if (!handler)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMEventGroup> systemGroup;
piTarget->GetSystemEventGroup(getter_AddRefs(systemGroup));
nsCOMPtr<nsIDOM3EventTarget> target = do_QueryInterface(piTarget);
target->RemoveGroupedEventListener(NS_LITERAL_STRING("keydown"), handler,
PR_FALSE, systemGroup);
target->RemoveGroupedEventListener(NS_LITERAL_STRING("keyup"), handler,
PR_FALSE, systemGroup);
target->RemoveGroupedEventListener(NS_LITERAL_STRING("keypress"), handler,
PR_FALSE, systemGroup);
contentNode->DeleteProperty(nsGkAtoms::listener);
// Release. Do this so that only the event receiver holds onto the key handler.
NS_RELEASE(handler);
return NS_OK;
}

View File

@ -88,7 +88,6 @@ class nsXBLService : public nsIXBLService,
// Used by XUL key bindings and for window XBL.
NS_IMETHOD AttachGlobalKeyHandler(nsPIDOMEventTarget* aTarget);
NS_IMETHOD DetachGlobalKeyHandler(nsPIDOMEventTarget* aTarget);
NS_DECL_NSIOBSERVER

View File

@ -356,13 +356,6 @@ nsXBLWindowKeyHandler::WalkHandlers(nsIDOMEvent* aKeyEvent, nsIAtom* aEventType)
}
}
nsCOMPtr<nsIContent> content = do_QueryInterface(el);
// skip keysets that are disabled
if (content && content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
nsGkAtoms::_true, eCaseMatters)) {
return NS_OK;
}
WalkHandlersInternal(aKeyEvent, aEventType, mHandler);
nsINativeKeyBindings *nativeBindings;

View File

@ -1689,14 +1689,6 @@ nsXULDocument::RemoveSubtreeFromDocument(nsIContent* aElement)
// document.
nsresult rv;
if (aElement->NodeInfo()->Equals(nsGkAtoms::keyset, kNameSpaceID_XUL)) {
nsCOMPtr<nsIXBLService> xblService(do_GetService("@mozilla.org/xbl;1"));
if (xblService) {
nsCOMPtr<nsPIDOMEventTarget> piTarget(do_QueryInterface(aElement));
xblService->DetachGlobalKeyHandler(piTarget);
}
}
// 1. Remove any children from the document.
PRUint32 count = aElement->GetChildCount();

View File

@ -64,8 +64,6 @@ _TEST_FILES = bug288254_window.xul \
frame_popup_anchor.xul \
test_preferences.xul \
window_preferences.xul \
test_keys.xul \
window_keys.xul \
$(NULL)
ifeq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))

View File

@ -1,31 +0,0 @@
<?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 title="Keys Test"
onload="setTimeout(runTest, 0);"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script>
SimpleTest.waitForExplicitFinish();
function runTest()
{
window.open("window_keys.xul", "_blank", "chrome,width=200,height=200");
}
</script>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</window>

View File

@ -1,129 +0,0 @@
<?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 title="Key Tests"
onfocus="setTimeout(runTest, 0);"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<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>
<![CDATA[
SimpleTest.waitForExplicitFinish();
var gExpected = null;
var keysToTest = [
["k-v", "V", { } ],
["", "V", { shiftKey: true } ],
["k-v-scy", "V", { ctrlKey: true } ],
["", "V", { altKey: true } ],
["", "V", { metaKey: true } ],
["k-v-scy", "V", { shiftKey: true, ctrlKey: true } ],
["", "V", { shiftKey: true, ctrlKey: true, altKey: true } ],
["k-e-y", "E", { } ],
["", "E", { shiftKey: true } ],
["", "E", { ctrlKey: true } ],
["", "E", { altKey: true } ],
["", "E", { metaKey: true } ],
["k-d-a", "D", { altKey: true } ],
["k-8-m", "8", { metaKey: true } ],
["k-c-scaym", "C", { metaKey: true } ],
["k-c-scaym", "C", { shiftKey: true, ctrlKey: true, altKey: true, metaKey: true } ],
["", "V", { shiftKey: true, ctrlKey: true, altKey: true } ],
["k-h-l", "H", { accelKey: true } ],
// ["k-j-s", "J", { accessKey: true } ],
["", "T", { } ],
["scommand", "Y", { } ],
["", "U", { } ],
];
function runTest()
{
iterateKeys(true, "normal");
var keyset = document.getElementById("keyset");
keyset.setAttribute("disabled", "true");
iterateKeys(false, "disabled");
var keyset = document.getElementById("keyset");
keyset.removeAttribute("disabled");
iterateKeys(true, "reenabled");
keyset.parentNode.removeChild(keyset);
iterateKeys(false, "removed");
document.documentElement.appendChild(keyset);
iterateKeys(true, "appended");
window.close();
window.opener.wrappedJSObject.SimpleTest.finish();
}
function iterateKeys(enabled, testid)
{
for (var k = 0; k < keysToTest.length; k++) {
gExpected = keysToTest[k];
var expectedKey = gExpected[0];
if (!gExpected[2].accessKey || navigator.platform.indexOf("Mac") == -1) {
synthesizeKey(gExpected[1], gExpected[2]);
ok((enabled && expectedKey) || expectedKey == "k-d-a" ?
!gExpected : gExpected, testid + " key step " + (k + 1));
}
}
}
function checkKey(event)
{
// the first element of the gExpected array holds the id of the <key> element
// that was expected. If this is empty, a handler wasn't expected to be called
if (gExpected[0])
is(event.originalTarget.id, gExpected[0], "key " + gExpected[1]);
else
is("key " + event.originalTarget.id + " was activated", "", "key " + gExpected[1]);
gExpected = null;
}
function is(l, r, n) { window.opener.wrappedJSObject.SimpleTest.is(l,r,n); }
function ok(v, n) { window.opener.wrappedJSObject.SimpleTest.ok(v,n); }
]]>
</script>
<command id="scommand" oncommand="checkKey(event)"/>
<command id="scommand-disabled" disabled="true"/>
<keyset id="keyset">
<key id="k-v" key="v" oncommand="checkKey(event)"/>
<key id="k-v-scy" key="v" modifiers="shift any control" oncommand="checkKey(event)"/>
<key id="k-e-y" key="e" modifiers="any" oncommand="checkKey(event)"/>
<key id="k-8-m" key="8" modifiers="meta" oncommand="checkKey(event)"/>
<key id="k-c-scaym" key="c" modifiers="shift control alt any meta" oncommand="checkKey(event)"/>
<key id="k-h-l" key="h" modifiers="accel" oncommand="checkKey(event)"/>
<key id="k-j-s" key="j" modifiers="access" oncommand="checkKey(event)"/>
<key id="k-t-y" disabled="true" key="t" oncommand="checkKey(event)"/>
<key id="k-y" key="y" command="scommand"/>
<key id="k-u" key="u" command="scommand-disabled"/>
</keyset>
<keyset id="keyset2">
<key id="k-d-a" key="d" modifiers="alt" oncommand="checkKey(event)"/>
</keyset>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</window>