Back out bug 818371 because what we used to do actually matches the spec.

This commit is contained in:
Boris Zbarsky 2012-12-16 00:16:47 -05:00
parent 901e71f467
commit e1514144fb
6 changed files with 29 additions and 76 deletions

View File

@ -79,8 +79,8 @@ class Element;
} // namespace mozilla
#define NS_IDOCUMENT_IID \
{ 0xcb362f1b, 0x8a05, 0x4d4f, \
{ 0x90, 0x63, 0xf2, 0x5f, 0x8b, 0x8c, 0xb2, 0xe1 } }
{ 0x1517f31a, 0x0ef9, 0x4629, \
{ 0xb4, 0x7f, 0x56, 0x31, 0x0d, 0x80, 0x61, 0xaf } }
// Flag for AddStyleSheet().
#define NS_STYLESHEET_FROM_CATALOG (1 << 0)
@ -1685,9 +1685,7 @@ public:
#undef DEPRECATED_OPERATION
void WarnOnceAbout(DeprecatedOperations aOperation, bool asError = false);
// This method may fire a DOM event; if it does so it will happen
// synchronously if aFireEventSync is true, asynchronously otherwise.
virtual void UpdateVisibilityState(bool aFireEventSync) = 0;
virtual void PostVisibilityUpdateEvent() = 0;
bool IsSyntheticDocument() { return mIsSyntheticDocument; }

View File

@ -7065,7 +7065,7 @@ nsDocument::OnPageShow(bool aPersisted,
SetImagesNeedAnimating(true);
}
UpdateVisibilityState(true);
UpdateVisibilityState();
nsCOMPtr<nsIDOMEventTarget> target = aDispatchStartTarget;
if (!target) {
@ -7127,7 +7127,7 @@ nsDocument::OnPageHide(bool aPersisted,
mVisible = false;
UpdateVisibilityState(true);
UpdateVisibilityState();
EnumerateExternalResources(NotifyPageHide, &aPersisted);
EnumerateFreezableElements(NotifyActivityChanged, nullptr);
@ -9485,37 +9485,25 @@ nsDocument::GetMozPointerLockElement(nsIDOMElement** aPointerLockedElement)
#undef TOUCH_EVENT
#undef EVENT
/* virtual */ void
nsDocument::UpdateVisibilityState(bool aFireEventSync)
void
nsDocument::UpdateVisibilityState()
{
VisibilityState oldState = mVisibilityState;
mVisibilityState = GetVisibilityState();
if (oldState != mVisibilityState) {
if (aFireEventSync) {
FireVisibilityChangeEvent();
} else {
nsCOMPtr<nsIRunnable> event =
NS_NewRunnableMethod(this, &nsDocument::FireVisibilityChangeEvent);
NS_DispatchToMainThread(event);
}
nsContentUtils::DispatchTrustedEvent(this, static_cast<nsIDocument*>(this),
NS_LITERAL_STRING("visibilitychange"),
/* bubbles = */ true,
/* cancelable = */ false);
nsContentUtils::DispatchTrustedEvent(this, static_cast<nsIDocument*>(this),
NS_LITERAL_STRING("mozvisibilitychange"),
/* bubbles = */ true,
/* cancelable = */ false);
EnumerateFreezableElements(NotifyActivityChanged, nullptr);
}
}
void
nsDocument::FireVisibilityChangeEvent()
{
nsContentUtils::DispatchTrustedEvent(this, static_cast<nsIDocument*>(this),
NS_LITERAL_STRING("visibilitychange"),
/* bubbles = */ true,
/* cancelable = */ false);
nsContentUtils::DispatchTrustedEvent(this, static_cast<nsIDocument*>(this),
NS_LITERAL_STRING("mozvisibilitychange"),
/* bubbles = */ true,
/* cancelable = */ false);
}
nsDocument::VisibilityState
nsDocument::GetVisibilityState() const
{
@ -9534,6 +9522,14 @@ nsDocument::GetVisibilityState() const
return eVisible;
}
/* virtual */ void
nsDocument::PostVisibilityUpdateEvent()
{
nsCOMPtr<nsIRunnable> event =
NS_NewRunnableMethod(this, &nsDocument::UpdateVisibilityState);
NS_DispatchToMainThread(event);
}
NS_IMETHODIMP
nsDocument::GetMozHidden(bool* aHidden)
{

View File

@ -995,8 +995,11 @@ public:
bool SetPointerLock(Element* aElement, int aCursorStyle);
static void UnlockPointer();
virtual void UpdateVisibilityState(bool aFireEventSync);
void FireVisibilityChangeEvent();
// This method may fire a DOM event; if it does so it will happen
// synchronously.
void UpdateVisibilityState();
// Posts an event to call UpdateVisibilityState
virtual void PostVisibilityUpdateEvent();
virtual void DocSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const;
// DocSizeOfIncludingThis is inherited from nsIDocument.

View File

@ -5219,7 +5219,7 @@ nsDocShell::SetIsActive(bool aIsActive)
win->SetIsBackground(!aIsActive);
nsCOMPtr<nsIDocument> doc = do_QueryInterface(win->GetExtantDocument());
if (doc) {
doc->UpdateVisibilityState(false);
doc->PostVisibilityUpdateEvent();
}
}

View File

@ -96,7 +96,6 @@ MOCHITEST_CHROME_FILES = \
test_bug789773.xul \
test_bug754029.xul \
bug754029_window.xul \
test_bug818371.xul \
docshell_helpers.js \
generic.html \
$(NULL)

View File

@ -1,43 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=818371
-->
<window title="Mozilla Bug 818371"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=818371"
target="_blank">Mozilla Bug 818371</a>
</body>
<browser id="b" src="data:text/html,&lt;iframe&gt;&lt;/iframe&gt;"></browser>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 818371 **/
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
function listener(e) {
ok(e.target.hidden, "Document should now be hidden");
ok(e.target.defaultView.frames[0].document.hidden,
"Subdocument should now be hidden");
e.target.removeEventListener("visibilitychange", listener);
SimpleTest.finish();
}
var doc = frames[0].document;
ok(!doc.hidden, "Document should be visible");
ok(!frames[0].frames[0].document.hidden,
"Subdocument should now be hidden");
doc.addEventListener("visibilitychange", listener);
$("b").docShell.isActive = false;
});
]]>
</script>
</window>