Skip to content

Commit

Permalink
Bug 1296993 (part 1) - Streamline nsIWidget::ReparentNativeWidget. r=…
Browse files Browse the repository at this point in the history
…mstange.

This patch does the following.

- Removes the return value, because none of the call sites check it.

- Puts an empty implementation into nsBaseWidget.

- Removes the empty implementations from several nsIWidget instances, because
  they can use the nsBaseWidget one.
  • Loading branch information
nnethercote committed Aug 25, 2016
1 parent 4abde03 commit 5b6fc35
Show file tree
Hide file tree
Showing 18 changed files with 14 additions and 51 deletions.
1 change: 0 additions & 1 deletion gfx/tests/gtest/TestCompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class MockWidget : public nsBaseWidget
NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
const InputContextAction& aAction) override {}
NS_IMETHOD_(InputContext) GetInputContext() override { abort(); }
NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) override { return NS_OK; }

private:
~MockWidget() {}
Expand Down
2 changes: 0 additions & 2 deletions widget/PuppetWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ class PuppetWidget : public nsBaseWidget
#if defined(XP_WIN)
void SetNativeData(uint32_t aDataType, uintptr_t aVal) override;
#endif
NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) override
{ return NS_ERROR_UNEXPECTED; }

// PuppetWidgets don't have any concept of titles.
NS_IMETHOD SetTitle(const nsAString& aTitle) override
Expand Down
7 changes: 0 additions & 7 deletions widget/android/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,13 +1653,6 @@ nsWindow::SetParent(nsIWidget *aNewParent)
return NS_OK;
}

NS_IMETHODIMP
nsWindow::ReparentNativeWidget(nsIWidget *aNewParent)
{
NS_PRECONDITION(aNewParent, "");
return NS_OK;
}

nsIWidget*
nsWindow::GetParent()
{
Expand Down
2 changes: 0 additions & 2 deletions widget/android/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ class nsWindow : public nsBaseWidget
LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE,
LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) override;

NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) override;

virtual bool NeedsPaint() override;
virtual void DrawWindowUnderlay(LayerManagerComposite* aManager, LayoutDeviceIntRect aRect) override;
virtual void DrawWindowOverlay(LayerManagerComposite* aManager, LayoutDeviceIntRect aRect) override;
Expand Down
2 changes: 1 addition & 1 deletion widget/cocoa/nsChildView.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ class nsChildView : public nsBaseWidget

nsCocoaWindow* GetXULWindowWidget();

NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) override;
virtual void ReparentNativeWidget(nsIWidget* aNewParent) override;

mozilla::widget::TextInputHandler* GetTextInputHandler()
{
Expand Down
11 changes: 5 additions & 6 deletions widget/cocoa/nsChildView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -770,27 +770,26 @@ static void PrintViewHierarchy(NSView *view)
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}

NS_IMETHODIMP
void
nsChildView::ReparentNativeWidget(nsIWidget* aNewParent)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;

NS_PRECONDITION(aNewParent, "");

if (mOnDestroyCalled)
return NS_OK;
return;

NSView<mozView>* newParentView =
(NSView<mozView>*)aNewParent->GetNativeData(NS_NATIVE_WIDGET);
NS_ENSURE_TRUE(newParentView, NS_ERROR_FAILURE);
NS_ENSURE_TRUE_VOID(newParentView);

// we hold a ref to mView, so this is safe
[mView removeFromSuperview];
mParentView = newParentView;
[mParentView addSubview:mView];
return NS_OK;

NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
NS_OBJC_END_TRY_ABORT_BLOCK;
}

void nsChildView::ResetParent()
Expand Down
2 changes: 0 additions & 2 deletions widget/cocoa/nsCocoaWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,6 @@ class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa

void SetPopupWindowLevel();

NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) override;

protected:
virtual ~nsCocoaWindow();

Expand Down
5 changes: 0 additions & 5 deletions widget/cocoa/nsCocoaWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,6 @@ static unsigned int WindowMaskForBorderStyle(nsBorderStyle aBorderStyle)
return mask;
}

NS_IMETHODIMP nsCocoaWindow::ReparentNativeWidget(nsIWidget* aNewParent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

// If aRectIsFrameRect, aRect specifies the frame rect of the new window.
// Otherwise, aRect.x/y specify the position of the window's frame relative to
// the bottom of the menubar and aRect.width/height specify the size of the
Expand Down
6 changes: 0 additions & 6 deletions widget/gonk/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,6 @@ nsWindow::GetInputContext()
return mInputContext;
}

NS_IMETHODIMP
nsWindow::ReparentNativeWidget(nsIWidget* aNewParent)
{
return NS_OK;
}

nsresult
nsWindow::MakeFullScreen(bool aFullScreen, nsIScreen*)
{
Expand Down
1 change: 0 additions & 1 deletion widget/gonk/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class nsWindow : public nsBaseWidget
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent);

virtual nsresult MakeFullScreen(
bool aFullScreen, nsIScreen* aTargetScreen = nullptr) override;
Expand Down
5 changes: 2 additions & 3 deletions widget/gtk/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ nsWindow::SetParent(nsIWidget *aNewParent)
return NS_OK;
}

NS_IMETHODIMP
void
nsWindow::ReparentNativeWidget(nsIWidget* aNewParent)
{
NS_PRECONDITION(aNewParent, "");
Expand All @@ -883,7 +883,7 @@ nsWindow::ReparentNativeWidget(nsIWidget* aNewParent)
// reparent.
MOZ_ASSERT(gdk_window_is_destroyed(mGdkWindow),
"live GdkWindow with no widget");
return NS_OK;
return;
}
MOZ_ASSERT(!gdk_window_is_destroyed(mGdkWindow),
"destroyed GdkWindow with widget");
Expand All @@ -901,7 +901,6 @@ nsWindow::ReparentNativeWidget(nsIWidget* aNewParent)

ReparentNativeWidgetInternal(aNewParent, newContainer, newParentWindow,
oldContainer);
return NS_OK;
}

void
Expand Down
2 changes: 1 addition & 1 deletion widget/gtk/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class nsWindow : public nsBaseWidget
static already_AddRefed<DrawTarget> GetDrawTargetForGdkDrawable(GdkDrawable* aDrawable,
const mozilla::gfx::IntSize& aSize);
#endif
NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) override;
virtual void ReparentNativeWidget(nsIWidget* aNewParent) override;

virtual nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
uint32_t aNativeMessage,
Expand Down
2 changes: 1 addition & 1 deletion widget/nsBaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference
mBorderStyle & eBorderStyle_title);
}

NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) override = 0;
virtual void ReparentNativeWidget(nsIWidget* aNewParent) override {}

virtual const SizeConstraints GetSizeConstraints() override;
virtual void SetSizeConstraints(const SizeConstraints& aConstraints) override;
Expand Down
2 changes: 1 addition & 1 deletion widget/nsIWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,7 @@ class nsIWidget : public nsISupports
* @param aNewParent the native widget of aNewParent is the new native
* parent widget
*/
NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) = 0;
virtual void ReparentNativeWidget(nsIWidget* aNewParent) = 0;

/**
* Return true if widget has it's own GL context
Expand Down
2 changes: 0 additions & 2 deletions widget/uikit/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ class nsWindow :
void* aCallbackData) override;
*/

NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) override;

protected:
virtual ~nsWindow();
void BringToFront();
Expand Down
6 changes: 0 additions & 6 deletions widget/uikit/nsWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,6 @@ - (void)drawRect:(CGRect)aRect inContext:(CGContextRef)aContext
return NS_OK;
}

NS_IMETHODIMP
nsWindow::ReparentNativeWidget(nsIWidget* aNewParent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsWindow::Show(bool aState)
{
Expand Down
5 changes: 2 additions & 3 deletions widget/windows/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,21 +1048,20 @@ NS_IMETHODIMP nsWindow::SetParent(nsIWidget *aNewParent)
return NS_OK;
}

NS_IMETHODIMP
void
nsWindow::ReparentNativeWidget(nsIWidget* aNewParent)
{
NS_PRECONDITION(aNewParent, "");

mParent = aNewParent;
if (mWindowType == eWindowType_popup) {
return NS_OK;
return;
}
HWND newParent = (HWND)aNewParent->GetNativeData(NS_NATIVE_WINDOW);
NS_ASSERTION(newParent, "Parent widget has a null native window handle");
if (newParent && mWnd) {
::SetParent(mWnd, newParent);
}
return NS_OK;
}

nsIWidget* nsWindow::GetParent(void)
Expand Down
2 changes: 1 addition & 1 deletion widget/windows/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class nsWindow : public nsWindowBase
}
void SetTaskbarPreview(nsITaskbarWindowPreview *preview) { mTaskbarPreview = do_GetWeakReference(preview); }

NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) override;
virtual void ReparentNativeWidget(nsIWidget* aNewParent) override;

// Open file picker tracking
void PickerOpen();
Expand Down

0 comments on commit 5b6fc35

Please sign in to comment.