Skip to content
Permalink
Browse files
Add a log channel for IntersectionObserver
https://bugs.webkit.org/show_bug.cgi?id=246028
<rdar://100770517>

Reviewed by Wenson Hsieh.

Add the beginnings of a log channel for IntersectionObserver, which dumps the records (without collapsing them all onto a single line).

* Source/WebCore/dom/DOMRectReadOnly.h:
(WebCore::DOMRectReadOnly::toFloatRect const):
* Source/WebCore/loader/ImageLoader.cpp:
(WebCore::ImageLoader::updateFromElement):
* Source/WebCore/page/IntersectionObserver.cpp:
(WebCore::IntersectionObserver::IntersectionObserver):
(WebCore::IntersectionObserver::notify):
* Source/WebCore/page/IntersectionObserverEntry.cpp:
(WebCore::operator<<):
* Source/WebCore/page/IntersectionObserverEntry.h:
* Source/WebCore/platform/Logging.h:

Canonical link: https://commits.webkit.org/255197@main
  • Loading branch information
smfr committed Oct 5, 2022
1 parent fcd2b36 commit 24ab2a368754d9133c2b3630a433358785dcb0f7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
@@ -26,6 +26,8 @@
#pragma once

#include "DOMRectInit.h"
#include "FloatConversion.h"
#include "FloatRect.h"
#include "ScriptWrappable.h"
#include <wtf/IsoMalloc.h>
#include <wtf/MathExtras.h>
@@ -53,6 +55,8 @@ class DOMRectReadOnly : public ScriptWrappable, public RefCounted<DOMRectReadOnl
double bottom() const { return WTF::nanPropagatingMax(m_y, m_y + m_height); }
double left() const { return WTF::nanPropagatingMin(m_x, m_x + m_width); }

FloatRect toFloatRect() const { return FloatRect { narrowPrecisionToFloat(m_x), narrowPrecisionToFloat(m_y), narrowPrecisionToFloat(m_width), narrowPrecisionToFloat(m_height) }; }

protected:
DOMRectReadOnly(double x, double y, double width, double height)
: m_x(x)
@@ -260,7 +260,7 @@ void ImageLoader::updateFromElement(RelevantMutation relevantMutation)
}
auto imageLoading = (m_lazyImageLoadState == LazyImageLoadState::Deferred) ? ImageLoading::DeferredUntilVisible : ImageLoading::Immediate;
newImage = document.cachedResourceLoader().requestImage(WTFMove(request), imageLoading).value_or(nullptr);
LOG_WITH_STREAM(LazyLoading, stream << "ImageLoader " << this << " updateFromElement " << element() << " - state changed from " << oldState << " to " << m_lazyImageLoadState << ", loading is" << imageLoading << " new image " << newImage.get());
LOG_WITH_STREAM(LazyLoading, stream << "ImageLoader " << this << " updateFromElement " << element() << " - state changed from " << oldState << " to " << m_lazyImageLoadState << ", loading is " << imageLoading << " new image " << newImage.get());
}

// If we do not have an image here, it means that a cross-site
@@ -37,6 +37,7 @@
#include "IntersectionObserverCallback.h"
#include "IntersectionObserverEntry.h"
#include "JSNodeCustom.h"
#include "Logging.h"
#include "Performance.h"
#include "WebCoreOpaqueRoot.h"
#include <JavaScriptCore/AbstractSlotVisitorInlines.h>
@@ -133,6 +134,8 @@ IntersectionObserver::IntersectionObserver(Document& document, Ref<IntersectionO
m_implicitRootDocument = frame->mainFrame().document();

std::sort(m_thresholds.begin(), m_thresholds.end());

LOG_WITH_STREAM(IntersectionObserver, stream << "Created IntersectionObserver " << this << " root " << root << " root margin " << m_rootMargin << " thresholds " << m_thresholds);
}

IntersectionObserver::~IntersectionObserver()
@@ -296,6 +299,14 @@ void IntersectionObserver::notify()
if (!context)
return;

#if !LOG_DISABLED
if (LogIntersectionObserver.state == WTFLogChannelState::On) {
TextStream recordsStream(TextStream::LineMode::MultipleLine);
recordsStream << takenRecords.records;
LOG_WITH_STREAM(IntersectionObserver, stream << "IntersectionObserver " << this << " notify - records " << recordsStream.release());
}
#endif

InspectorInstrumentation::willFireObserverCallback(*context, "IntersectionObserver"_s);
m_callback->handleEvent(*this, WTFMove(takenRecords.records), *this);
InspectorInstrumentation::didFireObserverCallback(*context);
@@ -43,4 +43,25 @@ IntersectionObserverEntry::IntersectionObserverEntry(const Init& init)
m_rootBounds = DOMRectReadOnly::fromRect(*init.rootBounds);
}

TextStream& operator<<(TextStream& ts, const IntersectionObserverEntry& entry)
{
TextStream::GroupScope scope(ts);
ts << "IntersectionObserverEntry " << &entry;
ts.dumpProperty("time", entry.time());

if (entry.rootBounds())
ts.dumpProperty("rootBounds", entry.rootBounds()->toFloatRect());

if (entry.boundingClientRect())
ts.dumpProperty("boundingClientRect", entry.boundingClientRect()->toFloatRect());

if (entry.intersectionRect())
ts.dumpProperty("intersectionRect", entry.intersectionRect()->toFloatRect());

ts.dumpProperty("isIntersecting", entry.isIntersecting());
ts.dumpProperty("intersectionRatio", entry.intersectionRatio());

return ts;
}

} // namespace WebCore
@@ -31,6 +31,10 @@
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>

namespace WTF {
class TextStream;
}

namespace WebCore {

class Element;
@@ -75,5 +79,6 @@ class IntersectionObserverEntry : public RefCounted<IntersectionObserverEntry> {
bool m_isIntersecting { false };
};

TextStream& operator<<(TextStream&, const IntersectionObserverEntry&);

} // namespace WebCore
@@ -73,6 +73,7 @@ namespace WebCore {
M(IndexedDB) \
M(IndexedDBOperations) \
M(Inspector) \
M(IntersectionObserver) \
M(Layers) \
M(Layout) \
M(LazyLoading) \

0 comments on commit 24ab2a3

Please sign in to comment.