private void maybeCloseAllPopups(Window focused, Window sourceWindow) {
    if (focused == null) {
      focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
      if (focused == null) {
        // Check if any browser is in focus (java focus can be in the process of transfer).
        JBCefBrowserBase browser = JBCefBrowserBase.getFocusedBrowser();
        if (browser != null && browser.getComponent() != null) {
          focused = SwingUtilities.getWindowAncestor(browser.getComponent());
        }
      }
    }

    Component ultimateParentForFocusedComponent = UIUtil.findUltimateParent(focused);
    Component ultimateParentForEventWindow = UIUtil.findUltimateParent(sourceWindow);

    boolean shouldCloseAllPopup = false;
    if (ultimateParentForEventWindow == null || ultimateParentForFocusedComponent == null) {
      shouldCloseAllPopup = true;
    }

    if (!shouldCloseAllPopup && ultimateParentForEventWindow instanceof IdeFrame ultimateParentWindowForEvent) {
      if (ultimateParentWindowForEvent.isInFullScreen()
          && !ultimateParentForFocusedComponent.equals(ultimateParentForEventWindow)) {
        shouldCloseAllPopup = true;
      }
    }

    if (shouldCloseAllPopup) {
      closeAllPopups();
    }
  }
private void maybeCloseAllPopups(Window focused, Window sourceWindow)