diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 3ef2452e8ba..ed32a1fc465 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -3261,7 +3261,14 @@ nsCSSFrameConstructor::InitializeSelectFrame(nsFrameConstructorState& aState, nsWidgetInitData widgetData; widgetData.mWindowType = eWindowType_popup; widgetData.mBorderStyle = eBorderStyle_default; - view->CreateWidgetForPopup(&widgetData); + +#if defined(XP_MACOSX) || defined(XP_BEOS) + static NS_DEFINE_IID(kCPopUpCID, NS_POPUP_CID); + view->CreateWidgetForPopup(kCPopUpCID, &widgetData); +#else + static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID); + view->CreateWidgetForPopup(kCChildCID, &widgetData); +#endif } } diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index f1150fc04ba..ed0e57c9b23 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -503,6 +503,7 @@ protected: //------------------------------------------------------------------ // Class IDs static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID); +static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); static NS_DEFINE_CID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID); //------------------------------------------------------------------ @@ -2347,11 +2348,11 @@ DocumentViewerImpl::MakeWindow(const nsSize& aSize, nsIView* aContainerView) rv = view->AttachToTopLevelWidget(mParentWidget); } else if (!aContainerView && mParentWidget) { - rv = view->CreateWidgetForParent(mParentWidget, initDataPtr, + rv = view->CreateWidgetForParent(kWidgetCID, mParentWidget, initDataPtr, PR_TRUE, PR_FALSE); } else { - rv = view->CreateWidget(initDataPtr, PR_TRUE, PR_FALSE); + rv = view->CreateWidget(kWidgetCID, initDataPtr, PR_TRUE, PR_FALSE); } if (NS_FAILED(rv)) return rv; diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 6642f87a76c..9814eeb4a64 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -7913,6 +7913,7 @@ nsIPresShell::RemoveRefreshObserverExternal(nsARefreshObserver* aObserver, #include "nsILinkHandler.h" static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID); +static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); static void LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg) @@ -8282,7 +8283,7 @@ PresShell::VerifyIncrementalReflow() NS_ENSURE_TRUE(view, PR_FALSE); //now create the widget for the view - rv = view->CreateWidgetForParent(parentWidget, nsnull, PR_TRUE); + rv = view->CreateWidgetForParent(kWidgetCID, parentWidget, nsnull, PR_TRUE); NS_ENSURE_SUCCESS(rv, PR_FALSE); // Setup hierarchical relationship in view manager diff --git a/layout/generic/nsFrameFrame.cpp b/layout/generic/nsFrameFrame.cpp index 44526019481..3cf991a8390 100644 --- a/layout/generic/nsFrameFrame.cpp +++ b/layout/generic/nsFrameFrame.cpp @@ -104,6 +104,8 @@ class AsyncFrameInit; +static NS_DEFINE_CID(kCChildCID, NS_CHILD_CID); + /****************************************************************************** * nsSubDocumentFrame *****************************************************************************/ @@ -294,7 +296,7 @@ nsSubDocumentFrame::Init(nsIContent* aContent, if (aParent->GetStyleDisplay()->mDisplay == NS_STYLE_DISPLAY_DECK && !view->HasWidget()) { - view->CreateWidget(); + view->CreateWidget(kCChildCID); } // Set the primary frame now so that @@ -965,7 +967,7 @@ nsSubDocumentFrame::CreateViewAndWidget(nsContentType aContentType) if (aContentType == eContentTypeContent) { // widget needed. - nsresult rv = innerView->CreateWidget(nsnull, + nsresult rv = innerView->CreateWidget(kCChildCID, nsnull, PR_TRUE, PR_TRUE, aContentType); if (NS_FAILED(rv)) { NS_WARNING("Couldn't create widget for frame."); diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index 32afa250082..bb42c0a3306 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -249,6 +249,7 @@ protected: // Class IDs static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID); +static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); NS_IMPL_ISUPPORTS1(nsPrintEngine, nsIObserver) @@ -1998,10 +1999,10 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO) nsIWidget* widget = nsnull; if (!frame) widget = mParentWidget; - rv = widget ? rootView->CreateWidgetForParent(widget, nsnull, + rv = widget ? rootView->CreateWidgetForParent(kWidgetCID, widget, nsnull, PR_TRUE, PR_TRUE, eContentTypeContent) - : rootView->CreateWidget(nsnull, + : rootView->CreateWidget(kWidgetCID, nsnull, PR_TRUE, PR_TRUE, eContentTypeContent); NS_ENSURE_SUCCESS(rv, rv); diff --git a/layout/xul/base/src/nsMenuPopupFrame.cpp b/layout/xul/base/src/nsMenuPopupFrame.cpp index 290dbd60fc9..45914bee965 100644 --- a/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -320,9 +320,15 @@ nsMenuPopupFrame::CreateWidgetForView(nsIView* aView) baseWindow->GetMainWidget(getter_AddRefs(parentWidget)); } - aView->CreateWidgetForPopup(&widgetData, parentWidget, +#if defined(XP_MACOSX) || defined(XP_BEOS) + static NS_DEFINE_IID(kCPopupCID, NS_POPUP_CID); + aView->CreateWidgetForPopup(kCPopupCID, &widgetData, parentWidget, PR_TRUE, PR_TRUE, eContentTypeUI); - +#else + static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID); + aView->CreateWidgetForPopup(kCChildCID, &widgetData, parentWidget, + PR_TRUE, PR_TRUE, eContentTypeInherit); +#endif nsIWidget* widget = aView->GetWidget(); widget->SetTransparencyMode(mode); widget->SetWindowShadowStyle(GetShadowStyle()); diff --git a/view/public/nsIView.h b/view/public/nsIView.h index 8d5245d89f6..4a79a254549 100644 --- a/view/public/nsIView.h +++ b/view/public/nsIView.h @@ -62,8 +62,8 @@ enum nsViewVisibility { }; #define NS_IVIEW_IID \ - { 0xba00349c, 0xe58a, 0x436a, \ - { 0x9f, 0x1f, 0x05, 0xb3, 0xdd, 0x9d, 0x9d, 0x36 } } + { 0x01258624, 0xca90, 0x47a4, \ + { 0xb1, 0xfd, 0x52, 0x11, 0x26, 0xe6, 0xc8, 0xdc } } // Public view flags are defined in this file #define NS_VIEW_FLAGS_PUBLIC 0x00FF @@ -279,6 +279,8 @@ public: * CreateWidget*() will look around in the view hierarchy for an * appropriate parent widget for the view. * + * @param aWindowIID IID for Widget type that this view + * should have associated with it. * @param aWidgetInitData data used to initialize this view's widget before * its create is called. * @param aContentType is either content, UI or inherit from parent window. @@ -286,7 +288,8 @@ public: * assistive technology like screen readers. * @return error status */ - nsresult CreateWidget(nsWidgetInitData *aWidgetInitData = nsnull, + nsresult CreateWidget(const nsIID &aWindowIID, + nsWidgetInitData *aWidgetInitData = nsnull, PRBool aEnableDragDrop = PR_TRUE, PRBool aResetVisibility = PR_TRUE, nsContentType aContentType = eContentTypeInherit); @@ -296,7 +299,8 @@ public: * |aParentWidget| must be nonnull. The other params are the same * as for |CreateWidget()|. */ - nsresult CreateWidgetForParent(nsIWidget* aParentWidget, + nsresult CreateWidgetForParent(const nsIID &aWindowIID, + nsIWidget* aParentWidget, nsWidgetInitData *aWidgetInitData = nsnull, PRBool aEnableDragDrop = PR_TRUE, PRBool aResetVisibility = PR_TRUE, @@ -309,7 +313,8 @@ public: * other params are the same as for |CreateWidget()|, except that * |aWidgetInitData| must be nonnull. */ - nsresult CreateWidgetForPopup(nsWidgetInitData *aWidgetInitData, + nsresult CreateWidgetForPopup(const nsIID &aWindowIID, + nsWidgetInitData *aWidgetInitData, nsIWidget* aParentWidget = nsnull, PRBool aEnableDragDrop = PR_TRUE, PRBool aResetVisibility = PR_TRUE, diff --git a/view/src/nsView.cpp b/view/src/nsView.cpp index a55549611f5..6840bb3315a 100644 --- a/view/src/nsView.cpp +++ b/view/src/nsView.cpp @@ -37,7 +37,6 @@ #include "nsView.h" #include "nsIWidget.h" -#include "nsWidgetsCID.h" #include "nsViewManager.h" #include "nsGUIEvent.h" #include "nsIDeviceContext.h" @@ -659,48 +658,58 @@ static PRInt32 FindNonAutoZIndex(nsView* aView) return 0; } -nsresult nsIView::CreateWidget(nsWidgetInitData *aWidgetInitData, +nsresult nsIView::CreateWidget(const nsIID &aWindowIID, + nsWidgetInitData *aWidgetInitData, PRBool aEnableDragDrop, PRBool aResetVisibility, nsContentType aContentType) { - return Impl()->CreateWidget(aWidgetInitData, + return Impl()->CreateWidget(aWindowIID, aWidgetInitData, aEnableDragDrop, aResetVisibility, aContentType); } -nsresult nsIView::CreateWidgetForParent(nsIWidget* aParentWidget, +nsresult nsIView::CreateWidgetForParent(const nsIID &aWindowIID, + nsIWidget* aParentWidget, nsWidgetInitData *aWidgetInitData, PRBool aEnableDragDrop, PRBool aResetVisibility, nsContentType aContentType) { - return Impl()->CreateWidgetForParent(aParentWidget, aWidgetInitData, + return Impl()->CreateWidgetForParent(aWindowIID, aParentWidget, + aWidgetInitData, aEnableDragDrop, aResetVisibility, aContentType); } -nsresult nsIView::CreateWidgetForPopup(nsWidgetInitData *aWidgetInitData, +nsresult nsIView::CreateWidgetForPopup(const nsIID &aWindowIID, + nsWidgetInitData *aWidgetInitData, nsIWidget* aParentWidget, PRBool aEnableDragDrop, PRBool aResetVisibility, nsContentType aContentType) { - return Impl()->CreateWidgetForPopup(aWidgetInitData, aParentWidget, + return Impl()->CreateWidgetForPopup(aWindowIID, aWidgetInitData, + aParentWidget, aEnableDragDrop, aResetVisibility, aContentType); } -nsresult nsView::CreateWidget(nsWidgetInitData *aWidgetInitData, +nsresult nsView::CreateWidget(const nsIID &aWindowIID, + nsWidgetInitData *aWidgetInitData, PRBool aEnableDragDrop, PRBool aResetVisibility, nsContentType aContentType) { - AssertNoWindow(); NS_ABORT_IF_FALSE(!aWidgetInitData || aWidgetInitData->mWindowType != eWindowType_popup, "Use CreateWidgetForPopup"); + nsresult rv = LoadWidget(aWindowIID); + if (NS_FAILED(rv)) { + return rv; + } + PRBool initDataPassedIn = PR_TRUE; nsWidgetInitData initData; if (!aWidgetInitData) { @@ -720,68 +729,65 @@ nsresult nsView::CreateWidget(nsWidgetInitData *aWidgetInitData, initData.mListenForResizes = (!initDataPassedIn && GetParent() && GetParent()->GetViewManager() != mViewManager); + nsIWidget* parentWidget = GetParent() ? GetParent()->GetNearestWidget(nsnull) : nsnull; - if (!parentWidget) { - NS_ERROR("nsView::CreateWidget without suitable parent widget??"); - return NS_ERROR_FAILURE; - } - // XXX: using aForceUseIWidgetParent=true to preserve previous - // semantics. It's not clear that it's actually needed. - mWindow = parentWidget->CreateChild(trect, ::HandleEvent, - dx, nsnull, nsnull, aWidgetInitData, - PR_TRUE).get(); - if (!mWindow) { - return NS_ERROR_FAILURE; - } - + mWindow->Create(parentWidget, nsnull, + trect, ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData); + InitializeWindow(aEnableDragDrop, aResetVisibility); return NS_OK; } -nsresult nsView::CreateWidgetForParent(nsIWidget* aParentWidget, +nsresult nsView::CreateWidgetForParent(const nsIID &aWindowIID, + nsIWidget* aParentWidget, nsWidgetInitData *aWidgetInitData, PRBool aEnableDragDrop, PRBool aResetVisibility, nsContentType aWindowType) { - AssertNoWindow(); NS_ABORT_IF_FALSE(!aWidgetInitData || aWidgetInitData->mWindowType != eWindowType_popup, "Use CreateWidgetForPopup"); NS_ABORT_IF_FALSE(aParentWidget, "Parent widget required"); + nsresult rv = LoadWidget(aWindowIID); + if (NS_FAILED(rv)) { + return rv; + } + nsIntRect trect = CalcWidgetBounds( aWidgetInitData ? aWidgetInitData->mWindowType : eWindowType_child); nsCOMPtr dx; mViewManager->GetDeviceContext(*getter_AddRefs(dx)); - mWindow = - aParentWidget->CreateChild(trect, ::HandleEvent, - dx, nsnull, nsnull, aWidgetInitData).get(); - if (!mWindow) { - return NS_ERROR_FAILURE; - } + mWindow->Create(nsnull, aParentWidget->GetNativeData(NS_NATIVE_WIDGET), + trect, ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData); InitializeWindow(aEnableDragDrop, aResetVisibility); return NS_OK; } -nsresult nsView::CreateWidgetForPopup(nsWidgetInitData *aWidgetInitData, +nsresult nsView::CreateWidgetForPopup(const nsIID &aWindowIID, + nsWidgetInitData *aWidgetInitData, nsIWidget* aParentWidget, PRBool aEnableDragDrop, PRBool aResetVisibility, nsContentType aWindowType) { - AssertNoWindow(); NS_ABORT_IF_FALSE(aWidgetInitData, "Widget init data required"); NS_ABORT_IF_FALSE(aWidgetInitData->mWindowType == eWindowType_popup, "Use one of the other CreateWidget methods"); + nsresult rv = LoadWidget(aWindowIID); + if (NS_FAILED(rv)) { + return rv; + } + nsIntRect trect = CalcWidgetBounds(aWidgetInitData->mWindowType); nsCOMPtr dx; @@ -790,13 +796,11 @@ nsresult nsView::CreateWidgetForPopup(nsWidgetInitData *aWidgetInitData, // XXX/cjones: having these two separate creation cases seems ... um // ... unnecessary, but it's the way the old code did it. Please // unify them by first finding a suitable parent nsIWidget, then - // getting rid of aForceUseIWidgetParent. + // passing only either the non-null parentWidget or the native ID to + // Create(). if (aParentWidget) { - // XXX: using aForceUseIWidgetParent=true to preserve previous - // semantics. It's not clear that it's actually needed. - mWindow = aParentWidget->CreateChild(trect, ::HandleEvent, - dx, nsnull, nsnull, aWidgetInitData, - PR_TRUE).get(); + mWindow->Create(aParentWidget, nsnull, trect, + ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData); } else { nsIWidget* nearestParent = GetParent() ? GetParent()->GetNearestWidget(nsnull) @@ -807,12 +811,8 @@ nsresult nsView::CreateWidgetForPopup(nsWidgetInitData *aWidgetInitData, return NS_ERROR_FAILURE; } - mWindow = - nearestParent->CreateChild(trect, ::HandleEvent, - dx, nsnull, nsnull, aWidgetInitData).get(); - } - if (!mWindow) { - return NS_ERROR_FAILURE; + mWindow->Create(nsnull, nearestParent->GetNativeData(NS_NATIVE_WIDGET), trect, + ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData); } InitializeWindow(aEnableDragDrop, aResetVisibility); @@ -825,10 +825,6 @@ nsView::InitializeWindow(PRBool aEnableDragDrop, PRBool aResetVisibility) { NS_ABORT_IF_FALSE(mWindow, "Must have a window to initialize"); - ViewWrapper* wrapper = new ViewWrapper(this); - NS_ADDREF(wrapper); // Will be released in ~nsView - mWindow->SetClientData(wrapper); - if (aEnableDragDrop) { mWindow->EnableDragDrop(PR_TRUE); } @@ -910,9 +906,11 @@ void nsView::SetZIndex(PRBool aAuto, PRInt32 aZIndex, PRBool aTopMost) } } -void nsView::AssertNoWindow() +// +// internal window creation functions +// +nsresult nsView::LoadWidget(const nsCID &aClassIID) { - // XXX: it would be nice to make this a strong assert if (NS_UNLIKELY(mWindow)) { NS_ERROR("We already have a window for this view? BAD"); ViewWrapper* wrapper = GetWrapperFor(mWindow); @@ -921,11 +919,18 @@ void nsView::AssertNoWindow() mWindow->Destroy(); NS_RELEASE(mWindow); } + + nsresult rv = CallCreateInstance(aClassIID, &mWindow); + if (NS_FAILED(rv)) { + return rv; + } + + ViewWrapper* wrapper = new ViewWrapper(this); + NS_ADDREF(wrapper); // Will be released in ~nsView + mWindow->SetClientData(wrapper); + return rv; } -// -// internal window creation functions -// EVENT_CALLBACK nsIView::AttachWidgetEventHandler(nsIWidget* aWidget) { #ifdef DEBUG diff --git a/view/src/nsView.h b/view/src/nsView.h index 764a6d1ef76..15260c95000 100644 --- a/view/src/nsView.h +++ b/view/src/nsView.h @@ -118,20 +118,23 @@ public: public: // See nsIView::CreateWidget. - nsresult CreateWidget(nsWidgetInitData *aWidgetInitData, + nsresult CreateWidget(const nsIID &aWindowIID, + nsWidgetInitData *aWidgetInitData, PRBool aEnableDragDrop, PRBool aResetVisibility, nsContentType aContentType); // See nsIView::CreateWidgetForParent. - nsresult CreateWidgetForParent(nsIWidget* aParentWidget, + nsresult CreateWidgetForParent(const nsIID &aWindowIID, + nsIWidget* aParentWidget, nsWidgetInitData *aWidgetInitData, PRBool aEnableDragDrop, PRBool aResetVisibility, nsContentType aContentType); // See nsIView::CreateWidgetForPopup. - nsresult CreateWidgetForPopup(nsWidgetInitData *aWidgetInitData, + nsresult CreateWidgetForPopup(const nsIID &aWindowIID, + nsWidgetInitData *aWidgetInitData, nsIWidget* aParentWidget, PRBool aEnableDragDrop, PRBool aResetVisibility, @@ -182,7 +185,7 @@ public: nsPoint ConvertFromParentCoords(nsPoint aPt) const; void ResetWidgetBounds(PRBool aRecurse, PRBool aMoveOnly, PRBool aInvalidateChangedSize); void SetPositionIgnoringChildWidgets(nscoord aX, nscoord aY); - void AssertNoWindow(); + nsresult LoadWidget(const nsCID &aClassIID); void NotifyEffectiveVisibilityChanged(PRBool aEffectivelyVisible); diff --git a/widget/src/cocoa/nsChildView.h b/widget/src/cocoa/nsChildView.h index 367c4bf4b7c..235920801d1 100644 --- a/widget/src/cocoa/nsChildView.h +++ b/widget/src/cocoa/nsChildView.h @@ -414,14 +414,6 @@ protected: void TearDownView(); nsCocoaWindow* GetXULWindowWidget(); - virtual already_AddRefed - AllocateChildPopupWidget() - { - static NS_DEFINE_IID(kCPopUpCID, NS_POPUP_CID); - nsCOMPtr widget = do_CreateInstance(kCPopUpCID); - return widget.forget(); - } - protected: NSView* mView; // my parallel cocoa view (ChildView or NativeScrollbarView), [STRONG]