Skip to content

Commit f398144

Browse files
committedOct 22, 2024
Backed out 4 changesets (bug 1924240) for causing failures related to nsBaseWidget. CLOSED TREE
Backed out changeset 4d75277ebe4e (bug 1924240) Backed out changeset 7cec75426e72 (bug 1924240) Backed out changeset 3c9fb8f4a18e (bug 1924240) Backed out changeset 66cf65217104 (bug 1924240)
1 parent 2a44eac commit f398144

18 files changed

+479
-150
lines changed
 

‎view/nsViewManager.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -662,13 +662,21 @@ void nsViewManager::DispatchEvent(WidgetGUIEvent* aEvent, nsView* aView,
662662
void nsViewManager::ReparentChildWidgets(nsView* aView, nsIWidget* aNewWidget) {
663663
MOZ_ASSERT(aNewWidget, "null widget");
664664

665-
if (nsIWidget* widget = aView->GetWidget()) {
665+
if (aView->HasWidget()) {
666666
// Check to see if the parent widget is the
667667
// same as the new parent. If not then reparent
668668
// the widget, otherwise there is nothing more
669669
// to do for the view and its descendants
670-
if (widget->GetParent() != aNewWidget) {
671-
widget->SetParent(aNewWidget);
670+
nsIWidget* widget = aView->GetWidget();
671+
nsIWidget* parentWidget = widget->GetParent();
672+
if (parentWidget) {
673+
// Child widget
674+
if (parentWidget != aNewWidget) {
675+
widget->SetParent(aNewWidget);
676+
}
677+
} else {
678+
// Toplevel widget (popup, dialog, etc)
679+
widget->ReparentNativeWidget(aNewWidget);
672680
}
673681
return;
674682
}

‎widget/PuppetWidget.cpp

+39-2
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,26 @@ PuppetWidget::~PuppetWidget() { Destroy(); }
9696
void PuppetWidget::InfallibleCreate(nsIWidget* aParent,
9797
const LayoutDeviceIntRect& aRect,
9898
widget::InitData* aInitData) {
99-
BaseCreate(aParent, aInitData);
99+
// FIXME(emilio): Why aParent = nullptr? Can we even get here with non-null
100+
// aParent?
101+
BaseCreate(/* aParent = */ nullptr, aInitData);
100102

101103
mBounds = aRect;
102104
mEnabled = true;
103105
mVisible = true;
104106

107+
mDrawTarget = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
108+
IntSize(1, 1), SurfaceFormat::B8G8R8A8);
109+
105110
mNeedIMEStateInit = MightNeedIMEFocus(aInitData);
106111

107-
Resize(mBounds.X(), mBounds.Y(), mBounds.Width(), mBounds.Height(), false);
112+
PuppetWidget* parent = static_cast<PuppetWidget*>(aParent);
113+
if (parent) {
114+
parent->SetChild(this);
115+
mWindowRenderer = parent->GetWindowRenderer();
116+
} else {
117+
Resize(mBounds.X(), mBounds.Y(), mBounds.Width(), mBounds.Height(), false);
118+
}
108119
mMemoryPressureObserver = MemoryPressureObserver::Create(this);
109120
}
110121

@@ -137,6 +148,7 @@ void PuppetWidget::Destroy() {
137148
mMemoryPressureObserver->Unregister();
138149
mMemoryPressureObserver = nullptr;
139150
}
151+
mChild = nullptr;
140152
if (mWindowRenderer) {
141153
mWindowRenderer->Destroy();
142154
}
@@ -151,6 +163,10 @@ void PuppetWidget::Show(bool aState) {
151163
bool wasVisible = mVisible;
152164
mVisible = aState;
153165

166+
if (mChild) {
167+
mChild->mVisible = aState;
168+
}
169+
154170
if (!wasVisible && mVisible) {
155171
// The previously attached widget listener is handy if
156172
// we're transitioning from page to page without dropping
@@ -171,6 +187,11 @@ void PuppetWidget::Resize(double aWidth, double aHeight, bool aRepaint) {
171187
mBounds.SizeTo(
172188
LayoutDeviceIntSize(NSToIntRound(aWidth), NSToIntRound(aHeight)));
173189

190+
if (mChild) {
191+
mChild->Resize(aWidth, aHeight, aRepaint);
192+
return;
193+
}
194+
174195
// XXX: roc says that |aRepaint| dictates whether or not to
175196
// invalidate the expanded area
176197
if (oldBounds.Size() < mBounds.Size() && aRepaint) {
@@ -204,6 +225,11 @@ void PuppetWidget::Invalidate(const LayoutDeviceIntRect& aRect) {
204225
debug_DumpInvalidate(stderr, this, &aRect, "PuppetWidget", 0);
205226
#endif
206227

228+
if (mChild) {
229+
mChild->Invalidate(aRect);
230+
return;
231+
}
232+
207233
if (mBrowserChild && !aRect.IsEmpty() && !mWidgetPaintTask.IsPending()) {
208234
mWidgetPaintTask = new WidgetPaintTask(this);
209235
nsCOMPtr<nsIRunnable> event(mWidgetPaintTask.get());
@@ -236,6 +262,9 @@ nsresult PuppetWidget::DispatchEvent(WidgetGUIEvent* aEvent,
236262
debug_DumpEvent(stdout, aEvent->mWidget, aEvent, "PuppetWidget", 0);
237263
#endif
238264

265+
MOZ_ASSERT(!mChild || mChild->mWindowType == WindowType::Popup,
266+
"Unexpected event dispatch!");
267+
239268
MOZ_ASSERT(!aEvent->AsKeyboardEvent() ||
240269
aEvent->mFlags.mIsSynthesizedForTests ||
241270
aEvent->AsKeyboardEvent()->AreAllEditCommandsInitialized(),
@@ -908,6 +937,14 @@ void PuppetWidget::SetCursor(const Cursor& aCursor) {
908937
mUpdateCursor = false;
909938
}
910939

940+
void PuppetWidget::SetChild(PuppetWidget* aChild) {
941+
MOZ_ASSERT(this != aChild, "can't parent a widget to itself");
942+
MOZ_ASSERT(!aChild->mChild,
943+
"fake widget 'hierarchy' only expected to have one level");
944+
945+
mChild = aChild;
946+
}
947+
911948
NS_IMETHODIMP
912949
PuppetWidget::WidgetPaintTask::Run() {
913950
if (mWidget) {

‎widget/PuppetWidget.h

+8
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ class PuppetWidget final : public nsBaseWidget,
303303
private:
304304
void Paint();
305305

306+
void SetChild(PuppetWidget* aChild);
307+
306308
nsresult RequestIMEToCommitComposition(bool aCancel);
307309
nsresult NotifyIMEOfFocusChange(const IMENotification& aIMENotification);
308310
nsresult NotifyIMEOfSelectionChange(const IMENotification& aIMENotification);
@@ -345,8 +347,14 @@ class PuppetWidget final : public nsBaseWidget,
345347
// it's possible for BrowserChild to outlive the PuppetWidget, we clear
346348
// this weak reference in Destroy()
347349
BrowserChild* mBrowserChild;
350+
// The "widget" to which we delegate events if we don't have an
351+
// event handler.
352+
RefPtr<PuppetWidget> mChild;
348353
nsRevocableEventPtr<WidgetPaintTask> mWidgetPaintTask;
349354
RefPtr<layers::MemoryPressureObserver> mMemoryPressureObserver;
355+
// XXX/cjones: keeping this around until we teach LayerManager to do
356+
// retained-content-only transactions
357+
RefPtr<DrawTarget> mDrawTarget;
350358
// IME
351359
IMENotificationRequests mIMENotificationRequestsOfParent;
352360
InputContext mInputContext;

‎widget/android/nsWindow.cpp

+41-17
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ void nsWindow::LogWindow(nsWindow* win, int index, int indent) {
21692169
char spaces[] = " ";
21702170
spaces[indent < 20 ? indent : 20] = 0;
21712171
ALOG("%s [% 2d] 0x%p [parent 0x%p] [% 3d,% 3dx% 3d,% 3d] vis %d type %d",
2172-
spaces, index, win, win->mParent, win->mBounds.x, win->mBounds.y,
2172+
spaces, index, win, win->mParent.get(), win->mBounds.x, win->mBounds.y,
21732173
win->mBounds.width, win->mBounds.height, win->mIsVisible,
21742174
int(win->mWindowType));
21752175
int i = 0;
@@ -2226,6 +2226,7 @@ nsresult nsWindow::Create(nsIWidget* aParent, const LayoutDeviceIntRect& aRect,
22262226
aInitData->mWindowType != WindowType::Invisible);
22272227

22282228
BaseCreate(aParent, aInitData);
2229+
mParent = static_cast<nsWindow*>(aParent);
22292230
MOZ_ASSERT_IF(!IsTopLevel(), aParent);
22302231

22312232
if (IsTopLevel()) {
@@ -2250,17 +2251,23 @@ void nsWindow::Destroy() {
22502251
// Stuff below may release the last ref to this
22512252
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
22522253

2253-
RemoveAllChildren();
2254+
while (RefPtr<nsWindow> kid = static_cast<nsWindow*>(mLastChild)) {
2255+
// why do we still have children?
2256+
ALOG("### Warning: Destroying window %p and reparenting child %p to null!",
2257+
this, kid.get());
2258+
RemoveChild(kid);
2259+
kid->mParent = nullptr;
2260+
}
22542261

22552262
// Ensure the compositor has been shutdown before this nsWindow is potentially
22562263
// deleted
22572264
nsBaseWidget::DestroyCompositor();
22582265

22592266
nsBaseWidget::Destroy();
22602267

2261-
if (IsTopLevel()) {
2262-
gTopLevelWindows.RemoveElement(this);
2263-
}
2268+
if (IsTopLevel()) gTopLevelWindows.RemoveElement(this);
2269+
2270+
SetParent(nullptr);
22642271

22652272
nsBaseWidget::OnDestroy();
22662273

@@ -2304,13 +2311,27 @@ void nsWindow::OnGeckoViewReady() {
23042311
acc->OnReady();
23052312
}
23062313

2307-
void nsWindow::DidChangeParent(nsIWidget*) {
2308-
// if we are now in the toplevel window's hierarchy, schedule a redraw
2309-
if (FindTopLevel() == nsWindow::TopWindow()) {
2310-
RedrawAll();
2314+
void nsWindow::SetParent(nsIWidget* aNewParent) {
2315+
if (mParent == aNewParent) {
2316+
return;
2317+
}
2318+
2319+
if (mParent) {
2320+
mParent->RemoveChild(this);
23112321
}
2322+
2323+
mParent = static_cast<nsWindow*>(aNewParent);
2324+
2325+
if (mParent) {
2326+
mParent->AddChild(this);
2327+
}
2328+
2329+
// if we are now in the toplevel window's hierarchy, schedule a redraw
2330+
if (FindTopLevel() == nsWindow::TopWindow()) RedrawAll();
23122331
}
23132332

2333+
nsIWidget* nsWindow::GetParent() { return mParent; }
2334+
23142335
RefPtr<MozPromise<bool, bool, false>> nsWindow::OnLoadRequest(
23152336
nsIURI* aUri, int32_t aWindowType, int32_t aFlags,
23162337
nsIPrincipal* aTriggeringPrincipal, bool aHasUserGesture,
@@ -2502,10 +2523,9 @@ void nsWindow::Invalidate(const LayoutDeviceIntRect& aRect) {}
25022523
nsWindow* nsWindow::FindTopLevel() {
25032524
nsWindow* toplevel = this;
25042525
while (toplevel) {
2505-
if (toplevel->IsTopLevel()) {
2506-
return toplevel;
2507-
}
2508-
toplevel = static_cast<nsWindow*>(toplevel->mParent);
2526+
if (toplevel->IsTopLevel()) return toplevel;
2527+
2528+
toplevel = toplevel->mParent;
25092529
}
25102530

25112531
ALOG(
@@ -2566,8 +2586,10 @@ LayoutDeviceIntRect nsWindow::GetScreenBounds() {
25662586
LayoutDeviceIntPoint nsWindow::WidgetToScreenOffset() {
25672587
LayoutDeviceIntPoint p(0, 0);
25682588

2569-
for (nsWindow* w = this; !!w; w = static_cast<nsWindow*>(w->mParent)) {
2570-
p += w->mBounds.TopLeft();
2589+
for (nsWindow* w = this; !!w; w = w->mParent) {
2590+
p.x += w->mBounds.x;
2591+
p.y += w->mBounds.y;
2592+
25712593
if (w->IsTopLevel()) {
25722594
break;
25732595
}
@@ -3058,7 +3080,8 @@ nsresult nsWindow::SynthesizeNativeTouchPoint(uint32_t aPointerId,
30583080

30593081
const auto& npzc = npzcSup->GetJavaNPZC();
30603082
const auto& bounds = FindTopLevel()->mBounds;
3061-
aPoint -= bounds.TopLeft();
3083+
aPoint.x -= bounds.x;
3084+
aPoint.y -= bounds.y;
30623085

30633086
DispatchToUiThread(
30643087
"nsWindow::SynthesizeNativeTouchPoint",
@@ -3083,7 +3106,8 @@ nsresult nsWindow::SynthesizeNativeMouseEvent(
30833106

30843107
const auto& npzc = npzcSup->GetJavaNPZC();
30853108
const auto& bounds = FindTopLevel()->mBounds;
3086-
aPoint -= bounds.TopLeft();
3109+
aPoint.x -= bounds.x;
3110+
aPoint.y -= bounds.y;
30873111

30883112
int32_t nativeMessage;
30893113
switch (aNativeMessage) {

‎widget/android/nsWindow.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class nsWindow final : public nsBaseWidget {
7171
bool aIsTopLevel);
7272

7373
private:
74+
RefPtr<nsWindow> mParent;
7475
nsCOMPtr<nsIUserIdleServiceInternal> mIdleService;
7576
mozilla::ScreenIntCoord mDynamicToolbarMaxHeight{0};
7677
mozilla::ScreenIntMargin mSafeAreaInsets;
@@ -158,7 +159,8 @@ class nsWindow final : public nsBaseWidget {
158159
const LayoutDeviceIntRect& aRect,
159160
InitData* aInitData) override;
160161
void Destroy() override;
161-
void DidChangeParent(nsIWidget* aNewParent) override;
162+
void SetParent(nsIWidget* aNewParent) override;
163+
nsIWidget* GetParent(void) override;
162164
float GetDPI() override;
163165
double GetDefaultScaleInternal() override;
164166
void Show(bool aState) override;

‎widget/cocoa/nsChildView.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ class nsChildView final : public nsBaseWidget {
304304
void Show(bool aState) override;
305305
bool IsVisible() const override;
306306

307+
void SetParent(nsIWidget* aNewParent) override;
308+
nsIWidget* GetParent() override;
307309
float GetDPI() override;
308310

309311
void Move(double aX, double aY) override;
@@ -461,6 +463,8 @@ class nsChildView final : public nsBaseWidget {
461463
const bool aIsVertical,
462464
const LayoutDeviceIntPoint& aPoint) override;
463465

466+
void ResetParent();
467+
464468
static bool DoHasPendingInputEvent();
465469
static uint32_t GetCurrentInputEventCount();
466470
static void UpdateCurrentInputEventCount();
@@ -469,7 +473,7 @@ class nsChildView final : public nsBaseWidget {
469473

470474
nsCocoaWindow* GetAppWindowWidget() const;
471475

472-
void DidChangeParent(nsIWidget*) override;
476+
void ReparentNativeWidget(nsIWidget* aNewParent) override;
473477

474478
mozilla::widget::TextInputHandler* GetTextInputHandler() {
475479
return mTextInputHandler;
@@ -558,6 +562,7 @@ class nsChildView final : public nsBaseWidget {
558562
InputContext mInputContext;
559563

560564
NSView* mParentView;
565+
nsCOMPtr<nsIWidget> mParentWidget;
561566

562567
#ifdef ACCESSIBILITY
563568
// weak ref to this childview's associated mozAccessible for speed reasons

0 commit comments

Comments
 (0)
Failed to load comments.