diff options
author | Moonchild <moonchild@palemoon.org> | 2020-11-20 09:47:03 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2020-11-20 09:47:03 +0000 |
commit | 5165ed02285315cc0bed7977c7bac6d0a90ca43c (patch) | |
tree | 9b761a21eb924915e51c2d803208e6c01b505a45 /widget/cocoa/VibrancyManager.mm | |
parent | e1db27e19989db11fef70f439cf95821316535b3 (diff) | |
parent | ca9abcdf1702c37bf00048dab3f460b2252873a3 (diff) | |
download | UXP-8dd3f67b8431f42fd367a7f64a1c14ba7ba708ec.tar UXP-8dd3f67b8431f42fd367a7f64a1c14ba7ba708ec.tar.gz UXP-8dd3f67b8431f42fd367a7f64a1c14ba7ba708ec.tar.lz UXP-8dd3f67b8431f42fd367a7f64a1c14ba7ba708ec.tar.xz UXP-8dd3f67b8431f42fd367a7f64a1c14ba7ba708ec.zip |
Merge branch 'redwood' into releaseRELBASE_20201124RELBASE_20201120RC_20201120
Diffstat (limited to 'widget/cocoa/VibrancyManager.mm')
-rw-r--r-- | widget/cocoa/VibrancyManager.mm | 74 |
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)]; |