Bug 1062801 - Fill vibrant window regions with the correct vibrancy fill color. r=smichaud

This commit is contained in:
Markus Stange 2014-10-07 16:18:01 +02:00
Родитель 603aed5594
Коммит eece1584e2
5 изменённых файлов: 67 добавлений и 0 удалений

Просмотреть файл

@ -75,6 +75,14 @@ public:
*/
void ClearVibrantAreas() const;
/**
* Return the fill color that should be drawn on top of the cleared window
* parts. Usually this would be drawn by -[NSVisualEffectView drawRect:].
* The returned color is opaque if the system-wide "Reduce transparency"
* preference is set.
*/
NSColor* VibrancyFillColorForType(VibrancyType aType);
/**
* Check whether the operating system supports vibrancy at all.
* You may only create a VibrancyManager instance if this returns true.

Просмотреть файл

@ -83,6 +83,26 @@ VibrancyManager::ClearVibrantRegion(const VibrantRegion& aVibrantRegion) const
}
}
@interface NSView(CurrentFillColor)
- (NSColor*)_currentFillColor;
@end
NSColor*
VibrancyManager::VibrancyFillColorForType(VibrancyType aType)
{
const nsTArray<NSView*>& views =
mVibrantRegions.LookupOrAdd(uint32_t(aType))->effectViews;
if (!views.IsEmpty() &&
[views[0] respondsToSelector:@selector(_currentFillColor)]) {
// -[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 [NSColor whiteColor];
}
static void
DrawRectNothing(id self, SEL _cmd, NSRect aRect)
{

Просмотреть файл

@ -329,6 +329,8 @@ typedef NSInteger NSEventGestureAxis;
- (BOOL)isCoveringTitlebar;
- (NSColor*)vibrancyFillColorForWidgetType:(uint8_t)aWidgetType;
// Simple gestures support
//
// XXX - The swipeWithEvent, beginGestureWithEvent, magnifyWithEvent,
@ -573,6 +575,7 @@ public:
void NotifyDirtyRegion(const nsIntRegion& aDirtyRegion);
void ClearVibrantAreas();
NSColor* VibrancyFillColorForWidgetType(uint8_t aWidgetType);
// unit conversion convenience functions
int32_t CocoaPointsToDevPixels(CGFloat aPts) const {

Просмотреть файл

@ -2656,6 +2656,17 @@ nsChildView::ClearVibrantAreas()
}
}
NSColor*
nsChildView::VibrancyFillColorForWidgetType(uint8_t aWidgetType)
{
if (VibrancyManager::SystemSupportsVibrancy()) {
return EnsureVibrancyManager().VibrancyFillColorForType(
aWidgetType == NS_THEME_MAC_VIBRANCY_LIGHT
? VibrancyType::LIGHT : VibrancyType::DARK);
}
return [NSColor whiteColor];
}
mozilla::VibrancyManager&
nsChildView::EnsureVibrancyManager()
{
@ -3639,6 +3650,14 @@ NSEvent* gLastDragMouseDownEvent = nil;
[(BaseWindow*)[self window] drawsContentsIntoWindowFrame];
}
- (NSColor*)vibrancyFillColorForWidgetType:(uint8_t)aWidgetType
{
if (!mGeckoChild) {
return [NSColor whiteColor];
}
return mGeckoChild->VibrancyFillColorForWidgetType(aWidgetType);
}
- (nsIntRegion)nativeDirtyRegionWithBoundingRect:(NSRect)aRect
{
nsIntRect boundingRect = mGeckoChild->CocoaPointsToDevPixels(aRect);

Просмотреть файл

@ -2858,6 +2858,23 @@ nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext,
case NS_THEME_RESIZER:
DrawResizer(cgContext, macRect, aFrame);
break;
case NS_THEME_MAC_VIBRANCY_LIGHT:
case NS_THEME_MAC_VIBRANCY_DARK:
{
NSWindow* win = NativeWindowForFrame(aFrame);
if ([win isKindOfClass:[ToolbarWindow class]]) {
NSGraphicsContext* savedContext = [NSGraphicsContext currentContext];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:cgContext flipped:YES]];
ChildView* childView = [(ToolbarWindow*)win mainChildView];
[[childView vibrancyFillColorForWidgetType:aWidgetType] set];
NSRectFill(NSRectFromCGRect(macRect));
[NSGraphicsContext setCurrentContext:savedContext];
}
break;
}
}
if (hidpi) {