Bug 582057, part h: Add an nsIWidget::CreateChild interface to sweep (relevant to this bug) code dealing with native widgets under the widget/src/* rug. sr=roc

This commit is contained in:
Chris Jones 2010-08-19 13:49:35 -05:00
Родитель 21a1ad45c1
Коммит 39dacad66c
5 изменённых файлов: 101 добавлений и 2 удалений

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

@ -111,8 +111,8 @@ typedef nsEventStatus (* EVENT_CALLBACK)(nsGUIEvent *event);
#endif
#define NS_IWIDGET_IID \
{ 0x193fcc7a, 0x2456, 0x4625, \
{ 0x85, 0x40, 0x38, 0xed, 0x00, 0x69, 0x93, 0xf5 } }
{ 0xe1dda370, 0xdf16, 0x4c92, \
{ 0x9b, 0x86, 0x4b, 0xd9, 0xcf, 0xff, 0x4e, 0xb1 } }
/*
* Window shadow styles
@ -237,6 +237,31 @@ class nsIWidget : public nsISupports {
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull) = 0;
/**
* Allocate, initialize, and return a widget that is a child of
* |this|. The returned widget (if nonnull) has gone through the
* equivalent of CreateInstance(widgetCID) + Create(...).
*
* |CreateChild()| lets widget backends decide whether to parent
* the new child widget to this, nonnatively parent it, or both.
* This interface exists to support the PuppetWidget backend,
* which is entirely non-native. All other params are the same as
* for |Create()|.
*
* |aForceUseIWidgetParent| forces |CreateChild()| to only use the
* |nsIWidget*| this, not its native widget (if it exists), when
* calling |Create()|. This is a timid hack around poorly
* understood code, and shouldn't be used in new code.
*/
virtual already_AddRefed<nsIWidget>
CreateChild(const nsIntRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull,
PRBool aForceUseIWidgetParent = PR_FALSE) = 0;
/**
* Attach to a top level widget.
*
@ -1212,6 +1237,8 @@ class nsIWidget : public nsISupports {
PRBool aIsHorizontal,
PRInt32 &aOverriddenDelta) = 0;
protected:
// keep the list of children. We also keep track of our siblings.
// The ownership model is as follows: parent holds a strong ref to

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

@ -193,6 +193,13 @@ protected:
PRBool DispatchWindowEvent(nsGUIEvent* event);
void HideKids(PRBool state);
virtual already_AddRefed<nsIWidget>
AllocateChildPopupWidget()
{
static NS_DEFINE_IID(kCPopUpCID, NS_POPUP_CID);
nsCOMPtr<nsIWidget> widget = do_CreateInstance(kCPopUpCID);
return widget.forget();
}
nsCOMPtr<nsIWidget> mParent;
nsWindow* mWindowParent;

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

@ -313,6 +313,14 @@ protected:
void SetUpWindowFilter();
void CleanUpWindowFilter();
virtual already_AddRefed<nsIWidget>
AllocateChildPopupWidget()
{
static NS_DEFINE_IID(kCPopUpCID, NS_POPUP_CID);
nsCOMPtr<nsIWidget> widget = do_CreateInstance(kCPopUpCID);
return widget.forget();
}
nsIWidget* mParent; // if we're a popup, this is our parent [WEAK]
BaseWindow* mWindow; // our cocoa window [STRONG]
WindowDelegate* mDelegate; // our delegate for processing window msgs [STRONG]

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

@ -246,6 +246,46 @@ NS_IMETHODIMP nsBaseWidget::SetClientData(void* aClientData)
return NS_OK;
}
already_AddRefed<nsIWidget>
nsBaseWidget::CreateChild(const nsIntRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData,
PRBool aForceUseIWidgetParent)
{
nsIWidget* parent = this;
nsNativeWidget nativeParent = nsnull;
if (!aForceUseIWidgetParent) {
// Use only either parent or nativeParent, not both, to match
// existing code. Eventually Create() should be divested of its
// nativeWidget parameter.
nativeParent = parent ? parent->GetNativeData(NS_NATIVE_WIDGET) : nsnull;
parent = nativeParent ? nsnull : parent;
NS_ABORT_IF_FALSE(!parent || !nativeParent, "messed up logic");
}
nsCOMPtr<nsIWidget> widget;
if (aInitData && aInitData->mWindowType == eWindowType_popup) {
widget = AllocateChildPopupWidget();
} else {
static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID);
widget = do_CreateInstance(kCChildCID);
}
if (widget &&
NS_SUCCEEDED(widget->Create(parent, nativeParent, aRect,
aHandleEventFunction,
aContext, aAppShell, aToolkit,
aInitData))) {
return widget.forget();
}
return nsnull;
}
// Attach a view to our widget which we'll send events to.
NS_IMETHODIMP
nsBaseWidget::AttachViewToTopLevel(EVENT_CALLBACK aViewEventFunction,

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

@ -39,6 +39,7 @@
#include "nsRect.h"
#include "nsIWidget.h"
#include "nsWidgetsCID.h"
#include "nsIToolkit.h"
#include "nsIAppShell.h"
#include "nsILocalFile.h"
@ -151,6 +152,14 @@ public:
NS_IMETHOD OnIMESelectionChange(void) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD OnDefaultButtonLoaded(const nsIntRect &aButtonRect) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD OverrideSystemMouseScrollSpeed(PRInt32 aOriginalDelta, PRBool aIsHorizontal, PRInt32 &aOverriddenDelta);
virtual already_AddRefed<nsIWidget>
CreateChild(const nsIntRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull,
PRBool aForceUseIWidgetParent = PR_FALSE);
NS_IMETHOD AttachViewToTopLevel(EVENT_CALLBACK aViewEventFunction, nsIDeviceContext *aContext);
virtual ViewWrapper* GetAttachedViewPtr();
NS_IMETHOD SetAttachedViewPtr(ViewWrapper* aViewWrapper);
@ -225,6 +234,14 @@ protected:
// if the new rectangles are different from the old rectangles.
PRBool StoreWindowClipRegion(const nsTArray<nsIntRect>& aRects);
virtual already_AddRefed<nsIWidget>
AllocateChildPopupWidget()
{
static NS_DEFINE_IID(kCPopUpCID, NS_CHILD_CID);
nsCOMPtr<nsIWidget> widget = do_CreateInstance(kCPopUpCID);
return widget.forget();
}
protected:
void* mClientData;
ViewWrapper* mViewWrapperPtr;