diff --git a/widget/cocoa/nsChildView.h b/widget/cocoa/nsChildView.h index 0c3d998dbef..01a6e5d0e06 100644 --- a/widget/cocoa/nsChildView.h +++ b/widget/cocoa/nsChildView.h @@ -553,6 +553,9 @@ public: } // unit conversion convenience functions + int32_t CocoaPointsToDevPixels(CGFloat aPts) { + return nsCocoaUtils::CocoaPointsToDevPixels(aPts, BackingScaleFactor()); + } nsIntPoint CocoaPointsToDevPixels(const NSPoint& aPt) { return nsCocoaUtils::CocoaPointsToDevPixels(aPt, BackingScaleFactor()); } diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 61309ea6340..0831f178cfe 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -2075,23 +2075,29 @@ nsChildView::MaybeDrawRoundedBottomCorners(GLManager* aManager, nsIntRect aRect) void nsChildView::UpdateThemeGeometries(const nsTArray& aThemeGeometries) { - NSWindow* win = [mView window]; - if (!win || ![win isKindOfClass:[ToolbarWindow class]]) + if (![mView window] || ![[mView window] isKindOfClass:[ToolbarWindow class]]) return; - float unifiedToolbarHeight = 0; - nsIntRect topPixelStrip(0, 0, [win frame].size.width, 1); + ToolbarWindow* win = (ToolbarWindow*)[mView window]; + bool drawsContentsIntoWindowFrame = [win drawsContentsIntoWindowFrame]; + int32_t windowWidth = mBounds.width; + int32_t titlebarHeight = CocoaPointsToDevPixels([win titlebarHeight]); + int32_t underTitlebarPos = drawsContentsIntoWindowFrame ? titlebarHeight : 0; + int32_t unifiedToolbarBottom = 0; for (uint32_t i = 0; i < aThemeGeometries.Length(); ++i) { const ThemeGeometry& g = aThemeGeometries[i]; if ((g.mWidgetType == NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR || g.mWidgetType == NS_THEME_TOOLBAR) && - g.mRect.Contains(topPixelStrip)) { - unifiedToolbarHeight = g.mRect.YMost(); + g.mRect.X() <= 0 && + g.mRect.XMost() >= windowWidth && + g.mRect.Y() <= underTitlebarPos) { + unifiedToolbarBottom = g.mRect.YMost(); } } - [(ToolbarWindow*)win - setUnifiedToolbarHeight:DevPixelsToCocoaPoints(unifiedToolbarHeight)]; + + CGFloat unifiedHeight = DevPixelsToCocoaPoints(titlebarHeight + unifiedToolbarBottom - underTitlebarPos); + [win setUnifiedToolbarHeight:unifiedHeight]; } NS_IMETHODIMP diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm index 3419620fc9e..12dcc40fac0 100644 --- a/widget/cocoa/nsCocoaWindow.mm +++ b/widget/cocoa/nsCocoaWindow.mm @@ -2870,7 +2870,7 @@ static const NSString* kStateShowsToolbarButton = @"showsToolbarButton"; [super setBackgroundColor:mColor]; mBackgroundColor = [[NSColor whiteColor] retain]; - mUnifiedToolbarHeight = 0.0f; + mUnifiedToolbarHeight = 22.0f; // setBottomCornerRounded: is a private API call, so we check to make sure // we respond to it just in case. @@ -2946,6 +2946,7 @@ static const NSString* kStateShowsToolbarButton = @"showsToolbarButton"; [self frame].size.width, [self titlebarHeight]); } +// Returns the unified height of titlebar + toolbar. - (float)unifiedToolbarHeight { return mUnifiedToolbarHeight; @@ -2957,15 +2958,16 @@ static const NSString* kStateShowsToolbarButton = @"showsToolbarButton"; return frameRect.size.height - [self contentRectForFrameRect:frameRect].size.height; } +// Stores the complete height of titlebar + toolbar. - (void)setUnifiedToolbarHeight:(float)aHeight { - if ([self drawsContentsIntoWindowFrame] || aHeight == mUnifiedToolbarHeight) + if (aHeight == mUnifiedToolbarHeight) return; mUnifiedToolbarHeight = aHeight; // Update sheet positioning hint. - [self setContentBorderThickness:mUnifiedToolbarHeight forEdge:NSMaxYEdge]; + [self setContentBorderThickness:mUnifiedToolbarHeight - [self titlebarHeight] forEdge:NSMaxYEdge]; // Redraw the title bar. If we're inside painting, we'll do it right now, // otherwise we'll just invalidate it. @@ -3152,18 +3154,18 @@ static const NSString* kStateShowsToolbarButton = @"showsToolbarButton"; static void DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect, - float aToolbarHeight, BOOL aIsMain) + float aUnifiedToolbarHeight, BOOL aIsMain) { if (aTitlebarRect.size.width * aTitlebarRect.size.height > CUIDRAW_MAX_AREA) { return; } - int unifiedHeight = aTitlebarRect.size.height + aToolbarHeight; + CUIDraw([NSWindow coreUIRenderer], aTitlebarRect, aContext, (CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys: @"kCUIWidgetWindowFrame", @"widget", @"regularwin", @"windowtype", (aIsMain ? @"normal" : @"inactive"), @"state", - [NSNumber numberWithInt:unifiedHeight], @"kCUIWindowFrameUnifiedTitleBarHeightKey", + [NSNumber numberWithInt:aUnifiedToolbarHeight], @"kCUIWindowFrameUnifiedTitleBarHeightKey", [NSNumber numberWithBool:YES], @"kCUIWindowFrameDrawTitleSeparatorKey", nil], nil); diff --git a/widget/cocoa/nsNativeThemeCocoa.h b/widget/cocoa/nsNativeThemeCocoa.h index 086fdbb718f..a0c5379e07f 100644 --- a/widget/cocoa/nsNativeThemeCocoa.h +++ b/widget/cocoa/nsNativeThemeCocoa.h @@ -108,6 +108,8 @@ protected: NSWindow* aWindow); void DrawStatusBar(CGContextRef cgContext, const HIRect& inBoxRect, nsIFrame *aFrame); + void DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect, + float aUnifiedHeight, BOOL aIsMain); void DrawResizer(CGContextRef cgContext, const HIRect& aRect, nsIFrame *aFrame); // Scrollbars diff --git a/widget/cocoa/nsNativeThemeCocoa.mm b/widget/cocoa/nsNativeThemeCocoa.mm index 157ad2257d8..3ca82c00a19 100644 --- a/widget/cocoa/nsNativeThemeCocoa.mm +++ b/widget/cocoa/nsNativeThemeCocoa.mm @@ -1782,7 +1782,7 @@ nsNativeThemeCocoa::GetParentScrollbarFrame(nsIFrame *aFrame) do { if (scrollbarFrame->GetType() == nsGkAtoms::scrollbarFrame) break; } while ((scrollbarFrame = scrollbarFrame->GetParent())); - + // We return null if we can't find a parent scrollbar frame return scrollbarFrame; } @@ -1790,16 +1790,18 @@ nsNativeThemeCocoa::GetParentScrollbarFrame(nsIFrame *aFrame) static bool ToolbarCanBeUnified(CGContextRef cgContext, const HIRect& inBoxRect, NSWindow* aWindow) { - if (![aWindow isKindOfClass:[ToolbarWindow class]] || - [(ToolbarWindow*)aWindow drawsContentsIntoWindowFrame]) + if (![aWindow isKindOfClass:[ToolbarWindow class]]) return false; - float unifiedToolbarHeight = [(ToolbarWindow*)aWindow unifiedToolbarHeight]; - CGAffineTransform ctm = CGContextGetUserSpaceToDeviceSpaceTransform(cgContext); - CGRect deviceRect = CGRectApplyAffineTransform(inBoxRect, ctm); + ToolbarWindow* win = (ToolbarWindow*)aWindow; + float unifiedToolbarHeight = [win unifiedToolbarHeight]; + float titlebarHeight = [win titlebarHeight]; + bool drawsContentsIntoWindowFrame = [win drawsContentsIntoWindowFrame]; + float underTitlebarPos = drawsContentsIntoWindowFrame ? titlebarHeight : 0; + return inBoxRect.origin.x == 0 && - deviceRect.size.width >= [aWindow frame].size.width && - inBoxRect.origin.y <= 0.0 && + inBoxRect.size.width >= [win frame].size.width && + inBoxRect.origin.y <= underTitlebarPos && floor(inBoxRect.origin.y + inBoxRect.size.height) <= unifiedToolbarHeight; } @@ -1809,15 +1811,14 @@ nsNativeThemeCocoa::DrawUnifiedToolbar(CGContextRef cgContext, const HIRect& inB { NS_OBJC_BEGIN_TRY_ABORT_BLOCK; - float titlebarHeight = [(ToolbarWindow*)aWindow titlebarHeight]; - float unifiedHeight = titlebarHeight + inBoxRect.size.height; + float unifiedHeight = [(ToolbarWindow*)aWindow unifiedToolbarHeight]; BOOL isMain = [aWindow isMainWindow]; CGContextSaveGState(cgContext); CGContextClipToRect(cgContext, inBoxRect); - CGRect drawRect = CGRectOffset(inBoxRect, 0, -titlebarHeight); + CGRect drawRect = CGRectOffset(inBoxRect, 0, inBoxRect.size.height - unifiedHeight); if (drawRect.size.width * drawRect.size.height <= CUIDRAW_MAX_AREA) { CUIDraw([NSWindow coreUIRenderer], drawRect, cgContext, (CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys: @@ -1873,6 +1874,34 @@ nsNativeThemeCocoa::DrawStatusBar(CGContextRef cgContext, const HIRect& inBoxRec NS_OBJC_END_TRY_ABORT_BLOCK; } +void +nsNativeThemeCocoa::DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect, + float aUnifiedHeight, BOOL aIsMain) +{ + NS_OBJC_BEGIN_TRY_ABORT_BLOCK; + + if (aTitlebarRect.size.width * aTitlebarRect.size.height > CUIDRAW_MAX_AREA) { + return; + } + + CGContextSaveGState(aContext); + + CUIDraw([NSWindow coreUIRenderer], aTitlebarRect, aContext, + (CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys: + @"kCUIWidgetWindowFrame", @"widget", + @"regularwin", @"windowtype", + (aIsMain ? @"normal" : @"inactive"), @"state", + [NSNumber numberWithInt:aUnifiedHeight], @"kCUIWindowFrameUnifiedTitleBarHeightKey", + [NSNumber numberWithBool:NO], @"kCUIWindowFrameDrawTitleSeparatorKey", + [NSNumber numberWithBool:YES], @"is.flipped", + nil], + nil); + + CGContextRestoreGState(aContext); + + NS_OBJC_END_TRY_ABORT_BLOCK; +} + static void RenderResizer(CGContextRef cgContext, const HIRect& aRenderRect, void* aData) { @@ -2135,6 +2164,14 @@ nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext, } break; + case NS_THEME_WINDOW_TITLEBAR: { + NSWindow* win = NativeWindowForFrame(aFrame); + BOOL isMain = [win isMainWindow]; + float unifiedToolbarHeight = [(ToolbarWindow*)win unifiedToolbarHeight]; + DrawNativeTitlebar(cgContext, macRect, unifiedToolbarHeight, isMain); + } + break; + case NS_THEME_TOOLBOX: { HIThemeHeaderDrawInfo hdi = { 0, kThemeStateActive, kHIThemeHeaderKindWindow }; HIThemeDrawHeader(&macRect, &hdi, cgContext, HITHEME_ORIENTATION); @@ -2961,6 +2998,7 @@ nsNativeThemeCocoa::ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* a case NS_THEME_DIALOG: case NS_THEME_WINDOW: + case NS_THEME_WINDOW_TITLEBAR: case NS_THEME_MENUPOPUP: case NS_THEME_MENUITEM: case NS_THEME_MENUSEPARATOR: