Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 9a77da4

Browse files
committed
Bug 1922956 - Further clean-up widget creation code-paths. r=win-reviewers,mac-reviewers,geckoview-reviewers,mstange,rkraesig,m_kato
This is all super-hacky (see a lot of the XXXcjones comments). Simplify it... We never create widgets with a bare native parent but no nsIWidget parent. Pass nsIWidgets and deal with things correctly. There were also things that were dealing with stuff that can't happen, like top level popups, children of PuppetWidgets, or such. Instead of overriding Create(), let's just teach nsBaseWidget about non-native (headless/puppet) widgets. Remove lots of old APIs for the native window stuff that are unused and/or unimplemented. Differential Revision: https://phabricator.services.mozilla.com/D224613
1 parent 1aeb6b3 commit 9a77da4

36 files changed

Lines changed: 164 additions & 445 deletions

docshell/base/nsDocShell.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4322,13 +4322,11 @@ bool nsDocShell::FillLoadStateFromCurrentEntry(
43224322
//*****************************************************************************
43234323

43244324
NS_IMETHODIMP
4325-
nsDocShell::InitWindow(nativeWindow aParentNativeWindow,
4326-
nsIWidget* aParentWidget, int32_t aX, int32_t aY,
4325+
nsDocShell::InitWindow(nsIWidget* aParentWidget, int32_t aX, int32_t aY,
43274326
int32_t aWidth, int32_t aHeight) {
43284327
SetParentWidget(aParentWidget);
43294328
SetPositionAndSize(aX, aY, aWidth, aHeight, 0);
43304329
NS_ENSURE_TRUE(Initialize(), NS_ERROR_FAILURE);
4331-
43324330
return NS_OK;
43334331
}
43344332

@@ -4610,24 +4608,6 @@ nsDocShell::SetParentWidget(nsIWidget* aParentWidget) {
46104608
return NS_OK;
46114609
}
46124610

4613-
NS_IMETHODIMP
4614-
nsDocShell::GetParentNativeWindow(nativeWindow* aParentNativeWindow) {
4615-
NS_ENSURE_ARG_POINTER(aParentNativeWindow);
4616-
4617-
if (mParentWidget) {
4618-
*aParentNativeWindow = mParentWidget->GetNativeData(NS_NATIVE_WIDGET);
4619-
} else {
4620-
*aParentNativeWindow = nullptr;
4621-
}
4622-
4623-
return NS_OK;
4624-
}
4625-
4626-
NS_IMETHODIMP
4627-
nsDocShell::SetParentNativeWindow(nativeWindow aParentNativeWindow) {
4628-
return NS_ERROR_NOT_IMPLEMENTED;
4629-
}
4630-
46314611
NS_IMETHODIMP
46324612
nsDocShell::GetNativeHandle(nsAString& aNativeHandle) {
46334613
// the nativeHandle should be accessed from nsIAppWindow

docshell/base/nsDocShellTreeOwner.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,7 @@ nsDocShellTreeOwner::GetHasPrimaryContent(bool* aResult) {
505505
//*****************************************************************************
506506

507507
NS_IMETHODIMP
508-
nsDocShellTreeOwner::InitWindow(nativeWindow aParentNativeWindow,
509-
nsIWidget* aParentWidget, int32_t aX,
508+
nsDocShellTreeOwner::InitWindow(nsIWidget* aParentWidget, int32_t aX,
510509
int32_t aY, int32_t aCX, int32_t aCY) {
511510
return NS_ERROR_NULL_POINTER;
512511
}
@@ -623,20 +622,6 @@ nsDocShellTreeOwner::SetParentWidget(nsIWidget* aParentWidget) {
623622
return NS_ERROR_NULL_POINTER;
624623
}
625624

626-
NS_IMETHODIMP
627-
nsDocShellTreeOwner::GetParentNativeWindow(nativeWindow* aParentNativeWindow) {
628-
nsCOMPtr<nsIBaseWindow> ownerWin = GetOwnerWin();
629-
if (ownerWin) {
630-
return ownerWin->GetParentNativeWindow(aParentNativeWindow);
631-
}
632-
return NS_ERROR_NULL_POINTER;
633-
}
634-
635-
NS_IMETHODIMP
636-
nsDocShellTreeOwner::SetParentNativeWindow(nativeWindow aParentNativeWindow) {
637-
return NS_ERROR_NULL_POINTER;
638-
}
639-
640625
NS_IMETHODIMP
641626
nsDocShellTreeOwner::GetNativeHandle(nsAString& aNativeHandle) {
642627
// the nativeHandle should be accessed from nsIAppWindow

dom/base/nsFrameLoader.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,7 @@ bool nsFrameLoader::Show(nsSubDocumentFrame* aFrame) {
10041004
}
10051005

10061006
RefPtr<nsDocShell> baseWindow = GetDocShell();
1007-
baseWindow->InitWindow(nullptr, view->GetWidget(), 0, 0, size.width,
1008-
size.height);
1007+
baseWindow->InitWindow(view->GetWidget(), 0, 0, size.width, size.height);
10091008
baseWindow->SetVisibility(true);
10101009
NS_ENSURE_TRUE(GetDocShell(), false);
10111010

dom/ipc/BrowserChild.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@ nsresult BrowserChild::Init(mozIDOMWindowProxy* aParent,
391391
NS_ERROR("couldn't create fake widget");
392392
return NS_ERROR_FAILURE;
393393
}
394-
mPuppetWidget->InfallibleCreate(nullptr,
395-
nullptr, // no parents
394+
mPuppetWidget->InfallibleCreate(nullptr, // No parent
396395
LayoutDeviceIntRect(0, 0, 0, 0),
397396
nullptr); // HandleWidgetEvent
398397

gfx/tests/gtest/MockWidget.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@ class MockWidget : public nsBaseWidget {
4747
return nullptr;
4848
}
4949

50-
virtual nsresult Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
51-
const LayoutDeviceIntRect& aRect,
50+
virtual nsresult Create(nsIWidget* aParent, const LayoutDeviceIntRect& aRect,
5251
InitData* aInitData = nullptr) override {
5352
return NS_OK;
5453
}
55-
virtual nsresult Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
56-
const DesktopIntRect& aRect,
54+
virtual nsresult Create(nsIWidget* aParent, const DesktopIntRect& aRect,
5755
InitData* aInitData = nullptr) override {
5856
return NS_OK;
5957
}

layout/base/PresShell.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10590,7 +10590,7 @@ bool PresShell::VerifyIncrementalReflow() {
1059010590
NS_ENSURE_TRUE(view, false);
1059110591

1059210592
// now create the widget for the view
10593-
rv = view->CreateWidgetForParent(parentWidget, true);
10593+
rv = view->CreateWidget(parentWidget, true);
1059410594
NS_ENSURE_SUCCESS(rv, false);
1059510595

1059610596
// Setup hierarchical relationship in view manager

layout/base/nsDocumentViewer.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,10 +2245,8 @@ nsresult nsDocumentViewer::MakeWindow(const nsSize& aSize,
22452245
// Reuse the top level parent widget.
22462246
rv = view->AttachToTopLevelWidget(mParentWidget);
22472247
mAttachedToParent = true;
2248-
} else if (!mParentWidget || aContainerView) {
2249-
rv = view->CreateWidget(true, false);
22502248
} else {
2251-
rv = view->CreateWidgetForParent(mParentWidget, true, false);
2249+
rv = view->CreateWidget(mParentWidget, true, false);
22522250
}
22532251
if (NS_FAILED(rv)) return rv;
22542252
}
@@ -3234,7 +3232,7 @@ bool nsDocumentViewer::ShouldAttachToTopLevel() {
32343232
}
32353233

32363234
// We always attach when using puppet widgets
3237-
if (nsIWidget::UsePuppetWidgets()) {
3235+
if (nsIWidget::UsePuppetWidgets() || mParentWidget->IsPuppetWidget()) {
32383236
return true;
32393237
}
32403238

toolkit/components/browser/nsWebBrowser.cpp

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ nsWebBrowser::nsWebBrowser(int aItemType)
5959
: mContentType(aItemType),
6060
mShouldEnableHistory(true),
6161
mWillChangeProcess(false),
62-
mParentNativeWindow(nullptr),
6362
mProgressListener(nullptr),
6463
mWidgetListenerDelegate(this),
6564
mBackgroundColor(0),
@@ -89,8 +88,7 @@ nsIWidget* nsWebBrowser::EnsureWidget() {
8988
LayoutDeviceIntRect bounds(0, 0, 0, 0);
9089

9190
mInternalWidget->SetWidgetListener(&mWidgetListenerDelegate);
92-
NS_ENSURE_SUCCESS(mInternalWidget->Create(nullptr, mParentNativeWindow,
93-
bounds, &widgetInit),
91+
NS_ENSURE_SUCCESS(mInternalWidget->Create(mParentWidget, bounds, &widgetInit),
9492
nullptr);
9593

9694
return mInternalWidget;
@@ -149,8 +147,7 @@ already_AddRefed<nsWebBrowser> nsWebBrowser::Create(
149147
// events from subframes. To solve that we install our own chrome event
150148
// handler that always gets called (even for subframes) for any bubbling
151149
// event.
152-
153-
nsresult rv = docShell->InitWindow(nullptr, docShellParentWidget, 0, 0, 0, 0);
150+
nsresult rv = docShell->InitWindow(docShellParentWidget, 0, 0, 0, 0);
154151
if (NS_WARN_IF(NS_FAILED(rv))) {
155152
return nullptr;
156153
}
@@ -860,8 +857,7 @@ nsWebBrowser::Cancel(nsresult aReason) {
860857
//*****************************************************************************
861858

862859
NS_IMETHODIMP
863-
nsWebBrowser::InitWindow(nativeWindow aParentNativeWindow,
864-
nsIWidget* aParentWidget, int32_t aX, int32_t aY,
860+
nsWebBrowser::InitWindow(nsIWidget* aParentWidget, int32_t aX, int32_t aY,
865861
int32_t aCX, int32_t aCY) {
866862
// nsIBaseWindow::InitWindow and nsIBaseWindow::Create
867863
// implementations have been merged into nsWebBrowser::Create
@@ -1013,32 +1009,7 @@ nsWebBrowser::GetParentWidget(nsIWidget** aParentWidget) {
10131009
NS_IMETHODIMP
10141010
nsWebBrowser::SetParentWidget(nsIWidget* aParentWidget) {
10151011
NS_ENSURE_STATE(!mDocShell);
1016-
10171012
mParentWidget = aParentWidget;
1018-
if (mParentWidget) {
1019-
mParentNativeWindow = mParentWidget->GetNativeData(NS_NATIVE_WIDGET);
1020-
} else {
1021-
mParentNativeWindow = nullptr;
1022-
}
1023-
1024-
return NS_OK;
1025-
}
1026-
1027-
NS_IMETHODIMP
1028-
nsWebBrowser::GetParentNativeWindow(nativeWindow* aParentNativeWindow) {
1029-
NS_ENSURE_ARG_POINTER(aParentNativeWindow);
1030-
1031-
*aParentNativeWindow = mParentNativeWindow;
1032-
1033-
return NS_OK;
1034-
}
1035-
1036-
NS_IMETHODIMP
1037-
nsWebBrowser::SetParentNativeWindow(nativeWindow aParentNativeWindow) {
1038-
NS_ENSURE_STATE(!mDocShell);
1039-
1040-
mParentNativeWindow = aParentNativeWindow;
1041-
10421013
return NS_OK;
10431014
}
10441015

toolkit/components/browser/nsWebBrowser.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ class nsWebBrowser final : public nsIWebBrowser,
141141
const uint32_t mContentType;
142142
bool mShouldEnableHistory;
143143
bool mWillChangeProcess;
144-
nativeWindow mParentNativeWindow;
145144
nsIWebProgressListener* mProgressListener;
146145

147146
nsCOMPtr<nsIPrintSettings> mPrintSettings;

view/nsView.cpp

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -502,43 +502,23 @@ struct DefaultWidgetInitData : public widget::InitData {
502502
}
503503
};
504504

505-
nsresult nsView::CreateWidget(bool aEnableDragDrop, bool aResetVisibility) {
505+
nsresult nsView::CreateWidget(nsIWidget* aParent, bool aEnableDragDrop,
506+
bool aResetVisibility) {
506507
AssertNoWindow();
507508

508509
DefaultWidgetInitData initData;
509510
LayoutDeviceIntRect trect =
510511
CalcWidgetBounds(initData.mWindowType, initData.mTransparencyMode);
511512

512-
nsIWidget* parentWidget =
513-
GetParent() ? GetParent()->GetNearestWidget(nullptr) : nullptr;
514-
if (!parentWidget) {
513+
if (!aParent && GetParent()) {
514+
aParent = GetParent()->GetNearestWidget(nullptr);
515+
}
516+
if (!aParent) {
515517
NS_ERROR("nsView::CreateWidget without suitable parent widget??");
516518
return NS_ERROR_FAILURE;
517519
}
518520

519-
// XXX: using aForceUseIWidgetParent=true to preserve previous
520-
// semantics. It's not clear that it's actually needed.
521-
mWindow = parentWidget->CreateChild(trect, &initData, true);
522-
if (!mWindow) {
523-
return NS_ERROR_FAILURE;
524-
}
525-
526-
InitializeWindow(aEnableDragDrop, aResetVisibility);
527-
528-
return NS_OK;
529-
}
530-
531-
nsresult nsView::CreateWidgetForParent(nsIWidget* aParentWidget,
532-
bool aEnableDragDrop,
533-
bool aResetVisibility) {
534-
AssertNoWindow();
535-
MOZ_ASSERT(aParentWidget, "Parent widget required");
536-
537-
DefaultWidgetInitData initData;
538-
LayoutDeviceIntRect trect =
539-
CalcWidgetBounds(initData.mWindowType, initData.mTransparencyMode);
540-
541-
mWindow = aParentWidget->CreateChild(trect, &initData);
521+
mWindow = aParent->CreateChild(trect, initData);
542522
if (!mWindow) {
543523
return NS_ERROR_FAILURE;
544524
}
@@ -549,7 +529,7 @@ nsresult nsView::CreateWidgetForParent(nsIWidget* aParentWidget,
549529
}
550530

551531
nsresult nsView::CreateWidgetForPopup(widget::InitData* aWidgetInitData,
552-
nsIWidget* aParentWidget) {
532+
nsIWidget* aParent) {
553533
AssertNoWindow();
554534
MOZ_ASSERT(aWidgetInitData, "Widget init data required");
555535
MOZ_ASSERT(aWidgetInitData->mWindowType == WindowType::Popup,
@@ -558,31 +538,20 @@ nsresult nsView::CreateWidgetForPopup(widget::InitData* aWidgetInitData,
558538
LayoutDeviceIntRect trect = CalcWidgetBounds(
559539
aWidgetInitData->mWindowType, aWidgetInitData->mTransparencyMode);
560540

561-
// XXX/cjones: having these two separate creation cases seems ... um
562-
// ... unnecessary, but it's the way the old code did it. Please
563-
// unify them by first finding a suitable parent nsIWidget, then
564-
// getting rid of aForceUseIWidgetParent.
565-
if (aParentWidget) {
566-
// XXX: using aForceUseIWidgetParent=true to preserve previous
567-
// semantics. It's not clear that it's actually needed.
568-
mWindow = aParentWidget->CreateChild(trect, aWidgetInitData, true);
569-
} else {
570-
nsIWidget* nearestParent =
571-
GetParent() ? GetParent()->GetNearestWidget(nullptr) : nullptr;
572-
if (!nearestParent) {
573-
// Without a parent, we can't make a popup. This can happen
574-
// when printing
575-
return NS_ERROR_FAILURE;
576-
}
577-
578-
mWindow = nearestParent->CreateChild(trect, aWidgetInitData);
541+
if (!aParent && GetParent()) {
542+
aParent = GetParent()->GetNearestWidget(nullptr);
543+
}
544+
if (!aParent) {
545+
NS_ERROR("nsView::CreateWidgetForPopup without suitable parent widget??");
546+
// Without a parent, we can't make a popup. This used to be able to happen
547+
// when printing, apparently.
548+
return NS_ERROR_FAILURE;
579549
}
550+
mWindow = aParent->CreateChild(trect, *aWidgetInitData);
580551
if (!mWindow) {
581552
return NS_ERROR_FAILURE;
582553
}
583-
584554
InitializeWindow(/* aEnableDragDrop = */ true, /* aResetVisibility = */ true);
585-
586555
return NS_OK;
587556
}
588557

0 commit comments

Comments
 (0)