зеркало из https://github.com/mozilla/pjs.git
Bug 582057, part a: Add nsIView::Impl() and nsView::CreateWidget() to get rid of |static_cast<nsView*>(this)|. r=roc
This commit is contained in:
Родитель
eb22a77b91
Коммит
1eedeb1aa6
|
@ -396,6 +396,10 @@ protected:
|
||||||
PRBool mWidgetIsTopLevel;
|
PRBool mWidgetIsTopLevel;
|
||||||
|
|
||||||
virtual ~nsIView() {}
|
virtual ~nsIView() {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsView* Impl();
|
||||||
|
const nsView* Impl() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsIView, NS_IVIEW_IID)
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsIView, NS_IVIEW_IID)
|
||||||
|
|
|
@ -394,7 +394,7 @@ nsIntRect nsIView::CalcWidgetBounds(nsWindowType aType)
|
||||||
|
|
||||||
nsRect viewBounds(mDimBounds);
|
nsRect viewBounds(mDimBounds);
|
||||||
|
|
||||||
nsView* parent = static_cast<nsView*>(GetParent());
|
nsView* parent = GetParent()->Impl();
|
||||||
if (parent) {
|
if (parent) {
|
||||||
nsPoint offset;
|
nsPoint offset;
|
||||||
nsIWidget* parentWidget = parent->GetNearestWidget(&offset, p2a);
|
nsIWidget* parentWidget = parent->GetNearestWidget(&offset, p2a);
|
||||||
|
@ -665,6 +665,19 @@ nsresult nsIView::CreateWidget(const nsIID &aWindowIID,
|
||||||
PRBool aResetVisibility,
|
PRBool aResetVisibility,
|
||||||
nsContentType aContentType,
|
nsContentType aContentType,
|
||||||
nsIWidget* aParentWidget)
|
nsIWidget* aParentWidget)
|
||||||
|
{
|
||||||
|
return Impl()->CreateWidget(aWindowIID, aWidgetInitData, aNative,
|
||||||
|
aEnableDragDrop, aResetVisibility,
|
||||||
|
aContentType, aParentWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult nsView::CreateWidget(const nsIID &aWindowIID,
|
||||||
|
nsWidgetInitData *aWidgetInitData,
|
||||||
|
nsNativeWidget aNative,
|
||||||
|
PRBool aEnableDragDrop,
|
||||||
|
PRBool aResetVisibility,
|
||||||
|
nsContentType aContentType,
|
||||||
|
nsIWidget* aParentWidget)
|
||||||
{
|
{
|
||||||
if (NS_UNLIKELY(mWindow)) {
|
if (NS_UNLIKELY(mWindow)) {
|
||||||
NS_ERROR("We already have a window for this view? BAD");
|
NS_ERROR("We already have a window for this view? BAD");
|
||||||
|
@ -675,13 +688,11 @@ nsresult nsIView::CreateWidget(const nsIID &aWindowIID,
|
||||||
NS_RELEASE(mWindow);
|
NS_RELEASE(mWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsView* v = static_cast<nsView*>(this);
|
nsIntRect trect = CalcWidgetBounds(aWidgetInitData
|
||||||
|
|
||||||
nsIntRect trect = v->CalcWidgetBounds(aWidgetInitData
|
|
||||||
? aWidgetInitData->mWindowType
|
? aWidgetInitData->mWindowType
|
||||||
: eWindowType_child);
|
: eWindowType_child);
|
||||||
|
|
||||||
if (NS_OK == v->LoadWidget(aWindowIID))
|
if (NS_OK == LoadWidget(aWindowIID))
|
||||||
{
|
{
|
||||||
PRBool usewidgets;
|
PRBool usewidgets;
|
||||||
nsCOMPtr<nsIDeviceContext> dx;
|
nsCOMPtr<nsIDeviceContext> dx;
|
||||||
|
@ -736,7 +747,7 @@ nsresult nsIView::CreateWidget(const nsIID &aWindowIID,
|
||||||
}
|
}
|
||||||
|
|
||||||
// propagate the z-index to the widget.
|
// propagate the z-index to the widget.
|
||||||
UpdateNativeWidgetZIndexes(v, FindNonAutoZIndex(v));
|
UpdateNativeWidgetZIndexes(this, FindNonAutoZIndex(this));
|
||||||
} else {
|
} else {
|
||||||
// We should tell the widget its size even if we don't create a
|
// We should tell the widget its size even if we don't create a
|
||||||
// native widget. (At the moment, this doesn't really matter,
|
// native widget. (At the moment, this doesn't really matter,
|
||||||
|
@ -749,7 +760,7 @@ nsresult nsIView::CreateWidget(const nsIID &aWindowIID,
|
||||||
//make sure visibility state is accurate
|
//make sure visibility state is accurate
|
||||||
|
|
||||||
if (aResetVisibility) {
|
if (aResetVisibility) {
|
||||||
v->SetVisibility(GetVisibility());
|
SetVisibility(GetVisibility());
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -778,8 +789,7 @@ nsresult nsIView::AttachToTopLevelWidget(nsIWidget* aWidget)
|
||||||
mWindow = aWidget;
|
mWindow = aWidget;
|
||||||
NS_ADDREF(mWindow);
|
NS_ADDREF(mWindow);
|
||||||
|
|
||||||
nsView* v = static_cast<nsView*>(this);
|
ViewWrapper* wrapper = new ViewWrapper(Impl());
|
||||||
ViewWrapper* wrapper = new ViewWrapper(v);
|
|
||||||
NS_ADDREF(wrapper);
|
NS_ADDREF(wrapper);
|
||||||
mWindow->SetAttachedViewPtr(wrapper);
|
mWindow->SetAttachedViewPtr(wrapper);
|
||||||
mWindow->EnableDragDrop(PR_TRUE);
|
mWindow->EnableDragDrop(PR_TRUE);
|
||||||
|
@ -853,8 +863,7 @@ EVENT_CALLBACK nsIView::AttachWidgetEventHandler(nsIWidget* aWidget)
|
||||||
NS_ASSERTION(!data, "Already got client data");
|
NS_ASSERTION(!data, "Already got client data");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nsView* v = static_cast<nsView*>(this);
|
ViewWrapper* wrapper = new ViewWrapper(Impl());
|
||||||
ViewWrapper* wrapper = new ViewWrapper(v);
|
|
||||||
if (!wrapper)
|
if (!wrapper)
|
||||||
return nsnull;
|
return nsnull;
|
||||||
NS_ADDREF(wrapper); // Will be released in DetachWidgetEventHandler
|
NS_ADDREF(wrapper); // Will be released in DetachWidgetEventHandler
|
||||||
|
@ -908,9 +917,8 @@ void nsIView::List(FILE* out, PRInt32 aIndent) const
|
||||||
|
|
||||||
nsPoint nsIView::GetOffsetTo(const nsIView* aOther) const
|
nsPoint nsIView::GetOffsetTo(const nsIView* aOther) const
|
||||||
{
|
{
|
||||||
const nsView* view = static_cast<const nsView*>(this);
|
return Impl()->GetOffsetTo(static_cast<const nsView*>(aOther),
|
||||||
return view->GetOffsetTo(static_cast<const nsView*>(aOther),
|
Impl()->GetViewManager()->AppUnitsPerDevPixel());
|
||||||
view->GetViewManager()->AppUnitsPerDevPixel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsPoint nsView::GetOffsetTo(const nsView* aOther) const
|
nsPoint nsView::GetOffsetTo(const nsView* aOther) const
|
||||||
|
@ -958,10 +966,12 @@ nsPoint nsIView::GetOffsetToWidget(nsIWidget* aWidget) const
|
||||||
{
|
{
|
||||||
nsPoint pt;
|
nsPoint pt;
|
||||||
// Get the view for widget
|
// Get the view for widget
|
||||||
nsView* widgetView = static_cast<nsView*>(GetViewFor(aWidget));
|
nsIView* widgetIView = GetViewFor(aWidget);
|
||||||
if (!widgetView) {
|
if (!widgetIView) {
|
||||||
return pt;
|
return pt;
|
||||||
}
|
}
|
||||||
|
nsView* widgetView = widgetIView->Impl();
|
||||||
|
|
||||||
// Get the offset to the widget view in the widget view's APD
|
// Get the offset to the widget view in the widget view's APD
|
||||||
// We get the offset in the widget view's APD first and then convert to our
|
// We get the offset in the widget view's APD first and then convert to our
|
||||||
// APD afterwards so that we can include the widget view's ViewToWidgetOffset
|
// APD afterwards so that we can include the widget view's ViewToWidgetOffset
|
||||||
|
@ -983,9 +993,8 @@ nsPoint nsIView::GetOffsetToWidget(nsIWidget* aWidget) const
|
||||||
|
|
||||||
nsIWidget* nsIView::GetNearestWidget(nsPoint* aOffset) const
|
nsIWidget* nsIView::GetNearestWidget(nsPoint* aOffset) const
|
||||||
{
|
{
|
||||||
const nsView* view = static_cast<const nsView*>(this);
|
return Impl()->GetNearestWidget(aOffset,
|
||||||
return view->GetNearestWidget(aOffset,
|
Impl()->GetViewManager()->AppUnitsPerDevPixel());
|
||||||
view->GetViewManager()->AppUnitsPerDevPixel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsIWidget* nsView::GetNearestWidget(nsPoint* aOffset) const
|
nsIWidget* nsView::GetNearestWidget(nsPoint* aOffset) const
|
||||||
|
@ -1056,6 +1065,18 @@ nsIView::SetDeletionObserver(nsWeakView* aDeletionObserver)
|
||||||
mDeletionObserver = aDeletionObserver;
|
mDeletionObserver = aDeletionObserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsView*
|
||||||
|
nsIView::Impl()
|
||||||
|
{
|
||||||
|
return static_cast<nsView*>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
const nsView*
|
||||||
|
nsIView::Impl() const
|
||||||
|
{
|
||||||
|
return static_cast<const nsView*>(this);
|
||||||
|
}
|
||||||
|
|
||||||
nsRect
|
nsRect
|
||||||
nsView::GetBoundsInParentUnits() const
|
nsView::GetBoundsInParentUnits() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -117,6 +117,15 @@ public:
|
||||||
void DropMouseGrabbing();
|
void DropMouseGrabbing();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// See nsIView::CreateWidget.
|
||||||
|
nsresult CreateWidget(const nsIID &aWindowIID,
|
||||||
|
nsWidgetInitData *aWidgetInitData,
|
||||||
|
nsNativeWidget aNative,
|
||||||
|
PRBool aEnableDragDrop,
|
||||||
|
PRBool aResetVisibility,
|
||||||
|
nsContentType aContentType,
|
||||||
|
nsIWidget* aParentWidget);
|
||||||
|
|
||||||
// NOT in nsIView, so only available in view module
|
// NOT in nsIView, so only available in view module
|
||||||
// These are also present in nsIView, but these versions return nsView and nsViewManager
|
// These are also present in nsIView, but these versions return nsView and nsViewManager
|
||||||
// instead of nsIView and nsIViewManager.
|
// instead of nsIView and nsIViewManager.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче