mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-21 09:49:14 +00:00
Bug 1142393 - Make menus look correct when 'Reduce transparency' is set. r=smichaud
This commit is contained in:
parent
f3eca43eb6
commit
9a4b1b5557
@ -87,6 +87,19 @@ VibrancyManager::ClearVibrantRegion(const VibrantRegion& aVibrantRegion) const
|
||||
- (NSColor*)_currentFillColor;
|
||||
@end
|
||||
|
||||
static NSColor*
|
||||
AdjustedColor(NSColor* aFillColor, VibrancyType aType)
|
||||
{
|
||||
if (aType == VibrancyType::MENU && [aFillColor alphaComponent] == 1.0) {
|
||||
// The opaque fill color that's used for the menu background when "Reduce
|
||||
// vibrancy" is checked in the system accessibility prefs is too dark.
|
||||
// This is probably because we're not using the right material for menus,
|
||||
// see VibrancyManager::CreateEffectView.
|
||||
return [NSColor colorWithDeviceWhite:0.96 alpha:1.0];
|
||||
}
|
||||
return aFillColor;
|
||||
}
|
||||
|
||||
NSColor*
|
||||
VibrancyManager::VibrancyFillColorForType(VibrancyType aType)
|
||||
{
|
||||
@ -98,7 +111,7 @@ VibrancyManager::VibrancyFillColorForType(VibrancyType aType)
|
||||
// -[NSVisualEffectView _currentFillColor] is the color that our view
|
||||
// would draw during its drawRect implementation, if we hadn't
|
||||
// disabled that.
|
||||
return [views[0] _currentFillColor];
|
||||
return AdjustedColor([views[0] _currentFillColor], aType);
|
||||
}
|
||||
return [NSColor whiteColor];
|
||||
}
|
||||
|
@ -2256,17 +2256,36 @@ nsNativeThemeCocoa::DrawResizer(CGContextRef cgContext, const HIRect& aRect,
|
||||
|
||||
static void
|
||||
DrawVibrancyBackground(CGContextRef cgContext, CGRect inBoxRect,
|
||||
nsIFrame* aFrame, nsITheme::ThemeGeometryType aThemeGeometryType)
|
||||
nsIFrame* aFrame, nsITheme::ThemeGeometryType aThemeGeometryType,
|
||||
int aCornerRadiusIfOpaque = 0)
|
||||
{
|
||||
ChildView* childView = ChildViewForFrame(aFrame);
|
||||
if (childView) {
|
||||
NSRect rect = NSRectFromCGRect(inBoxRect);
|
||||
NSGraphicsContext* savedContext = [NSGraphicsContext currentContext];
|
||||
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:cgContext flipped:YES]];
|
||||
[NSGraphicsContext saveGraphicsState];
|
||||
|
||||
[[childView vibrancyFillColorForThemeGeometryType:aThemeGeometryType] set];
|
||||
NSColor* fillColor = [childView vibrancyFillColorForThemeGeometryType:aThemeGeometryType];
|
||||
if ([fillColor alphaComponent] == 1.0 && aCornerRadiusIfOpaque > 0) {
|
||||
// The fillColor being opaque means that the system-wide pref "reduce
|
||||
// transparency" is set. In that scenario, we still go through all the
|
||||
// vibrancy rendering paths (VibrancyManager::SystemSupportsVibrancy()
|
||||
// will still return true), but the result just won't look "vibrant".
|
||||
// However, there's one unfortunate change of behavior that this pref
|
||||
// has: It stops the window server from applying window masks. We use
|
||||
// a window mask to get rounded corners on menus. So since the mask
|
||||
// doesn't work in "reduce vibrancy" mode, we need to do our own rounded
|
||||
// corner clipping here.
|
||||
[[NSBezierPath bezierPathWithRoundedRect:rect
|
||||
xRadius:aCornerRadiusIfOpaque
|
||||
yRadius:aCornerRadiusIfOpaque] addClip];
|
||||
}
|
||||
|
||||
[fillColor set];
|
||||
NSRectFill(rect);
|
||||
|
||||
[NSGraphicsContext restoreGraphicsState];
|
||||
[NSGraphicsContext setCurrentContext:savedContext];
|
||||
}
|
||||
}
|
||||
@ -2384,7 +2403,7 @@ nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext,
|
||||
|
||||
case NS_THEME_MENUPOPUP:
|
||||
if (VibrancyManager::SystemSupportsVibrancy()) {
|
||||
DrawVibrancyBackground(cgContext, macRect, aFrame, eThemeGeometryTypeMenu);
|
||||
DrawVibrancyBackground(cgContext, macRect, aFrame, eThemeGeometryTypeMenu, 4);
|
||||
} else {
|
||||
HIThemeMenuDrawInfo mdi;
|
||||
memset(&mdi, 0, sizeof(mdi));
|
||||
|
Loading…
x
Reference in New Issue
Block a user