Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Unified Diff: third_party/WebKit/Source/core/dom/IntersectionObserver.cpp

Issue 1580783003: Revert of Use Document, rather than document element, for implicit root. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@intersection-observer
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
diff --git a/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp b/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
index b29b69e8b46ed857ca07cd7f76d5b958fd182fe6..5758a6b37458696db61bd5631da75b8bb6608c87 100644
--- a/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
+++ b/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
@@ -7,13 +7,13 @@
#include "bindings/core/v8/ExceptionState.h"
#include "core/css/parser/CSSParserTokenRange.h"
#include "core/css/parser/CSSTokenizer.h"
+#include "core/dom/ElementIntersectionObserverData.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h"
#include "core/dom/IntersectionObserverCallback.h"
#include "core/dom/IntersectionObserverController.h"
#include "core/dom/IntersectionObserverEntry.h"
#include "core/dom/IntersectionObserverInit.h"
-#include "core/dom/NodeIntersectionObserverData.h"
#include "core/html/HTMLFrameOwnerElement.h"
#include "core/layout/LayoutView.h"
#include "platform/Timer.h"
@@ -81,17 +81,17 @@
IntersectionObserver* IntersectionObserver::create(const IntersectionObserverInit& observerInit, IntersectionObserverCallback& callback, ExceptionState& exceptionState)
{
- RefPtrWillBeRawPtr<Node> root = observerInit.root();
+ RefPtrWillBeRawPtr<Element> root = observerInit.root();
if (!root) {
// TODO(szager): Use Document instead of document element for implicit root. (crbug.com/570538)
ExecutionContext* context = callback.executionContext();
ASSERT(context->isDocument());
Frame* mainFrame = toDocument(context)->frame()->tree().top();
if (mainFrame && mainFrame->isLocalFrame())
- root = toLocalFrame(mainFrame)->document();
+ root = toLocalFrame(mainFrame)->document()->documentElement();
}
if (!root) {
- exceptionState.throwDOMException(HierarchyRequestError, "Unable to get root node in main frame to track.");
+ exceptionState.throwDOMException(HierarchyRequestError, "Unable to get root element in main frame to track.");
return nullptr;
}
@@ -112,18 +112,15 @@
return new IntersectionObserver(callback, *root, rootMargin, thresholds);
}
-IntersectionObserver::IntersectionObserver(IntersectionObserverCallback& callback, Node& root, const Vector<Length>& rootMargin, const Vector<float>& thresholds)
+IntersectionObserver::IntersectionObserver(IntersectionObserverCallback& callback, Element& root, const Vector<Length>& rootMargin, const Vector<float>& thresholds)
: m_callback(&callback)
+ , m_root(root.ensureIntersectionObserverData().createWeakPtr(&root))
, m_thresholds(thresholds)
, m_topMargin(Fixed)
, m_rightMargin(Fixed)
, m_bottomMargin(Fixed)
, m_leftMargin(Fixed)
{
- if (root.isDocumentNode())
- m_root = toDocument(root).ensureIntersectionObserverData().createWeakPtr(&root);
- else
- m_root = toElement(root).ensureIntersectionObserverData().createWeakPtr(&root);
switch (rootMargin.size()) {
case 0:
break;
@@ -152,24 +149,24 @@
root.document().ensureIntersectionObserverController().addTrackedObserver(*this);
}
-LayoutObject* IntersectionObserver::rootLayoutObject() const
-{
- Node* rootNode = root();
- if (rootNode->isDocumentNode())
- return toDocument(rootNode)->layoutView();
- return toElement(rootNode)->layoutObject();
+LayoutObject* IntersectionObserver::rootLayoutObject()
+{
+ Element* rootElement = root();
+ if (rootElement == rootElement->document().documentElement())
+ return rootElement->document().layoutView();
+ return rootElement->layoutObject();
}
bool IntersectionObserver::isDescendantOfRoot(const Element* target) const
{
// Is m_root an ancestor, through the DOM and frame trees, of target?
- Node* rootNode = root();
- if (!rootNode || !target || target == rootNode)
+ Element* rootElement = m_root.get();
+ if (!rootElement || !target || target == rootElement)
return false;
- if (!target->inDocument() || !rootNode->inDocument())
+ if (!target->inDocument() || !rootElement->inDocument())
return false;
- Document* rootDocument = &rootNode->document();
+ Document* rootDocument = &rootElement->document();
Document* targetDocument = &target->document();
while (targetDocument != rootDocument) {
target = targetDocument->ownerElement();
@@ -177,11 +174,7 @@
return false;
targetDocument = &target->document();
}
- if (rootNode->isDocumentNode()) {
- ASSERT(targetDocument == rootNode);
- return true;
- }
- return target->isDescendantOf(rootNode);
+ return target->isDescendantOf(rootElement);
}
void IntersectionObserver::observe(Element* target, ExceptionState& exceptionState)

Powered by Google App Engine
This is Rietveld 408576698