Bug 1602563 - [Linux] Allow nsWindow::Resize() reset aspect ratio, r=jhorak
authorMartin Stransky <stransky@redhat.com>
Tue, 10 Dec 2019 11:34:38 +0000
changeset 506222 374df506a9d412a961df2f3a90e67413434a73f8
parent 506221 d83d88a474ce1fd7a64c7351a0cf881740cd4347
child 506223 1744d3c7385498fc7cdaa97f9a091a1cde574aad
push id36900
push userdluca@mozilla.com
push dateTue, 10 Dec 2019 16:33:14 +0000
treeherdermozilla-central@f5d38101ac7c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1602563
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1602563 - [Linux] Allow nsWindow::Resize() reset aspect ratio, r=jhorak Differential Revision: https://phabricator.services.mozilla.com/D56443
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -981,16 +981,22 @@ void nsWindow::ConstrainPosition(bool aA
 }
 
 void nsWindow::SetSizeConstraints(const SizeConstraints& aConstraints) {
   LOG(("nsWindow::SetSizeConstraints [%p]\n", (void*)this));
 
   mSizeConstraints.mMinSize = GetSafeWindowSize(aConstraints.mMinSize);
   mSizeConstraints.mMaxSize = GetSafeWindowSize(aConstraints.mMaxSize);
 
+  ApplySizeConstraints();
+}
+
+void nsWindow::ApplySizeConstraints(void) {
+  LOG(("nsWindow::ApplySizeConstraints [%p]\n", (void*)this));
+
   if (mShell) {
     GdkGeometry geometry;
     geometry.min_width =
         DevicePixelsToGdkCoordRoundUp(mSizeConstraints.mMinSize.width);
     geometry.min_height =
         DevicePixelsToGdkCoordRoundUp(mSizeConstraints.mMinSize.height);
     geometry.max_width =
         DevicePixelsToGdkCoordRoundDown(mSizeConstraints.mMaxSize.width);
@@ -998,20 +1004,21 @@ void nsWindow::SetSizeConstraints(const 
         DevicePixelsToGdkCoordRoundDown(mSizeConstraints.mMaxSize.height);
 
     LOG(("    min width %d min height %d\n", geometry.min_width,
          geometry.min_height));
     LOG(("    max width %d max height %d\n", geometry.max_width,
          geometry.max_height));
 
     uint32_t hints = 0;
-    if (aConstraints.mMinSize != LayoutDeviceIntSize(0, 0)) {
+    if (mSizeConstraints.mMinSize != LayoutDeviceIntSize(0, 0)) {
       hints |= GDK_HINT_MIN_SIZE;
     }
-    if (aConstraints.mMaxSize != LayoutDeviceIntSize(NS_MAXSIZE, NS_MAXSIZE)) {
+    if (mSizeConstraints.mMaxSize !=
+        LayoutDeviceIntSize(NS_MAXSIZE, NS_MAXSIZE)) {
       hints |= GDK_HINT_MAX_SIZE;
     }
 
     if (mAspectRatio != 0.0f) {
       LOG(("    aspect %f\n", mAspectRatio));
       geometry.min_aspect = mAspectRatio;
       geometry.max_aspect = mAspectRatio;
       hints |= GDK_HINT_ASPECT;
@@ -1069,16 +1076,21 @@ void nsWindow::Resize(double aWidth, dou
   ConstrainSize(&width, &height);
 
   // For top-level windows, aWidth and aHeight should possibly be
   // interpreted as frame bounds, but NativeResize treats these as window
   // bounds (Bug 581866).
 
   mBounds.SizeTo(width, height);
 
+  // Recalculate aspect ratio when resized from DOM
+  if (mAspectRatio != 0.0) {
+    LockAspectRatio(true);
+  }
+
   if (!mCreated) return;
 
   NativeResize();
 
   NotifyRollupGeometryChange();
 
   // send a resize notification if this is a toplevel
   if (mIsTopLevel || mListenForResizes) {
@@ -7610,16 +7622,18 @@ void nsWindow::LockAspectRatio(bool aSho
     mAspectRatio = width / height;
     LOG(("nsWindow::LockAspectRatio() [%p] width %f height %f aspect %f\n",
          (void*)this, width, height, mAspectRatio));
   } else {
     mAspectRatio = 0.0;
     LOG(("nsWindow::LockAspectRatio() [%p] removed aspect ratio\n",
          (void*)this));
   }
+
+  ApplySizeConstraints();
 }
 
 #ifdef MOZ_WAYLAND
 void nsWindow::SetEGLNativeWindowSize(
     const LayoutDeviceIntSize& aEGLWindowSize) {
   if (mContainer && !mIsX11Display) {
     moz_container_egl_window_set_size(mContainer, aEGLWindowSize.width,
                                       aEGLWindowSize.height);
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -640,16 +640,18 @@ class nsWindow final : public nsBaseWidg
   virtual int32_t RoundsWidgetCoordinatesTo() override;
 
   void UpdateMozWindowActive();
 
   void ForceTitlebarRedraw();
 
   void SetPopupWindowDecoration(bool aShowOnTaskbar);
 
+  void ApplySizeConstraints(void);
+
   bool IsMainMenuWindow();
   GtkWidget* ConfigureWaylandPopupWindows();
   void HideWaylandWindow();
   void HideWaylandTooltips();
   void HideWaylandPopupAndAllChildren();
   void CleanupWaylandPopups();
   GtkWindow* GetCurrentTopmostWindow();