@@ -2169,7 +2169,7 @@ void nsWindow::LogWindow(nsWindow* win, int index, int indent) {
2169
2169
char spaces[] = " " ;
2170
2170
spaces[indent < 20 ? indent : 20 ] = 0 ;
2171
2171
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 ,
2173
2173
win->mBounds .width , win->mBounds .height , win->mIsVisible ,
2174
2174
int (win->mWindowType ));
2175
2175
int i = 0 ;
@@ -2226,6 +2226,7 @@ nsresult nsWindow::Create(nsIWidget* aParent, const LayoutDeviceIntRect& aRect,
2226
2226
aInitData->mWindowType != WindowType::Invisible);
2227
2227
2228
2228
BaseCreate (aParent, aInitData);
2229
+ mParent = static_cast <nsWindow*>(aParent);
2229
2230
MOZ_ASSERT_IF (!IsTopLevel (), aParent);
2230
2231
2231
2232
if (IsTopLevel ()) {
@@ -2250,17 +2251,23 @@ void nsWindow::Destroy() {
2250
2251
// Stuff below may release the last ref to this
2251
2252
nsCOMPtr<nsIWidget> kungFuDeathGrip (this );
2252
2253
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
+ }
2254
2261
2255
2262
// Ensure the compositor has been shutdown before this nsWindow is potentially
2256
2263
// deleted
2257
2264
nsBaseWidget::DestroyCompositor ();
2258
2265
2259
2266
nsBaseWidget::Destroy ();
2260
2267
2261
- if (IsTopLevel ()) {
2262
- gTopLevelWindows . RemoveElement ( this );
2263
- }
2268
+ if (IsTopLevel ()) gTopLevelWindows . RemoveElement ( this );
2269
+
2270
+ SetParent ( nullptr );
2264
2271
2265
2272
nsBaseWidget::OnDestroy ();
2266
2273
@@ -2304,13 +2311,27 @@ void nsWindow::OnGeckoViewReady() {
2304
2311
acc->OnReady ();
2305
2312
}
2306
2313
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 );
2311
2321
}
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 ();
2312
2331
}
2313
2332
2333
+ nsIWidget* nsWindow::GetParent () { return mParent ; }
2334
+
2314
2335
RefPtr<MozPromise<bool , bool , false >> nsWindow::OnLoadRequest (
2315
2336
nsIURI* aUri, int32_t aWindowType, int32_t aFlags,
2316
2337
nsIPrincipal* aTriggeringPrincipal, bool aHasUserGesture,
@@ -2502,10 +2523,9 @@ void nsWindow::Invalidate(const LayoutDeviceIntRect& aRect) {}
2502
2523
nsWindow* nsWindow::FindTopLevel () {
2503
2524
nsWindow* toplevel = this ;
2504
2525
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 ;
2509
2529
}
2510
2530
2511
2531
ALOG (
@@ -2566,8 +2586,10 @@ LayoutDeviceIntRect nsWindow::GetScreenBounds() {
2566
2586
LayoutDeviceIntPoint nsWindow::WidgetToScreenOffset () {
2567
2587
LayoutDeviceIntPoint p (0 , 0 );
2568
2588
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
+
2571
2593
if (w->IsTopLevel ()) {
2572
2594
break ;
2573
2595
}
@@ -3058,7 +3080,8 @@ nsresult nsWindow::SynthesizeNativeTouchPoint(uint32_t aPointerId,
3058
3080
3059
3081
const auto & npzc = npzcSup->GetJavaNPZC ();
3060
3082
const auto & bounds = FindTopLevel ()->mBounds ;
3061
- aPoint -= bounds.TopLeft ();
3083
+ aPoint.x -= bounds.x ;
3084
+ aPoint.y -= bounds.y ;
3062
3085
3063
3086
DispatchToUiThread (
3064
3087
" nsWindow::SynthesizeNativeTouchPoint" ,
@@ -3083,7 +3106,8 @@ nsresult nsWindow::SynthesizeNativeMouseEvent(
3083
3106
3084
3107
const auto & npzc = npzcSup->GetJavaNPZC ();
3085
3108
const auto & bounds = FindTopLevel ()->mBounds ;
3086
- aPoint -= bounds.TopLeft ();
3109
+ aPoint.x -= bounds.x ;
3110
+ aPoint.y -= bounds.y ;
3087
3111
3088
3112
int32_t nativeMessage;
3089
3113
switch (aNativeMessage) {
0 commit comments