Bug 1653615 - Ensure displayport snapping doesn't move by more than the margin. r=kats

Differential Revision: https://phabricator.services.mozilla.com/D84552
This commit is contained in:
Nicolas Silva 2020-07-24 07:09:47 +00:00
Родитель d93c5bb4f4
Коммит 6647720701
1 изменённых файлов: 23 добавлений и 1 удалений

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

@ -893,6 +893,19 @@ static nsRect GetDisplayPortFromMarginsData(
float sx = fmin(1.0, (xMargin + w) / w * 0.25);
posAlignment.width =
fmax(defaultAlignment, multiple * round(sx * w / multiple));
// Margins are usually large (multiple times screenRect's size, see the
// apz.x_skate_size_multiplier pref), however it can be be small on
// occasions. If the alignment is larger than the margin on the right, we
// could end up snapping the displayport to the left too much and miss
// some content on the right. Since the size is aligned independently we
// can't be sure it will compensate so we ensure that the alignment is
// never larger than the margin. The snapping always rounds down so we
// don't need to check the left margin.
float rightMargin = fabs(aMarginsData->mMargins.right);
if (posAlignment.width > rightMargin) {
posAlignment.width -=
multiple * ceil((posAlignment.width - rightMargin) / multiple);
}
} else {
posAlignment.width = defaultAlignment;
}
@ -902,6 +915,12 @@ static nsRect GetDisplayPortFromMarginsData(
float sy = fmin(1.0, (yMargin + h) / h * 0.25);
posAlignment.height =
fmax(defaultAlignment, multiple * round(sy * h / multiple));
float bottomMargin = fabs(aMarginsData->mMargins.bottom);
if (posAlignment.height > bottomMargin) {
posAlignment.height -=
multiple * ceil((posAlignment.height - bottomMargin) / multiple);
}
} else {
posAlignment.height = defaultAlignment;
}
@ -988,7 +1007,10 @@ static nsRect GetDisplayPortFromMarginsData(
ScreenPoint scrollPosScreen =
LayoutDevicePoint::FromAppUnits(scrollPos, auPerDevPixel) * res;
// Round-out the display port to the nearest alignment (tiles)
// Align the display port.
// TODO(bug 1654836): we currently align the origin and independently align
// the size. a better approach would be to round out the endpoints of the
// unaligned display port.
screenRect += scrollPosScreen;
float x = posAlignment.width * floor(screenRect.x / posAlignment.width);
float y = posAlignment.height * floor(screenRect.y / posAlignment.height);