Chromium Code Reviews| 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..c524107a2cabc3919c414f8afbf4a18a8e7b0dce 100644 |
| --- a/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp |
| +++ b/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp |
| @@ -210,8 +210,11 @@ void IntersectionObservation::computeIntersectionObservations( |
| // (i.e., they have a coincident edge or corner), we consider the |
| // intersection to have "crossed" a zero threshold, but not crossed |
| // any non-zero threshold. |
| + // When observer is observing the element/viewport ratio, ignore thresholds |
| + // and report any changes on ratio. |
| unsigned newThresholdIndex; |
| float newVisibleRatio = 0; |
| + bool isObservingRatio = m_observer->isObservingElementViewportRatio(); |
|
miu
2016/11/09 22:02:08
naming/semantics: IMHO, this shouldn't semanticall
xjz
2016/11/11 01:07:29
Not needed. Added a subclass to observe element/vi
|
| if (geometry.targetRect.isEmpty()) { |
| newThresholdIndex = geometry.doesIntersect ? 1 : 0; |
| } else if (!geometry.doesIntersect) { |
| @@ -220,12 +223,21 @@ void IntersectionObservation::computeIntersectionObservations( |
| 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); |
| + if (isObservingRatio) { |
| + float rootArea = geometry.rootRect.size().width().toFloat() * |
|
miu
2016/11/09 22:02:07
Doesn't seem like the math should be different. Wo
xjz
2016/11/11 01:07:29
They are different. The targetRect is the element
|
| + geometry.rootRect.size().height().toFloat(); |
| + newVisibleRatio = intersectionArea / rootArea; |
| + } else { |
| + float targetArea = geometry.targetRect.size().width().toFloat() * |
| + geometry.targetRect.size().height().toFloat(); |
| + newVisibleRatio = intersectionArea / targetArea; |
| + newThresholdIndex = observer().firstThresholdGreaterThan(newVisibleRatio); |
| + } |
| } |
| - if (m_lastThresholdIndex != newThresholdIndex) { |
| + bool shouldReportChange = |
| + (isObservingRatio && m_lastVisibleRatio != newVisibleRatio) || |
| + (!isObservingRatio && m_lastThresholdIndex != newThresholdIndex); |
| + if (shouldReportChange) { |
|
miu
2016/11/09 22:02:07
IMHO, this change should be:
if (m_lastThreshol
xjz
2016/11/11 01:07:29
I think we only want to report if the ratio is cha
|
| IntRect snappedRootBounds = pixelSnappedIntRect(geometry.rootRect); |
| IntRect* rootBoundsPointer = |
| m_shouldReportRootBounds ? &snappedRootBounds : nullptr; |
| @@ -234,7 +246,10 @@ void IntersectionObservation::computeIntersectionObservations( |
| rootBoundsPointer, pixelSnappedIntRect(geometry.intersectionRect), |
| target()); |
| observer().enqueueIntersectionObserverEntry(*newEntry); |
| - setLastThresholdIndex(newThresholdIndex); |
| + if (isObservingRatio) |
| + m_lastVisibleRatio = newVisibleRatio; |
| + else |
| + setLastThresholdIndex(newThresholdIndex); |
| } |
| } |