Bug 1699180. Don't try to double tap zoom to html elements. r=botond

It'll end up scrolling to the top.

Differential Revision: https://phabricator.services.mozilla.com/D110535
This commit is contained in:
Timothy Nikkel 2021-04-11 04:45:19 +00:00
parent af6b24b75f
commit a0dd7cb8c0

View File

@ -63,7 +63,9 @@ static already_AddRefed<dom::Element> ElementFromPoint(
return nullptr;
}
static bool ShouldZoomToElement(const nsCOMPtr<dom::Element>& aElement) {
static bool ShouldZoomToElement(
const nsCOMPtr<dom::Element>& aElement,
const RefPtr<dom::Document>& aRootContentDocument) {
if (nsIFrame* frame = aElement->GetPrimaryFrame()) {
if (frame->StyleDisplay()->IsInlineFlow() &&
// Replaced elements are suitable zoom targets because they act like
@ -73,6 +75,13 @@ static bool ShouldZoomToElement(const nsCOMPtr<dom::Element>& aElement) {
return false;
}
}
// Trying to zoom to the html element will just end up scrolling to the start
// of the document, return false and we'll run out of elements and just
// zoomout (without scrolling to the start).
if (aElement->OwnerDoc() == aRootContentDocument &&
aElement->IsHTMLElement(nsGkAtoms::html)) {
return false;
}
if (aElement->IsAnyOfHTMLElements(nsGkAtoms::li, nsGkAtoms::q)) {
return false;
}
@ -122,7 +131,7 @@ CSSRect CalculateRectToZoomTo(const RefPtr<dom::Document>& aRootContentDocument,
return zoomOut;
}
while (element && !ShouldZoomToElement(element)) {
while (element && !ShouldZoomToElement(element, aRootContentDocument)) {
element = element->GetParentElement();
}