Bug 1768360 [Wayland] Don't use move-to-rect with invalid/missing anchor r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D146782
This commit is contained in:
stransky 2022-05-19 11:58:14 +00:00
Родитель 1677fb63f8
Коммит 85bfbfeed8
2 изменённых файлов: 28 добавлений и 14 удалений

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

@ -2108,7 +2108,7 @@ void nsWindow::NativeMoveResizeWaylandPopup(bool aMove, bool aResize) {
bool trackedInHierarchy = WaylandPopupConfigure();
// Read popup position from layout if it was moved.
// Read popup position from layout if it was moved or newly created.
// This position is used by move-to-rect method as we need anchor and other
// info to place popup correctly.
// We need WaylandPopupConfigure() to be called before to have all needed
@ -2356,10 +2356,14 @@ nsWindow::WaylandPopupGetPositionFromLayout() {
}
return {
anchorRect, rectAnchor, menuAnchor, hints,
anchorRect,
rectAnchor,
menuAnchor,
hints,
DevicePixelsToGdkPointRoundDown(LayoutDevicePoint::FromAppUnitsToNearest(
popupMargin.mPopupOffset,
popupFrame->PresContext()->AppUnitsPerDevPixel()))};
popupFrame->PresContext()->AppUnitsPerDevPixel())),
true};
}
void nsWindow::WaylandPopupMove() {
@ -2370,19 +2374,28 @@ void nsWindow::WaylandPopupMove() {
GdkWindow*, const GdkRectangle*, GdkGravity, GdkGravity, GdkAnchorHints,
gint, gint))dlsym(RTLD_DEFAULT, "gdk_window_move_to_rect");
GdkWindow* gdkWindow = gtk_widget_get_window(GTK_WIDGET(mShell));
nsMenuPopupFrame* popupFrame = GetMenuPopupFrame(GetFrame());
LOG(" original widget popup position [%d, %d]\n", mPopupPosition.x,
mPopupPosition.y);
LOG(" relative widget popup position [%d, %d]\n", mRelativePopupPosition.x,
mRelativePopupPosition.y);
if (mPopupUseMoveToRect) {
mPopupUseMoveToRect = sGdkWindowMoveToRect && gdkWindow && popupFrame;
if (mPopupUseMoveToRect && !sGdkWindowMoveToRect) {
LOG(" can't use move-to-rect due missing gdk_window_move_to_rect()");
mPopupUseMoveToRect = false;
}
LOG(" popup use move to rect %d\n", mPopupUseMoveToRect);
GdkWindow* gdkWindow = gtk_widget_get_window(GTK_WIDGET(mShell));
nsMenuPopupFrame* popupFrame = GetMenuPopupFrame(GetFrame());
if (mPopupUseMoveToRect && !gdkWindow || !popupFrame) {
LOG(" can't use move-to-rect due missing gdkWindow or popupFrame");
mPopupUseMoveToRect = false;
}
if (mPopupUseMoveToRect && !mPopupMoveToRectParams.mAnchorSet) {
LOG(" can't use move-to-rect due missing anchor");
mPopupUseMoveToRect = false;
}
LOG(" popup use move to rect %d\n", mPopupUseMoveToRect);
if (!mPopupUseMoveToRect) {
if (mNeedsShow && mPopupType != ePopupTypeTooltip) {

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

@ -705,11 +705,12 @@ class nsWindow final : public nsBaseWidget {
// we need to reuse last GdkWindowMoveToRect params to avoid
// popup movement.
struct WaylandPopupMoveToRectParams {
LayoutDeviceIntRect mAnchorRect;
GdkGravity mAnchorRectType;
GdkGravity mPopupAnchorType;
GdkAnchorHints mHints;
GdkPoint mOffset;
LayoutDeviceIntRect mAnchorRect = {0, 0, 0, 0};
GdkGravity mAnchorRectType = GDK_GRAVITY_NORTH_WEST;
GdkGravity mPopupAnchorType = GDK_GRAVITY_NORTH_WEST;
GdkAnchorHints mHints = GDK_ANCHOR_SLIDE;
GdkPoint mOffset = {0, 0};
bool mAnchorSet = false;
};
WaylandPopupMoveToRectParams mPopupMoveToRectParams;