Skip to content

Commit 39ff190

Browse files
committedJan 24, 2023
Bug 1811487 - Clean-up popup hide / rollup APIs. r=cmartin,stransky
I'm about to extend them for bug 1811486, where I want to force in some cases the rolled up popups to hide synchronously. These APIs use a ton of boolean arguments that make them error prone, so refactor them a bit to use strongly typed enums and flags. Differential Revision: https://phabricator.services.mozilla.com/D167381
1 parent fba7fef commit 39ff190

20 files changed

+264
-242
lines changed
 

‎browser/components/customizableui/test/browser_1484275_PanelMultiView_toggle_with_other_popup.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ add_task(async function test_PanelMultiView_toggle_with_other_popup() {
4343
eventTypeToWait: "mouseup",
4444
});
4545

46-
if (AppConstants.platform == "win") {
47-
// On Windows, the operation will close both popups.
46+
// On Windows and macOS, the operation will close both popups.
47+
if (AppConstants.platform == "win" || AppConstants.platform == "macosx") {
4848
await gCUITestUtils.hidePanelMultiView(PanelUI.panel, clickFn);
4949
await new Promise(resolve => executeSoon(resolve));
5050

‎browser/components/customizableui/test/browser_PanelMultiView_keyboard.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,11 @@ add_task(async function testTabOpenMenulist() {
290290
await shown;
291291
ok(gMainMenulist.open, "menulist open");
292292
let menuHidden = BrowserTestUtils.waitForEvent(popup, "popuphidden");
293-
let panelHidden = BrowserTestUtils.waitForEvent(gPanel, "popuphidden");
294293
EventUtils.synthesizeKey("KEY_Tab");
295294
await menuHidden;
296295
ok(!gMainMenulist.open, "menulist closed after Tab");
297-
// Tab in an open menulist closes the menulist, but also dismisses the panel
298-
// above it (bug 1566673). So, we just wait for the panel to hide rather than
299-
// using hidePopup().
300-
await panelHidden;
296+
is(gPanel.state, "open", "Panel should be open");
297+
await hidePopup();
301298
});
302299

303300
if (AppConstants.platform == "macosx") {
@@ -327,14 +324,11 @@ if (AppConstants.platform == "macosx") {
327324
);
328325

329326
let menuHidden = BrowserTestUtils.waitForEvent(popup, "popuphidden");
330-
let panelHidden = BrowserTestUtils.waitForEvent(gPanel, "popuphidden");
331327
EventUtils.synthesizeKey("KEY_Tab");
332328
await menuHidden;
333329
ok(!gMainMenulist.open, "menulist closed after Tab");
334-
// Tab in an open menulist closes the menulist, but also dismisses the panel
335-
// above it (bug 1566673). So, we just wait for the panel to hide rather than
336-
// using hidePopup().
337-
await panelHidden;
330+
is(gPanel.state, "open", "Panel should be open");
331+
await hidePopup();
338332
});
339333
}
340334

‎dom/xul/XULButtonElement.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ void XULButtonElement::HandleEnterKeyPress(WidgetEvent& aEvent) {
9595
#ifdef XP_WIN
9696
if (XULPopupElement* popup = GetContainingPopupElement()) {
9797
if (nsXULPopupManager* pm = nsXULPopupManager::GetInstance()) {
98-
pm->HidePopup(popup, /* aHideChain = */ true,
99-
/* aDeselectMenu = */ true, /* aAsynchronous = */ true,
100-
/* aIsCancel = */ false);
98+
pm->HidePopup(
99+
popup, {HidePopupOption::HideChain, HidePopupOption::DeselectMenu,
100+
HidePopupOption::Async});
101101
}
102102
}
103103
#endif
@@ -211,7 +211,11 @@ void XULButtonElement::CloseMenuPopup(bool aDeselectMenu) {
211211
return;
212212
}
213213
if (auto* popup = GetMenuPopupContent()) {
214-
pm->HidePopup(popup, false, aDeselectMenu, true, false);
214+
HidePopupOptions options{HidePopupOption::Async};
215+
if (aDeselectMenu) {
216+
options += HidePopupOption::DeselectMenu;
217+
}
218+
pm->HidePopup(popup, options);
215219
}
216220
}
217221

‎dom/xul/XULPopupElement.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,14 @@ void XULPopupElement::OpenPopupAtScreenRect(const nsAString& aPosition,
106106

107107
void XULPopupElement::HidePopup(bool aCancel) {
108108
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
109-
if (pm) {
110-
pm->HidePopup(this, false, true, false, aCancel);
109+
if (!pm) {
110+
return;
111+
}
112+
HidePopupOptions options{HidePopupOption::DeselectMenu};
113+
if (aCancel) {
114+
options += HidePopupOption::IsRollup;
111115
}
116+
pm->HidePopup(this, options);
112117
}
113118

114119
static Modifiers ConvertModifiers(const ActivateMenuItemOptions& aModifiers) {

‎dom/xul/nsXULPopupListener.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ void nsXULPopupListener::ClosePopup() {
170170
// popup is hidden. Use asynchronous hiding just to be safe so we don't
171171
// fire events during destruction.
172172
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
173-
if (pm) pm->HidePopup(mPopupContent, false, true, true, false);
173+
if (pm)
174+
pm->HidePopup(mPopupContent,
175+
{HidePopupOption::DeselectMenu, HidePopupOption::Async});
174176
mPopupContent = nullptr; // release the popup
175177
}
176178
} // ClosePopup

‎layout/xul/nsMenuBarListener.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ nsresult nsMenuBarListener::KeyUp(Event* aKeyEvent) {
207207
// handle key events when menubar is active and IME should be
208208
// disabled.
209209
if (nsXULPopupManager* pm = nsXULPopupManager::GetInstance()) {
210-
pm->Rollup(0, false, nullptr, nullptr);
210+
pm->Rollup({});
211211
}
212212
// If menubar active state is changed or the menubar is destroyed
213213
// during closing the popups, we should do nothing anymore.

‎layout/xul/nsMenuPopupFrame.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include <algorithm>
6363

6464
#include "X11UndefineNone.h"
65+
#include "nsXULPopupManager.h"
6566

6667
using namespace mozilla;
6768
using mozilla::dom::Document;
@@ -2460,7 +2461,8 @@ void nsMenuPopupFrame::CheckForAnchorChange(nsRect& aRect) {
24602461
if (pm) {
24612462
// As the caller will be iterating over the open popups, hide
24622463
// asyncronously.
2463-
pm->HidePopup(mContent, false, true, true, false);
2464+
pm->HidePopup(mContent,
2465+
{HidePopupOption::DeselectMenu, HidePopupOption::Async});
24642466
}
24652467

24662468
return;

0 commit comments

Comments
 (0)
Failed to load comments.