Bug 527685 - Simplify widget transparency handling. r=josh, r=roc
authorMarkus Stange <mstange@themasta.com>
Fri, 13 Nov 2009 23:58:15 +0100
changeset 34853 9ce4279f72f0f94206f62c791e563a9a4217b0b2
parent 34852 fe9f7efe466444cd716a98a9a4b491ee906765cf
child 34854 88fc188da88bde899ffbee082632fe1d639e5e99
push id10305
push usermstange@themasta.com
push dateSat, 14 Nov 2009 09:41:34 +0000
treeherdermozilla-central@3cdaf0a84414 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjosh, roc
bugs527685
milestone1.9.3a1pre
Bug 527685 - Simplify widget transparency handling. r=josh, r=roc Store the window's transparency state on the NSWindow and use it for all of its subviews, instead of only making the top-level NSView transparent.
widget/src/cocoa/nsChildView.h
widget/src/cocoa/nsChildView.mm
widget/src/cocoa/nsCocoaWindow.h
widget/src/cocoa/nsCocoaWindow.mm
--- a/widget/src/cocoa/nsChildView.h
+++ b/widget/src/cocoa/nsChildView.h
@@ -150,19 +150,16 @@ enum {
   
   // when mouseDown: is called, we store its event here (strong)
   NSEvent* mLastMouseDownEvent;
   
   // rects that were invalidated during a draw, so have pending drawing
   NSMutableArray* mPendingDirtyRects;
   BOOL mPendingFullDisplay;
 
-  // All views are always opaque (non-transparent). The only exception is when we're
-  // the content view in a transparent XUL window.
-  BOOL mIsTransparent;
   PRIntervalTime mLastShadowInvalidation;
   BOOL mNeedsShadowInvalidation;
 
   // Holds our drag service across multiple drag calls. The reference to the
   // service is obtained when the mouse enters the view and is released when
   // the mouse exits or there is a drop. This prevents us from having to
   // re-establish the connection to the service manager many times per second
   // when handling |draggingUpdated:| messages.
@@ -202,18 +199,16 @@ enum {
 
 // these are sent to the first responder when the window key status changes
 - (void)viewsWindowDidBecomeKey;
 - (void)viewsWindowDidResignKey;
 
 // Stop NSView hierarchy being changed during [ChildView drawRect:]
 - (void)delayedTearDown;
 
-- (void)setTransparent:(BOOL)transparent;
-
 - (void)sendFocusEvent:(PRUint32)eventType;
 
 - (void)handleMouseMoved:(NSEvent*)aEvent;
 
 - (void)drawRect:(NSRect)aRect inContext:(CGContextRef)aContext;
 
 - (void)sendMouseEnterOrExitEvent:(NSEvent*)aEvent
                             enter:(BOOL)aEnter
--- a/widget/src/cocoa/nsChildView.mm
+++ b/widget/src/cocoa/nsChildView.mm
@@ -802,38 +802,33 @@ void* nsChildView::GetNativeData(PRUint3
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSNULL;
 }
 
 #pragma mark -
 
 nsTransparencyMode nsChildView::GetTransparencyMode()
 {
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
-
-  return [mView isOpaque] ? eTransparencyOpaque : eTransparencyTransparent;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK;
-  return eTransparencyOpaque;
+  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
+
+  nsCocoaWindow* windowWidget = GetXULWindowWidget();
+  return windowWidget ? windowWidget->GetTransparencyMode() : eTransparencyOpaque;
+
+  NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(eTransparencyOpaque);
 }
 
 // This is called by nsContainerFrame on the root widget for all window types
 // except popup windows (when nsCocoaWindow::SetTransparencyMode is used instead).
 void nsChildView::SetTransparencyMode(nsTransparencyMode aMode)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
-  BOOL isTransparent = aMode == eTransparencyTransparent;
-  BOOL currentTransparency = ![[mView window] isOpaque];
-  if (isTransparent != currentTransparency) {
-    nsCocoaWindow *widget = GetXULWindowWidget();
-    if (widget) {
-      widget->MakeBackgroundTransparent(aMode);
-      [(ChildView*)mView setTransparent:isTransparent];
-    }
+  nsCocoaWindow* windowWidget = GetXULWindowWidget();
+  if (windowWidget) {
+    windowWidget->SetTransparencyMode(aMode);
   }
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 NS_IMETHODIMP nsChildView::IsVisible(PRBool& outState)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
@@ -2392,24 +2387,19 @@ NSEvent* gLastDragMouseDownEvent = nil;
 
 // Make the origin of this view the topLeft corner (gecko origin) rather
 // than the bottomLeft corner (standard cocoa origin).
 - (BOOL)isFlipped
 {
   return YES;
 }
 
-- (void)setTransparent:(BOOL)transparent
-{
-  mIsTransparent = transparent;
-}
-
 - (BOOL)isOpaque
 {
-  return !mIsTransparent;
+  return [[self window] isOpaque];
 }
 
 -(void)setIsPluginView:(BOOL)aIsPlugin
 {
   mIsPluginView = aIsPlugin;
 }
 
 
--- a/widget/src/cocoa/nsCocoaWindow.h
+++ b/widget/src/cocoa/nsCocoaWindow.h
@@ -267,18 +267,16 @@ public:
     NSWindow *GetCocoaWindow() { return mWindow; }
 
     void SetMenuBar(nsMenuBarX* aMenuBar);
     nsMenuBarX *GetMenuBar();
 
     // nsIKBStateControl interface
     NS_IMETHOD ResetInputState();
     
-    void MakeBackgroundTransparent(PRBool aTransparent);
-
     NS_IMETHOD BeginSecureKeyboardInput();
     NS_IMETHOD EndSecureKeyboardInput();
 
     static void UnifiedShading(void* aInfo, const CGFloat* aIn, CGFloat* aOut);
 
 protected:
 
   nsresult             CreateNativeWindow(const NSRect &aRect,
--- a/widget/src/cocoa/nsCocoaWindow.mm
+++ b/widget/src/cocoa/nsCocoaWindow.mm
@@ -799,57 +799,36 @@ nsCocoaWindow::Scroll(const nsIntPoint& 
                       const nsTArray<nsIntRect>& aDestRects,
                       const nsTArray<Configuration>& aConfigurations)
 {
   if (mPopupContentView) {
     mPopupContentView->Scroll(aDelta, aDestRects, aConfigurations);
   }
 }
 
-void nsCocoaWindow::MakeBackgroundTransparent(PRBool aTransparent)
-{
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
-
-  BOOL currentTransparency = ![mWindow isOpaque];
-  if (aTransparent != currentTransparency) {
-    [mWindow setOpaque:!aTransparent];
-    [mWindow setBackgroundColor:(aTransparent ? [NSColor clearColor] : [NSColor whiteColor])];
-  }
-
-  NS_OBJC_END_TRY_ABORT_BLOCK;
-}
-
 nsTransparencyMode nsCocoaWindow::GetTransparencyMode()
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
 
   return [mWindow isOpaque] ? eTransparencyOpaque : eTransparencyTransparent;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(eTransparencyOpaque);
 }
 
 // This is called from nsMenuPopupFrame when making a popup transparent.
 // For other window types, nsChildView::SetTransparencyMode is used.
 void nsCocoaWindow::SetTransparencyMode(nsTransparencyMode aMode)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   BOOL isTransparent = aMode == eTransparencyTransparent;
-
   BOOL currentTransparency = ![mWindow isOpaque];
   if (isTransparent != currentTransparency) {
-    // Take care of window transparency
-    MakeBackgroundTransparent(isTransparent);
-    // Make sure our content view is also transparent
-    if (mPopupContentView) {
-      ChildView *childView = (ChildView*)mPopupContentView->GetNativeData(NS_NATIVE_WIDGET);
-      if (childView) {
-        [childView setTransparent:isTransparent];
-      }
-    }
+    [mWindow setOpaque:!isTransparent];
+    [mWindow setBackgroundColor:(isTransparent ? [NSColor clearColor] : [NSColor whiteColor])];
   }
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 NS_IMETHODIMP nsCocoaWindow::Enable(PRBool aState)
 {
   return NS_OK;