Commit c02251d2 authored by Stefan Zager's avatar Stefan Zager Committed by Commit Bot

[IntersectionObserver] Report coordinates as CSS pixels.

Prior to this patch, IntersectionObserverEntry was reporting
coordinates in device pixels.

BUG=887974

Change-Id: Ic91748cd2eb9b828a787bb4372d5d5b10bcf8cfb
Reviewed-on: https://chromium-review.googlesource.com/1250121
Commit-Queue: Stefan Zager <szager@chromium.org>
Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595190}
parent 742a4e21
......@@ -13,7 +13,7 @@ pre, #log {
overflow: visible;
height: 200px;
width: 160px;
border: 7px solid black;
border: 8px solid black;
}
#target {
margin: 10px;
......@@ -50,12 +50,35 @@ function step0() {
var targetBounds = clientBounds(target);
target.style.transform = "translateY(195px)";
runTestCycle(step1, "target.style.transform = 'translateY(195px)'");
checkLastEntry(entries, 0, targetBounds.concat(0, 0, 0, 0, 8, 182, 8, 222, false));
checkLastEntry(entries, 0, targetBounds.concat(0, 0, 0, 0, 8, 184, 8, 224, false));
}
function step1() {
var targetBounds = clientBounds(target);
target.style.transform = "translateY(300px)";
runTestCycle(step2, "target.style.transform = 'translateY(300px)'");
checkLastEntry(entries, 1, targetBounds.concat(26, 146, 221, 224, 8, 184, 8, 224, true));
}
function step2() {
var targetBounds = clientBounds(target);
target.style.transform = "";
checkLastEntry(entries, 1, targetBounds.concat(25, 145, 220, 222, 8, 182, 8, 222, true));
target.style.zoom = "2";
runTestCycle(step3, "target.style.zoom = 2");
checkLastEntry(entries, 2, targetBounds.concat(0, 0, 0, 0, 8, 184, 8, 224, false));
}
function step3() {
var targetBounds = clientBounds(target);
var intersectionWidth = (
176 // root width including border
-8 // root left border
-20 // target left margin * target zoom
) / 2; // convert to target's zoom factor.
var intersectionHeight = (216 - 8 - 20) / 2;
var intersectionRect = [targetBounds[0], targetBounds[0] + intersectionWidth,
targetBounds[2], targetBounds[2] + intersectionHeight];
checkLastEntry(entries, 3, targetBounds.concat(intersectionRect).concat(8, 184, 8, 224, true));
}
</script>
......@@ -120,12 +120,12 @@ void IntersectionObservation::Compute(unsigned flags) {
if (last_threshold_index_ != new_threshold_index ||
last_is_visible_ != is_visible) {
FloatRect snapped_root_bounds(geometry.RootRect());
FloatRect root_bounds(geometry.UnZoomedRootRect());
FloatRect* root_bounds_pointer =
report_root_bounds ? &snapped_root_bounds : nullptr;
report_root_bounds ? &root_bounds : nullptr;
IntersectionObserverEntry* new_entry = new IntersectionObserverEntry(
timestamp, new_visible_ratio, FloatRect(geometry.TargetRect()),
root_bounds_pointer, FloatRect(geometry.IntersectionRect()),
timestamp, new_visible_ratio, FloatRect(geometry.UnZoomedTargetRect()),
root_bounds_pointer, FloatRect(geometry.UnZoomedIntersectionRect()),
new_threshold_index > 0, is_visible, Target());
entries_.push_back(new_entry);
ToDocument(Observer()->GetExecutionContext())
......
......@@ -8,6 +8,7 @@
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/html/html_frame_owner_element.h"
#include "third_party/blink/renderer/core/layout/adjust_for_absolute_zoom.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/layout/layout_inline.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
......@@ -233,4 +234,28 @@ void IntersectionGeometry::ComputeGeometry() {
MapRootRectToRootFrameCoordinates();
}
LayoutRect IntersectionGeometry::UnZoomedTargetRect() const {
if (!target_)
return target_rect_;
FloatRect rect(target_rect_);
AdjustForAbsoluteZoom::AdjustFloatRect(rect, *target_);
return LayoutRect(rect);
}
LayoutRect IntersectionGeometry::UnZoomedIntersectionRect() const {
if (!target_)
return intersection_rect_;
FloatRect rect(intersection_rect_);
AdjustForAbsoluteZoom::AdjustFloatRect(rect, *target_);
return LayoutRect(rect);
}
LayoutRect IntersectionGeometry::UnZoomedRootRect() const {
if (!root_)
return root_rect_;
FloatRect rect(root_rect_);
AdjustForAbsoluteZoom::AdjustFloatRect(rect, *root_);
return LayoutRect(rect);
}
} // namespace blink
......@@ -38,12 +38,18 @@ class IntersectionGeometry {
// Client rect in the coordinate system of the frame containing target.
LayoutRect TargetRect() const { return target_rect_; }
// Target rect in CSS pixels
LayoutRect UnZoomedTargetRect() const;
// Client rect in the coordinate system of the frame containing target.
LayoutRect IntersectionRect() const { return intersection_rect_; }
// Intersection rect in CSS pixels
LayoutRect UnZoomedIntersectionRect() const;
// Client rect in the coordinate system of the frame containing root.
LayoutRect RootRect() const { return root_rect_; }
// Root rect in CSS pixels
LayoutRect UnZoomedRootRect() const;
bool DoesIntersect() const { return does_intersect_; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment