Skip to content

Commit

Permalink
Bug 1811487 - Clean-up popup hide / rollup APIs. r=cmartin
Browse files Browse the repository at this point in the history
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
  • Loading branch information
emilio committed Jan 23, 2023
1 parent 0807bf1 commit e8d9ad8
Show file tree
Hide file tree
Showing 19 changed files with 221 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,12 @@ add_task(async function testTabOpenMenulist() {
await shown;
ok(gMainMenulist.open, "menulist open");
let menuHidden = BrowserTestUtils.waitForEvent(popup, "popuphidden");
let panelHidden = BrowserTestUtils.waitForEvent(gPanel, "popuphidden");
EventUtils.synthesizeKey("KEY_Tab");
await menuHidden;
ok(!gMainMenulist.open, "menulist closed after Tab");
// Tab in an open menulist closes the menulist, but also dismisses the panel
// above it (bug 1566673). So, we just wait for the panel to hide rather than
// using hidePopup().
await panelHidden;

is(gPanel.state, "open", "Panel should be open");
await hidePopup();
});

if (AppConstants.platform == "macosx") {
Expand Down
12 changes: 8 additions & 4 deletions dom/xul/XULButtonElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ void XULButtonElement::HandleEnterKeyPress(WidgetEvent& aEvent) {
#ifdef XP_WIN
if (XULPopupElement* popup = GetContainingPopupElement()) {
if (nsXULPopupManager* pm = nsXULPopupManager::GetInstance()) {
pm->HidePopup(popup, /* aHideChain = */ true,
/* aDeselectMenu = */ true, /* aAsynchronous = */ true,
/* aIsCancel = */ false);
pm->HidePopup(
popup, {HidePopupOption::HideChain, HidePopupOption::DeselectMenu,
HidePopupOption::Async});
}
}
#endif
Expand Down Expand Up @@ -211,7 +211,11 @@ void XULButtonElement::CloseMenuPopup(bool aDeselectMenu) {
return;
}
if (auto* popup = GetMenuPopupContent()) {
pm->HidePopup(popup, false, aDeselectMenu, true, false);
HidePopupOptions options{HidePopupOption::Async};
if (aDeselectMenu) {
options += HidePopupOption::DeselectMenu;
}
pm->HidePopup(popup, options);
}
}

Expand Down
9 changes: 7 additions & 2 deletions dom/xul/XULPopupElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@ void XULPopupElement::OpenPopupAtScreenRect(const nsAString& aPosition,

void XULPopupElement::HidePopup(bool aCancel) {
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
if (pm) {
pm->HidePopup(this, false, true, false, aCancel);
if (!pm) {
return;
}
HidePopupOptions options{HidePopupOption::DeselectMenu};
if (aCancel) {
options += HidePopupOption::IsRollup;
}
pm->HidePopup(this, options);
}

static Modifiers ConvertModifiers(const ActivateMenuItemOptions& aModifiers) {
Expand Down
4 changes: 3 additions & 1 deletion dom/xul/nsXULPopupListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ void nsXULPopupListener::ClosePopup() {
// popup is hidden. Use asynchronous hiding just to be safe so we don't
// fire events during destruction.
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
if (pm) pm->HidePopup(mPopupContent, false, true, true, false);
if (pm)
pm->HidePopup(mPopupContent,
{HidePopupOption::DeselectMenu, HidePopupOption::Async});
mPopupContent = nullptr; // release the popup
}
} // ClosePopup
Expand Down
2 changes: 1 addition & 1 deletion layout/xul/nsMenuBarListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ nsresult nsMenuBarListener::KeyUp(Event* aKeyEvent) {
// handle key events when menubar is active and IME should be
// disabled.
if (nsXULPopupManager* pm = nsXULPopupManager::GetInstance()) {
pm->Rollup(0, false, nullptr, nullptr);
pm->Rollup({});
}
// If menubar active state is changed or the menubar is destroyed
// during closing the popups, we should do nothing anymore.
Expand Down
4 changes: 3 additions & 1 deletion layout/xul/nsMenuPopupFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#include <algorithm>

#include "X11UndefineNone.h"
#include "nsXULPopupManager.h"

using namespace mozilla;
using mozilla::dom::Document;
Expand Down Expand Up @@ -2463,7 +2464,8 @@ void nsMenuPopupFrame::CheckForAnchorChange(nsRect& aRect) {
if (pm) {
// As the caller will be iterating over the open popups, hide
// asyncronously.
pm->HidePopup(mContent, false, true, true, false);
pm->HidePopup(mContent,
{HidePopupOption::DeselectMenu, HidePopupOption::Async});
}

return;
Expand Down
Loading

0 comments on commit e8d9ad8

Please sign in to comment.