Bug 365405 - the xbl binding for a menupopup is attached only once the menu is opened, after popupshowing is dispatched. r=josh, sr=jst.

This commit is contained in:
mozilla.mano%sent.com 2007-02-21 23:37:34 +00:00
Родитель f904eec95c
Коммит 7c840e8620
3 изменённых файлов: 37 добавлений и 3 удалений

Просмотреть файл

@ -74,6 +74,8 @@ REQUIRES = xpcom \
appshell \ appshell \
thebes \ thebes \
cairo \ cairo \
js \
xpconnect \
$(NULL) $(NULL)
ifdef MOZ_ENABLE_GLITZ ifdef MOZ_ENABLE_GLITZ

Просмотреть файл

@ -159,6 +159,7 @@ protected:
PRPackedBool mDestroyHandlerCalled; PRPackedBool mDestroyHandlerCalled;
PRPackedBool mNeedsRebuild; PRPackedBool mNeedsRebuild;
PRPackedBool mConstructed; PRPackedBool mConstructed;
PRPackedBool mXBLAttached;
PRPackedBool mVisible; // are we visible to the user? PRPackedBool mVisible; // are we visible to the user?
}; };

Просмотреть файл

@ -69,6 +69,11 @@
#include "nsCRT.h" #include "nsCRT.h"
#include "jsapi.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h"
#include "nsIXPConnect.h"
// externs defined in nsChildView.mm // externs defined in nsChildView.mm
extern nsIRollupListener * gRollupListener; extern nsIRollupListener * gRollupListener;
extern nsIWidget * gRollupWidget; extern nsIWidget * gRollupWidget;
@ -102,7 +107,8 @@ NS_IMPL_ISUPPORTS4(nsMenuX, nsIMenu, nsIMenuListener, nsIChangeObserver, nsISupp
nsMenuX::nsMenuX() nsMenuX::nsMenuX()
: mParent(nsnull), mManager(nsnull), mMacMenuID(0), mMacMenu(nil), : mParent(nsnull), mManager(nsnull), mMacMenuID(0), mMacMenu(nil),
mIsEnabled(PR_TRUE), mDestroyHandlerCalled(PR_FALSE), mIsEnabled(PR_TRUE), mDestroyHandlerCalled(PR_FALSE),
mNeedsRebuild(PR_TRUE), mConstructed(PR_FALSE), mVisible(PR_TRUE) mNeedsRebuild(PR_TRUE), mConstructed(PR_FALSE), mVisible(PR_TRUE),
mXBLAttached(PR_FALSE)
{ {
mMenuDelegate = [[MenuDelegate alloc] initWithGeckoMenu:this]; mMenuDelegate = [[MenuDelegate alloc] initWithGeckoMenu:this];
@ -470,6 +476,31 @@ nsEventStatus nsMenuX::MenuConstruct(
if (!menuPopup) if (!menuPopup)
return nsEventStatus_eIgnore; return nsEventStatus_eIgnore;
// bug 365405: Manually wrap the menupopup node to make sure it's bounded
if (!mXBLAttached) {
nsresult rv;
nsCOMPtr<nsIXPConnect> xpconnect =
do_GetService(nsIXPConnect::GetCID(), &rv);
if (NS_SUCCEEDED(rv)) {
nsIDocument* ownerDoc = menuPopup->GetOwnerDoc();
nsIScriptGlobalObject* sgo;
if (ownerDoc && (sgo = ownerDoc->GetScriptGlobalObject())) {
nsCOMPtr<nsIScriptContext> scriptContext = sgo->GetContext();
JSObject* global = sgo->GetGlobalJSObject();
if (scriptContext && global) {
JSContext* cx = (JSContext*)scriptContext->GetNativeContext();
if (cx) {
nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
xpconnect->WrapNative(cx, global,
menuPopup, NS_GET_IID(nsISupports),
getter_AddRefs(wrapper));
mXBLAttached = PR_TRUE;
}
}
}
}
}
// Iterate over the kids // Iterate over the kids
PRUint32 count = menuPopup->GetChildCount(); PRUint32 count = menuPopup->GetChildCount();
for (PRUint32 i = 0; i < count; i++) { for (PRUint32 i = 0; i < count; i++) {