Bug 599241 - Draw the persona's accent colour in the titlebar in OpenGL mode as a stop-gap measure until we can draw proper content in the titlebar again. r=mstange a=b
authorJoe Drew <joe@drew.ca>
Wed, 29 Sep 2010 14:37:44 -0400
changeset 54779 a976293325c61a727b8e845b58c4396eb5a7db4e
parent 54778 879acd43522e4f1598ec2bd746f79673d685928c
child 54780 3fd2c9ce4e9c64116f67847f55d23a408e8df329
push idunknown
push userunknown
push dateunknown
reviewersmstange, b
bugs599241
milestone2.0b7pre
Bug 599241 - Draw the persona's accent colour in the titlebar in OpenGL mode as a stop-gap measure until we can draw proper content in the titlebar again. r=mstange a=b
toolkit/content/LightweightThemeConsumer.jsm
widget/src/cocoa/nsChildView.h
widget/src/cocoa/nsChildView.mm
widget/src/cocoa/nsCocoaWindow.mm
--- a/toolkit/content/LightweightThemeConsumer.jsm
+++ b/toolkit/content/LightweightThemeConsumer.jsm
@@ -93,16 +93,25 @@ LightweightThemeConsumer.prototype = {
       _setImage(footer, active, aData.footerURL);
       if (active && aData.footerURL)
         footer.setAttribute("lwthemefooter", "true");
       else
         footer.removeAttribute("lwthemefooter");
     }
 
 #ifdef XP_MACOSX
+
+    if (active && aData.accentcolor) {
+      root.setAttribute("activetitlebarcolor", aData.accentcolor);
+      root.setAttribute("inactivetitlebarcolor", aData.accentcolor);
+    } else {
+      root.removeAttribute("activetitlebarcolor");
+      root.removeAttribute("inactivetitlebarcolor");
+    }
+
     if (active)
       root.setAttribute("drawintitlebar", "true");
     else
       root.removeAttribute("drawintitlebar");
 #endif
   }
 }
 
--- a/widget/src/cocoa/nsChildView.h
+++ b/widget/src/cocoa/nsChildView.h
@@ -223,16 +223,18 @@ extern "C" long TSMProcessRawKeyEvent(Ev
 - (void)pluginRequestsComplexTextInputForCurrentEvent;
 
 - (void)update;
 - (void)lockFocus;
 - (void) _surfaceNeedsUpdate:(NSNotification*)notification;
 
 - (BOOL)isPluginView;
 
+- (BOOL)isUsingOpenGL;
+
 // Simple gestures support
 //
 // XXX - The swipeWithEvent, beginGestureWithEvent, magnifyWithEvent,
 // rotateWithEvent, and endGestureWithEvent methods are part of a
 // PRIVATE interface exported by nsResponder and reverse-engineering
 // was necessary to obtain the methods' prototypes. Thus, Apple may
 // change the interface in the future without notice.
 //
--- a/widget/src/cocoa/nsChildView.mm
+++ b/widget/src/cocoa/nsChildView.mm
@@ -2583,28 +2583,37 @@ NSEvent* gLastDragMouseDownEvent = nil;
   }
 }
 
 - (void) _surfaceNeedsUpdate:(NSNotification*)notification
 {
    [self update];
 }
 
+- (BOOL) isUsingOpenGL
+{
+    return mGeckoChild && mGeckoChild->GetLayerManager()->GetBackendType() == LayerManager::LAYERS_OPENGL;
+}
+
 // The display system has told us that a portion of our view is dirty. Tell
 // gecko to paint it
 - (void)drawRect:(NSRect)aRect
 {
+  float oldHeight = [self beginMaybeResetUnifiedToolbar];
+
   CGContextRef cgContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
   [self drawRect:aRect inContext:cgContext];
 
   // If we're a transparent window and our contents have changed, we need
   // to make sure the shadow is updated to the new contents.
   if ([[self window] isKindOfClass:[BaseWindow class]]) {
     [(BaseWindow*)[self window] deferredInvalidateShadow];
   }
+
+  [self endMaybeResetUnifiedToolbar:oldHeight];
 }
 
 - (void)drawRect:(NSRect)aRect inContext:(CGContextRef)aContext
 {
   PRBool isVisible;
   if (!mGeckoChild || NS_FAILED(mGeckoChild->IsVisible(isVisible)) ||
       !isVisible)
     return;
@@ -2693,36 +2702,32 @@ NSEvent* gLastDragMouseDownEvent = nil;
   for (;;) {
     const nsIntRect* r = iter.Next();
     if (!r)
       break;
     targetContext->Rectangle(gfxRect(r->x, r->y, r->width, r->height));
   }
   targetContext->Clip();
 
-  float oldHeight = [self beginMaybeResetUnifiedToolbar];
-
   nsAutoRetainCocoaObject kungFuDeathGrip(self);
   PRBool painted;
   {
     nsBaseWidget::AutoLayerManagerSetup
       setupLayerManager(mGeckoChild, targetContext, BasicLayerManager::BUFFER_NONE);
     painted = mGeckoChild->DispatchWindowEvent(paintEvent);
   }
 
   if (!painted && [self isOpaque]) {
     // Gecko refused to draw, but we've claimed to be opaque, so we have to
     // draw something--fill with white.
     CGContextSetRGBFillColor(aContext, 1, 1, 1, 1);
     CGContextFillRect(aContext, CGRectMake(aRect.origin.x, aRect.origin.y,
                                            aRect.size.width, aRect.size.height));
   }
 
-  [self endMaybeResetUnifiedToolbar:oldHeight];
-
   // note that the cairo surface *MUST* be destroyed at this point,
   // or bad things will happen (since we can't keep the cgContext around
   // beyond this drawRect message handler)
 
 #ifdef DEBUG_UPDATE
   fprintf (stderr, "---- update done ----\n");
 
 #if 0
--- a/widget/src/cocoa/nsCocoaWindow.mm
+++ b/widget/src/cocoa/nsCocoaWindow.mm
@@ -2436,20 +2436,28 @@ ContentPatternDrawCallback(void* aInfo, 
 
   NSRect titlebarRect = NSMakeRect(0, 0, [window frame].size.width, [window titlebarHeight]);
   [(ChildView*)view drawRect:titlebarRect inContext:aContext];
 }
 
 - (void)setFill
 {
   CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
-  CGPatternDrawPatternCallback cb = [mWindow drawsContentsIntoWindowFrame] ?
+  CGPatternDrawPatternCallback cb;
+  float patternWidth;
+  NSView* view = [[[mWindow contentView] subviews] lastObject];
+  if (view && [view isKindOfClass:[ChildView class]] && [(ChildView*)view isUsingOpenGL]) {
+    cb = &RepeatedPatternDrawCallback;
+    patternWidth = sPatternWidth;
+  } else {
+    cb = [mWindow drawsContentsIntoWindowFrame] ?
                                       &ContentPatternDrawCallback : &RepeatedPatternDrawCallback;
+    patternWidth = [mWindow drawsContentsIntoWindowFrame] ? [mWindow frame].size.width : sPatternWidth;
+  }
   CGPatternCallbacks callbacks = {0, cb, NULL};
-  float patternWidth = [mWindow drawsContentsIntoWindowFrame] ? [mWindow frame].size.width : sPatternWidth;
   CGPatternRef pattern = CGPatternCreate(mWindow, CGRectMake(0.0f, 0.0f, patternWidth, [mWindow frame].size.height), 
                                          CGAffineTransformIdentity, patternWidth, [mWindow frame].size.height,
                                          kCGPatternTilingConstantSpacing, true, &callbacks);
 
   // Set the pattern as the fill, which is what we were asked to do. All our
   // drawing will take place in the patternDraw callback.
   CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(NULL);
   CGContextSetFillColorSpace(context, patternSpace);