[tbb-commits] [tor-browser] 19/46: Bug 1795815 - Fix cursor intersection detection on OOP iframes. r=smaug, a=dmeehan

gitolite role git at cupani.torproject.org
Wed Nov 16 20:42:59 UTC 2022


This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch base-browser-102.5.0esr-12.0-1
in repository tor-browser.

commit 51c19d603d5e2eabfa8228856ba4482b4bb08051
Author: Emilio Cobos Álvarez <emilio at crisal.io>
AuthorDate: Thu Oct 20 10:16:58 2022 +0000

    Bug 1795815 - Fix cursor intersection detection on OOP iframes. r=smaug, a=dmeehan
    
    Differential Revision: https://phabricator.services.mozilla.com/D159783
---
 dom/base/DOMIntersectionObserver.cpp | 13 +++++++++++++
 dom/base/DOMIntersectionObserver.h   |  2 ++
 dom/events/EventStateManager.cpp     | 23 +++++++++++------------
 3 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/dom/base/DOMIntersectionObserver.cpp b/dom/base/DOMIntersectionObserver.cpp
index 78450a64c816..773ea62574ff 100644
--- a/dom/base/DOMIntersectionObserver.cpp
+++ b/dom/base/DOMIntersectionObserver.cpp
@@ -667,6 +667,19 @@ IntersectionOutput DOMIntersectionObserver::Intersect(
   return {isSimilarOrigin, rootBounds, targetRect, intersectionRect};
 }
 
+IntersectionOutput DOMIntersectionObserver::Intersect(
+    const IntersectionInput& aInput, const nsRect& aTargetRect) {
+  nsRect rootBounds = aInput.mRootRect;
+  rootBounds.Inflate(aInput.mRootMargin);
+  auto intersectionRect =
+      EdgeInclusiveIntersection(aInput.mRootRect, aTargetRect);
+  if (intersectionRect && aInput.mRemoteDocumentVisibleRect) {
+    intersectionRect = EdgeInclusiveIntersection(
+        *intersectionRect, *aInput.mRemoteDocumentVisibleRect);
+  }
+  return {true, rootBounds, aTargetRect, intersectionRect};
+}
+
 // https://w3c.github.io/IntersectionObserver/#update-intersection-observations-algo
 // (step 2)
 void DOMIntersectionObserver::Update(Document* aDocument,
diff --git a/dom/base/DOMIntersectionObserver.h b/dom/base/DOMIntersectionObserver.h
index 4b16a7e3a2da..ce985543af90 100644
--- a/dom/base/DOMIntersectionObserver.h
+++ b/dom/base/DOMIntersectionObserver.h
@@ -152,6 +152,8 @@ class DOMIntersectionObserver final : public nsISupports,
       const Document& aDocument, const nsINode* aRoot,
       const StyleRect<LengthPercentage>* aRootMargin);
   static IntersectionOutput Intersect(const IntersectionInput&, Element&);
+  // Intersects with a given rect, already relative to the root frame.
+  static IntersectionOutput Intersect(const IntersectionInput&, const nsRect&);
 
   void Update(Document* aDocument, DOMHighResTimeStamp time);
   MOZ_CAN_RUN_SCRIPT void Notify();
diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp
index 736fd054e813..e5abeff2f50e 100644
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -33,6 +33,7 @@
 #include "mozilla/dom/BrowsingContext.h"
 #include "mozilla/dom/CanonicalBrowsingContext.h"
 #include "mozilla/dom/ContentChild.h"
+#include "mozilla/dom/DOMIntersectionObserver.h"
 #include "mozilla/dom/DragEvent.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/FrameLoaderBinding.h"
@@ -4033,23 +4034,19 @@ static bool ShouldBlockCustomCursor(nsPresContext* aPresContext,
     return false;
   }
 
-  // We don't want to deal with iframes, just let them do their thing unless
-  // they intersect UI.
-  //
-  // TODO(emilio, bug 1525561): In a fission world, we should have a better way
-  // to find the event coordinates relative to the content area.
-  nsPresContext* topLevel =
-      aPresContext->GetInProcessRootContentDocumentPresContext();
-  if (!topLevel) {
+  auto input = DOMIntersectionObserver::ComputeInput(*aPresContext->Document(),
+                                                     nullptr, nullptr);
+
+  if (!input.mRootFrame) {
     return false;
   }
 
   nsPoint point = nsLayoutUtils::GetEventCoordinatesRelativeTo(
-      aEvent, RelativeTo{topLevel->PresShell()->GetRootFrame()});
+      aEvent, RelativeTo{input.mRootFrame});
 
   // The cursor size won't be affected by our full zoom in the parent process,
   // so undo that before checking the rect.
-  float zoom = topLevel->GetFullZoom();
+  float zoom = aPresContext->GetFullZoom();
 
   // Also adjust for accessibility cursor scaling factor.
   zoom /= LookAndFeel::GetFloat(LookAndFeel::FloatID::CursorScale, 1.0f);
@@ -4059,8 +4056,10 @@ static bool ShouldBlockCustomCursor(nsPresContext* aPresContext,
   nsPoint hotspot(CSSPixel::ToAppUnits(aCursor.mHotspot.x / zoom),
                   CSSPixel::ToAppUnits(aCursor.mHotspot.y / zoom));
 
-  nsRect cursorRect(point - hotspot, size);
-  return !topLevel->GetVisibleArea().Contains(cursorRect);
+  const nsRect cursorRect(point - hotspot, size);
+  auto output = DOMIntersectionObserver::Intersect(input, cursorRect);
+  return !output.mIntersectionRect ||
+         !(*output.mIntersectionRect == cursorRect);
 }
 
 static gfx::IntPoint ComputeHotspot(imgIContainer* aContainer,

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tbb-commits mailing list