Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (245641 => 245642)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2019-05-22 20:08:15 UTC (rev 245641)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2019-05-22 20:22:44 UTC (rev 245642)
@@ -1,3 +1,16 @@
+2019-05-22 Ali Juma <[email protected]>
+
+ Intersection Observer: bounding client rect is wrong for an inline element
+ https://bugs.webkit.org/show_bug.cgi?id=198009
+
+ Reviewed by Simon Fraser.
+
+ Import test added upstream in
+ https://github.com/web-platform-tests/wpt/commit/cf40205c68f739ae23429439de13d125e3df9f7a
+
+ * web-platform-tests/intersection-observer/inline-with-block-child-client-rect-expected.txt: Added.
+ * web-platform-tests/intersection-observer/inline-with-block-child-client-rect.html: Added.
+
2019-05-22 Antoine Quint <[email protected]>
[iOS] Compatibility mouse events aren't prevented by calling preventDefault() on pointerdown
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/inline-with-block-child-client-rect-expected.txt (0 => 245642)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/inline-with-block-child-client-rect-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/inline-with-block-child-client-rect-expected.txt 2019-05-22 20:22:44 UTC (rev 245642)
@@ -0,0 +1,5 @@
+
+
+PASS Inline target containing a block child
+PASS First rAF
+
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/inline-with-block-child-client-rect.html (0 => 245642)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/inline-with-block-child-client-rect.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/inline-with-block-child-client-rect.html 2019-05-22 20:22:44 UTC (rev 245642)
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<script src=""
+<script src=""
+<script src=""
+
+<style>
+pre, #log {
+ position: absolute;
+ top: 120px;
+ left: 0;
+}
+#target {
+ display: inline;
+}
+</style>
+
+<div id="target">
+ <div>
+ <img width=100 height=100 />
+ </div>
+</div>
+
+<script>
+var vw = document.documentElement.clientWidth;
+var vh = document.documentElement.clientHeight;
+var entries = [];
+var target;
+
+runTestCycle(function() {
+ target = document.getElementById("target");
+ assert_true(!!target, "target exists");
+ var observer = new IntersectionObserver(function(changes) {
+ entries = entries.concat(changes)
+ });
+ observer.observe(target);
+ entries = entries.concat(observer.takeRecords());
+ assert_equals(entries.length, 0, "No initial notifications.");
+ runTestCycle(step0, "First rAF");
+}, "Inline target containing a block child");
+
+function step0() {
+ assert_equals(entries.length, 1);
+ checkRect(entries[0].boundingClientRect, clientBounds(target),
+ "entry.boundingClientRect == target.getBoundingClientRect()");
+}
+</script>
Modified: trunk/Source/WebCore/ChangeLog (245641 => 245642)
--- trunk/Source/WebCore/ChangeLog 2019-05-22 20:08:15 UTC (rev 245641)
+++ trunk/Source/WebCore/ChangeLog 2019-05-22 20:22:44 UTC (rev 245642)
@@ -1,3 +1,22 @@
+2019-05-22 Ali Juma <[email protected]>
+
+ Intersection Observer: bounding client rect is wrong for an inline element
+ https://bugs.webkit.org/show_bug.cgi?id=198009
+
+ Reviewed by Simon Fraser.
+
+ Make target rect computation for inline elements share logic with the computation
+ of bounding client rects.
+
+ Test: imported/w3c/web-platform-tests/intersection-observer/inline-with-block-child-client-rect.html
+
+ * dom/Document.cpp:
+ (WebCore::computeIntersectionState):
+ * dom/Element.cpp:
+ (WebCore::Element::boundingAbsoluteRectWithoutLayout):
+ (WebCore::Element::boundingClientRect):
+ * dom/Element.h:
+
2019-05-22 Antoine Quint <[email protected]>
[iOS] Compatibility mouse events aren't prevented by calling preventDefault() on pointerdown
Modified: trunk/Source/WebCore/dom/Document.cpp (245641 => 245642)
--- trunk/Source/WebCore/dom/Document.cpp 2019-05-22 20:08:15 UTC (rev 245641)
+++ trunk/Source/WebCore/dom/Document.cpp 2019-05-22 20:22:44 UTC (rev 245642)
@@ -7349,9 +7349,13 @@
LayoutRect localTargetBounds;
if (is<RenderBox>(*targetRenderer))
localTargetBounds = downcast<RenderBox>(targetRenderer)->borderBoundingBox();
- else if (is<RenderInline>(targetRenderer))
- localTargetBounds = downcast<RenderInline>(targetRenderer)->linesBoundingBox();
- else if (is<RenderLineBreak>(targetRenderer))
+ else if (is<RenderInline>(targetRenderer)) {
+ auto pair = target.boundingAbsoluteRectWithoutLayout();
+ if (pair) {
+ FloatRect absoluteTargetBounds = pair->second;
+ localTargetBounds = enclosingLayoutRect(targetRenderer->absoluteToLocalQuad(absoluteTargetBounds).boundingBox());
+ }
+ } else if (is<RenderLineBreak>(targetRenderer))
localTargetBounds = downcast<RenderLineBreak>(targetRenderer)->linesBoundingBox();
Optional<LayoutRect> rootLocalTargetRect;
Modified: trunk/Source/WebCore/dom/Element.cpp (245641 => 245642)
--- trunk/Source/WebCore/dom/Element.cpp 2019-05-22 20:08:15 UTC (rev 245641)
+++ trunk/Source/WebCore/dom/Element.cpp 2019-05-22 20:22:44 UTC (rev 245642)
@@ -1424,10 +1424,8 @@
return DOMRectList::create(quads);
}
-FloatRect Element::boundingClientRect()
+Optional<std::pair<RenderObject*, FloatRect>> Element::boundingAbsoluteRectWithoutLayout()
{
- document().updateLayoutIgnorePendingStylesheets();
-
RenderObject* renderer = this->renderer();
Vector<FloatQuad> quads;
if (isSVGElement() && renderer && !renderer->isSVGRoot()) {
@@ -1443,12 +1441,23 @@
renderBoxModelObject->absoluteQuads(quads);
if (quads.isEmpty())
- return { };
+ return WTF::nullopt;
FloatRect result = quads[0].boundingBox();
for (size_t i = 1; i < quads.size(); ++i)
result.unite(quads[i].boundingBox());
+ return std::make_pair(renderer, result);
+}
+
+FloatRect Element::boundingClientRect()
+{
+ document().updateLayoutIgnorePendingStylesheets();
+ auto pair = boundingAbsoluteRectWithoutLayout();
+ if (!pair)
+ return { };
+ RenderObject* renderer = pair->first;
+ FloatRect result = pair->second;
document().convertAbsoluteToClientRect(result, renderer->style());
return result;
}
Modified: trunk/Source/WebCore/dom/Element.h (245641 => 245642)
--- trunk/Source/WebCore/dom/Element.h 2019-05-22 20:08:15 UTC (rev 245641)
+++ trunk/Source/WebCore/dom/Element.h 2019-05-22 20:22:44 UTC (rev 245642)
@@ -189,6 +189,8 @@
WEBCORE_EXPORT IntRect boundsInRootViewSpace();
+ Optional<std::pair<RenderObject*, FloatRect>> boundingAbsoluteRectWithoutLayout();
+
WEBCORE_EXPORT FloatRect boundingClientRect();
WEBCORE_EXPORT Ref<DOMRectList> getClientRects();