Commit 59fdd4c4 authored by smichaud@pobox.com's avatar smichaud@pobox.com
Browse files

App focus wierdness with sheets. b=431429 r=josh sr=roc a=dsicore

parent b1086f79
Loading
Loading
Loading
Loading
+28 −33
Original line number Diff line number Diff line
@@ -489,18 +489,14 @@ NS_IMETHODIMP nsCocoaWindow::SetModal(PRBool aState)
  nsCocoaWindow *aParent = static_cast<nsCocoaWindow*>(mParent);
  if (aState) {
    ++gXULModalLevel;
    // When a window gets "set modal", make the window(s) that it appears over
    // behave as they should.  We can't rely entirely on native methods to do
    // this, for the following reasons:
    // 1) The OS runs modal non-sheet windows in an event loop (using
    //    [NSApplication runModalForWindow:] or similar methods) that's
    //    incompatible with the modal event loop in nsXULWindow::ShowModal().
    // 2) Even sheets (whose native modal event loop _is_ compatible) behave
    //    better if we also do the following.  (For example, sheets don't
    //    natively "modalize" popup windows that have popped up from the
    //    window the sheet appears above.)
    // Apple's sheets are (natively) window-modal, and we've preserved that.
    // But (for complex reasons) non-sheet modal windows need to be app-modal.
    // When a non-sheet window gets "set modal", make the window(s) that it
    // appears over behave as they should.  We can't rely on native methods to
    // do this, for the following reason:  The OS runs modal non-sheet windows
    // in an event loop (using [NSApplication runModalForWindow:] or similar
    // methods) that's incompatible with the modal event loop in nsXULWindow::
    // ShowModal() (each of these event loops is "exclusive", and can't run at
    // the same time as other (similar) event loops).
    if (mWindowType != eWindowType_sheet) {
      while (aParent) {
        if (aParent->mNumModalDescendents++ == 0) {
          NSWindow *aWindow = aParent->GetCocoaWindow();
@@ -512,7 +508,6 @@ NS_IMETHODIMP nsCocoaWindow::SetModal(PRBool aState)
        }
        aParent = static_cast<nsCocoaWindow*>(aParent->mParent);
      }
    if (mWindowType != eWindowType_sheet) {
      [mWindow setLevel:NSModalPanelWindowLevel];
      nsCocoaWindowList *windowList = new nsCocoaWindowList;
      if (windowList) {
@@ -525,6 +520,7 @@ NS_IMETHODIMP nsCocoaWindow::SetModal(PRBool aState)
  else {
    --gXULModalLevel;
    NS_ASSERTION(gXULModalLevel >= 0, "Mismatched call to nsCocoaWindow::SetModal(PR_FALSE)!");
    if (mWindowType != eWindowType_sheet) {
      while (aParent) {
        if (--aParent->mNumModalDescendents == 0) {
          NSWindow *aWindow = aParent->GetCocoaWindow();
@@ -537,7 +533,6 @@ NS_IMETHODIMP nsCocoaWindow::SetModal(PRBool aState)
        NS_ASSERTION(aParent->mNumModalDescendents >= 0, "Widget hierarchy changed while modal!");
        aParent = static_cast<nsCocoaWindow*>(aParent->mParent);
      }
    if (mWindowType != eWindowType_sheet) {
      if (gAppModalWindowList) {
        NS_ASSERTION(gAppModalWindowList->window == this, "Widget hierarchy changed while modal!");
        nsCocoaWindowList *saved = gAppModalWindowList;