Bug 1701749. When computing the double tap rect if there is a overflow rect that contains the bounding client rect use that. r=emilio

I'm not sure if this is better overall or not, it's better for the testcase in this bug (a div with a large amount of visible overflow).

This code is a direct port of javascript code, so it only had the option of using getBoundingClientRect.

Differential Revision: https://phabricator.services.mozilla.com/D110534
This commit is contained in:
Timothy Nikkel 2021-04-12 07:45:08 +00:00
Родитель f9c528b63b
Коммит ddd6cffdc0
5 изменённых файлов: 364 добавлений и 10 удалений

Просмотреть файл

@ -0,0 +1,317 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=2100"/>
<title>Check that double tapping on overflow centers the zoom where we double tap</title>
<script type="application/javascript" src="apz_test_native_event_utils.js"></script>
<script type="application/javascript" src="apz_test_utils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<script type="application/javascript">
async function doubleTapOn(element, x, y) {
let useTouchpad = (location.search == "?touchpad");
let transformEndPromise = promiseTransformEnd();
if (useTouchpad) {
synthesizeNativeTouchpadDoubleTap(element, x, y);
} else {
synthesizeNativeTap(element, x, y);
synthesizeNativeTap(element, x, y);
}
// Wait for the APZ:TransformEnd to fire
await transformEndPromise;
// Flush state so we can query an accurate resolution
await promiseApzFlushedRepaints();
}
async function test() {
var resolution = getResolution();
ok(resolution > 0,
"The initial_resolution is " + resolution + ", which is some sane value");
// instant scroll to the bottom of the page
window.scrollTo({
top: 10000,
left: 0,
behavior: 'auto'
});
await promiseApzFlushedRepaints();
let scrollPos = window.scrollY;
ok(scrollPos > 1500, "window scrolled down");
info("window.scrollY " + window.scrollY);
info("window.innerHeight " + window.innerHeight);
info("document.documentElement.scrollHeight " + document.documentElement.scrollHeight);
let target = document.getElementById("target");
let x = 10;
let y = document.documentElement.scrollHeight - 60;
// Check that double-tapping once zooms in
await doubleTapOn(target, x, y);
var prev_resolution = resolution;
resolution = getResolution();
ok(resolution > prev_resolution, "The first double-tap has increased the resolution to " + resolution);
ok(window.scrollY > 1500, "window is still scrolled down");
ok(window.scrollY >= scrollPos-2, "window is still scrolled down");
info("window.scrollY " + window.scrollY);
}
waitUntilApzStable()
.then(test)
.then(subtestDone, subtestFailed);
</script>
<style>
.container {
background-color: #eee;
width: 200px;
height: 50px;
border: 1px dotted black;
overflow: visible;
}
</style>
</head>
<body>
<div id="target" class="container">
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
Text text text text text text text text text text text text text text text text
</div>
</body>
</html>

Просмотреть файл

@ -28,6 +28,7 @@ var subtests = [
{"file": "helper_doubletap_zoom_textarea.html", "prefs": doubletap_prefs},
{"file": "helper_doubletap_zoom_horizontal_center.html", "prefs": visualviewport_and_doubletap_prefs},
{"file": "helper_doubletap_zoom_bug1702464.html", "prefs": visualviewport_and_doubletap_prefs},
{"file": "helper_doubletap_zoom_large_overflow.html", "prefs": doubletap_prefs},
];
if (getPlatform() == "mac") {
@ -41,6 +42,7 @@ if (getPlatform() == "mac") {
{"file": "helper_doubletap_zoom_bug1702464.html?touchpad", "prefs": visualviewport_and_doubletap_prefs},
{"file": "helper_doubletap_zoom_htmlelement.html", "prefs": doubletap_prefs}, // scrollbars don't receive events or take space on android
{"file": "helper_doubletap_zoom_htmlelement.html?touchpad", "prefs": doubletap_prefs},
{"file": "helper_doubletap_zoom_large_overflow.html?touchpad", "prefs": doubletap_prefs}
);
}

Просмотреть файл

@ -145,12 +145,37 @@ CSSRect CalculateRectToZoomTo(const RefPtr<dom::Document>& aRootContentDocument,
CSSRect compositedArea(visualScrollOffset,
metrics.CalculateCompositedSizeInCssPixels());
const CSSCoord margin = 15;
CSSRect rect =
nsLayoutUtils::GetBoundingContentRect(element, rootScrollFrame);
Maybe<CSSRect> nearestScrollClip;
CSSRect rect = nsLayoutUtils::GetBoundingContentRect(element, rootScrollFrame,
&nearestScrollClip);
CSSPoint point = CSSPoint::FromAppUnits(
ViewportUtils::VisualToLayout(CSSPoint::ToAppUnits(aPoint), presShell));
CSSPoint documentRelativePoint =
point + CSSPoint::FromAppUnits(rootScrollFrame->GetScrollPosition());
// In some cases, like overflow: visible and overflowing content, the bounding
// client rect of the targeted element won't contain the point the user double
// tapped on. In that case we use the scrollable overflow rect if it contains
// the user point.
if (!rect.Contains(documentRelativePoint)) {
if (nsIFrame* scrolledFrame = rootScrollFrame->GetScrolledFrame()) {
if (nsIFrame* f = element->GetPrimaryFrame()) {
CSSRect overflowRect =
CSSRect::FromAppUnits(nsLayoutUtils::TransformFrameRectToAncestor(
f, f->ScrollableOverflowRect(),
RelativeTo{scrolledFrame, ViewportType::Layout}));
if (nearestScrollClip.isSome()) {
overflowRect = nearestScrollClip->Intersect(overflowRect);
}
if (overflowRect.Contains(documentRelativePoint)) {
rect = overflowRect;
}
}
}
}
// If the element is taller than the visible area of the page scale
// the height of the |rect| so that it has the same aspect ratio as
// the root frame. The clipped |rect| is centered on the y value of
@ -159,9 +184,7 @@ CSSRect CalculateRectToZoomTo(const RefPtr<dom::Document>& aRootContentDocument,
const float widthRatio = rect.Width() / compositedArea.Width();
float targetHeight = compositedArea.Height() * widthRatio;
if (widthRatio < 0.9 && targetHeight < rect.Height()) {
const CSSPoint scrollPoint =
CSSPoint::FromAppUnits(rootScrollFrame->GetScrollPosition());
float newY = point.y + scrollPoint.y - (targetHeight * 0.5f);
float newY = documentRelativePoint.y - (targetHeight * 0.5f);
if ((newY + targetHeight) > rect.YMost()) {
rect.MoveByY(rect.Height() - targetHeight);
} else if (newY > rect.Y()) {

Просмотреть файл

@ -8992,16 +8992,18 @@ nsBlockFrame* nsLayoutUtils::GetFloatContainingBlock(nsIFrame* aFrame) {
// Element::GetBoundingClientRect().
/* static */
CSSRect nsLayoutUtils::GetBoundingContentRect(
const nsIContent* aContent, const nsIScrollableFrame* aRootScrollFrame) {
const nsIContent* aContent, const nsIScrollableFrame* aRootScrollFrame,
Maybe<CSSRect>* aOutNearestScrollClip) {
if (nsIFrame* frame = aContent->GetPrimaryFrame()) {
return GetBoundingFrameRect(frame, aRootScrollFrame);
return GetBoundingFrameRect(frame, aRootScrollFrame, aOutNearestScrollClip);
}
return CSSRect();
}
/* static */
CSSRect nsLayoutUtils::GetBoundingFrameRect(
nsIFrame* aFrame, const nsIScrollableFrame* aRootScrollFrame) {
nsIFrame* aFrame, const nsIScrollableFrame* aRootScrollFrame,
Maybe<CSSRect>* aOutNearestScrollClip) {
CSSRect result;
nsIFrame* relativeTo = aRootScrollFrame->GetScrolledFrame();
result = CSSRect::FromAppUnits(nsLayoutUtils::GetAllInFlowRectsUnion(
@ -9021,6 +9023,10 @@ CSSRect nsLayoutUtils::GetBoundingFrameRect(
CSSRect::FromAppUnits(nsLayoutUtils::TransformFrameRectToAncestor(
subFrame, subFrame->GetRectRelativeToSelf(), relativeTo));
if (aOutNearestScrollClip) {
*aOutNearestScrollClip = Some(subFrameRect);
}
result = subFrameRect.Intersect(result);
}
return result;

Просмотреть файл

@ -2802,15 +2802,21 @@ class nsLayoutUtils {
* of the scrolled content of |aRootScrollFrame|.
* Where the element is contained inside a scrollable subframe, the
* bounding rect is clipped to the bounds of the subframe.
* If non-null aOutNearestScrollClip will be filled in with the rect of the
* nearest scroll frame (excluding aRootScrollFrame) that is an ancestor of
* the frame of aContent, if such exists, in the same coords are the returned
* rect. This rect is used to clip the result.
*/
static CSSRect GetBoundingContentRect(
const nsIContent* aContent, const nsIScrollableFrame* aRootScrollFrame);
const nsIContent* aContent, const nsIScrollableFrame* aRootScrollFrame,
mozilla::Maybe<CSSRect>* aOutNearestScrollClip = nullptr);
/**
* Similar to GetBoundingContentRect for nsIFrame.
*/
static CSSRect GetBoundingFrameRect(
nsIFrame* aFrame, const nsIScrollableFrame* aRootScrollFrame);
nsIFrame* aFrame, const nsIScrollableFrame* aRootScrollFrame,
mozilla::Maybe<CSSRect>* aOutNearestScrollClip = nullptr);
/**
* Returns the first ancestor who is a float containing block.