@@ -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 . get () , win->mBounds .x , win->mBounds .y ,
2172
+ spaces, index , win, win->mParent , 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,7 +2226,6 @@ 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);
2230
2229
MOZ_ASSERT_IF (!IsTopLevel (), aParent);
2231
2230
2232
2231
if (IsTopLevel ()) {
@@ -2251,23 +2250,17 @@ void nsWindow::Destroy() {
2251
2250
// Stuff below may release the last ref to this
2252
2251
nsCOMPtr<nsIWidget> kungFuDeathGrip (this );
2253
2252
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
- }
2253
+ RemoveAllChildren ();
2261
2254
2262
2255
// Ensure the compositor has been shutdown before this nsWindow is potentially
2263
2256
// deleted
2264
2257
nsBaseWidget::DestroyCompositor ();
2265
2258
2266
2259
nsBaseWidget::Destroy ();
2267
2260
2268
- if (IsTopLevel ()) gTopLevelWindows . RemoveElement ( this );
2269
-
2270
- SetParent ( nullptr );
2261
+ if (IsTopLevel ()) {
2262
+ gTopLevelWindows . RemoveElement ( this );
2263
+ }
2271
2264
2272
2265
nsBaseWidget::OnDestroy ();
2273
2266
@@ -2311,27 +2304,13 @@ void nsWindow::OnGeckoViewReady() {
2311
2304
acc->OnReady ();
2312
2305
}
2313
2306
2314
- void nsWindow::SetParent (nsIWidget* aNewParent) {
2315
- if (mParent == aNewParent) {
2316
- return ;
2317
- }
2318
-
2319
- if (mParent ) {
2320
- mParent ->RemoveChild (this );
2321
- }
2322
-
2323
- mParent = static_cast <nsWindow*>(aNewParent);
2324
-
2325
- if (mParent ) {
2326
- mParent ->AddChild (this );
2327
- }
2328
-
2307
+ void nsWindow::DidChangeParent (nsIWidget*) {
2329
2308
// if we are now in the toplevel window's hierarchy, schedule a redraw
2330
- if (FindTopLevel () == nsWindow::TopWindow ()) RedrawAll ();
2309
+ if (FindTopLevel () == nsWindow::TopWindow ()) {
2310
+ RedrawAll ();
2311
+ }
2331
2312
}
2332
2313
2333
- nsIWidget* nsWindow::GetParent () { return mParent ; }
2334
-
2335
2314
RefPtr<MozPromise<bool , bool , false >> nsWindow::OnLoadRequest (
2336
2315
nsIURI* aUri, int32_t aWindowType, int32_t aFlags,
2337
2316
nsIPrincipal* aTriggeringPrincipal, bool aHasUserGesture,
@@ -2523,9 +2502,10 @@ void nsWindow::Invalidate(const LayoutDeviceIntRect& aRect) {}
2523
2502
nsWindow* nsWindow::FindTopLevel () {
2524
2503
nsWindow* toplevel = this ;
2525
2504
while (toplevel) {
2526
- if (toplevel->IsTopLevel ()) return toplevel;
2527
-
2528
- toplevel = toplevel->mParent ;
2505
+ if (toplevel->IsTopLevel ()) {
2506
+ return toplevel;
2507
+ }
2508
+ toplevel = static_cast <nsWindow*>(toplevel->mParent );
2529
2509
}
2530
2510
2531
2511
ALOG (
@@ -2586,10 +2566,8 @@ LayoutDeviceIntRect nsWindow::GetScreenBounds() {
2586
2566
LayoutDeviceIntPoint nsWindow::WidgetToScreenOffset () {
2587
2567
LayoutDeviceIntPoint p (0 , 0 );
2588
2568
2589
- for (nsWindow* w = this ; !!w; w = w->mParent ) {
2590
- p.x += w->mBounds .x ;
2591
- p.y += w->mBounds .y ;
2592
-
2569
+ for (nsWindow* w = this ; !!w; w = static_cast <nsWindow*>(w->mParent )) {
2570
+ p += w->mBounds .TopLeft ();
2593
2571
if (w->IsTopLevel ()) {
2594
2572
break ;
2595
2573
}
@@ -3080,8 +3058,7 @@ nsresult nsWindow::SynthesizeNativeTouchPoint(uint32_t aPointerId,
3080
3058
3081
3059
const auto & npzc = npzcSup->GetJavaNPZC ();
3082
3060
const auto & bounds = FindTopLevel ()->mBounds ;
3083
- aPoint.x -= bounds.x ;
3084
- aPoint.y -= bounds.y ;
3061
+ aPoint -= bounds.TopLeft ();
3085
3062
3086
3063
DispatchToUiThread (
3087
3064
" nsWindow::SynthesizeNativeTouchPoint" ,
@@ -3106,8 +3083,7 @@ nsresult nsWindow::SynthesizeNativeMouseEvent(
3106
3083
3107
3084
const auto & npzc = npzcSup->GetJavaNPZC ();
3108
3085
const auto & bounds = FindTopLevel ()->mBounds ;
3109
- aPoint.x -= bounds.x ;
3110
- aPoint.y -= bounds.y ;
3086
+ aPoint -= bounds.TopLeft ();
3111
3087
3112
3088
int32_t nativeMessage;
3113
3089
switch (aNativeMessage) {
0 commit comments