Bug 1673055 - Simplify other code now that SystemSupportsVibrancy() always returns true. r=haik
authorMarkus Stange <mstange.moz@gmail.com>
Mon, 26 Oct 2020 23:17:11 +0000
changeset 554697 16f70160113595805b0adac104d8f566b326cdbf
parent 554696 319226c9991799d6181a244843e38dac10b21662
child 554698 8d7ff75d700a8e3d81afe4a68c66fbcd4be9171a
push id37898
push userabutkovits@mozilla.com
push dateWed, 28 Oct 2020 09:24:21 +0000
treeherdermozilla-central@83bf4fd3b1fb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershaik
bugs1673055
milestone84.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 1673055 - Simplify other code now that SystemSupportsVibrancy() always returns true. r=haik Differential Revision: https://phabricator.services.mozilla.com/D94629
widget/cocoa/VibrancyManager.h
widget/cocoa/VibrancyManager.mm
widget/cocoa/nsChildView.mm
widget/cocoa/nsCocoaWindow.mm
widget/cocoa/nsNativeThemeCocoa.mm
--- a/widget/cocoa/VibrancyManager.h
+++ b/widget/cocoa/VibrancyManager.h
@@ -52,42 +52,33 @@ class VibrancyManager {
    *
    * @param aCoordinateConverter  The nsChildView to use for converting
    *   nsIntRect device pixel coordinates into Cocoa NSRect coordinates. Must
    *   outlive this VibrancyManager instance.
    * @param aContainerView  The view that's going to be the superview of the
    *   NSVisualEffectViews which will be created for vibrant regions.
    */
   VibrancyManager(const nsChildView& aCoordinateConverter, NSView* aContainerView)
-      : mCoordinateConverter(aCoordinateConverter), mContainerView(aContainerView) {
-    MOZ_ASSERT(SystemSupportsVibrancy(), "Don't instantiate this if !SystemSupportsVibrancy()");
-  }
+      : mCoordinateConverter(aCoordinateConverter), mContainerView(aContainerView) {}
 
   /**
    * Update the placement of the NSVisualEffectViews inside the container
    * NSView so that they cover aRegion, and create new NSVisualEffectViews
    * or remove existing ones as needed.
    * @param aType   The vibrancy type to use in the region.
    * @param aRegion The vibrant area, in device pixels.
    * @return Whether the region changed.
    */
   bool UpdateVibrantRegion(VibrancyType aType, const LayoutDeviceIntRegion& aRegion);
 
   bool HasVibrantRegions() { return !mVibrantRegions.IsEmpty(); }
 
   LayoutDeviceIntRegion GetUnionOfVibrantRegions() const;
 
   /**
-   * Check whether the operating system supports vibrancy at all.
-   * You may only create a VibrancyManager instance if this returns true.
-   * @return Whether VibrancyManager can be used on this OS.
-   */
-  static bool SystemSupportsVibrancy();
-
-  /**
    * Create an NSVisualEffectView for the specified vibrancy type. The return
    * value is not autoreleased. We return an object of type NSView* because we
    * compile with an SDK that does not contain a definition for
    * NSVisualEffectView.
    * @param aIsContainer Whether this NSView will have child views. This value
    *                     affects hit testing: Container views will pass through
    *                     hit testing requests to their children, and leaf views
    *                     will be transparent to hit testing.
--- a/widget/cocoa/VibrancyManager.mm
+++ b/widget/cocoa/VibrancyManager.mm
@@ -145,10 +145,8 @@ LayoutDeviceIntRegion VibrancyManager::G
   }
   return result;
 }
 
 /* static */ NSView* VibrancyManager::CreateEffectView(VibrancyType aType, BOOL aIsContainer) {
   return aIsContainer ? [[MOZVibrantView alloc] initWithFrame:NSZeroRect vibrancyType:aType]
                       : [[MOZVibrantLeafView alloc] initWithFrame:NSZeroRect vibrancyType:aType];
 }
-
-/* static */ bool VibrancyManager::SystemSupportsVibrancy() { return true; }
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -1839,20 +1839,16 @@ static void MakeRegionsNonOverlappingImp
 // sorted low priority to high priority.
 template <typename Region, typename... Regions>
 static void MakeRegionsNonOverlapping(Region& aFirst, Regions&... aRest) {
   Region unionOfAll;
   MakeRegionsNonOverlappingImpl(unionOfAll, aFirst, aRest...);
 }
 
 void nsChildView::UpdateVibrancy(const nsTArray<ThemeGeometry>& aThemeGeometries) {
-  if (!VibrancyManager::SystemSupportsVibrancy()) {
-    return;
-  }
-
   LayoutDeviceIntRegion sheetRegion = GatherVibrantRegion(aThemeGeometries, VibrancyType::SHEET);
   LayoutDeviceIntRegion vibrantLightRegion =
       GatherVibrantRegion(aThemeGeometries, VibrancyType::LIGHT);
   LayoutDeviceIntRegion vibrantDarkRegion =
       GatherVibrantRegion(aThemeGeometries, VibrancyType::DARK);
   LayoutDeviceIntRegion menuRegion = GatherVibrantRegion(aThemeGeometries, VibrancyType::MENU);
   LayoutDeviceIntRegion tooltipRegion =
       GatherVibrantRegion(aThemeGeometries, VibrancyType::TOOLTIP);
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -3177,20 +3177,16 @@ static NSImage* GetMenuMaskImage() {
   NSView* childView = [[self mainChildView] retain];
   [childView removeFromSuperview];
   [aNewWrapper addSubview:childView];
   [childView release];
   [super setContentView:aNewWrapper];
 }
 
 - (void)setUseMenuStyle:(BOOL)aValue {
-  if (!VibrancyManager::SystemSupportsVibrancy()) {
-    return;
-  }
-
   if (aValue && !mUseMenuStyle) {
     // Turn on rounded corner masking.
     NSView* effectView = VibrancyManager::CreateEffectView(VibrancyType::MENU, YES);
     if ([effectView respondsToSelector:@selector(setMaskImage:)]) {
       [effectView setMaskImage:GetMenuMaskImage()];
     }
     [self swapOutChildViewWrapper:effectView];
     [effectView release];
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -1151,17 +1151,17 @@ void nsNativeThemeCocoa::DrawMenuIcon(CG
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 nsNativeThemeCocoa::MenuItemParams nsNativeThemeCocoa::ComputeMenuItemParams(
     nsIFrame* aFrame, EventStates aEventState, bool aIsChecked) {
   bool isDisabled = IsDisabled(aFrame, aEventState);
 
   MenuItemParams params;
-  params.backgroundIsVibrant = VibrancyManager::SystemSupportsVibrancy();
+  params.backgroundIsVibrant = true;
   params.checked = aIsChecked;
   params.disabled = isDisabled;
   params.selected = !isDisabled && CheckBooleanAttr(aFrame, nsGkAtoms::menuactive);
   params.rtl = IsFrameRTL(aFrame);
   return params;
 }
 
 static void SetCGContextFillColor(CGContextRef cgContext, const sRGBColor& aColor) {
@@ -2518,20 +2518,17 @@ Maybe<nsNativeThemeCocoa::WidgetInfo> ns
     nativeWidgetRect.Scale(0.5f);
     originalHeight *= 0.5f;
   }
 
   EventStates eventState = GetContentState(aFrame, aAppearance);
 
   switch (aAppearance) {
     case StyleAppearance::Menupopup:
-      if (VibrancyManager::SystemSupportsVibrancy()) {
-        return Nothing();
-      }
-      return Some(WidgetInfo::MenuBackground(ComputeMenuBackgroundParams(aFrame, eventState)));
+      return Nothing();
 
     case StyleAppearance::Menuarrow:
       return Some(
           WidgetInfo::MenuIcon(ComputeMenuIconParams(aFrame, eventState, MenuIcon::eMenuArrow)));
 
     case StyleAppearance::Menuitem:
     case StyleAppearance::Checkmenuitem:
       return Some(WidgetInfo::MenuItem(ComputeMenuItemParams(
@@ -2544,20 +2541,17 @@ Maybe<nsNativeThemeCocoa::WidgetInfo> ns
     case StyleAppearance::ButtonArrowDown: {
       MenuIcon icon = aAppearance == StyleAppearance::ButtonArrowUp
                           ? MenuIcon::eMenuUpScrollArrow
                           : MenuIcon::eMenuDownScrollArrow;
       return Some(WidgetInfo::MenuIcon(ComputeMenuIconParams(aFrame, eventState, icon)));
     }
 
     case StyleAppearance::Tooltip:
-      if (VibrancyManager::SystemSupportsVibrancy()) {
-        return Nothing();
-      }
-      return Some(WidgetInfo::Tooltip());
+      return Nothing();
 
     case StyleAppearance::Checkbox:
     case StyleAppearance::Radio: {
       bool isCheckbox = (aAppearance == StyleAppearance::Checkbox);
 
       CheckboxOrRadioParams params;
       params.state = CheckboxOrRadioState::eOff;
       if (isCheckbox && GetIndeterminate(aFrame)) {
@@ -2823,27 +2817,24 @@ Maybe<nsNativeThemeCocoa::WidgetInfo> ns
 
     case StyleAppearance::Textarea:
       return Some(WidgetInfo::MultilineTextField(eventState.HasState(NS_EVENT_STATE_FOCUS)));
 
     case StyleAppearance::Listbox:
       return Some(WidgetInfo::ListBox());
 
     case StyleAppearance::MozMacSourceList: {
-      if (VibrancyManager::SystemSupportsVibrancy()) {
-        return Nothing();
-      }
-      return Some(WidgetInfo::SourceList(FrameIsInActiveWindow(aFrame)));
+      return Nothing();
     }
 
     case StyleAppearance::MozMacSourceListSelection:
     case StyleAppearance::MozMacActiveSourceListSelection: {
       // We only support vibrancy for source list selections if we're inside
       // a source list, because we need the background to be transparent.
-      if (VibrancyManager::SystemSupportsVibrancy() && IsInSourceList(aFrame)) {
+      if (IsInSourceList(aFrame)) {
         return Nothing();
       }
       bool isInActiveWindow = FrameIsInActiveWindow(aFrame);
       if (aAppearance == StyleAppearance::MozMacActiveSourceListSelection) {
         return Some(WidgetInfo::ActiveSourceListSelection(isInActiveWindow));
       }
       return Some(WidgetInfo::InactiveSourceListSelection(isInActiveWindow));
     }
@@ -3156,39 +3147,22 @@ bool nsNativeThemeCocoa::CreateWebRender
   //  - If the case in DrawWidgetBackground draws nothing for the given widget
   //    type, then don't list it here. We will hit the "default: return true;"
   //    case.
   //  - If the case in DrawWidgetBackground draws something simple for the given
   //    widget type, imitate that drawing using WebRender commands.
   //  - If the case in DrawWidgetBackground draws something complicated for the
   //    given widget type, return false here.
   switch (aAppearance) {
-    case StyleAppearance::Menupopup:
-      if (VibrancyManager::SystemSupportsVibrancy()) {
-        return true;
-      }
-      return false;
-
     case StyleAppearance::Menuarrow:
     case StyleAppearance::Menuitem:
     case StyleAppearance::Checkmenuitem:
     case StyleAppearance::Menuseparator:
-      return false;
-
     case StyleAppearance::ButtonArrowUp:
     case StyleAppearance::ButtonArrowDown:
-      return false;
-
-    case StyleAppearance::Tooltip:
-      if (!VibrancyManager::SystemSupportsVibrancy()) {
-        aBuilder.PushRect(bounds, bounds, true,
-                          wr::ToColorF(ToDeviceColor(kTooltipBackgroundColor)));
-      }
-      return true;
-
     case StyleAppearance::Checkbox:
     case StyleAppearance::Radio:
     case StyleAppearance::Button:
     case StyleAppearance::FocusOutline:
     case StyleAppearance::MozMacHelpButton:
     case StyleAppearance::MozMacDisclosureButtonOpen:
     case StyleAppearance::MozMacDisclosureButtonClosed:
     case StyleAppearance::Spinner:
@@ -3284,22 +3258,16 @@ bool nsNativeThemeCocoa::CreateWebRender
       wr::LayoutSideOffsets borderWidths =
           wr::ToBorderWidths(borderWidth, borderWidth, borderWidth, borderWidth);
 
       mozilla::Range<const wr::BorderSide> wrsides(side, 4);
       aBuilder.PushBorder(bounds, bounds, true, borderWidths, wrsides, borderRadius);
       return true;
     }
 
-    case StyleAppearance::MozMacSourceList:
-      if (VibrancyManager::SystemSupportsVibrancy()) {
-        return true;
-      }
-      return false;
-
     case StyleAppearance::Tab:
     case StyleAppearance::Tabpanels:
     case StyleAppearance::Resizer:
       return false;
 
     default:
       return true;
   }
@@ -3893,17 +3861,17 @@ bool nsNativeThemeCocoa::ThemeSupportsWi
 
     case StyleAppearance::FocusOutline:
       return true;
 
     case StyleAppearance::MozMacVibrancyLight:
     case StyleAppearance::MozMacVibrancyDark:
     case StyleAppearance::MozMacVibrantTitlebarLight:
     case StyleAppearance::MozMacVibrantTitlebarDark:
-      return VibrancyManager::SystemSupportsVibrancy();
+      return true;
     default:
       break;
   }
 
   return false;
 }
 
 bool nsNativeThemeCocoa::WidgetIsContainer(StyleAppearance aAppearance) {