Bug 288763, problems with context menupopup cause a crash on window close, r=enndeakin, sr=bz

This commit is contained in:
Olli.Pettay%helsinki.fi 2006-08-02 08:24:21 +00:00
parent 492ad73ac7
commit 4d9109ceaa
3 changed files with 50 additions and 1 deletions

View File

@ -81,6 +81,7 @@
#include "nsPIDOMWindow.h"
#include "nsIFrame.h"
#include "nsIMenuFrame.h"
// on win32 and os/2, context menus come up on mouse up. On other platforms,
// they appear on mouse down. Certain bits of code care about this difference.
@ -586,6 +587,21 @@ XULPopupListenerImpl::LaunchPopup(PRInt32 aClientX, PRInt32 aClientY)
if ( !popupContent )
return NS_OK;
// Submenus can't be used as context menus or popups, bug 288763.
// Similar code also in nsXULTooltipListener::GetTooltipFor.
nsCOMPtr<nsIContent> popup = do_QueryInterface(popupContent);
nsIContent* parent = popup->GetParent();
if (parent) {
nsIDocument* doc = parent->GetCurrentDoc();
nsIPresShell* presShell = doc ? doc->GetShellAt(0) : nsnull;
nsIFrame* frame = presShell ? presShell->GetPrimaryFrameFor(parent) : nsnull;
if (frame) {
nsIMenuFrame* menu = nsnull;
CallQueryInterface(frame, &menu);
NS_ENSURE_FALSE(menu, NS_OK);
}
}
// We have some popup content. Obtain our window.
nsPIDOMWindow *domWindow = document->GetWindow();

View File

@ -46,6 +46,7 @@
#include "nsXULAtoms.h"
#include "nsIPresShell.h"
#include "nsIFrame.h"
#include "nsIMenuFrame.h"
#include "nsIPopupBoxObject.h"
#include "nsIServiceManager.h"
#ifdef MOZ_XUL
@ -557,7 +558,7 @@ GetImmediateChild(nsIContent* aContent, nsIAtom *aTag, nsIContent** aResult)
}
nsresult
nsXULTooltipListener::GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip)
nsXULTooltipListener::FindTooltip(nsIContent* aTarget, nsIContent** aTooltip)
{
if (!aTarget)
return NS_ERROR_NULL_POINTER;
@ -631,6 +632,34 @@ nsXULTooltipListener::GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip)
return NS_OK;
}
nsresult
nsXULTooltipListener::GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip)
{
*aTooltip = nsnull;
nsCOMPtr<nsIContent> tooltip;
nsresult rv = FindTooltip(aTarget, getter_AddRefs(tooltip));
if (NS_FAILED(rv) || !tooltip) {
return rv;
}
// Submenus can't be used as tooltips, see bug 288763.
nsIContent* parent = tooltip->GetParent();
if (parent) {
nsIDocument* doc = parent->GetCurrentDoc();
nsIPresShell* presShell = doc ? doc->GetShellAt(0) : nsnull;
nsIFrame* frame = presShell ? presShell->GetPrimaryFrameFor(parent) : nsnull;
if (frame) {
nsIMenuFrame* menu = nsnull;
CallQueryInterface(frame, &menu);
NS_ENSURE_FALSE(menu, NS_ERROR_FAILURE);
}
}
tooltip.swap(*aTooltip);
return rv;
}
nsresult
nsXULTooltipListener::DestroyTooltip()
{

View File

@ -119,6 +119,10 @@ protected:
nsresult LaunchTooltip(nsIContent* aTarget, PRInt32 aX, PRInt32 aY);
nsresult HideTooltip();
nsresult DestroyTooltip();
// This method tries to find a tooltip for aTarget.
nsresult FindTooltip(nsIContent* aTarget, nsIContent** aTooltip);
// This method calls FindTooltip and checks that the tooltip
// can be really used (i.e. tooltip is not a menu).
nsresult GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip);
static int ToolbarTipsPrefChanged(const char *aPref, void *aClosure);