Bug 1283299 - Part 5: Undecorate GTK window when chrome margins are 0. r?karlt draft
authorAndrew Comminos <andrew@comminos.com>
Tue, 05 Jul 2016 14:07:09 -0400
changeset 384222 813dfd170698cbcf9beba959e010196fe939702f
parent 384221 308e1f3d729801b0a694ec9f59749cbedfd5047d
child 384223 74b7a833bc8e98b22313405e6fce9ee38c4f022e
push id22212
push userbmo:andrew@comminos.com
push dateTue, 05 Jul 2016 20:52:16 +0000
reviewerskarlt
bugs1283299
milestone50.0a1
Bug 1283299 - Part 5: Undecorate GTK window when chrome margins are 0. r?karlt MozReview-Commit-ID: Lxm8sCpUhG2
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -476,16 +476,17 @@ nsWindow::nsWindow()
     mTransparencyBitmapHeight = 0;
 
 #if GTK_CHECK_VERSION(3,4,0)
     mLastScrollEventTime = GDK_CURRENT_TIME;
 #endif
 
     mFallbackSurface = nullptr;
     mPendingConfigures = 0;
+    mDrawsInTitlebar = false;
 }
 
 nsWindow::~nsWindow()
 {
     LOG(("nsWindow::~nsWindow() [%p]\n", (void *)this));
 
     delete[] mTransparencyBitmap;
     mTransparencyBitmap = nullptr;
@@ -6881,16 +6882,37 @@ nsWindow::ClearCachedResources()
     for (GList* list = children; list; list = list->next) {
         nsWindow* window = get_window_for_gdk_window(GDK_WINDOW(list->data));
         if (window) {
             window->ClearCachedResources();
         }
     }
 }
 
+NS_IMETHODIMP
+nsWindow::SetNonClientMargins(LayoutDeviceIntMargin &aMargins)
+{
+  SetDrawsInTitlebar(aMargins.top == 0);
+  return NS_OK;
+}
+
+void
+nsWindow::SetDrawsInTitlebar(bool aState)
+{
+  if (aState == mDrawsInTitlebar)
+    return;
+
+  if (mShell) {
+    NS_WARNING("gtk_window_set_decorated may not have any effect when called on a window that is already visible.");
+    gtk_window_set_decorated(GTK_WINDOW(mShell), !aState);
+  }
+
+  mDrawsInTitlebar = aState;
+}
+
 bool
 nsWindow::HasARGBVisual() const
 {
   if (!mGdkWindow) {
     NS_WARNING("nsWindow::HasARGBVisual called before realization!");
     return false;
   }
   return gdk_window_get_visual(mGdkWindow)
@@ -7179,8 +7201,14 @@ nsWindow::SynthesizeNativeTouchPoint(uin
 }
 #endif
 
 int32_t
 nsWindow::RoundsWidgetCoordinatesTo()
 {
     return GdkScaleFactor();
 }
+
+bool
+nsWindow::IsClientDecorated() const
+{
+    return mDrawsInTitlebar;
+}
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -349,16 +349,20 @@ public:
     virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
                                                 TouchPointerState aPointerState,
                                                 LayoutDeviceIntPoint aPoint,
                                                 double aPointerPressure,
                                                 uint32_t aPointerOrientation,
                                                 nsIObserver* aObserver) override;
 #endif
 
+    NS_IMETHOD SetNonClientMargins(LayoutDeviceIntMargin& aMargins) override;
+
+    void SetDrawsInTitlebar(bool aState) override;
+
     bool HasARGBVisual() const;
     bool IsComposited() const;
 
     // If true, 'solid' client side decorations (without an alpha channel)
     // should be used if available.
     bool UseSolidCSD() const;
 
     // HiDPI scale conversion
@@ -388,16 +392,19 @@ protected:
     // Helper for SetParent and ReparentNativeWidget.
     void ReparentNativeWidgetInternal(nsIWidget* aNewParent,
                                       GtkWidget* aNewContainer,
                                       GdkWindow* aNewParentWindow,
                                       GtkWidget* aOldContainer);
 
     virtual void RegisterTouchWindow() override;
 
+    // Decorations
+    bool IsClientDecorated() const;
+
     nsCOMPtr<nsIWidget> mParent;
     // Is this a toplevel window?
     bool                mIsTopLevel;
     // Has this widget been destroyed yet?
     bool                mIsDestroyed;
 
     // Should we send resize events on all resizes?
     bool                mListenForResizes;
@@ -552,16 +559,19 @@ private:
     void   InitDragEvent(mozilla::WidgetDragEvent& aEvent);
 
     float              mLastMotionPressure;
 
     // Remember the last sizemode so that we can restore it when
     // leaving fullscreen
     nsSizeMode         mLastSizeMode;
 
+    // If true, draw our own window decorations (where supported).
+    bool mDrawsInTitlebar;
+
     static bool DragInProgress(void);
 
     void DispatchMissedButtonReleases(GdkEventCrossing *aGdkEvent);
 
     // nsBaseWidget
     virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr,
                                           LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE,
                                           LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) override;