diff --git a/widget/cocoa/nsChildView.h b/widget/cocoa/nsChildView.h index 2861ca38ab4..db19a1fa57b 100644 --- a/widget/cocoa/nsChildView.h +++ b/widget/cocoa/nsChildView.h @@ -105,6 +105,18 @@ class GLManager; @interface NSView (Undocumented) +// Draws the title string of a window. +// Present on NSThemeFrame since at least 10.6. +// _drawTitleBar is somewhat complex, and has changed over the years +// since OS X 10.6. But in that time it's never done anything that +// would break when called outside of -[NSView drawRect:] (which we +// sometimes do), or whose output can't be redirected to a +// CGContextRef object (which we also sometimes do). This is likely +// to remain true for the indefinite future. However we should +// check _drawTitleBar in each new major version of OS X. For more +// information see bug 877767. +- (void)_drawTitleBar:(NSRect)aRect; + // Returns an NSRect that is the bounding box for all an NSView's dirty // rectangles (ones that need to be redrawn). The full list of dirty // rectangles can be obtained by calling -[NSView _dirtyRegion] and then diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 5173b633ead..806643b181a 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -151,6 +151,7 @@ uint32_t nsChildView::sLastInputEventCount = 0; - (void)clearCorners; // Overlay drawing functions for traditional CGContext drawing +- (void)drawTitleString; - (void)drawTitlebarHighlight; - (void)maskTopCornersInContext:(CGContextRef)aContext; @@ -2096,6 +2097,11 @@ nsChildView::UpdateTitlebarImageBuffer() NSGraphicsContext* context = [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:[frameView isFlipped]]; [NSGraphicsContext setCurrentContext:context]; + // Draw the title string. + if ([frameView respondsToSelector:@selector(_drawTitleBar:)]) { + [frameView _drawTitleBar:[frameView bounds]]; + } + // Draw the titlebar controls into the titlebar image. for (id view in [window titlebarControls]) { NSRect viewFrame = [view frame]; @@ -3101,6 +3107,7 @@ NSEvent* gLastDragMouseDownEvent = nil; } if ([self isCoveringTitlebar]) { + [self drawTitleString]; [self drawTitlebarHighlight]; [self maskTopCornersInContext:aContext]; } @@ -3270,6 +3277,26 @@ NSEvent* gLastDragMouseDownEvent = nil; CGContextRestoreGState(aContext); } +- (void)drawTitleString +{ + NSView* frameView = [[[self window] contentView] superview]; + if (![frameView respondsToSelector:@selector(_drawTitleBar:)]) { + return; + } + + NSGraphicsContext* oldContext = [NSGraphicsContext currentContext]; + CGContextRef ctx = (CGContextRef)[oldContext graphicsPort]; + CGContextSaveGState(ctx); + if ([oldContext isFlipped] != [frameView isFlipped]) { + CGContextTranslateCTM(ctx, 0, [self bounds].size.height); + CGContextScaleCTM(ctx, 1, -1); + } + [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:[frameView isFlipped]]]; + [frameView _drawTitleBar:[frameView bounds]]; + CGContextRestoreGState(ctx); + [NSGraphicsContext setCurrentContext:oldContext]; +} + - (void)drawTitlebarHighlight { DrawTitlebarHighlight([self bounds].size, [self cornerRadius],