Bug 603793: Switch off drop shadows under some conditions. r=roc a=blocking-final
authorBas Schouten <bschouten@mozilla.com>
Sat, 19 Feb 2011 03:49:11 +0000
changeset 62852 7a99ba70cd6363e5880c18f14533270d2bcc7b6f
parent 62851 b0bf06306261f118bf660c1c3538746c5b071353
child 62853 70f2033fac3673c713549af22047b40317601781
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewersroc, blocking-final
bugs603793
milestone2.0b12pre
Bug 603793: Switch off drop shadows under some conditions. r=roc a=blocking-final
widget/src/windows/nsWindow.cpp
widget/src/windows/nsWindow.h
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -245,16 +245,17 @@ using namespace mozilla::layers;
  **************************************************************/
 
 /**************************************************************
  *
  * SECTION: nsWindow statics
  *
  **************************************************************/
 
+PRBool          nsWindow::sDropShadowEnabled      = PR_TRUE;
 PRUint32        nsWindow::sInstanceCount          = 0;
 PRBool          nsWindow::sSwitchKeyboardLayout   = PR_FALSE;
 BOOL            nsWindow::sIsOleInitialized       = FALSE;
 HCURSOR         nsWindow::sHCursor                = NULL;
 imgIContainer*  nsWindow::sCursorImgContainer     = nsnull;
 nsWindow*       nsWindow::sCurrentWindow          = nsnull;
 PRBool          nsWindow::sJustGotDeactivate      = PR_FALSE;
 PRBool          nsWindow::sJustGotActivate        = PR_FALSE;
@@ -1040,16 +1041,29 @@ BOOL nsWindow::SetNSWindowPtr(HWND aWnd,
   if (ptr == NULL) {
     ::RemovePropW(aWnd, GetNSWindowPropName());
     return TRUE;
   } else {
     return ::SetPropW(aWnd, GetNSWindowPropName(), (HANDLE)ptr);
   }
 }
 
+static BOOL CALLBACK AddMonitor(HMONITOR, HDC, LPRECT, LPARAM aParam)
+{
+  (*(PRInt32*)aParam)++;
+  return TRUE;
+}
+
+PRInt32 nsWindow::GetMonitorCount()
+{
+  PRInt32 monitorCount = 0;
+  EnumDisplayMonitors(NULL, NULL, AddMonitor, (LPARAM)&monitorCount);
+  return monitorCount;
+}
+
 /**************************************************************
  *
  * SECTION: nsIWidget::SetParent, nsIWidget::GetParent
  *
  * Set or clear the parent widgets using window properties, and
  * handles calculating native parent handles.
  *
  **************************************************************/
@@ -1206,16 +1220,39 @@ NS_METHOD nsWindow::Show(PRBool bState)
       (mWindowType == eWindowType_toplevel ||
        mWindowType == eWindowType_dialog ||
        mWindowType == eWindowType_popup))
   {
     splash->Close();
   }
 #endif
 
+  if (mWindowType == eWindowType_popup) {
+    // See bug 603793. When we try to draw D3D10 windows with a drop shadow
+    // without the DWM on a secondary monitor, windows fails to composite
+    // our windows correctly. We therefor switch off the drop shadow for
+    // pop-up windows when the DWM is disabled and two monitors are
+    // connected.
+    if (gfxWindowsPlatform::GetPlatform()->GetRenderMode() ==
+        gfxWindowsPlatform::RENDER_DIRECT2D &&
+        GetMonitorCount() > 1 &&
+        !nsUXThemeData::CheckForCompositor())
+    {
+      if (sDropShadowEnabled) {
+        ::SetClassLongA(mWnd, GCL_STYLE, 0);
+        sDropShadowEnabled = PR_FALSE;
+      }
+    } else {
+      if (!sDropShadowEnabled) {
+        ::SetClassLongA(mWnd, GCL_STYLE, CS_DROPSHADOW);
+        sDropShadowEnabled = PR_TRUE;
+      }
+    }
+  }
+
 #ifdef NS_FUNCTION_TIMER
   static bool firstShow = true;
   if (firstShow &&
       (mWindowType == eWindowType_toplevel ||
        mWindowType == eWindowType_dialog ||
        mWindowType == eWindowType_popup))
   {
     firstShow = false;
--- a/widget/src/windows/nsWindow.h
+++ b/widget/src/windows/nsWindow.h
@@ -318,16 +318,17 @@ protected:
   static void             AllowD3D9Callback(nsWindow *aWindow);
   static void             AllowD3D9WithReinitializeCallback(nsWindow *aWindow);
   static BOOL CALLBACK    FindOurWindowAtPointCallback(HWND aHWND, LPARAM aLPARAM);
 
   /**
    * Window utilities
    */
   static BOOL             SetNSWindowPtr(HWND aWnd, nsWindow * ptr);
+  static PRInt32          GetMonitorCount();
   LPARAM                  lParamToScreen(LPARAM lParam);
   LPARAM                  lParamToClient(LPARAM lParam);
   virtual void            SubclassWindow(BOOL bState);
   PRBool                  CanTakeFocus();
   PRBool                  UpdateNonClientMargins(PRInt32 aSizeMode = -1, PRBool aReflowWindow = PR_TRUE);
   void                    UpdateGetWindowInfoCaptionStatus(PRBool aActiveCaption);
   void                    ResetLayout();
   void                    InvalidateNonClientRegion();
@@ -527,16 +528,17 @@ protected:
   HIMC                  mOldIMC;
   IMEContext            mIMEContext;
   nsNativeDragTarget*   mNativeDragTarget;
   HKL                   mLastKeyboardLayout;
   nsPopupType           mPopupType;
   nsSizeMode            mOldSizeMode;
   WindowHook            mWindowHook;
   DWORD                 mAssumeWheelIsZoomUntil;
+  static PRBool         sDropShadowEnabled;
   static PRUint32       sInstanceCount;
   static TriStateBool   sCanQuit;
   static nsWindow*      sCurrentWindow;
   static BOOL           sIsOleInitialized;
   static HCURSOR        sHCursor;
   static imgIContainer* sCursorImgContainer;
   static PRBool         sSwitchKeyboardLayout;
   static PRBool         sJustGotDeactivate;