diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
commit | a90a5cba08fdf6c0ceb95101c275108a152a3aed (patch) | |
tree | 532507288f3defd7f4dcf1af49698bcb76034855 /widget/cocoa/VibrancyManager.mm | |
parent | Adding debian version 126.0.1-1. (diff) | |
download | firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'widget/cocoa/VibrancyManager.mm')
-rw-r--r-- | widget/cocoa/VibrancyManager.mm | 74 |
1 files changed, 21 insertions, 53 deletions
diff --git a/widget/cocoa/VibrancyManager.mm b/widget/cocoa/VibrancyManager.mm index 6062acb931..a2bef29a19 100644 --- a/widget/cocoa/VibrancyManager.mm +++ b/widget/cocoa/VibrancyManager.mm @@ -5,6 +5,9 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "VibrancyManager.h" +#include "ViewRegion.h" +#include "nsRegion.h" +#include "ViewRegion.h" #import <objc/message.h> @@ -20,18 +23,10 @@ using namespace mozilla; vibrancyType:(VibrancyType)aVibrancyType; @end -@interface MOZVibrantLeafView : MOZVibrantView -@end - static NSVisualEffectState VisualEffectStateForVibrancyType( VibrancyType aType) { switch (aType) { - case VibrancyType::TOOLTIP: - case VibrancyType::MENU: - // Tooltip and menu windows are never "key", so we need to tell the - // vibrancy effect to look active regardless of window state. - return NSVisualEffectStateActive; - case VibrancyType::TITLEBAR: + case VibrancyType::Titlebar: break; } return NSVisualEffectStateFollowsWindowActiveState; @@ -40,11 +35,7 @@ static NSVisualEffectState VisualEffectStateForVibrancyType( static NSVisualEffectMaterial VisualEffectMaterialForVibrancyType( VibrancyType aType) { switch (aType) { - case VibrancyType::TOOLTIP: - return (NSVisualEffectMaterial)NSVisualEffectMaterialToolTip; - case VibrancyType::MENU: - return NSVisualEffectMaterialMenu; - case VibrancyType::TITLEBAR: + case VibrancyType::Titlebar: return NSVisualEffectMaterialTitlebar; } } @@ -52,10 +43,7 @@ static NSVisualEffectMaterial VisualEffectMaterialForVibrancyType( static NSVisualEffectBlendingMode VisualEffectBlendingModeForVibrancyType( VibrancyType aType) { switch (aType) { - case VibrancyType::TOOLTIP: - case VibrancyType::MENU: - return NSVisualEffectBlendingModeBehindWindow; - case VibrancyType::TITLEBAR: + case VibrancyType::Titlebar: return StaticPrefs::widget_macos_titlebar_blend_mode_behind_window() ? NSVisualEffectBlendingModeBehindWindow : NSVisualEffectBlendingModeWithinWindow; @@ -63,7 +51,6 @@ static NSVisualEffectBlendingMode VisualEffectBlendingModeForVibrancyType( } @implementation MOZVibrantView - - (instancetype)initWithFrame:(NSRect)aRect vibrancyType:(VibrancyType)aType { self = [super initWithFrame:aRect]; mType = aType; @@ -76,50 +63,31 @@ static NSVisualEffectBlendingMode VisualEffectBlendingModeForVibrancyType( return self; } -// Don't override allowsVibrancy here, because this view may have subviews, and -// returning YES from allowsVibrancy forces on foreground vibrancy for all -// descendant views, which can have unintended effects. - -@end - -@implementation MOZVibrantLeafView - - (NSView*)hitTest:(NSPoint)aPoint { // This view must be transparent to mouse events. return nil; } +@end -// MOZVibrantLeafView does not have subviews, so we can return YES here without -// having unintended effects on other contents of the window. -- (BOOL)allowsVibrancy { - return NO; -} +VibrancyManager::VibrancyManager(const nsChildView& aCoordinateConverter, + NSView* aContainerView) + : mCoordinateConverter(aCoordinateConverter), + mContainerView(aContainerView) {} -@end +VibrancyManager::~VibrancyManager() = default; bool VibrancyManager::UpdateVibrantRegion( VibrancyType aType, const LayoutDeviceIntRegion& aRegion) { + auto& slot = mVibrantRegions[aType]; if (aRegion.IsEmpty()) { - return mVibrantRegions.Remove(uint32_t(aType)); + bool hadRegion = !!slot; + slot = nullptr; + return hadRegion; } - auto& vr = *mVibrantRegions.GetOrInsertNew(uint32_t(aType)); - return vr.UpdateRegion(aRegion, mCoordinateConverter, mContainerView, ^() { - return CreateEffectView(aType); - }); -} - -LayoutDeviceIntRegion VibrancyManager::GetUnionOfVibrantRegions() const { - LayoutDeviceIntRegion result; - for (const auto& region : mVibrantRegions.Values()) { - result.OrWith(region->Region()); + if (!slot) { + slot = MakeUnique<ViewRegion>(); } - return result; -} - -/* static */ NSView* VibrancyManager::CreateEffectView(VibrancyType aType, - BOOL aIsContainer) { - return aIsContainer ? [[MOZVibrantView alloc] initWithFrame:NSZeroRect - vibrancyType:aType] - : [[MOZVibrantLeafView alloc] initWithFrame:NSZeroRect - vibrancyType:aType]; + return slot->UpdateRegion(aRegion, mCoordinateConverter, mContainerView, ^() { + return [[MOZVibrantView alloc] initWithFrame:NSZeroRect vibrancyType:aType]; + }); } |