Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Unified Diff: third_party/WebKit/Source/core/dom/IntersectionObservation.cpp

Issue 2566943004: IntersectionObserver: compute correct intersection ratio for 0x0 elements (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/intersection-observer/zero-area-element-visible.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/IntersectionObservation.cpp
diff --git a/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp b/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp
index c9c04457e5ea67c7f176de9f8542466870e0c392..cc7b8ee03fb815a7f311fa35c015fc22719006fb 100644
--- a/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp
+++ b/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp
@@ -211,19 +211,22 @@ void IntersectionObservation::computeIntersectionObservations(
// intersection to have "crossed" a zero threshold, but not crossed
// any non-zero threshold.
unsigned newThresholdIndex;
- float newVisibleRatio = 0;
- if (geometry.targetRect.isEmpty()) {
- newThresholdIndex = geometry.doesIntersect ? 1 : 0;
- } else if (!geometry.doesIntersect) {
- newThresholdIndex = 0;
- } else {
- float intersectionArea =
- geometry.intersectionRect.size().width().toFloat() *
- geometry.intersectionRect.size().height().toFloat();
- float targetArea = geometry.targetRect.size().width().toFloat() *
- geometry.targetRect.size().height().toFloat();
- newVisibleRatio = intersectionArea / targetArea;
+ float newVisibleRatio;
+ if (geometry.doesIntersect) {
+ if (geometry.targetRect.isEmpty()) {
+ newVisibleRatio = 1;
+ } else {
+ float intersectionArea =
+ geometry.intersectionRect.size().width().toFloat() *
+ geometry.intersectionRect.size().height().toFloat();
+ float targetArea = geometry.targetRect.size().width().toFloat() *
+ geometry.targetRect.size().height().toFloat();
+ newVisibleRatio = intersectionArea / targetArea;
+ }
newThresholdIndex = observer().firstThresholdGreaterThan(newVisibleRatio);
+ } else {
+ newVisibleRatio = 0;
+ newThresholdIndex = 0;
}
if (m_lastThresholdIndex != newThresholdIndex) {
IntRect snappedRootBounds = pixelSnappedIntRect(geometry.rootRect);
« no previous file with comments | « third_party/WebKit/LayoutTests/intersection-observer/zero-area-element-visible.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698