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..8d6a7b07776c07c08b564db4881aedca8833163a 100644 |
| --- a/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp |
| +++ b/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp |
| @@ -22,6 +22,8 @@ IntersectionObservation::IntersectionObservation(IntersectionObserver& observer, |
| m_shouldReportRootBounds(shouldReportRootBounds), |
| m_lastThresholdIndex(0) {} |
| +IntersectionObservation::~IntersectionObservation() {} |
| + |
| void IntersectionObservation::applyRootMargin(LayoutRect& rect) const { |
| if (m_shouldReportRootBounds) |
| m_observer->applyRootMargin(rect); |
| @@ -255,4 +257,37 @@ DEFINE_TRACE(IntersectionObservation) { |
| visitor->trace(m_target); |
| } |
| +IntersectViewportRatioObservation::IntersectViewportRatioObservation( |
| + IntersectionObserver& observer, |
| + Element& element) |
| + : IntersectionObservation(observer, element, true) {} |
| + |
| +IntersectViewportRatioObservation::~IntersectViewportRatioObservation() {} |
| + |
| +void IntersectViewportRatioObservation::computeIntersectionObservations( |
| + DOMHighResTimeStamp timestamp) { |
| + IntersectionGeometry geometry; |
| + if (!computeGeometry(geometry)) |
| + return; |
| + |
| + float newVisibleRatio = 0; |
| + if (!geometry.targetRect.isEmpty() && geometry.doesIntersect) { |
|
miu
2016/11/14 21:03:33
This should check that |rootRect| is not empty ins
xjz
2016/11/15 23:03:39
Done.
|
| + float intersectionArea = |
| + geometry.intersectionRect.size().width().toFloat() * |
| + geometry.intersectionRect.size().height().toFloat(); |
| + float rootArea = geometry.rootRect.size().width().toFloat() * |
| + geometry.rootRect.size().height().toFloat(); |
| + newVisibleRatio = intersectionArea / rootArea; |
| + } |
| + if (newVisibleRatio != m_lastVisibleRatio) { |
|
miu
2016/11/14 21:03:33
A second thought on this: Maybe we should send the
xjz
2016/11/15 23:03:39
Since we don't know the more intelligent logic for
|
| + IntRect snappedRootBounds = pixelSnappedIntRect(geometry.rootRect); |
| + IntersectionObserverEntry* newEntry = new IntersectionObserverEntry( |
| + timestamp, newVisibleRatio, pixelSnappedIntRect(geometry.targetRect), |
| + &snappedRootBounds, pixelSnappedIntRect(geometry.intersectionRect), |
| + target()); |
| + observer().enqueueIntersectionObserverEntry(*newEntry); |
| + m_lastVisibleRatio = newVisibleRatio; |
| + } |
| +} |
| + |
| } // namespace blink |