diff --git a/mozilla/widget/src/cocoa/nsChildView.mm b/mozilla/widget/src/cocoa/nsChildView.mm index f122b2a8772..a2410cd637b 100644 --- a/mozilla/widget/src/cocoa/nsChildView.mm +++ b/mozilla/widget/src/cocoa/nsChildView.mm @@ -1563,9 +1563,18 @@ NS_IMETHODIMP nsChildView::DispatchEvent(nsGUIEvent* event, nsEventStatus& aStat aStatus = nsEventStatus_eIgnore; if (! mDestructorCalled) { - nsIWidget* aWidget = event->widget; - NS_IF_ADDREF(aWidget); - + nsCOMPtr kungFuDeathGrip(event->widget); + nsCOMPtr kungFuDeathGrip2; + + if (mParentWidget) { + nsWindowType type; + mParentWidget->GetWindowType(type); + if (type == eWindowType_popup) { + event->widget = mParentWidget; + kungFuDeathGrip2 = mParentWidget; + } + } + if (mMenuListener != nsnull) { if (NS_MENU_EVENT == event->eventStructType) aStatus = mMenuListener->MenuSelected( static_cast(*event) ); @@ -1577,7 +1586,6 @@ NS_IMETHODIMP nsChildView::DispatchEvent(nsGUIEvent* event, nsEventStatus& aStat if ((aStatus != nsEventStatus_eConsumeNoDefault) && (mEventListener != nsnull)) aStatus = mEventListener->ProcessEvent(*event); - NS_IF_RELEASE(aWidget); } return NS_OK; } diff --git a/mozilla/widget/src/cocoa/nsCocoaWindow.h b/mozilla/widget/src/cocoa/nsCocoaWindow.h index 3322fa2b5ee..a4724b8f6d5 100644 --- a/mozilla/widget/src/cocoa/nsCocoaWindow.h +++ b/mozilla/widget/src/cocoa/nsCocoaWindow.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -46,6 +46,7 @@ #include "nsPIWidgetCocoa.h" class nsCocoaWindow; +class nsChildView; @interface WindowDelegate : NSObject @@ -90,6 +91,7 @@ public: nsIToolkit *aToolkit = nsnull, nsWidgetInitData *aInitData = nsnull); + NS_IMETHOD Destroy(); // Utility method for implementing both Create(nsIWidget ...) and // Create(nsNativeWidget...) @@ -103,12 +105,14 @@ public: nsNativeWidget aNativeWindow = nsnull); NS_IMETHOD Show(PRBool aState); - + NS_IMETHOD AddMouseListener(nsIMouseListener * aListener); + NS_IMETHOD AddEventListener(nsIEventListener * aListener); + NS_IMETHOD AddMenuListener(nsIMenuListener * aListener); NS_IMETHOD Enable(PRBool aState); NS_IMETHOD IsEnabled(PRBool *aState); NS_IMETHOD SetModal(PRBool aState) { return NS_OK; } NS_IMETHOD IsVisible(PRBool & aState); - NS_IMETHOD SetFocus(PRBool aState=PR_FALSE) { return NS_OK; } + NS_IMETHOD SetFocus(PRBool aState=PR_FALSE); NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar); virtual nsIMenuBar* GetMenuBar(); NS_IMETHOD ShowMenuBar(PRBool aShow); @@ -134,10 +138,10 @@ public: virtual nsIFontMetrics* GetFont(void) { return nsnull; } NS_IMETHOD SetFont(const nsFont &aFont) { return NS_OK; } - NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous) { return NS_OK; } - NS_IMETHOD Invalidate(PRBool aIsSynchronous) { return NS_OK; }; - NS_IMETHOD Update() { return NS_OK; } - NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) { return NS_OK; } + NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous); + NS_IMETHOD Invalidate(PRBool aIsSynchronous); + NS_IMETHOD Update(); + NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *alCipRect) { return NS_OK; } NS_IMETHOD SetColorMap(nsColorMap *aColorMap) { return NS_OK; } NS_IMETHOD BeginResizingChildren(void) { return NS_OK; } NS_IMETHOD EndResizingChildren(void) { return NS_OK; } @@ -165,6 +169,8 @@ protected: WindowDelegate* mDelegate; // our delegate for processing window msgs [STRONG] nsCOMPtr mMenuBar; NSWindow* mSheetWindowParent; // if this is a sheet, this is the NSWindow it's attached to + nsChildView* mPopupContentView; // if this is a popup, this is its content widget + PRPackedBool mIsResizing; // we originated the resize, prevent infinite recursion PRPackedBool mWindowMadeHere; // true if we created the window, false for embedding diff --git a/mozilla/widget/src/cocoa/nsCocoaWindow.mm b/mozilla/widget/src/cocoa/nsCocoaWindow.mm index 8262dbe6abc..df2aecf369d 100644 --- a/mozilla/widget/src/cocoa/nsCocoaWindow.mm +++ b/mozilla/widget/src/cocoa/nsCocoaWindow.mm @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -129,6 +129,7 @@ nsCocoaWindow::nsCocoaWindow() , mWindow(nil) , mDelegate(nil) , mSheetWindowParent(nil) +, mPopupContentView(nil) , mIsResizing(PR_FALSE) , mWindowMadeHere(PR_FALSE) , mVisible(PR_FALSE) @@ -150,6 +151,8 @@ nsCocoaWindow::~nsCocoaWindow() [mWindow autorelease]; [mDelegate autorelease]; } + + NS_IF_RELEASE(mPopupContentView); } @@ -355,6 +358,19 @@ nsresult nsCocoaWindow::StandardCreate(nsIWidget *aParent, if (mWindowType == eWindowType_popup) { [mWindow setLevel:NSPopUpMenuWindowLevel]; [mWindow setHasShadow:YES]; + + // we need to make our content view a ChildView + mPopupContentView = new nsChildView(); + if (mPopupContentView) { + NS_ADDREF(mPopupContentView); + + nsIWidget* thisAsWidget = NS_STATIC_CAST(nsIWidget*, this); + mPopupContentView->StandardCreate(thisAsWidget, aRect, aHandleEventFunction, + aContext, aAppShell, aToolkit, nsnull, nsnull); + + ChildView* newContentView = (ChildView*)mPopupContentView->GetNativeData(NS_NATIVE_WIDGET); + [mWindow setContentView:newContentView]; + } } else if (mWindowType == eWindowType_invisible) { [mWindow setLevel:kCGDesktopWindowLevelKey]; @@ -411,6 +427,18 @@ NS_IMETHODIMP nsCocoaWindow::Create(nsIWidget* aParent, aContext, aAppShell, aToolkit, aInitData, nsnull)); } +NS_IMETHODIMP nsCocoaWindow::Destroy() +{ + if (mPopupContentView) + mPopupContentView->Destroy(); + + nsBaseWidget::OnDestroy(); + nsBaseWidget::Destroy(); + + mMouseListener = nsnull; + mEventListener = nsnull; + mMenuListener = nsnull; +} void* nsCocoaWindow::GetNativeData(PRUint32 aDataType) { @@ -424,7 +452,7 @@ void* nsCocoaWindow::GetNativeData(PRUint32 aDataType) retVal = [mWindow contentView]; break; - case NS_NATIVE_WINDOW: + case NS_NATIVE_WINDOW: retVal = mWindow; break; @@ -570,6 +598,51 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState) } } + if (mPopupContentView) + mPopupContentView->Show(bState); + + return NS_OK; +} + +NS_METHOD nsCocoaWindow::AddMouseListener(nsIMouseListener * aListener) +{ + nsBaseWidget::AddMouseListener(aListener); + + if (mPopupContentView) + mPopupContentView->AddMouseListener(aListener); + + return NS_OK; +} + +/** +* Processes a mouse pressed event +* +**/ +NS_METHOD nsCocoaWindow::AddEventListener(nsIEventListener * aListener) +{ + nsBaseWidget::AddEventListener(aListener); + + if (mPopupContentView) + mPopupContentView->AddEventListener(aListener); + + return NS_OK; +} + +/** +* Add a menu listener +* This interface should only be called by the menu services manager +* This will AddRef() the menu listener +* This will Release() a previously set menu listener +* +**/ + +NS_METHOD nsCocoaWindow::AddMenuListener(nsIMenuListener * aListener) +{ + nsBaseWidget::AddMenuListener(aListener); + + if (mPopupContentView) + mPopupContentView->AddMenuListener(aListener); + return NS_OK; } @@ -723,6 +796,31 @@ NS_IMETHODIMP nsCocoaWindow::SetTitle(const nsAString& aTitle) } +NS_IMETHODIMP nsCocoaWindow::Invalidate(const nsRect & aRect, PRBool aIsSynchronous) +{ + if (mPopupContentView) + return mPopupContentView->Invalidate(aRect, aIsSynchronous); + + return NS_OK; +} + +NS_IMETHODIMP nsCocoaWindow::Invalidate(PRBool aIsSynchronous) +{ + if (mPopupContentView) + return mPopupContentView->Invalidate(aIsSynchronous); + + return NS_OK; +} + +NS_IMETHODIMP nsCocoaWindow::Update() +{ + if (mPopupContentView) + return mPopupContentView->Update(); + + return NS_OK; +} + + // // Pass notification of some drag event to Gecko // @@ -879,6 +977,14 @@ NS_IMETHODIMP nsCocoaWindow::SetMenuBar(nsIMenuBar *aMenuBar) } +NS_IMETHODIMP nsCocoaWindow::SetFocus(PRBool aState) +{ + if (mPopupContentView) + mPopupContentView->SetFocus(aState); + + return NS_OK; +} + NS_IMETHODIMP nsCocoaWindow::ShowMenuBar(PRBool aShow) { return NS_ERROR_FAILURE;