summaryrefslogtreecommitdiffstats
path: root/widget/cocoa/nsChildView.mm
diff options
context:
space:
mode:
Diffstat (limited to 'widget/cocoa/nsChildView.mm')
-rw-r--r--widget/cocoa/nsChildView.mm44
1 files changed, 32 insertions, 12 deletions
diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm
index d3241a983f..b57df15825 100644
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -1726,32 +1726,52 @@ static Maybe<VibrancyType> ThemeGeometryTypeToVibrancyType(
nsITheme::ThemeGeometryType aThemeGeometryType) {
switch (aThemeGeometryType) {
case eThemeGeometryTypeTitlebar:
- return Some(VibrancyType::TITLEBAR);
+ return Some(VibrancyType::Titlebar);
default:
return Nothing();
}
}
-static LayoutDeviceIntRegion GatherVibrantRegion(
- const nsTArray<nsIWidget::ThemeGeometry>& aThemeGeometries,
- VibrancyType aVibrancyType) {
- LayoutDeviceIntRegion region;
+static EnumeratedArray<VibrancyType, LayoutDeviceIntRegion>
+GatherVibrantRegions(Span<const nsIWidget::ThemeGeometry> aThemeGeometries) {
+ EnumeratedArray<VibrancyType, LayoutDeviceIntRegion> regions;
for (const auto& geometry : aThemeGeometries) {
- if (ThemeGeometryTypeToVibrancyType(geometry.mType) ==
- Some(aVibrancyType)) {
- region.OrWith(geometry.mRect);
+ auto vibrancyType = ThemeGeometryTypeToVibrancyType(geometry.mType);
+ if (!vibrancyType) {
+ continue;
}
+ regions[*vibrancyType].OrWith(geometry.mRect);
+ }
+ return regions;
+}
+
+// Subtracts parts from regions in such a way that they don't have any overlap.
+// Each region in the argument list will have the union of all the regions
+// *following* it subtracted from itself. In other words, the arguments are
+// treated as low priority to high priority.
+static void MakeRegionsNonOverlapping(Span<LayoutDeviceIntRegion> aRegions) {
+ LayoutDeviceIntRegion unionOfAll;
+ for (auto& region : aRegions) {
+ region.SubOut(unionOfAll);
+ unionOfAll.OrWith(region);
}
- return region;
}
void nsChildView::UpdateVibrancy(
const nsTArray<ThemeGeometry>& aThemeGeometries) {
- LayoutDeviceIntRegion titlebarRegion =
- GatherVibrantRegion(aThemeGeometries, VibrancyType::TITLEBAR);
+ auto regions = GatherVibrantRegions(aThemeGeometries);
+ MakeRegionsNonOverlapping(regions);
auto& vm = EnsureVibrancyManager();
- bool changed = vm.UpdateVibrantRegion(VibrancyType::TITLEBAR, titlebarRegion);
+ bool changed = false;
+
+ // EnumeratedArray doesn't have an iterator that also yields the enum type,
+ // but we rely on VibrancyType being contiguous and starting at 0, so we can
+ // do that manually.
+ size_t i = 0;
+ for (const auto& region : regions) {
+ changed |= vm.UpdateVibrantRegion(VibrancyType(i++), region);
+ }
if (changed) {
SuspendAsyncCATransactions();