From 6487a8b3abbc302a0c2be5d1705231417e433a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 29 Apr 2025 14:04:53 +0000 Subject: [PATCH] Bug 1919165 - Remove support for WindowType::Child, which is now unused. r=stransky We don't take this codepath anymore in any platform. Windows and GTK were already asserting against it. Differential Revision: https://phabricator.services.mozilla.com/D245640 --- layout/base/nsLayoutUtils.cpp | 27 +---- toolkit/components/browser/nsWebBrowser.cpp | 127 +------------------- toolkit/components/browser/nsWebBrowser.h | 28 ----- view/nsView.cpp | 1 - widget/InitData.h | 7 +- widget/cocoa/nsCocoaWindow.mm | 7 -- widget/gtk/nsWindow.cpp | 3 - widget/nsBaseWidget.cpp | 13 +- widget/nsIWidget.h | 2 +- widget/windows/nsWindow.cpp | 9 -- 10 files changed, 15 insertions(+), 209 deletions(-) diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index e27a14426155..c16dac217e49 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -2405,33 +2405,10 @@ nsRect nsLayoutUtils::TransformFrameRectToAncestor( NSFloatPixelsToAppUnits(float(result.height), destAppUnitsPerDevPixel)); } -static LayoutDeviceIntPoint GetWidgetOffset(nsIWidget* aWidget, - nsIWidget*& aRootWidget) { - LayoutDeviceIntPoint offset(0, 0); - while (aWidget->GetWindowType() == widget::WindowType::Child) { - nsIWidget* parent = aWidget->GetParent(); - if (!parent) { - break; - } - LayoutDeviceIntRect bounds = aWidget->GetBounds(); - offset += bounds.TopLeft(); - aWidget = parent; - } - aRootWidget = aWidget; - return offset; -} - LayoutDeviceIntPoint nsLayoutUtils::WidgetToWidgetOffset(nsIWidget* aFrom, nsIWidget* aTo) { - nsIWidget* fromRoot; - LayoutDeviceIntPoint fromOffset = GetWidgetOffset(aFrom, fromRoot); - nsIWidget* toRoot; - LayoutDeviceIntPoint toOffset = GetWidgetOffset(aTo, toRoot); - - if (fromRoot != toRoot) { - fromOffset = aFrom->WidgetToScreenOffset(); - toOffset = aTo->WidgetToScreenOffset(); - } + auto fromOffset = aFrom->WidgetToScreenOffset(); + auto toOffset = aTo->WidgetToScreenOffset(); return fromOffset - toOffset; } diff --git a/toolkit/components/browser/nsWebBrowser.cpp b/toolkit/components/browser/nsWebBrowser.cpp index 17cc7a6bbbac..fbeb39f99f98 100644 --- a/toolkit/components/browser/nsWebBrowser.cpp +++ b/toolkit/components/browser/nsWebBrowser.cpp @@ -60,7 +60,6 @@ nsWebBrowser::nsWebBrowser(int aItemType) mShouldEnableHistory(true), mWillChangeProcess(false), mProgressListener(nullptr), - mWidgetListenerDelegate(this), mBackgroundColor(0), mPersistCurrentState(nsIWebBrowserPersist::PERSIST_STATE_READY), mPersistResult(NS_OK), @@ -73,25 +72,8 @@ nsWebBrowser::nsWebBrowser(int aItemType) nsWebBrowser::~nsWebBrowser() { InternalDestroy(); } nsIWidget* nsWebBrowser::EnsureWidget() { - if (mParentWidget) { - return mParentWidget; - } - - mInternalWidget = nsIWidget::CreateChildWindow(); - if (NS_WARN_IF(!mInternalWidget)) { - return nullptr; - } - - widget::InitData widgetInit; - widgetInit.mClipChildren = true; - widgetInit.mWindowType = widget::WindowType::Child; - LayoutDeviceIntRect bounds(0, 0, 0, 0); - - mInternalWidget->SetWidgetListener(&mWidgetListenerDelegate); - NS_ENSURE_SUCCESS(mInternalWidget->Create(mParentWidget, bounds, &widgetInit), - nullptr); - - return mInternalWidget; + MOZ_DIAGNOSTIC_ASSERT(mParentWidget); + return mParentWidget; } /* static */ @@ -163,12 +145,6 @@ already_AddRefed nsWebBrowser::Create( } void nsWebBrowser::InternalDestroy() { - if (mInternalWidget) { - mInternalWidget->SetWidgetListener(nullptr); - mInternalWidget->Destroy(); - mInternalWidget = nullptr; // Force release here. - } - SetDocShell(nullptr); if (mDocShellTreeOwner) { @@ -941,14 +917,7 @@ nsWebBrowser::SetPositionAndSize(int32_t aX, int32_t aY, int32_t aCX, int32_t doc_x = aX; int32_t doc_y = aY; - // If there is an internal widget we need to make the docShell coordinates - // relative to the internal widget rather than the calling app's parent. // We also need to resize our widget then. - if (mInternalWidget) { - doc_x = doc_y = 0; - mInternalWidget->Resize(aX, aY, aCX, aCY, - !!(aFlags & nsIBaseWindow::eRepaint)); - } // Now reposition/ resize the doc NS_ENSURE_SUCCESS( mDocShell->SetPositionAndSize(doc_x, doc_y, aCX, aCY, aFlags), @@ -960,24 +929,6 @@ nsWebBrowser::SetPositionAndSize(int32_t aX, int32_t aY, int32_t aCX, NS_IMETHODIMP nsWebBrowser::GetPositionAndSize(int32_t* aX, int32_t* aY, int32_t* aCX, int32_t* aCY) { - if (mInternalWidget) { - LayoutDeviceIntRect bounds = mInternalWidget->GetBounds(); - - if (aX) { - *aX = bounds.X(); - } - if (aY) { - *aY = bounds.Y(); - } - if (aCX) { - *aCX = bounds.Width(); - } - if (aCY) { - *aCY = bounds.Height(); - } - return NS_OK; - } - // Can directly return this as it is the // same interface, thus same returns. return mDocShell->GetPositionAndSize(aX, aY, aCX, aCY); @@ -1041,9 +992,6 @@ NS_IMETHODIMP nsWebBrowser::SetVisibility(bool aVisibility) { if (mDocShell) { NS_ENSURE_SUCCESS(mDocShell->SetVisibility(aVisibility), NS_ERROR_FAILURE); - if (mInternalWidget) { - mInternalWidget->Show(aVisibility); - } } return NS_OK; @@ -1051,35 +999,18 @@ nsWebBrowser::SetVisibility(bool aVisibility) { NS_IMETHODIMP nsWebBrowser::GetEnabled(bool* aEnabled) { - if (mInternalWidget) { - *aEnabled = mInternalWidget->IsEnabled(); - return NS_OK; - } - return NS_ERROR_FAILURE; } NS_IMETHODIMP nsWebBrowser::SetEnabled(bool aEnabled) { - if (mInternalWidget) { - mInternalWidget->Enable(aEnabled); - return NS_OK; - } return NS_ERROR_FAILURE; } NS_IMETHODIMP nsWebBrowser::GetMainWidget(nsIWidget** aMainWidget) { NS_ENSURE_ARG_POINTER(aMainWidget); - - if (mInternalWidget) { - *aMainWidget = mInternalWidget; - } else { - *aMainWidget = mParentWidget; - } - - NS_IF_ADDREF(*aMainWidget); - + NS_IF_ADDREF(*aMainWidget = mParentWidget); return NS_OK; } @@ -1143,42 +1074,6 @@ void nsWebBrowser::EnsureDocShellTreeOwner() { mDocShellTreeOwner->WebBrowser(this); } -void nsWebBrowser::WindowActivated() { -#if defined(DEBUG_smaug) - RefPtr document = mDocShell->GetDocument(); - nsAutoString documentURI; - document->GetDocumentURI(documentURI); - printf("nsWebBrowser::NS_ACTIVATE %p %s\n", (void*)this, - NS_ConvertUTF16toUTF8(documentURI).get()); -#endif - FocusActivate(nsFocusManager::GenerateFocusActionId()); -} - -void nsWebBrowser::WindowDeactivated() { -#if defined(DEBUG_smaug) - RefPtr document = mDocShell->GetDocument(); - nsAutoString documentURI; - document->GetDocumentURI(documentURI); - printf("nsWebBrowser::NS_DEACTIVATE %p %s\n", (void*)this, - NS_ConvertUTF16toUTF8(documentURI).get()); -#endif - FocusDeactivate(nsFocusManager::GenerateFocusActionId()); -} - -bool nsWebBrowser::PaintWindow(nsIWidget* aWidget, - LayoutDeviceIntRegion aRegion) { - WindowRenderer* renderer = aWidget->GetWindowRenderer(); - NS_ASSERTION(renderer, "Must be in paint event"); - if (FallbackRenderer* fallback = renderer->AsFallback()) { - if (fallback->BeginTransaction()) { - fallback->EndTransactionWithColor(aRegion.GetBounds().ToUnknownRect(), - ToDeviceColor(mBackgroundColor)); - } - return true; - } - return false; -} - void nsWebBrowser::FocusActivate(uint64_t aActionId) { if (RefPtr fm = nsFocusManager::GetFocusManager()) { if (nsCOMPtr window = GetWindow()) { @@ -1201,19 +1096,3 @@ void nsWebBrowser::SetWillChangeProcess() { nsDocShell::Cast(mDocShell)->SetWillChangeProcess(); } } - -void nsWebBrowser::WidgetListenerDelegate::WindowActivated() { - RefPtr holder = mWebBrowser; - holder->WindowActivated(); -} - -void nsWebBrowser::WidgetListenerDelegate::WindowDeactivated() { - RefPtr holder = mWebBrowser; - holder->WindowDeactivated(); -} - -bool nsWebBrowser::WidgetListenerDelegate::PaintWindow( - nsIWidget* aWidget, mozilla::LayoutDeviceIntRegion aRegion) { - RefPtr holder = mWebBrowser; - return holder->PaintWindow(aWidget, aRegion); -} diff --git a/toolkit/components/browser/nsWebBrowser.h b/toolkit/components/browser/nsWebBrowser.h index 6b032f2a57d8..eee526d1e905 100644 --- a/toolkit/components/browser/nsWebBrowser.h +++ b/toolkit/components/browser/nsWebBrowser.h @@ -72,24 +72,6 @@ class nsWebBrowser final : public nsIWebBrowser, friend class nsDocShellTreeOwner; public: - // The implementation of non-refcounted nsIWidgetListener, which would hold a - // strong reference on stack before calling nsWebBrowser's - // MOZ_CAN_RUN_SCRIPT methods. - class WidgetListenerDelegate : public nsIWidgetListener { - public: - explicit WidgetListenerDelegate(nsWebBrowser* aWebBrowser) - : mWebBrowser(aWebBrowser) {} - MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void WindowActivated() override; - MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void WindowDeactivated() override; - MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual bool PaintWindow( - nsIWidget* aWidget, mozilla::LayoutDeviceIntRegion aRegion) override; - - private: - // The lifetime of WidgetListenerDelegate is bound to nsWebBrowser so we - // just use raw pointer here. - nsWebBrowser* mWebBrowser; - }; - NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsWebBrowser, nsIWebBrowser) @@ -122,13 +104,6 @@ class nsWebBrowser final : public nsIWebBrowser, void EnsureDocShellTreeOwner(); nsIWidget* EnsureWidget(); - - // nsIWidgetListener methods for WidgetListenerDelegate. - MOZ_CAN_RUN_SCRIPT void WindowActivated(); - MOZ_CAN_RUN_SCRIPT void WindowDeactivated(); - MOZ_CAN_RUN_SCRIPT bool PaintWindow(nsIWidget* aWidget, - mozilla::LayoutDeviceIntRegion aRegion); - explicit nsWebBrowser(int aItemType); protected: @@ -136,7 +111,6 @@ class nsWebBrowser final : public nsIWebBrowser, RefPtr mDocShell; mozilla::OriginAttributes mOriginAttributes; - nsCOMPtr mInternalWidget; nsCOMPtr mWWatch; const uint32_t mContentType; bool mShouldEnableHistory; @@ -145,8 +119,6 @@ class nsWebBrowser final : public nsIWebBrowser, nsCOMPtr mPrintSettings; - WidgetListenerDelegate mWidgetListenerDelegate; - // cached background color nscolor mBackgroundColor; diff --git a/view/nsView.cpp b/view/nsView.cpp index 0d7ecfccc492..93135b8dc9ff 100644 --- a/view/nsView.cpp +++ b/view/nsView.cpp @@ -467,7 +467,6 @@ void nsView::RemoveChild(nsView* child) { struct DefaultWidgetInitData : public widget::InitData { DefaultWidgetInitData() : widget::InitData() { - mWindowType = WindowType::Child; mClipChildren = true; mClipSiblings = true; } diff --git a/widget/InitData.h b/widget/InitData.h index 5d8ac23fd4d0..5590bb84785a 100644 --- a/widget/InitData.h +++ b/widget/InitData.h @@ -15,11 +15,8 @@ namespace mozilla::widget { // Window types enum class WindowType : uint8_t { TopLevel, // default top level window - Dialog, // top level window but usually handled differently - // by the OS + Dialog, // top level window but usually handled differently by the OS Popup, // used for combo boxes, etc - Child, // child windows (contained inside a window on the - // desktop (has no border)) Invisible, // a special hidden window (not to be created by arbitrary code) }; @@ -77,7 +74,7 @@ enum class TransparencyMode : uint8_t { // Basic struct for widget initialization data. // @see Create member function of nsIWidget struct InitData { - WindowType mWindowType = WindowType::Child; + WindowType mWindowType = WindowType::TopLevel; BorderStyle mBorderStyle = BorderStyle::Default; PopupType mPopupHint = PopupType::Panel; PopupLevel mPopupLevel = PopupLevel::Top; diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm index 8b43278269a2..35116311ea6f 100644 --- a/widget/cocoa/nsCocoaWindow.mm +++ b/widget/cocoa/nsCocoaWindow.mm @@ -4552,9 +4552,6 @@ DesktopToLayoutDeviceScale ParentBackingScaleFactor(nsIWidget* aParent) { static DesktopRect GetWidgetScreenRectForChildren(nsIWidget* aWidget) { mozilla::DesktopToLayoutDeviceScale scale = aWidget->GetDesktopToDeviceScale(); - if (aWidget->GetWindowType() == WindowType::Child) { - return aWidget->GetScreenBounds() / scale; - } return aWidget->GetClientBounds() / scale; } @@ -4686,7 +4683,6 @@ nsresult nsCocoaWindow::CreateNativeWindow(const NSRect& aRect, // Configure the window we will create based on the window type. switch (mWindowType) { case WindowType::Invisible: - case WindowType::Child: break; case WindowType::Popup: if (aBorderStyle != BorderStyle::Default && @@ -4978,9 +4974,6 @@ void nsCocoaWindow::SetModal(bool aModal) { // (similar) event loops). for (auto* ancestorWidget = mParent; ancestorWidget; ancestorWidget = ancestorWidget->GetParent()) { - if (ancestorWidget->GetWindowType() == WindowType::Child) { - continue; - } auto* ancestor = static_cast(ancestorWidget); const bool changed = aModal ? ancestor->mNumModalDescendants++ == 0 : --ancestor->mNumModalDescendants == 0; diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 8d8d49b24cce..0e68c63a8956 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -467,7 +467,6 @@ nsWindow::nsWindow() mConfiguredClearColor(false), mGotNonBlankPaint(false), mNeedsToRetryCapturingMouse(false) { - mWindowType = WindowType::Child; mSizeConstraints.mMaxSize = GetSafeWindowSize(mSizeConstraints.mMaxSize); if (!gGlobalsInitialized) { @@ -6016,8 +6015,6 @@ nsresult nsWindow::Create(nsIWidget* aParent, const LayoutDeviceIntRect& aRect, auto* parentnsWindow = static_cast(aParent); LOG(" parent window [%p]", parentnsWindow); - MOZ_DIAGNOSTIC_ASSERT(mWindowType != WindowType::Child); - MOZ_ASSERT_IF(mWindowType == WindowType::Popup, parentnsWindow); if (mWindowType != WindowType::Dialog && mWindowType != WindowType::Popup && diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index af93fc166055..f1c07a82eb89 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -516,10 +516,9 @@ already_AddRefed nsBaseWidget::CreateChild( // Attach a view to our widget which we'll send events to. void nsBaseWidget::AttachViewToTopLevel(bool aUseAttachedEvents) { - NS_ASSERTION((mWindowType == WindowType::TopLevel || + NS_ASSERTION(mWindowType == WindowType::TopLevel || mWindowType == WindowType::Dialog || - mWindowType == WindowType::Invisible || - mWindowType == WindowType::Child), + mWindowType == WindowType::Invisible, "Can't attach to window of that type"); mUseAttachedEvents = aUseAttachedEvents; @@ -969,8 +968,8 @@ bool nsBaseWidget::UseAPZ() const { return false; } - // Always use APZ for top-level windows - if (mWindowType == WindowType::TopLevel || mWindowType == WindowType::Child) { + // Always use APZ for top-level windows. XXX what about Dialog? + if (mWindowType == WindowType::TopLevel) { return true; } @@ -986,7 +985,9 @@ bool nsBaseWidget::UseAPZ() const { if (HasRemoteContent()) { return mWindowType == WindowType::Dialog || mWindowType == WindowType::Popup; - } else if (StaticPrefs::apz_popups_without_remote_enabled()) { + } + + if (StaticPrefs::apz_popups_without_remote_enabled()) { return mWindowType == WindowType::Popup; } diff --git a/widget/nsIWidget.h b/widget/nsIWidget.h index c6401e110692..2b0baf108e6d 100644 --- a/widget/nsIWidget.h +++ b/widget/nsIWidget.h @@ -2094,7 +2094,7 @@ class nsIWidget : public nsISupports { nsIWidget* MOZ_NON_OWNING_REF mParent = nullptr; // When Destroy() is called, the sub class should set this true. bool mOnDestroyCalled = false; - WindowType mWindowType = WindowType::Child; + WindowType mWindowType = WindowType::TopLevel; WidgetType mWidgetType = WidgetType::Native; }; diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 59b1f941d0da..1e3122a0f1c0 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -671,8 +671,6 @@ nsWindow::nsWindow() mCachedHitTestTime(TimeStamp::Now()), mSizeConstraintsScale(GetDefaultScale().scale), mDesktopId("DesktopIdMutex") { - MOZ_ASSERT(mWindowType == WindowType::Child); - if (!gInitializedVirtualDesktopManager) { TaskController::Get()->AddTask( MakeAndAddRef()); @@ -873,7 +871,6 @@ nsresult nsWindow::Create(nsIWidget* aParent, const LayoutDeviceIntRect& aRect, if (!aInitData) aInitData = &defaultInitData; MOZ_DIAGNOSTIC_ASSERT(aInitData->mWindowType != WindowType::Invisible); - MOZ_DIAGNOSTIC_ASSERT(aInitData->mWindowType != WindowType::Child); mBounds = aRect; @@ -1310,10 +1307,6 @@ static DWORD WindowStylesRemovedForBorderStyle(BorderStyle aStyle) { DWORD nsWindow::WindowStyle() { DWORD style; switch (mWindowType) { - case WindowType::Child: - style = WS_OVERLAPPED; - break; - case WindowType::Dialog: style = WS_OVERLAPPED | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | DS_MODALFRAME | WS_CLIPCHILDREN; @@ -1345,8 +1338,6 @@ DWORD nsWindow::WindowStyle() { // Return nsWindow extended styles DWORD nsWindow::WindowExStyle() { switch (mWindowType) { - case WindowType::Child: - return 0; case WindowType::Popup: { DWORD extendedStyle = WS_EX_TOOLWINDOW; if (mPopupLevel == PopupLevel::Top) {