Index: third_party/WebKit/Source/core/layout/LayoutView.cpp |
diff --git a/third_party/WebKit/Source/core/layout/LayoutView.cpp b/third_party/WebKit/Source/core/layout/LayoutView.cpp |
index aa3ccf3f2599d681445a8a682a191d7b98273321..858c8d2d2bab94658c3d7a283e1c24d83c7d545c 100644 |
--- a/third_party/WebKit/Source/core/layout/LayoutView.cpp |
+++ b/third_party/WebKit/Source/core/layout/LayoutView.cpp |
@@ -23,6 +23,7 @@ |
#include "core/dom/Document.h" |
#include "core/dom/Element.h" |
+#include "core/dom/IntersectionObserver.h" |
#include "core/editing/FrameSelection.h" |
#include "core/frame/LocalFrame.h" |
#include "core/frame/Settings.h" |
@@ -954,4 +955,35 @@ void LayoutView::willBeDestroyed() |
m_compositor.clear(); |
} |
+void LayoutView::addIntersectionObserverTarget(LayoutObject* obj) |
+{ |
+ m_intersectionObserverTargets.add(obj, IntRect()); |
+} |
+ |
+void LayoutView::removeIntersectionObserverTarget(LayoutObject* obj) |
+{ |
+ m_intersectionObserverTargets.remove(obj); |
+} |
+ |
+void LayoutView::computeIntersectionObservations(const FloatRect& rootBounds) |
+{ |
+ for (auto& obj : m_intersectionObserverTargets) { |
+ LayoutObject* layoutObject = obj.key; |
+ Node* node = layoutObject->node(); |
+ if (!node || !node->isElementNode()) |
+ continue; |
+ FloatRect bounds = layoutObject->absoluteBoundingBoxFloatRect(); |
+ FloatRect intersection(bounds); |
+ intersection.intersect(rootBounds); |
+ const FloatRect& oldIntersection = obj.value; |
+ if (oldIntersection == intersection) |
+ continue; |
+ obj.value = intersection; |
+ Element* element = toElement(node); |
+ for (auto& observer : element->intersectionObservers()) { |
+ observer->enqueueIntersectionObserverEntry(IntersectionObserverEntry::create(0, bounds, rootBounds, intersection, element)); |
+ } |
+ } |
+} |
+ |
} // namespace blink |