Bug 1421088 - Don't pass an NSWindow* to DrawUnifiedToolbar. r=spohl

MozReview-Commit-ID: 52uB5QeVsVw

--HG--
extra : rebase_source : d0ddfa0065dac20acdfd988c62f656e9a4d805f2
This commit is contained in:
Markus Stange 2017-11-30 18:46:37 -05:00
parent 2c79d13c9c
commit efe7856118
2 changed files with 18 additions and 11 deletions

View File

@ -158,6 +158,11 @@ public:
bool rtl = false;
};
struct UnifiedToolbarParams {
float unifiedHeight = 0.0f;
bool isMain = false;
};
struct TreeHeaderCellParams {
ControlParams controlParams;
TreeSortDirection sortDirection = eTreeSortDirection_Natural;
@ -298,7 +303,7 @@ protected:
const HIRect& inBoxRect, SpinButton aDrawnButton,
const SpinButtonParams& aParams);
void DrawUnifiedToolbar(CGContextRef cgContext, const HIRect& inBoxRect,
NSWindow* aWindow);
const UnifiedToolbarParams& aParams);
void DrawStatusBar(CGContextRef cgContext, const HIRect& inBoxRect,
nsIFrame *aFrame);
void DrawResizer(CGContextRef cgContext, const HIRect& aRect, nsIFrame *aFrame);

View File

@ -2444,7 +2444,7 @@ nsNativeThemeCocoa::GetParentScrollbarFrame(nsIFrame *aFrame)
}
static bool
ToolbarCanBeUnified(CGContextRef cgContext, const HIRect& inBoxRect, NSWindow* aWindow)
ToolbarCanBeUnified(const HIRect& inBoxRect, NSWindow* aWindow)
{
if (![aWindow isKindOfClass:[ToolbarWindow class]])
return false;
@ -2488,20 +2488,18 @@ DrawNativeTitlebarToolbarWithSquareCorners(CGContextRef aContext, const CGRect&
void
nsNativeThemeCocoa::DrawUnifiedToolbar(CGContextRef cgContext, const HIRect& inBoxRect,
NSWindow* aWindow)
const UnifiedToolbarParams& aParams)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
CGContextSaveGState(cgContext);
CGContextClipToRect(cgContext, inBoxRect);
CGFloat unifiedHeight = std::max([(ToolbarWindow*)aWindow unifiedToolbarHeight],
inBoxRect.size.height);
BOOL isMain = [aWindow isMainWindow];
CGFloat titlebarHeight = unifiedHeight - inBoxRect.size.height;
CGFloat titlebarHeight = aParams.unifiedHeight - inBoxRect.size.height;
CGRect drawRect = CGRectMake(inBoxRect.origin.x, inBoxRect.origin.y - titlebarHeight,
inBoxRect.size.width, inBoxRect.size.height + titlebarHeight);
DrawNativeTitlebarToolbarWithSquareCorners(cgContext, drawRect, unifiedHeight, isMain, YES);
DrawNativeTitlebarToolbarWithSquareCorners(
cgContext, drawRect, aParams.unifiedHeight, aParams.isMain, YES);
CGContextRestoreGState(cgContext);
@ -2919,11 +2917,15 @@ nsNativeThemeCocoa::DrawWidgetBackground(gfxContext* aContext,
case NS_THEME_TOOLBAR: {
NSWindow* win = NativeWindowForFrame(aFrame);
if (ToolbarCanBeUnified(cgContext, macRect, win)) {
DrawUnifiedToolbar(cgContext, macRect, win);
bool isMain = [win isMainWindow];
if (ToolbarCanBeUnified(macRect, win)) {
float unifiedHeight =
std::max([(ToolbarWindow*)win unifiedToolbarHeight],
macRect.size.height);
DrawUnifiedToolbar(cgContext, macRect,
UnifiedToolbarParams{unifiedHeight, isMain});
break;
}
BOOL isMain = [win isMainWindow];
CGRect drawRect = macRect;
// top border