mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 457672 - window blur event is not fired when opening a new tab, r+sr=jst
This commit is contained in:
parent
31502d65d8
commit
9fd913e7a2
@ -995,40 +995,41 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext,
|
||||
gLastFocusedPresContextWeak,
|
||||
&blurevent, nsnull, &blurstatus);
|
||||
|
||||
nsCOMPtr<nsIEventStateManager> esm;
|
||||
if (!mCurrentFocus && gLastFocusedContent) {
|
||||
// We also need to blur the previously focused content node here,
|
||||
// if we don't have a focused content node in this document.
|
||||
// (SendFocusBlur isn't called in this case).
|
||||
|
||||
if (gLastFocusedContent) {
|
||||
nsCOMPtr<nsIDocument> doc = gLastFocusedContent->GetCurrentDoc();
|
||||
if (doc) {
|
||||
nsIPresShell *shell = doc->GetPrimaryShell();
|
||||
if (shell) {
|
||||
nsCOMPtr<nsPresContext> oldPresContext = shell->GetPresContext();
|
||||
esm = oldPresContext->EventStateManager();
|
||||
if (esm) {
|
||||
esm->SetFocusedContent(gLastFocusedContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIContent> blurContent = gLastFocusedContent;
|
||||
blurevent.target = nsnull;
|
||||
nsEventDispatcher::Dispatch(gLastFocusedContent,
|
||||
gLastFocusedPresContextWeak,
|
||||
&blurevent, nsnull, &blurstatus);
|
||||
|
||||
// XXX bryner this isn't quite right -- it can result in
|
||||
// firing two blur events on the content.
|
||||
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
if (gLastFocusedContent) // could have changed in Dispatch
|
||||
doc = gLastFocusedContent->GetDocument();
|
||||
if (doc) {
|
||||
nsIPresShell *shell = doc->GetPrimaryShell();
|
||||
if (shell) {
|
||||
nsCOMPtr<nsPresContext> oldPresContext =
|
||||
shell->GetPresContext();
|
||||
|
||||
nsCOMPtr<nsIEventStateManager> esm;
|
||||
esm = oldPresContext->EventStateManager();
|
||||
esm->SetFocusedContent(gLastFocusedContent);
|
||||
nsEventDispatcher::Dispatch(gLastFocusedContent,
|
||||
oldPresContext,
|
||||
&blurevent, nsnull, &blurstatus);
|
||||
esm->SetFocusedContent(nsnull);
|
||||
NS_IF_RELEASE(gLastFocusedContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ourWindow) {
|
||||
// Clear the target so that Dispatch can set it back correctly.
|
||||
blurevent.target = nsnull;
|
||||
nsEventDispatcher::Dispatch(ourWindow, gLastFocusedPresContextWeak,
|
||||
&blurevent, nsnull, &blurstatus);
|
||||
}
|
||||
|
||||
if (esm) {
|
||||
esm->SetFocusedContent(nsnull);
|
||||
}
|
||||
NS_IF_RELEASE(gLastFocusedContent);
|
||||
}
|
||||
|
||||
if (focusController)
|
||||
|
@ -63,6 +63,8 @@ _TEST_FILES = \
|
||||
test_bug443985.html \
|
||||
test_bug447736.html \
|
||||
test_bug456273.html \
|
||||
test_bug457672.html \
|
||||
bug457672.html \
|
||||
test_draggableprop.html \
|
||||
test_dragstart.html \
|
||||
$(NULL)
|
||||
|
12
content/events/test/bug457672.html
Normal file
12
content/events/test/bug457672.html
Normal file
@ -0,0 +1,12 @@
|
||||
<html>
|
||||
<head>
|
||||
<script>
|
||||
function done() {
|
||||
window.focus();
|
||||
window.close();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="done();">
|
||||
</body>
|
||||
</html>
|
52
content/events/test/test_bug457672.html
Normal file
52
content/events/test/test_bug457672.html
Normal file
@ -0,0 +1,52 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=457672
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 457672</title>
|
||||
<script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<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=457672">Mozilla Bug 457672</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 457672 **/
|
||||
|
||||
var windowBlurCount = 0;
|
||||
|
||||
function listener(evt) {
|
||||
if (evt.type == "focus") {
|
||||
is(windowBlurCount, 1,
|
||||
"Window should have got blur event when opening a new tab!")
|
||||
SimpleTest.finish();
|
||||
} else if (evt.type == "blur") {
|
||||
++windowBlurCount;
|
||||
}
|
||||
document.getElementById('log').textContent += evt.target + ":" + evt.type + "\n";
|
||||
}
|
||||
|
||||
function startTest() {
|
||||
window.focus();
|
||||
// Note, focus/blur don't bubble
|
||||
window.addEventListener("focus", listener, false);
|
||||
window.addEventListener("blur", listener, false);
|
||||
window.open("bug457672.html", "", "");
|
||||
}
|
||||
|
||||
addLoadEvent(startTest);
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
<pre id="log">
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user