Bug 1370034 - Add nsIWidget::SetWindowOpacity and implement it on Mac. r?spohl draft
authorMarkus Stange <mstange@themasta.com>
Wed, 14 Jun 2017 19:14:02 -0400
changeset 596312 014c89d42ff0a91cf56626ed7d537134ad63246a
parent 596311 0641b031aaa8834c863a54c046079dbe490a0319
child 596313 9a1c79a11ad6ceeb30fb53c08accb3769e3a147e
push id64577
push userbmo:mstange@themasta.com
push dateMon, 19 Jun 2017 04:31:30 +0000
reviewersspohl
bugs1370034
milestone56.0a1
Bug 1370034 - Add nsIWidget::SetWindowOpacity and implement it on Mac. r?spohl MozReview-Commit-ID: ILqHQuQ4whl
widget/cocoa/nsCocoaWindow.h
widget/cocoa/nsCocoaWindow.mm
widget/nsIWidget.h
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -310,16 +310,17 @@ public:
                                    nsEventStatus& aStatus) override;
     virtual void CaptureRollupEvents(nsIRollupListener * aListener,
                                      bool aDoCapture) override;
     virtual MOZ_MUST_USE nsresult GetAttention(int32_t aCycleCount) override;
     virtual bool HasPendingInputEvent() override;
     virtual nsTransparencyMode GetTransparencyMode() override;
     virtual void SetTransparencyMode(nsTransparencyMode aMode) override;
     virtual void SetWindowShadowStyle(int32_t aStyle) override;
+    virtual void SetWindowOpacity(float aOpacity) override;
     virtual void SetShowsToolbarButton(bool aShow) override;
     virtual void SetShowsFullScreenButton(bool aShow) override;
     virtual void SetWindowAnimationType(WindowAnimationType aType) override;
     virtual void SetDrawsTitle(bool aDrawTitle) override;
     virtual void SetUseBrightTitlebarForeground(bool aBrightForeground) override;
     virtual nsresult SetNonClientMargins(LayoutDeviceIntMargin& aMargins) override;
     virtual void SetWindowTitlebarColor(nscolor aColor, bool aActive) override;
     virtual void SetDrawsInTitlebar(bool aState) override;
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -2159,16 +2159,30 @@ nsCocoaWindow::SetWindowShadowStyle(int3
 
   [mWindow setUseMenuStyle:(aStyle == NS_STYLE_WINDOW_SHADOW_MENU)];
   AdjustWindowShadow();
   SetWindowBackgroundBlur();
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
+void
+nsCocoaWindow::SetWindowOpacity(float aOpacity)
+{
+  NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
+
+  if (!mWindow) {
+    return;
+  }
+
+  [mWindow setAlphaValue:(CGFloat)aOpacity];
+
+  NS_OBJC_END_TRY_ABORT_BLOCK;
+}
+
 void nsCocoaWindow::SetShowsToolbarButton(bool aShow)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   if (mWindow)
     [mWindow setShowsToolbarButton:aShow];
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -1100,16 +1100,24 @@ class nsIWidget : public nsISupports
 
     /**
      * Set the shadow style of the window.
      *
      * Ignored on child widgets and on non-Mac platforms.
      */
     virtual void SetWindowShadowStyle(int32_t aStyle) = 0;
 
+    /**
+     * Set the opacity of the window.
+     * Values need to be between 0.0f (invisible) and 1.0f (fully opaque).
+     *
+     * Ignored on child widgets and on non-Mac platforms.
+     */
+    virtual void SetWindowOpacity(float aOpacity) {}
+
     /*
      * On Mac OS X, this method shows or hides the pill button in the titlebar
      * that's used to collapse the toolbar.
      *
      * Ignored on child widgets and on non-Mac platforms.
      */
     virtual void SetShowsToolbarButton(bool aShow) = 0;