Bug 1566422 - Avoid unnecessary coordinate conversions when showing tooltips, r=emilio

We currently start with screen-relative coordinates, translate them to
widget-relative coordinates, and then translate them back to screen-relative
coordinates when actually showing the tooltip in XULBrowserWindow.showTooltip().
There's no reason for the extra conversions, so we can just send screen-relative
coordinates directly.

Since the widget origin for out-of-process frames is the origin of the frame
itself (instead of the tab, which is the case for in-process frames), the
screen-to-widget conversion was incorrect, and was causing a bug in how the
tooltip was being positioned. Avoiding that conversion altogether also fixes
that bug.

Differential Revision: https://phabricator.services.mozilla.com/D86750
This commit is contained in:
Kashav Madan 2020-08-11 22:01:40 +00:00
Родитель 39f40e654c
Коммит 255b3f3ecb
2 изменённых файлов: 4 добавлений и 31 удалений

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

@ -5024,29 +5024,10 @@ var XULBrowserWindow = {
return;
}
// The x,y coordinates are relative to the <browser> element using
// the chrome zoom level.
let elt = document.getElementById("remoteBrowserTooltip");
elt.label = tooltip;
elt.style.direction = direction;
let screenX;
let screenY;
if (browser instanceof XULElement) {
// XUL element such as <browser> has the `screenX` and `screenY` fields.
// https://searchfox.org/mozilla-central/source/dom/webidl/XULElement.webidl
screenX = browser.screenX;
screenY = browser.screenY;
} else {
// In case of HTML element such as <iframe> which RDM uses,
// calculate the coordinate manually since it does not have the fields.
const componentBounds = browser.getBoundingClientRect();
screenX = window.screenX + componentBounds.x;
screenY = window.screenY + componentBounds.y;
}
elt.openPopupAtScreen(screenX + x, screenY + y, false, null);
elt.openPopupAtScreen(x, y, false, null);
},
hideTooltip() {

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

@ -1287,17 +1287,9 @@ void ChromeTooltipListener::sTooltipCallback(nsITimer* aTimer,
if (textFound && (!self->mTooltipShownOnce ||
tooltipText != self->mLastShownTooltipText)) {
LayoutDeviceIntPoint screenDot = widget->WidgetToScreenOffset();
double scaleFactor = 1.0;
if (presShell->GetPresContext()) {
nsDeviceContext* dc = presShell->GetPresContext()->DeviceContext();
scaleFactor = double(AppUnitsPerCSSPixel()) /
dc->AppUnitsPerDevPixelAtUnitFullZoom();
}
// ShowTooltip expects widget-relative position.
self->ShowTooltip(self->mMouseScreenX - screenDot.x / scaleFactor,
self->mMouseScreenY - screenDot.y / scaleFactor,
tooltipText, directionText);
// ShowTooltip expects screen-relative position.
self->ShowTooltip(self->mMouseScreenX, self->mMouseScreenY, tooltipText,
directionText);
self->mLastShownTooltipText = std::move(tooltipText);
self->mLastDocshell = do_GetWeakReference(
self->mPossibleTooltipNode->OwnerDoc()->GetDocShell());