Bug 1421974 - refactor nsWindow::HideWindowChrome() to nsWindow::SetWindowDecoration() and share it with nsWindow::SetDrawsInTitlebar, r?jhorak draft
authorMartin Stransky <stransky@redhat.com>
Fri, 01 Dec 2017 15:09:11 +0100
changeset 706229 36da4aee5eba3e01e0092efd36dd216070046e30
parent 706025 a21f4e2ce5186e2dc9ee411b07e9348866b4ef30
child 706230 c1514ca175cf545221ba8c3da9eca28cfb188817
child 707505 0c352cfe3c901a282702031ed451cfadbf37a27e
child 707587 d33ef927659cfa53c7bdd2f7b237eb423a116294
push id91744
push userstransky@redhat.com
push dateFri, 01 Dec 2017 14:34:07 +0000
reviewersjhorak
bugs1421974
milestone59.0a1
Bug 1421974 - refactor nsWindow::HideWindowChrome() to nsWindow::SetWindowDecoration() and share it with nsWindow::SetDrawsInTitlebar, r?jhorak MozReview-Commit-ID: 3xEdMXq9JvJ
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -5072,47 +5072,42 @@ nsWindow::MakeFullScreen(bool aFullScree
     }
 
     NS_ASSERTION(mLastSizeMode != nsSizeMode_Fullscreen,
                  "mLastSizeMode should never be fullscreen");
     return NS_OK;
 }
 
 void
-nsWindow::HideWindowChrome(bool aShouldHide)
+nsWindow::SetWindowDecoration(nsBorderStyle aStyle)
 {
     if (!mShell) {
         // Pass the request to the toplevel window
         GtkWidget *topWidget = GetToplevelWidget();
         if (!topWidget)
             return;
 
         nsWindow *topWindow = get_window_for_gtk_widget(topWidget);
         if (!topWindow)
             return;
 
-        topWindow->HideWindowChrome(aShouldHide);
+        topWindow->SetWindowDecoration(aStyle);
         return;
     }
 
     // Sawfish, metacity, and presumably other window managers get
     // confused if we change the window decorations while the window
     // is visible.
     bool wasVisible = false;
     if (gdk_window_is_visible(mGdkWindow)) {
         gdk_window_hide(mGdkWindow);
         wasVisible = true;
     }
 
-    gint wmd;
-    if (aShouldHide)
-        wmd = 0;
-    else
-        wmd = ConvertBorderStyles(mBorderStyle);
-
+    gint wmd = ConvertBorderStyles(aStyle);
     if (wmd != -1)
       gdk_window_set_decorations(mGdkWindow, (GdkWMDecoration) wmd);
 
     if (wasVisible)
         gdk_window_show(mGdkWindow);
 
     // For some window managers, adding or removing window decorations
     // requires unmapping and remapping our toplevel window.  Go ahead
@@ -5121,16 +5116,22 @@ nsWindow::HideWindowChrome(bool aShouldH
     // and GetWindowPos is called)
 #ifdef MOZ_X11
     XSync(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()) , False);
 #else
     gdk_flush ();
 #endif /* MOZ_X11 */
 }
 
+void
+nsWindow::HideWindowChrome(bool aShouldHide)
+{
+    SetWindowDecoration(aShouldHide ? eBorderStyle_none : mBorderStyle);
+}
+
 bool
 nsWindow::CheckForRollup(gdouble aMouseX, gdouble aMouseY,
                          bool aIsWheel, bool aAlwaysRollup)
 {
     nsIRollupListener* rollupListener = GetActiveRollupListener();
     nsCOMPtr<nsIWidget> rollupWidget;
     if (rollupListener) {
         rollupWidget = rollupListener->GetRollupWidget();
@@ -6641,24 +6642,19 @@ nsWindow::SetNonClientMargins(LayoutDevi
 
 void
 nsWindow::SetDrawsInTitlebar(bool aState)
 {
   if (!mIsCSDAvailable || aState == mIsCSDEnabled)
       return;
 
   if (mShell) {
-      gint wmd;
-      if (aState) {
-          wmd = GetCSDSupportLevel() == CSD_SUPPORT_FULL ? GDK_DECOR_BORDER : 0;
-      } else {
-          wmd = ConvertBorderStyles(mBorderStyle);
+      if (GetCSDSupportLevel() == CSD_SUPPORT_FULL) {
+          SetWindowDecoration(aState ? eBorderStyle_border : mBorderStyle);
       }
-      gdk_window_set_decorations(gtk_widget_get_window(mShell),
-                                 (GdkWMDecoration) wmd);
   }
 
   mIsCSDEnabled = aState;
 }
 
 gint
 nsWindow::GdkScaleFactor()
 {
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -430,16 +430,17 @@ protected:
     bool               mIsX11Display;
 
 private:
     void               DestroyChildWindows();
     GtkWidget         *GetToplevelWidget();
     nsWindow          *GetContainerWindow();
     void               SetUrgencyHint(GtkWidget *top_window, bool state);
     void               SetDefaultIcon(void);
+    void               SetWindowDecoration(nsBorderStyle aStyle);
     void               InitButtonEvent(mozilla::WidgetMouseEvent& aEvent,
                                        GdkEventButton* aGdkEvent);
     bool               DispatchCommandEvent(nsAtom* aCommand);
     bool               DispatchContentCommandEvent(mozilla::EventMessage aMsg);
     bool               CheckForRollup(gdouble aMouseX, gdouble aMouseY,
                                       bool aIsWheel, bool aAlwaysRollup);
     void               CheckForRollupDuringGrab()
     {
@@ -448,17 +449,16 @@ private:
 
     bool               GetDragInfo(mozilla::WidgetMouseEvent* aMouseEvent,
                                    GdkWindow** aWindow, gint* aButton,
                                    gint* aRootX, gint* aRootY);
     void               ClearCachedResources();
     nsIWidgetListener* GetListener();
     bool               IsComposited() const;
 
-
     GtkWidget          *mShell;
     MozContainer       *mContainer;
     GdkWindow          *mGdkWindow;
     PlatformCompositorWidgetDelegate* mCompositorWidgetDelegate;
 
 
     uint32_t            mHasMappedToplevel : 1,
                         mIsFullyObscured : 1,