From 3fb7ea6a201df9b06e24a734df4fddc7e7e60e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 31 Jan 2023 10:41:29 +0000 Subject: [PATCH] Bug 1813554 - Clean-up CheckResizerEdge. r=stransky No behavior change. Differential Revision: https://phabricator.services.mozilla.com/D168282 --- widget/gtk/nsWindow.cpp | 75 ++++++++++++++++++++++------------------- widget/gtk/nsWindow.h | 7 ++-- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 98aa41a2b444..036b48bdaef5 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -4291,45 +4291,52 @@ void nsWindow::OnLeaveNotifyEvent(GdkEventCrossing* aEvent) { DispatchInputEvent(&event); } -bool nsWindow::CheckResizerEdge(LayoutDeviceIntPoint aPoint, - GdkWindowEdge& aOutEdge) { +Maybe nsWindow::CheckResizerEdge( + const LayoutDeviceIntPoint& aPoint) { // We only need to handle resizers for PIP window. if (!mIsPIPWindow) { - return false; + return {}; } - // Don't allow resizing maximized windows. + // Don't allow resizing maximized/fullscreen windows. if (mSizeMode != nsSizeMode_Normal) { - return false; + return {}; } #define RESIZER_SIZE 15 - int resizerSize = RESIZER_SIZE * GdkCeiledScaleFactor(); - int topDist = aPoint.y; - int leftDist = aPoint.x; - int rightDist = mBounds.width - aPoint.x; - int bottomDist = mBounds.height - aPoint.y; + const int resizerSize = RESIZER_SIZE * GdkCeiledScaleFactor(); + const int topDist = aPoint.y; + const int leftDist = aPoint.x; + const int rightDist = mBounds.width - aPoint.x; + const int bottomDist = mBounds.height - aPoint.y; - if (leftDist <= resizerSize && topDist <= resizerSize) { - aOutEdge = GDK_WINDOW_EDGE_NORTH_WEST; - } else if (rightDist <= resizerSize && topDist <= resizerSize) { - aOutEdge = GDK_WINDOW_EDGE_NORTH_EAST; - } else if (leftDist <= resizerSize && bottomDist <= resizerSize) { - aOutEdge = GDK_WINDOW_EDGE_SOUTH_WEST; - } else if (rightDist <= resizerSize && bottomDist <= resizerSize) { - aOutEdge = GDK_WINDOW_EDGE_SOUTH_EAST; - } else if (topDist <= resizerSize) { - aOutEdge = GDK_WINDOW_EDGE_NORTH; - } else if (leftDist <= resizerSize) { - aOutEdge = GDK_WINDOW_EDGE_WEST; - } else if (rightDist <= resizerSize) { - aOutEdge = GDK_WINDOW_EDGE_EAST; - } else if (bottomDist <= resizerSize) { - aOutEdge = GDK_WINDOW_EDGE_SOUTH; - } else { - return false; + if (topDist <= resizerSize) { + if (rightDist <= resizerSize) { + return Some(GDK_WINDOW_EDGE_NORTH_EAST); + } + if (leftDist <= resizerSize) { + return Some(GDK_WINDOW_EDGE_NORTH_WEST); + } + return Some(GDK_WINDOW_EDGE_NORTH); } - return true; + + if (bottomDist <= resizerSize) { + if (leftDist <= resizerSize) { + return Some(GDK_WINDOW_EDGE_SOUTH_WEST); + } + if (rightDist <= resizerSize) { + return Some(GDK_WINDOW_EDGE_SOUTH_EAST); + } + return Some(GDK_WINDOW_EDGE_SOUTH); + } + + if (leftDist <= resizerSize) { + return Some(GDK_WINDOW_EDGE_WEST); + } + if (rightDist <= resizerSize) { + return Some(GDK_WINDOW_EDGE_EAST); + } + return {}; } template @@ -4378,11 +4385,10 @@ void nsWindow::OnMotionNotifyEvent(GdkEventMotion* aEvent) { } } - GdkWindowEdge edge; const auto refPoint = GetRefPoint(this, aEvent); - if (CheckResizerEdge(refPoint, edge)) { + if (auto edge = CheckResizerEdge(refPoint)) { nsCursor cursor = eCursor_none; - switch (edge) { + switch (*edge) { case GDK_WINDOW_EDGE_NORTH: cursor = eCursor_n_resize; break; @@ -4586,9 +4592,8 @@ void nsWindow::OnButtonPressEvent(GdkEventButton* aEvent) { } // Check to see if the event is within our window's resize region - GdkWindowEdge edge; - if (CheckResizerEdge(refPoint, edge)) { - gdk_window_begin_resize_drag(gtk_widget_get_window(mShell), edge, + if (auto edge = CheckResizerEdge(refPoint)) { + gdk_window_begin_resize_drag(gtk_widget_get_window(mShell), *edge, aEvent->button, aEvent->x_root, aEvent->y_root, aEvent->time); return; diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h index fceb3ff2f118..8deea839eeca 100644 --- a/widget/gtk/nsWindow.h +++ b/widget/gtk/nsWindow.h @@ -518,9 +518,10 @@ class nsWindow final : public nsBaseWidget { LayoutDeviceIntSize aSize); void NativeMoveResizeWaylandPopup(bool aMove, bool aResize); - // Returns true if the given point (in device pixels) is within a resizer - // region of the window. Only used when drawing decorations client side. - bool CheckResizerEdge(LayoutDeviceIntPoint aPoint, GdkWindowEdge& aOutEdge); + // Returns a window edge if the given point (in device pixels) is within a + // resizer region of the window. + // Only used when drawing decorations client side. + mozilla::Maybe CheckResizerEdge(const LayoutDeviceIntPoint&); GtkTextDirection GetTextDirection();