Bug 1359318 - (intersection-observer) Map intersectionRect to the coordinate space of the target document. r=mstange
authorTobias Schneider <schneider@jancona.com>
Fri, 02 Jun 2017 14:11:31 -0700
changeset 410424 279a08ffe577ec62a6b9d5ca76fe25bd117dd2b3
parent 410423 35a1edcf472648b9fab32a6766527fe198d4a4b6
child 410425 f18f7ef1d81f273f6d0b9b4afd1e0980b65ae523
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1359318
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1359318 - (intersection-observer) Map intersectionRect to the coordinate space of the target document. r=mstange
dom/base/DOMIntersectionObserver.cpp
testing/web-platform/meta/intersection-observer/display-none.html.ini
testing/web-platform/meta/intersection-observer/iframe-no-root.html.ini
testing/web-platform/meta/intersection-observer/multiple-thresholds.html.ini
testing/web-platform/meta/intersection-observer/root-margin.html.ini
testing/web-platform/meta/intersection-observer/same-document-no-root.html.ini
testing/web-platform/meta/intersection-observer/same-document-zero-size-target.html.ini
testing/web-platform/meta/intersection-observer/shadow-content.html.ini
--- a/dom/base/DOMIntersectionObserver.cpp
+++ b/dom/base/DOMIntersectionObserver.cpp
@@ -325,25 +325,26 @@ DOMIntersectionObserver::Update(nsIDocum
     rootMargin.Side(side) = nsLayoutUtils::ComputeCBDependentValue(basis, coord);
   }
 
   for (auto iter = mObservationTargets.Iter(); !iter.Done(); iter.Next()) {
     Element* target = iter.Get()->GetKey();
     nsIFrame* targetFrame = target->GetPrimaryFrame();
     nsRect targetRect;
     Maybe<nsRect> intersectionRect;
+    bool isSameDoc = root && root->GetComposedDoc() == target->GetComposedDoc();
 
     if (rootFrame && targetFrame) {
       // If mRoot is set we are testing intersection with a container element
       // instead of the implicit root.
       if (mRoot) {
         // Skip further processing of this target if it is not in the same
         // Document as the intersection root, e.g. if root is an element of
         // the main document and target an element from an embedded iframe.
-        if (target->GetComposedDoc() != root->GetComposedDoc()) {
+        if (!isSameDoc) {
           continue;
         }
         // Skip further processing of this target if is not a descendant of the
         // intersection root in the containing block chain. E.g. this would be
         // the case if the target is in a position:absolute element whose
         // containing block is an ancestor of root.
         if (!nsLayoutUtils::IsAncestorFrameCrossDoc(rootFrame, targetFrame)) {
           continue;
@@ -405,22 +406,22 @@ DOMIntersectionObserver::Update(nsIDocum
           targetFrame,
           intersectionRect.value(),
           nsLayoutUtils::GetContainingBlockForClientRect(rootFrame)
       );
       intersectionRect = EdgeInclusiveIntersection(
         intersectionRectRelativeToRoot,
         rootIntersectionRect
       );
-      if (intersectionRect.isSome()) {
-        intersectionRect = Some(nsLayoutUtils::TransformFrameRectToAncestor(
-          nsLayoutUtils::GetContainingBlockForClientRect(rootFrame),
-          intersectionRect.value(),
-          targetFrame->PresContext()->PresShell()->GetRootScrollFrame()
-        ));
+      if (intersectionRect.isSome() && !isSameDoc) {
+        nsRect rect = intersectionRect.value();
+        nsPresContext* presContext = targetFrame->PresContext();
+        nsLayoutUtils::TransformRect(rootFrame,
+          presContext->PresShell()->GetRootScrollFrame(), rect);
+        intersectionRect = Some(rect);
       }
     }
 
     double targetArea = targetRect.width * targetRect.height;
     double intersectionArea = !intersectionRect ?
       0 : intersectionRect->width * intersectionRect->height;
     
     double intersectionRatio;
--- a/testing/web-platform/meta/intersection-observer/display-none.html.ini
+++ b/testing/web-platform/meta/intersection-observer/display-none.html.ini
@@ -1,3 +1,2 @@
 [display-none.html]
   type: testharness
-  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1359318
--- a/testing/web-platform/meta/intersection-observer/iframe-no-root.html.ini
+++ b/testing/web-platform/meta/intersection-observer/iframe-no-root.html.ini
@@ -1,4 +1,2 @@
 [iframe-no-root.html]
   type: testharness
-  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1359318
-
--- a/testing/web-platform/meta/intersection-observer/multiple-thresholds.html.ini
+++ b/testing/web-platform/meta/intersection-observer/multiple-thresholds.html.ini
@@ -1,3 +1,2 @@
 [multiple-thresholds.html]
   type: testharness
-  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1359318
--- a/testing/web-platform/meta/intersection-observer/root-margin.html.ini
+++ b/testing/web-platform/meta/intersection-observer/root-margin.html.ini
@@ -1,3 +1,2 @@
 [root-margin.html]
   type: testharness
-  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1359318
--- a/testing/web-platform/meta/intersection-observer/same-document-no-root.html.ini
+++ b/testing/web-platform/meta/intersection-observer/same-document-no-root.html.ini
@@ -1,3 +1,2 @@
 [same-document-no-root.html]
   type: testharness
-  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1359318
--- a/testing/web-platform/meta/intersection-observer/same-document-zero-size-target.html.ini
+++ b/testing/web-platform/meta/intersection-observer/same-document-zero-size-target.html.ini
@@ -1,3 +1,2 @@
 [same-document-zero-size-target.html]
   type: testharness
-  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1359318
--- a/testing/web-platform/meta/intersection-observer/shadow-content.html.ini
+++ b/testing/web-platform/meta/intersection-observer/shadow-content.html.ini
@@ -1,4 +1,3 @@
 [shadow-content.html]
   type: testharness
   prefs: [dom.webcomponents.enabled:true]
-  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1359318