Index: third_party/WebKit/Source/core/dom/Element.cpp |
diff --git a/third_party/WebKit/Source/core/dom/Element.cpp b/third_party/WebKit/Source/core/dom/Element.cpp |
index 446c4b9c662702900816af142c80273a978b0431..15f36a3dd283dbe644e3cc58a4f57523f5b8051f 100644 |
--- a/third_party/WebKit/Source/core/dom/Element.cpp |
+++ b/third_party/WebKit/Source/core/dom/Element.cpp |
@@ -59,6 +59,8 @@ |
#include "core/dom/ExceptionCode.h" |
#include "core/dom/FirstLetterPseudoElement.h" |
#include "core/dom/Fullscreen.h" |
+#include "core/dom/IntersectionObserver.h" |
+#include "core/dom/IntersectionObserverRegistry.h" |
#include "core/dom/LayoutTreeBuilder.h" |
#include "core/dom/MutationObserverInterestGroup.h" |
#include "core/dom/MutationRecord.h" |
@@ -105,6 +107,8 @@ |
#include "core/html/HTMLTemplateElement.h" |
#include "core/html/parser/HTMLParserIdioms.h" |
#include "core/inspector/InspectorInstrumentation.h" |
+#include "core/layout/LayoutInline.h" |
+#include "core/layout/LayoutPart.h" |
#include "core/layout/LayoutTextFragment.h" |
#include "core/layout/LayoutView.h" |
#include "core/loader/DocumentLoader.h" |
@@ -1449,8 +1453,21 @@ Node::InsertionNotificationRequest Element::insertedInto(ContainerNode* insertio |
if (!insertionPoint->isInTreeScope()) |
return InsertionDone; |
- if (hasRareData()) |
- elementRareData()->clearClassListValueForQuirksMode(); |
+ if (hasRareData()) { |
+ ElementRareData* rareData = elementRareData(); |
+ rareData->clearClassListValueForQuirksMode(); |
+ if (rareData->hasIntersectionObserver()) { |
+ IntersectionObserverRegistry* registry = document().intersectionObserverRegistry(); |
+ for (auto& observer: rareData->intersectionObservers()) { |
+ registry->addTrackedObserver(*observer); |
+ observer->setActive(true); |
+ } |
+ } |
+ if (rareData->hasIntersectionObservation()) { |
+ for (auto& observation: rareData->intersectionObservations()) |
+ observation->setActive(observation->observer()->isDescendantOfRoot(this)); |
+ } |
+ } |
if (isUpgradedCustomElement() && inDocument()) |
CustomElement::didAttach(this, document()); |
@@ -1528,6 +1545,12 @@ void Element::removedFrom(ContainerNode* insertionPoint) |
if (ElementAnimations* elementAnimations = data->elementAnimations()) |
elementAnimations->cssAnimations().cancel(); |
+ |
+ if (data->hasIntersectionObserver()) { |
+ document().intersectionObserverRegistry()->removeTrackedObserversForRoot(this); |
+ data->deactivateAllIntersectionObservers(); |
+ } |
+ data->deactivateAllIntersectionObservations(); |
} |
} |
@@ -3561,6 +3584,93 @@ bool Element::supportsStyleSharing() const |
return true; |
} |
+WeakPtrWillBeRawPtr<Element> Element::createWeakPtr() |
+{ |
+#if ENABLE(OILPAN) |
+ return this; |
+#else |
+ return ensureElementRareData().createWeakPtr(this); |
+#endif |
+} |
+ |
+void Element::addIntersectionObservation(IntersectionObservation& observation) |
+{ |
+ ensureElementRareData().intersectionObservations().add(&observation); |
+} |
+ |
+void Element::removeIntersectionObservation(IntersectionObservation& observation) |
+{ |
+ if (!hasRareData() || !elementRareData()->hasIntersectionObservation()) |
+ return; |
+ elementRareData()->intersectionObservations().remove(&observation); |
+} |
+ |
+bool Element::computeIntersection(Element* root, LayoutRect& targetRect, LayoutRect& rootRect, LayoutRect& intersectionRect) |
+{ |
+ // TODO: support zero-size targetRect |
+ intersectionRect = targetRect = toLayoutBoxModelObject(layoutObject())->visualOverflowRect(); |
+ if (!computeElementIntersection(root, targetRect, intersectionRect)) |
+ return false; |
+ |
+ LayoutObject* rootLayoutObject = root->layoutObject(); |
+ rootRect = toLayoutBoxModelObject(rootLayoutObject)->visualOverflowRect(); |
+ |
+ // Adjust all rects from root coordinates to document coordinates. |
+ rootRect = LayoutRect(rootLayoutObject->localToAbsoluteQuad(FloatQuad(FloatRect(rootRect))).boundingBox()); |
+ targetRect = LayoutRect(rootLayoutObject->localToAbsoluteQuad(FloatQuad(FloatRect(targetRect))).boundingBox()); |
+ intersectionRect = LayoutRect(rootLayoutObject->localToAbsoluteQuad(FloatQuad(FloatRect(intersectionRect))).boundingBox()); |
+ |
+ return true; |
+} |
+ |
+bool Element::computeElementIntersection(Element* root, LayoutRect& targetRect, LayoutRect& intersectionRect) |
+{ |
+ // TODO: mapRectToPaintInvalidationBacking probably doesn't do exactly the clipping we want, |
+ // and it doesn't support rootMargin at all. |
+ // TODO: Support SVG |
+ if (root == this) |
+ return true; |
+ Element* target = this; |
+ while (&target->document() != &root->document()) { |
+ target = target->computeFrameIntersection(targetRect, intersectionRect); |
+ if (!target) |
+ return false; |
+ // TODO: adjust for border, padding, scrollbars, writing mode. |
+ } |
+ ASSERT(target->isDescendantOf(root)); |
+ |
+ bool rootIsDocumentElement = (root == root->document().documentElement()); |
+ LayoutObject* rootLayoutObject = rootIsDocumentElement ? root->document().layoutView() : root->layoutObject(); |
+ if (!rootLayoutObject->isBoxModelObject()) |
+ return false; |
+ target->layoutObject()->mapRectToPaintInvalidationBacking(toLayoutBoxModelObject(rootLayoutObject), intersectionRect, nullptr); |
+ targetRect = LayoutRect(target->layoutObject()->localToContainerQuad(FloatQuad(FloatRect(targetRect)), toLayoutBoxModelObject(rootLayoutObject)).boundingBox()); |
+ if (rootIsDocumentElement) |
+ root->computeFrameIntersection(targetRect, intersectionRect); |
+ |
+ return true; |
+} |
+ |
+Element* Element::computeFrameIntersection(LayoutRect& targetRect, LayoutRect& intersectionRect) |
+{ |
+ if (!computeElementIntersection(document().documentElement(), targetRect, intersectionRect)) |
+ return nullptr; |
+ FrameView* frameView = document().view(); |
+ ASSERT(frameView); |
+ |
+ // Until root layer scrolling is finished, we need to clip to the visible content area of the FrameView. |
+ intersectionRect.moveBy(LayoutPoint(-frameView->scrollPosition())); |
+ LayoutRect frameClipRect(LayoutPoint(), LayoutSize(frameView->visibleContentSize())); |
+ intersectionRect.intersect(frameClipRect); |
+ |
+ LocalFrame* frame = document().frame(); |
+ ASSERT(frame); |
+ LayoutObject* frameOwner = frame->ownerLayoutObject(); |
+ if (!frameOwner) |
+ return nullptr; |
+ return toElement(frameOwner->node()); |
+} |
+ |
DEFINE_TRACE(Element) |
{ |
#if ENABLE(OILPAN) |