tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 6851c1266ddf94534d14e5da95a1659edf604d07
parent 79e3fdc22a4b4e0993a64eb57a03550c0e85c967
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date:   Mon, 17 Nov 2025 04:26:07 +0000

Bug 2000153 - Clean up paint listener set-up. r=tnikkel,masayuki

Differential Revision: https://phabricator.services.mozilla.com/D272734

Diffstat:
Mgfx/layers/ipc/SharedSurfacesChild.cpp | 22+++-------------------
Mwidget/PuppetWidget.cpp | 31++++++++++---------------------
Mwidget/PuppetWidget.h | 2--
Mwidget/cocoa/nsCocoaWindow.h | 4----
Mwidget/cocoa/nsCocoaWindow.mm | 1-
Mwidget/gtk/nsWindow.cpp | 16++++++----------
Mwidget/gtk/nsWindow.h | 1-
Mwidget/nsIWidget.cpp | 33++++++++-------------------------
Mwidget/nsIWidget.h | 28++++++++++++++++++++--------
Mwidget/windows/nsWindow.h | 1-
Mwidget/windows/nsWindowGfx.cpp | 5-----
11 files changed, 47 insertions(+), 97 deletions(-)

diff --git a/gfx/layers/ipc/SharedSurfacesChild.cpp b/gfx/layers/ipc/SharedSurfacesChild.cpp @@ -474,24 +474,6 @@ void SharedSurfacesAnimation::HoldSurfaceForRecycling( aEntry.mPendingRelease.AppendElement(aSurface); } -// This will get the widget listener that handles painting. Generally, this is -// the attached widget listener (or previously attached if the attached is paint -// suppressed). Otherwise it is the widget listener. There should be a function -// in nsIWidget that does this for us but there isn't yet. -static nsIWidgetListener* GetPaintWidgetListener(nsIWidget* aWidget) { - if (auto* attached = aWidget->GetAttachedWidgetListener()) { - if (attached->IsPaintSuppressed()) { - if (auto* previouslyAttached = - aWidget->GetPreviouslyAttachedWidgetListener()) { - return previouslyAttached; - } - } - return attached; - } - - return aWidget->GetWidgetListener(); -} - nsresult SharedSurfacesAnimation::SetCurrentFrame( SourceSurfaceSharedData* aSurface, const gfx::IntRect& aDirtyRect) { MOZ_ASSERT(aSurface); @@ -521,9 +503,11 @@ nsresult SharedSurfacesAnimation::SetCurrentFrame( // Only root compositor bridge childs record if they are paused, so check // the refresh driver. if (auto* widget = entry.mManager->LayerManager()->GetWidget()) { - nsIWidgetListener* wl = GetPaintWidgetListener(widget); + nsIWidgetListener* wl = widget->GetPaintListener(); // Note call to wl->GetView() to make sure this is view type widget // listener even though we don't use the view in this code. + // FIXME(emilio): Do popups do the right thing here? Maybe we should not + // check for GetView()? if (wl && wl->GetView() && wl->GetPresShell()) { if (auto* rd = wl->GetPresShell()->GetRefreshDriver()) { if (rd->IsThrottled()) { diff --git a/widget/PuppetWidget.cpp b/widget/PuppetWidget.cpp @@ -177,14 +177,13 @@ void PuppetWidget::Resize(const DesktopSize& aSize, bool aRepaint) { InvalidateRegion(this, dirty); } - // call WindowResized() on both the current listener, and possibly + // call WindowResized() on both the current paint listener, and possibly // also the previous one if we're in a state where we're drawing that one // because the current one is paint suppressed if (!oldBounds.IsEqualEdges(mBounds) && mAttachedWidgetListener) { - if (GetCurrentWidgetListener() && - GetCurrentWidgetListener() != mAttachedWidgetListener) { - GetCurrentWidgetListener()->WindowResized(this, mBounds.Width(), - mBounds.Height()); + if (auto* paintListener = GetPaintListener(); + paintListener && paintListener != mAttachedWidgetListener) { + paintListener->WindowResized(this, mBounds.Width(), mBounds.Height()); } mAttachedWidgetListener->WindowResized(this, mBounds.Width(), mBounds.Height()); @@ -897,16 +896,18 @@ PuppetWidget::WidgetPaintTask::Run() { } void PuppetWidget::Paint() { - if (!GetCurrentWidgetListener()) return; + if (!GetPaintListener()) { + return; + } mWidgetPaintTask.Revoke(); RefPtr<PuppetWidget> strongThis(this); - GetCurrentWidgetListener()->WillPaintWindow(this); + GetPaintListener()->WillPaintWindow(this); - if (GetCurrentWidgetListener()) { - GetCurrentWidgetListener()->DidPaintWindow(); + if (auto* listener = GetPaintListener()) { + listener->DidPaintWindow(); } } @@ -979,18 +980,6 @@ void PuppetWidget::UpdateSafeAreaInsets( mSafeAreaInsets = aSafeAreaInsets; } -nsIWidgetListener* PuppetWidget::GetCurrentWidgetListener() { - if (!mPreviouslyAttachedWidgetListener || !mAttachedWidgetListener) { - return mAttachedWidgetListener; - } - - if (mAttachedWidgetListener->IsPaintSuppressed()) { - return mPreviouslyAttachedWidgetListener; - } - - return mAttachedWidgetListener; -} - void PuppetWidget::ZoomToRect(const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId, const CSSRect& aRect, const uint32_t& aFlags) { diff --git a/widget/PuppetWidget.h b/widget/PuppetWidget.h @@ -317,8 +317,6 @@ class PuppetWidget final : public nsIWidget, bool GetCaretRect(LayoutDeviceIntRect& aCaretRect, uint32_t aCaretOffset); uint32_t GetCaretOffset(); - nsIWidgetListener* GetCurrentWidgetListener(); - // When this widget caches input context and currently managed by // IMEStateManager, the cache is valid. bool HaveValidInputContextCache() const; diff --git a/widget/cocoa/nsCocoaWindow.h b/widget/cocoa/nsCocoaWindow.h @@ -489,10 +489,6 @@ class nsCocoaWindow final : public nsIWidget { void CocoaSendToplevelActivateEvents(); void CocoaSendToplevelDeactivateEvents(); - nsIWidgetListener* GetPaintListener() const { - return mAttachedWidgetListener ? mAttachedWidgetListener : mWidgetListener; - } - enum class TransitionType { Windowed, Fullscreen, diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm @@ -6,7 +6,6 @@ #include "nsCocoaWindow.h" -#include "mozilla/EventForwards.h" #include "nsArrayUtils.h" #include "MOZDynamicCursor.h" #include "nsIAppStartup.h" diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp @@ -615,10 +615,6 @@ void nsWindow::DispatchResized() { } } -nsIWidgetListener* nsWindow::GetListener() { - return mAttachedWidgetListener ? mAttachedWidgetListener : mWidgetListener; -} - void nsWindow::OnDestroy() { if (mOnDestroyCalled) { return; @@ -4129,8 +4125,8 @@ gboolean nsWindow::OnExposeEvent(cairo_t* cr) { } #endif - if (!GetListener()) { - LOG("quit, !GetListener()"); + if (!GetPaintListener()) { + LOG("quit, !GetPaintListener()"); return FALSE; } @@ -4155,7 +4151,7 @@ gboolean nsWindow::OnExposeEvent(cairo_t* cr) { // Dispatch WillPaintWindow notification to allow scripts etc. to run // before we paint. It also spins event loop which may show/hide the window // so we may have new renderer etc. - GetListener()->WillPaintWindow(this); + GetPaintListener()->WillPaintWindow(this); // If the window has been destroyed during the will paint notification, // there is nothing left to do. @@ -4166,7 +4162,7 @@ gboolean nsWindow::OnExposeEvent(cairo_t* cr) { // Re-get all rendering components since the will paint notification // might have killed it. - nsIWidgetListener* listener = GetListener(); + nsIWidgetListener* listener = GetPaintListener(); if (!listener) { LOG("quit, !listener"); return FALSE; @@ -4198,7 +4194,7 @@ gboolean nsWindow::OnExposeEvent(cairo_t* cr) { // Re-get the listener since the will paint notification might have // killed it. - listener = GetListener(); + listener = GetPaintListener(); if (!listener) { return TRUE; } @@ -4250,7 +4246,7 @@ gboolean nsWindow::OnExposeEvent(cairo_t* cr) { // Re-get the listener since the will paint notification might have // killed it. - listener = GetListener(); + listener = GetPaintListener(); if (!listener) { return TRUE; } diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h @@ -567,7 +567,6 @@ class nsWindow final : public nsIWidget { bool GetDragInfo(mozilla::WidgetMouseEvent* aMouseEvent, GdkWindow** aWindow, gint* aButton, gint* aRootX, gint* aRootY); - nsIWidgetListener* GetListener(); nsWindow* GetTransientForWindowIfPopup(); bool IsHandlingTouchSequence(GdkEventSequence* aSequence); diff --git a/widget/nsIWidget.cpp b/widget/nsIWidget.cpp @@ -535,14 +535,6 @@ LayoutDeviceIntRect nsIWidget::MaybeRoundToDisplayPixels( // //------------------------------------------------------------------------- -nsIWidgetListener* nsIWidget::GetWidgetListener() const { - return mWidgetListener; -} - -void nsIWidget::SetWidgetListener(nsIWidgetListener* aWidgetListener) { - mWidgetListener = aWidgetListener; -} - already_AddRefed<nsIWidget> nsIWidget::CreateChild( const LayoutDeviceIntRect& aRect, const widget::InitData& aInitData) { MOZ_ASSERT(aInitData.mWindowType == WindowType::Popup, @@ -588,23 +580,6 @@ void nsIWidget::AttachViewToTopLevel(bool aUseAttachedEvents) { mUseAttachedEvents = aUseAttachedEvents; } -nsIWidgetListener* nsIWidget::GetAttachedWidgetListener() const { - return mAttachedWidgetListener; -} - -nsIWidgetListener* nsIWidget::GetPreviouslyAttachedWidgetListener() { - return mPreviouslyAttachedWidgetListener; -} - -void nsIWidget::SetPreviouslyAttachedWidgetListener( - nsIWidgetListener* aListener) { - mPreviouslyAttachedWidgetListener = aListener; -} - -void nsIWidget::SetAttachedWidgetListener(nsIWidgetListener* aListener) { - mAttachedWidgetListener = aListener; -} - //------------------------------------------------------------------------- // // Close this nsIWidget @@ -2034,6 +2009,14 @@ PresShell* nsIWidget::GetPresShell() const { return nullptr; } +nsIWidgetListener* nsIWidget::GetPaintListener() const { + if (mPreviouslyAttachedWidgetListener && mAttachedWidgetListener && + mAttachedWidgetListener->IsPaintSuppressed()) { + return mPreviouslyAttachedWidgetListener; + } + return mAttachedWidgetListener ? mAttachedWidgetListener : mWidgetListener; +} + void* nsIWidget::GetPseudoIMEContext() { TextEventDispatcher* dispatcher = GetTextEventDispatcher(); if (!dispatcher) { diff --git a/widget/nsIWidget.h b/widget/nsIWidget.h @@ -556,17 +556,24 @@ class nsIWidget : public nsSupportsWeakReference { * aUseAttachedEvents if true, events are sent to the attached listener * instead of the normal listener. */ - virtual void AttachViewToTopLevel(bool aUseAttachedEvents); + void AttachViewToTopLevel(bool aUseAttachedEvents); /** * Accessor functions to get and set the attached listener. Used by * nsView in connection with AttachViewToTopLevel above. */ - virtual void SetAttachedWidgetListener(nsIWidgetListener* aListener); - virtual nsIWidgetListener* GetAttachedWidgetListener() const; - virtual void SetPreviouslyAttachedWidgetListener( - nsIWidgetListener* aListener); - virtual nsIWidgetListener* GetPreviouslyAttachedWidgetListener(); + void SetAttachedWidgetListener(nsIWidgetListener* aListener) { + mAttachedWidgetListener = aListener; + } + nsIWidgetListener* GetAttachedWidgetListener() const { + return mAttachedWidgetListener; + } + void SetPreviouslyAttachedWidgetListener(nsIWidgetListener* aListener) { + mPreviouslyAttachedWidgetListener = aListener; + } + nsIWidgetListener* GetPreviouslyAttachedWidgetListener() { + return mPreviouslyAttachedWidgetListener; + } /** * Notifies the root widget of a non-blank paint. @@ -577,8 +584,13 @@ class nsIWidget : public nsSupportsWeakReference { * Accessor functions to get and set the listener which handles various * actions for the widget. */ - virtual nsIWidgetListener* GetWidgetListener() const; - virtual void SetWidgetListener(nsIWidgetListener* alistener); + nsIWidgetListener* GetWidgetListener() const { return mWidgetListener; } + void SetWidgetListener(nsIWidgetListener* aListener) { + mWidgetListener = aListener; + } + + /** Returns the listener used for painting */ + nsIWidgetListener* GetPaintListener() const; /** * Close and destroy the internal native window. diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h @@ -641,7 +641,6 @@ class nsWindow final : public nsIWidget { static HWND WindowAtMouse(); static bool IsTopLevelMouseExit(HWND aWnd); LayoutDeviceIntRegion GetRegionToPaint(const PAINTSTRUCT& ps, HDC aDC) const; - nsIWidgetListener* GetPaintListener(); void CreateCompositor() override; void DestroyCompositor() override; diff --git a/widget/windows/nsWindowGfx.cpp b/widget/windows/nsWindowGfx.cpp @@ -112,11 +112,6 @@ LayoutDeviceIntRegion nsWindow::GetRegionToPaint(const PAINTSTRUCT& ps, return fullRegion; } -nsIWidgetListener* nsWindow::GetPaintListener() { - if (mDestroyCalled) return nullptr; - return mAttachedWidgetListener ? mAttachedWidgetListener : mWidgetListener; -} - void nsWindow::ForcePresent() { if (mResizeState != RESIZING) { if (CompositorBridgeChild* remoteRenderer = GetRemoteRenderer()) {