Bug 1721306, hide the tooltip when deactivating a BrowserParent, r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D121756
This commit is contained in:
Olli Pettay 2021-08-06 15:13:36 +00:00
Родитель b1a7acb403
Коммит ece46d2b64
5 изменённых файлов: 60 добавлений и 4 удалений

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

@ -1376,8 +1376,12 @@ void SessionHistoryEntry::SetFrameLoader(nsFrameLoader* aFrameLoader) {
MOZ_RELEASE_ASSERT(!aFrameLoader || mozilla::BFCacheInParent());
SharedInfo()->SetFrameLoader(aFrameLoader);
if (aFrameLoader) {
if (BrowserParent* bp = aFrameLoader->GetBrowserParent()) {
bp->Deactivated();
if (BrowsingContext* bc = aFrameLoader->GetMaybePendingBrowsingContext()) {
bc->PreOrderWalk([&](BrowsingContext* aContext) {
if (BrowserParent* bp = aContext->Canonical()->GetBrowserParent()) {
bp->Deactivated();
}
});
}
// When a new frameloader is stored, try to evict some older

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

@ -235,7 +235,8 @@ BrowserParent::BrowserParent(ContentParent* aManager, const TabId& aTabId,
mHasPresented(false),
mIsReadyToHandleInputEvents(false),
mIsMouseEnterIntoWidgetEventSuppressed(false),
mLockedNativePointer(false) {
mLockedNativePointer(false),
mShowingTooltip(false) {
MOZ_ASSERT(aManager);
// When the input event queue is disabled, we don't need to handle the case
// that some input events are dispatched before PBrowserConstructor.
@ -597,6 +598,10 @@ void BrowserParent::RemoveWindowListeners() {
}
void BrowserParent::Deactivated() {
if (mShowingTooltip) {
// Reuse the normal tooltip hiding method.
mozilla::Unused << RecvHideTooltip();
}
UnlockNativePointer();
UnsetTopLevelWebFocus(this);
UnsetLastMouseRemoteTarget(this);
@ -2296,11 +2301,16 @@ mozilla::ipc::IPCResult BrowserParent::RecvShowTooltip(
nsCOMPtr<Element> el = do_QueryInterface(flo);
if (!el) return IPC_OK();
xulBrowserWindow->ShowTooltip(aX, aY, aTooltip, aDirection, el);
if (NS_SUCCEEDED(
xulBrowserWindow->ShowTooltip(aX, aY, aTooltip, aDirection, el))) {
mShowingTooltip = true;
}
return IPC_OK();
}
mozilla::ipc::IPCResult BrowserParent::RecvHideTooltip() {
mShowingTooltip = false;
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow = GetXULBrowserWindow();
if (!xulBrowserWindow) {
return IPC_OK();

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

@ -973,6 +973,9 @@ class BrowserParent final : public PBrowserParent,
// True after RecvLockNativePointer has been called and until
// UnlockNativePointer has been called.
bool mLockedNativePointer : 1;
// True between ShowTooltip and HideTooltip messages.
bool mShowingTooltip : 1;
};
struct MOZ_STACK_CLASS BrowserParent::AutoUseNewTab final {

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

@ -23,6 +23,7 @@ skip-if =
verify
apple_silicon # crash
[browser_domainPolicy.js]
[browser_hide_tooltip.js]
[browser_memory_distribution_telemetry.js]
skip-if = true
!e10s # This is an e10s only probe, but the test is currently broken. See Bug 1449991

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

@ -0,0 +1,38 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_hiding_tooltip() {
let page1 = "data:text/html,<html title='title'><body>page 1<body></html>";
let page2 = "data:text/html,<html><body>page 2</body></html>";
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
opening: page1,
});
let popup = new Promise(function(resolve) {
window.addEventListener("popupshown", resolve, { once: true });
});
// Fire a mousemove to trigger the tooltip.
EventUtils.synthesizeMouseAtCenter(gBrowser.selectedBrowser, {
type: "mousemove",
});
await popup;
let hiding = new Promise(function(resolve) {
window.addEventListener("popuphiding", resolve, { once: true });
});
let loaded = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser,
false,
page2
);
BrowserTestUtils.loadURI(gBrowser, page2);
await loaded;
await hiding;
ok(true, "Should have hidden the tooltip");
BrowserTestUtils.removeTab(tab);
});