summaryrefslogtreecommitdiffstats
path: root/widget/cocoa/VibrancyManager.mm
diff options
context:
space:
mode:
authorBrian Smith <brian@dbsoft.org>2020-11-16 07:23:44 -0600
committerMoonchild <moonchild@palemoon.org>2020-11-19 22:44:22 +0000
commit4f0f4aa8794ef12260d9d973b40ad3b942b69b72 (patch)
treec17d559d242f6b7c4a045a5845b78e9d81d841f1 /widget/cocoa/VibrancyManager.mm
parent53ca366d2b34f237e42f8108d7a71586b5285e44 (diff)
downloadUXP-4f0f4aa8794ef12260d9d973b40ad3b942b69b72.tar
UXP-4f0f4aa8794ef12260d9d973b40ad3b942b69b72.tar.gz
UXP-4f0f4aa8794ef12260d9d973b40ad3b942b69b72.tar.lz
UXP-4f0f4aa8794ef12260d9d973b40ad3b942b69b72.tar.xz
UXP-4f0f4aa8794ef12260d9d973b40ad3b942b69b72.zip
Issue #1667 - Part 2: Add MacOS 11.0 Big Sur widget compatibility
This involves refactoring the vibrancy and OpenGL/Pixel rendering changes contained in the following Mozilla meta bugs: 1496823 and 1491445 Also add Big Sur to the features tests and update popup menu look and feel based on Mozilla bug 1656301.
Diffstat (limited to 'widget/cocoa/VibrancyManager.mm')
-rw-r--r--widget/cocoa/VibrancyManager.mm74
1 files changed, 24 insertions, 50 deletions
diff --git a/widget/cocoa/VibrancyManager.mm b/widget/cocoa/VibrancyManager.mm
index b6176de2b..93a774254 100644
--- a/widget/cocoa/VibrancyManager.mm
+++ b/widget/cocoa/VibrancyManager.mm
@@ -24,24 +24,6 @@ VibrancyManager::UpdateVibrantRegion(VibrancyType aType,
});
}
-void
-VibrancyManager::ClearVibrantAreas() const
-{
- for (auto iter = mVibrantRegions.ConstIter(); !iter.Done(); iter.Next()) {
- ClearVibrantRegion(iter.UserData()->Region());
- }
-}
-
-void
-VibrancyManager::ClearVibrantRegion(const LayoutDeviceIntRegion& aVibrantRegion) const
-{
- [[NSColor clearColor] set];
-
- for (auto iter = aVibrantRegion.RectIter(); !iter.Done(); iter.Next()) {
- NSRectFill(mCoordinateConverter.DevPixelsToCocoaPoints(iter.Get()));
- }
-}
-
@interface NSView(CurrentFillColor)
- (NSColor*)_currentFillColor;
@end
@@ -65,9 +47,8 @@ VibrancyManager::VibrancyFillColorForType(VibrancyType aType)
NSView* view = mVibrantRegions.LookupOrAdd(uint32_t(aType))->GetAnyView();
if (view && [view respondsToSelector:@selector(_currentFillColor)]) {
- // -[NSVisualEffectView _currentFillColor] is the color that our view
- // would draw during its drawRect implementation, if we hadn't
- // disabled that.
+ // -[NSVisualEffectView _currentFillColor] is the color that the view
+ // draws in its drawRect implementation.
return AdjustedColor([view _currentFillColor], aType);
}
return [NSColor whiteColor];
@@ -88,19 +69,6 @@ VibrancyManager::VibrancyFontSmoothingBackgroundColorForType(VibrancyType aType)
return [NSColor clearColor];
}
-static void
-DrawRectNothing(id self, SEL _cmd, NSRect aRect)
-{
- // The super implementation would clear the background.
- // That's fine for views that are placed below their content, but our
- // setup is different: Our drawn content is drawn to mContainerView, which
- // sits below this EffectView. So we must not clear the background here,
- // because we'd erase that drawn content.
- // Of course the regular content drawing still needs to clear the background
- // behind vibrant areas. This is taken care of by having nsNativeThemeCocoa
- // return true from NeedToClearBackgroundBehindWidget for vibrant widgets.
-}
-
static NSView*
HitTestNil(id self, SEL _cmd, NSPoint aPoint)
{
@@ -116,21 +84,20 @@ AllowsVibrancyYes(id self, SEL _cmd)
}
static Class
-CreateEffectViewClass(BOOL aForegroundVibrancy)
+CreateEffectViewClass(BOOL aForegroundVibrancy, BOOL aIsContainer)
{
- // Create a class called EffectView that inherits from NSVisualEffectView
- // and overrides the methods -[NSVisualEffectView drawRect:] and
- // -[NSView hitTest:].
+ // Create a class that inherits from NSVisualEffectView and overrides the
+ // methods -[NSView hitTest:] and -[NSVisualEffectView allowsVibrancy].
Class NSVisualEffectViewClass = NSClassFromString(@"NSVisualEffectView");
const char* className = aForegroundVibrancy
? "EffectViewWithForegroundVibrancy" : "EffectViewWithoutForegroundVibrancy";
Class EffectViewClass = objc_allocateClassPair(NSVisualEffectViewClass, className, 0);
- class_addMethod(EffectViewClass, @selector(drawRect:), (IMP)DrawRectNothing,
- "v@:{CGRect={CGPoint=dd}{CGSize=dd}}");
- class_addMethod(EffectViewClass, @selector(hitTest:), (IMP)HitTestNil,
- "@@:{CGPoint=dd}");
+ if (!aIsContainer) {
+ class_addMethod(EffectViewClass, @selector(hitTest:), (IMP)HitTestNil,
+ "@@:{CGPoint=dd}");
+ }
if (aForegroundVibrancy) {
- // Also override the -[NSView allowsVibrancy] method to return YES.
+ // Override the -[NSView allowsVibrancy] method to return YES.
class_addMethod(EffectViewClass, @selector(allowsVibrancy), (IMP)AllowsVibrancyYes, "I@:");
}
return EffectViewClass;
@@ -217,13 +184,20 @@ enum {
@end
NSView*
-VibrancyManager::CreateEffectView(VibrancyType aType)
-{
- static Class EffectViewClassWithoutForegroundVibrancy = CreateEffectViewClass(NO);
- static Class EffectViewClassWithForegroundVibrancy = CreateEffectViewClass(YES);
-
- Class EffectViewClass = HasVibrantForeground(aType)
- ? EffectViewClassWithForegroundVibrancy : EffectViewClassWithoutForegroundVibrancy;
+VibrancyManager::CreateEffectView(VibrancyType aType, BOOL aIsContainer)
+{
+ static Class EffectViewWithoutForegroundVibrancy = CreateEffectViewClass(NO, NO);
+ static Class EffectViewWithForegroundVibrancy = CreateEffectViewClass(YES, NO);
+ static Class EffectViewContainer = CreateEffectViewClass(NO, YES);
+
+ // Pick the right NSVisualEffectView subclass for the desired vibrancy mode.
+ // For "container" views, never use foreground vibrancy, because returning
+ // YES from allowsVibrancy forces on foreground vibrancy for all descendant
+ // views which can have unintended effects.
+ Class EffectViewClass = aIsContainer
+ ? EffectViewContainer
+ : (HasVibrantForeground(aType) ? EffectViewWithForegroundVibrancy
+ : EffectViewWithoutForegroundVibrancy);
NSView* effectView = [[EffectViewClass alloc] initWithFrame:NSZeroRect];
[effectView performSelector:@selector(setAppearance:)
withObject:AppearanceForVibrancyType(aType)];