| 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 2351061beffa6fe31b4f88515be7642791eec300..a8274c114e7751aa8995061b300bb852cfe09435 100644
|
| --- a/third_party/WebKit/Source/core/dom/Element.cpp
|
| +++ b/third_party/WebKit/Source/core/dom/Element.cpp
|
| @@ -59,6 +59,7 @@
|
| #include "core/dom/ExceptionCode.h"
|
| #include "core/dom/FirstLetterPseudoElement.h"
|
| #include "core/dom/Fullscreen.h"
|
| +#include "core/dom/IntersectionObserver.h"
|
| #include "core/dom/LayoutTreeBuilder.h"
|
| #include "core/dom/MutationObserverInterestGroup.h"
|
| #include "core/dom/MutationRecord.h"
|
| @@ -105,6 +106,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"
|
| @@ -170,6 +173,8 @@ Element::~Element()
|
| {
|
| ASSERT(needsAttach());
|
|
|
| + disconnectIntersectionObservations();
|
| +
|
| #if !ENABLE(OILPAN)
|
| if (hasRareData()) {
|
| elementRareData()->clearShadow();
|
| @@ -1449,8 +1454,14 @@ Node::InsertionNotificationRequest Element::insertedInto(ContainerNode* insertio
|
| if (!insertionPoint->isInTreeScope())
|
| return InsertionDone;
|
|
|
| - if (hasRareData())
|
| - elementRareData()->clearClassListValueForQuirksMode();
|
| + if (hasRareData()) {
|
| + ElementRareData* rareData = elementRareData();
|
| + rareData->clearClassListValueForQuirksMode();
|
| + if (rareData->hasIntersectionObservation()) {
|
| + for (auto& observation: rareData->intersectionObservations())
|
| + observation->setActive(observation->observer()->isDescendantOfRoot(this));
|
| + }
|
| + }
|
|
|
| if (isUpgradedCustomElement() && inDocument())
|
| CustomElement::didAttach(this, document());
|
| @@ -1528,6 +1539,8 @@ void Element::removedFrom(ContainerNode* insertionPoint)
|
|
|
| if (ElementAnimations* elementAnimations = data->elementAnimations())
|
| elementAnimations->cssAnimations().cancel();
|
| +
|
| + data->deactivateAllIntersectionObservations();
|
| }
|
| }
|
|
|
| @@ -3569,6 +3582,79 @@ bool Element::supportsStyleSharing() const
|
| return true;
|
| }
|
|
|
| +WeakPtr<Element> Element::createWeakPtr()
|
| +{
|
| + return ensureElementRareData().createWeakPtr(this);
|
| +}
|
| +
|
| +void Element::addIntersectionObservation(IntersectionObservation& observation)
|
| +{
|
| + ensureElementRareData().intersectionObservations().add(&observation);
|
| +}
|
| +
|
| +void Element::removeIntersectionObservation(IntersectionObservation& observation)
|
| +{
|
| + if (!hasRareData() || !elementRareData()->hasIntersectionObservation())
|
| + return;
|
| + elementRareData()->intersectionObservations().remove(&observation);
|
| +}
|
| +
|
| +void Element::disconnectIntersectionObservations()
|
| +{
|
| + if (!hasRareData() || !elementRareData()->hasIntersectionObservation())
|
| + return;
|
| + HeapVector<Member<IntersectionObservation>> toRemove;
|
| + for (auto& observation: elementRareData()->intersectionObservations())
|
| + toRemove.append(observation);
|
| + for (auto& observation: toRemove) {
|
| + if (observation->observer()->root() == this)
|
| + observation->observer()->disconnect();
|
| + else
|
| + observation->disconnect();
|
| + }
|
| +}
|
| +
|
| +bool Element::computeIntersection(Element* root, LayoutRect& targetRect, LayoutRect& rootRect, LayoutRect& intersectionRect)
|
| +{
|
| + // TODO: support zero-size targetRect
|
| + intersectionRect = targetRect = toLayoutBoxModelObject(layoutObject())->visualOverflowRect();
|
| +
|
| + if (root) {
|
| + ASSERT(root->isInTreeScope());
|
| + ASSERT(isDescendantOf(root));
|
| + // TODO: Support SVG
|
| + if (!root->layoutObject()->isBoxModelObject())
|
| + return false;
|
| + rootRect = toLayoutBoxModelObject(root->layoutObject())->visualOverflowRect();
|
| + layoutObject()->mapRectToPaintInvalidationBacking(toLayoutBoxModelObject(root->layoutObject()), intersectionRect, nullptr);
|
| +
|
| + // Convert rects to frame coordinates.
|
| + targetRect.moveBy(LayoutPoint(layoutObject()->localToAbsolute()));
|
| + LayoutPoint rootOffset = LayoutPoint(root->layoutObject()->localToAbsolute());
|
| + intersectionRect.moveBy(rootOffset);
|
| + rootRect.moveBy(rootOffset);
|
| + } else {
|
| + Element* target = this;
|
| + LocalFrame* frame = document().frame();
|
| + while (target) {
|
| + targetRect.moveBy(LayoutPoint(target->layoutObject()->localToAbsolute()));
|
| + Document& document = target->document();
|
| + LayoutView* layoutView = document.layoutView();
|
| + ASSERT(layoutView);
|
| + // TODO: mapRectToPaintInvalidationBacking probably doesn't do exactly the clipping we want,
|
| + // and it doesn't support rootMargin at all.
|
| + target->layoutObject()->mapRectToPaintInvalidationBacking(layoutView, intersectionRect, nullptr);
|
| + frame = document.frame();
|
| + ASSERT(frame);
|
| + target = toElement(frame->ownerLayoutObject()->node());
|
| + }
|
| + rootRect = LayoutRect(frame->view()->scrollableArea()->visibleContentRect());
|
| + intersectionRect = intersection(intersectionRect, rootRect);
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| DEFINE_TRACE(Element)
|
| {
|
| #if ENABLE(OILPAN)
|
|
|