Commit 46dd8a0d authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

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
parent 89a7e7fe
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -43,8 +43,8 @@ add_task(async function test_PanelMultiView_toggle_with_other_popup() {
          eventTypeToWait: "mouseup",
        });

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

+4 −10
Original line number Diff line number Diff line
@@ -290,14 +290,11 @@ 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") {
@@ -327,14 +324,11 @@ if (AppConstants.platform == "macosx") {
    );

    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();
  });
}

+8 −4
Original line number Diff line number Diff line
@@ -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
@@ -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);
  }
}

+7 −2
Original line number Diff line number Diff line
@@ -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) {
+3 −1
Original line number Diff line number Diff line
@@ -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
Loading