Bug 1768285 - Clean up unused -moz-window-shadow values. r=jwatt
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 17 May 2022 23:20:48 +0000
changeset 618079 135f6d473a24298f8343c28884a775013e4313f6
parent 618078 1e98fd258975d2e4bc9b7d9ed20d4d0a91f7cf9f
child 618080 5023abfa59b34c58583ecdc1bac051fcbbf858f2
push id163021
push userealvarez@mozilla.com
push dateTue, 17 May 2022 23:23:11 +0000
treeherderautoland@135f6d473a24 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1768285, 1768278, 1767815
milestone102.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 1768285 - Clean up unused -moz-window-shadow values. r=jwatt After bug 1768278 and bug 1767815 there's no more uses of the cliprounded value in the tree (also it causes artifacts on HiDPI screens so we probably don't want new usages). The "sheet" value is unused, and the other values other than "default" and "none" are only derived from "default", so they don't need to be exposed in the style system. Differential Revision: https://phabricator.services.mozilla.com/D145821
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
layout/style/nsStyleConsts.h
layout/xul/nsMenuPopupFrame.cpp
servo/components/style/properties/longhands/ui.mako.rs
widget/cocoa/nsCocoaWindow.mm
widget/windows/nsWindow.cpp
widget/windows/nsWindow.h
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -6803,34 +6803,16 @@ bool nsLayoutUtils::HasNonZeroCornerOnSi
     if (NonZeroCorner(aCorners.Get(corner)) &&
         IsCornerAdjacentToSide(corner / 2, aSide))
       return true;
   }
   return false;
 }
 
 /* static */
-LayoutDeviceSize nsLayoutUtils::GetBorderRadiusForMenuDropShadow(
-    const nsIFrame* aFrame) {
-  if (aFrame->StyleUIReset()->mWindowShadow != StyleWindowShadow::Cliprounded) {
-    return {};
-  }
-
-  nscoord cssRadii[8];
-  if (!aFrame->GetBorderRadii(cssRadii)) {
-    return {};
-  }
-
-  RectCornerRadii devPxRadii;
-  nsCSSRendering::ComputePixelRadii(
-      cssRadii, aFrame->PresContext()->AppUnitsPerDevPixel(), &devPxRadii);
-  return LayoutDeviceSize::FromUnknownSize(devPxRadii.TopLeft());
-}
-
-/* static */
 nsTransparencyMode nsLayoutUtils::GetFrameTransparency(
     nsIFrame* aBackgroundFrame, nsIFrame* aCSSRootFrame) {
   if (aCSSRootFrame->StyleEffects()->mOpacity < 1.0f)
     return eTransparencyTransparent;
 
   if (HasNonZeroCorner(aCSSRootFrame->StyleBorder()->mBorderRadius))
     return eTransparencyTransparent;
 
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -2061,23 +2061,16 @@ class nsLayoutUtils {
   /**
    * Determine if there is any corner radius on corners adjacent to the
    * given side.
    */
   static bool HasNonZeroCornerOnSide(const mozilla::BorderRadius& aCorners,
                                      mozilla::Side aSide);
 
   /**
-   * Return the border radius size (width, height) based only on the top-left
-   * corner. This is a special case used for drawing the Windows 10 drop-shadow.
-   */
-  static mozilla::LayoutDeviceSize GetBorderRadiusForMenuDropShadow(
-      const nsIFrame*);
-
-  /**
    * Determine if a widget is likely to require transparency or translucency.
    *   @param aBackgroundFrame The frame that the background is set on. For
    *                           <window>s, this will be the canvas frame.
    *   @param aCSSRootFrame    The frame that holds CSS properties affecting
    *                           the widget's transparency. For menupopups,
    *                           aBackgroundFrame and aCSSRootFrame will be the
    *                           same.
    *   @return a value suitable for passing to SetWindowTranslucency.
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -624,20 +624,21 @@ enum class StyleImeMode : uint8_t {
 
 /*
  * -moz-window-shadow
  * Also used in widget code
  */
 enum class StyleWindowShadow : uint8_t {
   None,
   Default,
+
+  // These can't be specified in CSS, they get computed from the "default"
+  // value.
   Menu,
   Tooltip,
-  Sheet,
-  Cliprounded,  // clip border to popup border-radius
 };
 
 // dominant-baseline
 enum class StyleDominantBaseline : uint8_t {
   Auto,
   Ideographic,
   Alphabetic,
   Hanging,
--- a/layout/xul/nsMenuPopupFrame.cpp
+++ b/layout/xul/nsMenuPopupFrame.cpp
@@ -362,21 +362,19 @@ nsresult nsMenuPopupFrame::CreateWidgetF
   nsIContent* parentContent = GetContent()->GetParent();
   nsAtom* tag = nullptr;
   if (parentContent && parentContent->IsXULElement())
     tag = parentContent->NodeInfo()->NameAtom();
   widgetData.mHasRemoteContent = remote;
   widgetData.mSupportTranslucency = mode == eTransparencyTransparent;
   widgetData.mPopupLevel = PopupLevel(widgetData.mNoAutoHide);
 
-  // The special cases are menulists and handling the Windows 10
-  // drop-shadow on menus with rounded borders.
+  // The special cases are menulists.
   widgetData.mDropShadow =
-      !(mode == eTransparencyTransparent || tag == nsGkAtoms::menulist) ||
-      StyleUIReset()->mWindowShadow == StyleWindowShadow::Cliprounded;
+      !(mode == eTransparencyTransparent || tag == nsGkAtoms::menulist);
 
   // panels which have a parent level need a parent widget. This allows them to
   // always appear in front of the parent window but behind other windows that
   // should be in front of it.
   nsCOMPtr<nsIWidget> parentWidget;
   if (widgetData.mPopupLevel != ePopupLevelTop) {
     nsCOMPtr<nsIDocShellTreeItem> dsti = PresContext()->GetDocShell();
     if (!dsti) return NS_ERROR_FAILURE;
--- a/servo/components/style/properties/longhands/ui.mako.rs
+++ b/servo/components/style/properties/longhands/ui.mako.rs
@@ -46,22 +46,25 @@
     "default drag no-drag",
     engines="gecko",
     gecko_ffi_name="mWindowDragging",
     gecko_enum_prefix="StyleWindowDragging",
     animation_value_type="discrete",
     spec="None (Nonstandard Firefox-only property)",
 )}
 
+// TODO(emilio): Maybe make shadow behavior on macOS match Linux / Windows, and remove this
+// property.
 ${helpers.single_keyword(
     "-moz-window-shadow",
-    "default none menu tooltip sheet cliprounded",
+    "default none",
     engines="gecko",
     gecko_ffi_name="mWindowShadow",
     gecko_enum_prefix="StyleWindowShadow",
+    gecko_inexhaustive=True,
     animation_value_type="discrete",
     enabled_in="chrome",
     spec="None (Nonstandard internal property)",
 )}
 
 ${helpers.predefined_type(
     "-moz-window-opacity",
     "Opacity",
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -4014,18 +4014,16 @@ static const NSUInteger kWindowShadowOpt
   }
 
   switch (self.shadowStyle) {
     case StyleWindowShadow::None:
       return kWindowShadowOptionsNoShadow;
 
     case StyleWindowShadow::Default:  // we treat "default" as "default panel"
     case StyleWindowShadow::Menu:
-    case StyleWindowShadow::Sheet:
-    case StyleWindowShadow::Cliprounded:  // this is a Windows-only value.
       return kWindowShadowOptionsMenu;
 
     case StyleWindowShadow::Tooltip:
       if (nsCocoaFeatures::OnMojaveOrLater()) {
         return kWindowShadowOptionsTooltipMojaveOrLater;
       }
       return kWindowShadowOptionsMenu;
   }
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -1811,62 +1811,28 @@ bool nsWindow::IsVisible() const { retur
  *
  * SECTION: Window clipping utilities
  *
  * Used in Size and Move operations for setting the proper
  * window clipping regions for window transparency.
  *
  **************************************************************/
 
-static bool ShouldHaveRoundedMenuDropShadow(nsWindow* aWindow) {
-  nsView* view = nsView::GetViewFor(aWindow);
-  return view && view->GetFrame() &&
-         view->GetFrame()->StyleUIReset()->mWindowShadow ==
-             StyleWindowShadow::Cliprounded;
-}
-
 // XP and Vista visual styles sometimes require window clipping regions to be
 // applied for proper transparency. These routines are called on size and move
 // operations.
 // XXX this is apparently still needed in Windows 7 and later
 void nsWindow::ClearThemeRegion() {
-  if (mWindowType == eWindowType_popup &&
-      (mPopupType == ePopupTypeTooltip || mPopupType == ePopupTypeMenu ||
-       mPopupType == ePopupTypePanel) &&
-      ShouldHaveRoundedMenuDropShadow(this)) {
-    SetWindowRgn(mWnd, nullptr, false);
-  } else if (!HasGlass() &&
-             (mWindowType == eWindowType_popup && !IsPopupWithTitleBar() &&
-              (mPopupType == ePopupTypeTooltip ||
-               mPopupType == ePopupTypePanel))) {
+  if (!HasGlass() &&
+      (mWindowType == eWindowType_popup && !IsPopupWithTitleBar() &&
+       (mPopupType == ePopupTypeTooltip || mPopupType == ePopupTypePanel))) {
     SetWindowRgn(mWnd, nullptr, false);
   }
 }
 
-void nsWindow::SetThemeRegion() {
-  // Clip the window to the rounded rect area of the popup if needed.
-  if (mWindowType == eWindowType_popup &&
-      (mPopupType == ePopupTypeTooltip || mPopupType == ePopupTypeMenu ||
-       mPopupType == ePopupTypePanel)) {
-    if (nsView* view = nsView::GetViewFor(this)) {
-      LayoutDeviceSize size =
-          nsLayoutUtils::GetBorderRadiusForMenuDropShadow(view->GetFrame());
-      if (size.width || size.height) {
-        int32_t width = NSToIntRound(size.width);
-        int32_t height = NSToIntRound(size.height);
-        HRGN region = CreateRoundRectRgn(0, 0, mBounds.Width() + 1,
-                                         mBounds.Height() + 1, width, height);
-        if (!SetWindowRgn(mWnd, region, false)) {
-          DeleteObject(region);  // region setting failed so delete the region.
-        }
-      }
-    }
-  }
-}
-
 /**************************************************************
  *
  * SECTION: Touch and APZ-related functions
  *
  **************************************************************/
 
 void nsWindow::RegisterTouchWindow() {
   mTouchWindow = true;
@@ -2050,18 +2016,16 @@ void nsWindow::Move(double aX, double aY
       UINT flags = SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE;
       double oldScale = mDefaultScale;
       mResizeState = IN_SIZEMOVE;
       VERIFY(::SetWindowPos(mWnd, nullptr, x, y, 0, 0, flags));
       mResizeState = NOT_RESIZING;
       if (WinUtils::LogToPhysFactor(mWnd) != oldScale) {
         ChangedDPI();
       }
-
-      SetThemeRegion();
     }
 
     ResizeDirectManipulationViewport();
   }
   NotifyRollupGeometryChange();
 }
 
 // Resize this component
@@ -2119,17 +2083,16 @@ void nsWindow::Resize(double aWidth, dou
       mResizeState = RESIZING;
       VERIFY(
           ::SetWindowPos(mWnd, nullptr, 0, 0, width, GetHeight(height), flags));
 
       mResizeState = NOT_RESIZING;
       if (WinUtils::LogToPhysFactor(mWnd) != oldScale) {
         ChangedDPI();
       }
-      SetThemeRegion();
     }
 
     ResizeDirectManipulationViewport();
   }
 
   if (aRepaint) Invalidate();
 
   NotifyRollupGeometryChange();
@@ -2209,17 +2172,16 @@ void nsWindow::Resize(double aX, double 
 
       if (mTransitionWnd) {
         // If we have a fullscreen transition window, we need to make
         // it topmost again, otherwise the taskbar may be raised by
         // the system unexpectedly when we leave fullscreen state.
         ::SetWindowPos(mTransitionWnd, HWND_TOPMOST, 0, 0, 0, 0,
                        SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
       }
-      SetThemeRegion();
     }
 
     ResizeDirectManipulationViewport();
   }
 
   if (aRepaint) Invalidate();
 
   NotifyRollupGeometryChange();
--- a/widget/windows/nsWindow.h
+++ b/widget/windows/nsWindow.h
@@ -611,17 +611,16 @@ class nsWindow final : public nsBaseWidg
   // This method registers the given window class, and returns the class name.
   const wchar_t* RegisterWindowClass(const wchar_t* aClassName,
                                      UINT aExtraStyle, LPWSTR aIconID) const;
 
   /**
    * XP and Vista theming support for windows with rounded edges
    */
   void ClearThemeRegion();
-  void SetThemeRegion();
 
   /**
    * Popup hooks
    */
   static void ScheduleHookTimer(HWND aWnd, UINT aMsgId);
   static void RegisterSpecialDropdownHooks();
   static void UnregisterSpecialDropdownHooks();
   static bool GetPopupsToRollup(