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 d54240953a41d9654d01dadb43402f3721bc3ebc..92d52fa4d8ad473a90a16deb8f70d112e717574a 100644 |
--- a/third_party/WebKit/Source/core/dom/Element.cpp |
+++ b/third_party/WebKit/Source/core/dom/Element.cpp |
@@ -60,6 +60,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" |
@@ -106,6 +108,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" |
@@ -1450,8 +1454,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()); |
@@ -1529,6 +1546,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(); |
} |
} |
@@ -3570,6 +3593,55 @@ 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) |
+{ |
+ bool rootIsDocumentElement = (root == root->document().documentElement()); |
+ LayoutObject* rootLayoutObject = rootIsDocumentElement ? root->document().layoutView() : root->layoutObject(); |
+ if (!rootLayoutObject->isBoxModelObject()) |
+ return false; |
+ intersectionRect = targetRect = toLayoutBoxModelObject(layoutObject())->visualOverflowRect(); |
+ layoutObject()->mapRectToPaintInvalidationBacking(toLayoutBoxModelObject(rootLayoutObject), intersectionRect, nullptr); |
+ targetRect = LayoutRect(layoutObject()->localToAbsoluteQuad(FloatQuad(FloatRect(targetRect)), UseTransforms | ApplyContainerFlip | TraverseDocumentBoundaries).boundingBox()); |
+ intersectionRect = LayoutRect(rootLayoutObject->localToAbsoluteQuad(FloatQuad(FloatRect(intersectionRect))).boundingBox()); |
+ LayoutPoint scrollPosition(root->document().view()->scrollPosition()); |
+ if (rootIsDocumentElement) { |
+ rootRect = LayoutRect(root->document().view()->visibleContentRect()); |
+ intersectionRect.intersect(rootRect); |
+ } else if (rootLayoutObject->isBox()) { |
+ rootRect = LayoutRect(toLayoutBox(rootLayoutObject)->absoluteContentBox()); |
+ } else { |
+ rootRect = LayoutRect(rootLayoutObject->absoluteBoundingBoxRect()); |
+ } |
+ targetRect.moveBy(-scrollPosition); |
+ intersectionRect.moveBy(-scrollPosition); |
+ rootRect.moveBy(-scrollPosition); |
+ if (intersectionRect.size().isZero()) |
+ intersectionRect = LayoutRect(); |
+ |
+ return true; |
+} |
+ |
void Element::logEventIfIsolatedWorldAndInDocument(const String& eventName, const String& arg1, const String& arg2) |
{ |
if (!inDocument()) |