Bug 1045213 - Add a MakeRegionsNonOverlapping function for less repetitive code. r=botond
authorMarkus Stange <mstange@themasta.com>
Wed, 04 Feb 2015 17:25:19 -0500
changeset 227518 caac1a006b9d296a5348d72e600e6f2f999675b2
parent 227517 c07194e580ced108e81f17ca0f924ac4664c6d0b
child 227519 b46cb1ef16f86c74a605cbafb7d6f988942f5b2d
push id55145
push usermstange@themasta.com
push dateWed, 04 Feb 2015 22:25:37 +0000
treeherdermozilla-inbound@b46cb1ef16f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1045213
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1045213 - Add a MakeRegionsNonOverlapping function for less repetitive code. r=botond
widget/cocoa/nsChildView.mm
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -2357,16 +2357,38 @@ GatherThemeGeometryRegion(const nsTArray
     const nsIWidget::ThemeGeometry& g = aThemeGeometries[i];
     if (g.mType == aThemeGeometryType) {
       region.OrWith(g.mRect);
     }
   }
   return region;
 }
 
+template<typename T>
+static void MakeRegionsNonOverlappingImpl(T& aOutUnion) { }
+
+template<typename T, typename ... TT>
+static void MakeRegionsNonOverlappingImpl(T& aOutUnion, T& aFirst, TT& ... aRest)
+{
+  MakeRegionsNonOverlappingImpl(aOutUnion, aRest...);
+  aFirst.SubOut(aOutUnion);
+  aOutUnion.OrWith(aFirst);
+}
+
+// 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
+// sorted low priority to high priority.
+template<typename T, typename ... TT>
+static void MakeRegionsNonOverlapping(T& aFirst, TT& ... aRest)
+{
+  T unionOfAll;
+  MakeRegionsNonOverlappingImpl(unionOfAll, aFirst, aRest...);
+}
+
 void
 nsChildView::UpdateVibrancy(const nsTArray<ThemeGeometry>& aThemeGeometries)
 {
   if (!VibrancyManager::SystemSupportsVibrancy()) {
     return;
   }
 
   nsIntRegion vibrantLightRegion =
@@ -2375,26 +2397,18 @@ nsChildView::UpdateVibrancy(const nsTArr
     GatherThemeGeometryRegion(aThemeGeometries, nsNativeThemeCocoa::eThemeGeometryTypeVibrancyDark);
   nsIntRegion menuRegion =
     GatherThemeGeometryRegion(aThemeGeometries, nsNativeThemeCocoa::eThemeGeometryTypeMenu);
   nsIntRegion tooltipRegion =
     GatherThemeGeometryRegion(aThemeGeometries, nsNativeThemeCocoa::eThemeGeometryTypeTooltip);
   nsIntRegion highlightedMenuItemRegion =
     GatherThemeGeometryRegion(aThemeGeometries, nsNativeThemeCocoa::eThemeGeometryTypeHighlightedMenuItem);
 
-  vibrantDarkRegion.SubOut(vibrantLightRegion);
-  vibrantDarkRegion.SubOut(menuRegion);
-  vibrantDarkRegion.SubOut(tooltipRegion);
-  vibrantDarkRegion.SubOut(highlightedMenuItemRegion);
-  vibrantLightRegion.SubOut(menuRegion);
-  vibrantLightRegion.SubOut(tooltipRegion);
-  vibrantLightRegion.SubOut(highlightedMenuItemRegion);
-  menuRegion.SubOut(tooltipRegion);
-  menuRegion.SubOut(highlightedMenuItemRegion);
-  tooltipRegion.SubOut(highlightedMenuItemRegion);
+  MakeRegionsNonOverlapping(vibrantLightRegion, vibrantDarkRegion, menuRegion,
+                            tooltipRegion, highlightedMenuItemRegion);
 
   auto& vm = EnsureVibrancyManager();
   vm.UpdateVibrantRegion(VibrancyType::LIGHT, vibrantLightRegion);
   vm.UpdateVibrantRegion(VibrancyType::TOOLTIP, tooltipRegion);
   vm.UpdateVibrantRegion(VibrancyType::MENU, menuRegion);
   vm.UpdateVibrantRegion(VibrancyType::HIGHLIGHTED_MENUITEM, highlightedMenuItemRegion);
   vm.UpdateVibrantRegion(VibrancyType::DARK, vibrantDarkRegion);
 }