commit 1baa0244f227965bad4a0f28cb1ca90213a75255
parent b314d21751072aaeca44a2823f6d549f2966ee58
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date: Wed, 12 Nov 2025 06:31:00 +0000
Bug 1946263 - Clear mouse capture only if under the document that's going away. r=tnikkel,layout-reviewers
I couldn't repro this locally but I think the paragraph below explains
what's going on.
Bug 1998125 made nsView::DropMouseGrabbing clear the mouse grab
unconditionally. Instead do it if only on our document to restore the
previous behavior when the document is going away.
Differential Revision: https://phabricator.services.mozilla.com/D272202
Diffstat:
3 files changed, 3 insertions(+), 12 deletions(-)
diff --git a/layout/generic/ViewportFrame.cpp b/layout/generic/ViewportFrame.cpp
@@ -344,6 +344,9 @@ void ViewportFrame::Destroy(DestroyContext& aContext) {
if (auto* view = GetView()) {
view->SetFrame(nullptr);
}
+ if (PresShell()->IsDestroying()) {
+ PresShell::ClearMouseCapture(this);
+ }
nsContainerFrame::Destroy(aContext);
}
diff --git a/view/nsView.cpp b/view/nsView.cpp
@@ -42,18 +42,10 @@ nsView::nsView(nsViewManager* aViewManager)
// SetViewContentTransparency.
}
-void nsView::DropMouseGrabbing() {
- if (mViewManager->GetPresShell()) {
- PresShell::ClearMouseCapture();
- }
-}
-
nsView::~nsView() {
MOZ_COUNT_DTOR(nsView);
if (mViewManager) {
- DropMouseGrabbing();
-
nsView* rootView = mViewManager->GetRootView();
if (rootView == this) {
// Inform the view manager that the root view has gone away...
diff --git a/view/nsView.h b/view/nsView.h
@@ -306,10 +306,6 @@ class nsView final : public nsIWidgetListener {
*/
void SetDimensions(const nsRect& aRect);
- // Helper function to get mouse grabbing off this view (by moving it to the
- // parent, if we can)
- void DropMouseGrabbing();
-
bool IsDirty() const { return mIsDirty; }
void SetIsDirty(bool aDirty) { mIsDirty = aDirty; }