Bug 1621319 - Implement GetWidgetBorder properly for some widgets. r=mstange
☠☠ backed out by 814f2005218b ☠ ☠
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 10 Mar 2020 19:33:56 +0000
changeset 584783 0522121ddf224a265ca97387dc0057f0f1fd1ff9
parent 584782 b65f1bde461a6f05de965f842c9a6e9328f51860
child 584784 9181798549f23ad1444142ac9d69a5aef90c9f1e
push id2321
push userffxbld-merge
push dateMon, 27 Apr 2020 16:26:39 +0000
treeherdermozilla-release@38a505a56ec4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1621319
milestone76.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 1621319 - Implement GetWidgetBorder properly for some widgets. r=mstange I've left checkbox / radio / range-thumb alone because they don't have borders on gtk either. We need this for the next patch to fix our test. In particular, our combination of padding + no border means that sanityEventUtils tries to hit an <input>, but it hits the anonymous scrollable element instead, and asserts that it doesn't. I don't think that test is particularly correct, but implementing GetWidgetBorder works around it, and seems like the right thing to do anyways. Differential Revision: https://phabricator.services.mozilla.com/D66240
widget/nsNativeBasicTheme.cpp
--- a/widget/nsNativeBasicTheme.cpp
+++ b/widget/nsNativeBasicTheme.cpp
@@ -63,16 +63,19 @@ static const sRGBColor sScrollbarButtonA
 static const sRGBColor sScrollbarButtonHoverColor(sRGBColor(0.86f, 0.86f,
                                                             0.86f));
 static const sRGBColor sButtonColor(sRGBColor(0.98f, 0.98f, 0.98f));
 static const sRGBColor sButtonHoverColor(sRGBColor(0.94f, 0.94f, 0.96f));
 static const sRGBColor sButtonActiveColor(sRGBColor(0.88f, 0.88f, 0.90f));
 static const sRGBColor sWhiteColor(sRGBColor(1.0f, 1.0f, 1.0f, 0.0f));
 
 static const CSSIntCoord kMinimumWidgetSize = 17;
+static const CSSCoord kButtonBorderWidth = 1.0f;
+static const CSSCoord kMenulistBorderWidth = 1.0f;
+static const CSSCoord kTextFieldBorderWidth = 1.0f;
 
 }  // namespace widget
 }  // namespace mozilla
 
 NS_IMPL_ISUPPORTS_INHERITED(nsNativeBasicTheme, nsNativeTheme, nsITheme)
 
 static uint32_t GetDPIRatio(nsIFrame* aFrame) {
   return AppUnitsPerCSSPixel() / aFrame->PresContext()
@@ -299,21 +302,20 @@ static void PaintTextField(DrawTarget* a
                            const EventStates& aState, uint32_t aDpi) {
   bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
   bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
 
   const sRGBColor& backgroundColor =
       isDisabled ? sDisabledColor : sBackgroundColor;
   const sRGBColor& borderColor = isHovered ? sBorderHoverColor : sBorderColor;
 
-  const CSSCoord kBorderWidth = 1.0f;
   const CSSCoord kRadius = 4.0f;
 
   PaintRoundedRectWithBorder(aDrawTarget, aRect, backgroundColor, borderColor,
-                             kBorderWidth, kRadius, aDpi);
+                             kTextFieldBorderWidth, kRadius, aDpi);
 }
 
 std::pair<sRGBColor, sRGBColor> ComputeButtonColors(
     const EventStates& aState, bool aIsDatetimeResetButton = false) {
   bool isActive =
       aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
   bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
   bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
@@ -336,24 +338,23 @@ std::pair<sRGBColor, sRGBColor> ComputeB
 
   const sRGBColor& borderColor = isHovered ? sBorderHoverColor : sBorderColor;
 
   return std::make_pair(backgroundColor, borderColor);
 }
 
 static void PaintMenulist(DrawTarget* aDrawTarget, const Rect& aRect,
                           const EventStates& aState, uint32_t aDpi) {
-  const CSSCoord kBorderWidth = 1.0f;
   const CSSCoord kRadius = 4.0f;
 
   sRGBColor backgroundColor, borderColor;
   std::tie(backgroundColor, borderColor) = ComputeButtonColors(aState);
 
   PaintRoundedRectWithBorder(aDrawTarget, aRect, backgroundColor, borderColor,
-                             kBorderWidth, kRadius, aDpi);
+                             kMenulistBorderWidth, kRadius, aDpi);
 }
 
 static void PaintArrow(DrawTarget* aDrawTarget, const Rect& aRect,
                        const int32_t aArrowPolygonX[],
                        const int32_t aArrowPolygonY[],
                        const int32_t aArrowNumPoints, const int32_t aArrowSize,
                        const sRGBColor aFillColor, uint32_t aDpi) {
   nscoord paintScale = std::min(aRect.width, aRect.height) / aArrowSize;
@@ -554,26 +555,25 @@ static void PaintScrollbarbutton(DrawTar
   RefPtr<Path> path = builder->Finish();
   aDrawTarget->Stroke(path, ColorPattern(ToDeviceColor(sScrollbarBorderColor)),
                       StrokeOptions(1.0f * aDpi));
 }
 
 static void PaintButton(nsIFrame* aFrame, DrawTarget* aDrawTarget,
                         const Rect& aRect, const EventStates& aState,
                         uint32_t aDpi) {
-  const CSSCoord kBorderWidth = 1.0f;
   const CSSCoord kRadius = 4.0f;
 
   // FIXME: The DateTimeResetButton bit feels like a bit of a hack.
   sRGBColor backgroundColor, borderColor;
   std::tie(backgroundColor, borderColor) =
       ComputeButtonColors(aState, IsDateTimeResetButton(aFrame));
 
   PaintRoundedRectWithBorder(aDrawTarget, aRect, backgroundColor, borderColor,
-                             kBorderWidth, kRadius, aDpi);
+                             kButtonBorderWidth, kRadius, aDpi);
 }
 
 static void PaintRangeThumb(DrawTarget* aDrawTarget, const Rect& aRect,
                             const EventStates& aState, uint32_t aDpi) {
   const CSSCoord kBorderWidth = 2.0f;
 
   sRGBColor backgroundColor, borderColor;
   std::tie(backgroundColor, borderColor) = ComputeButtonColors(aState);
@@ -692,17 +692,38 @@ nsNativeBasicTheme::CreateWebRenderComma
 aBuilder, mozilla::wr::IpcResourceUpdateQueue& aResources, const
 mozilla::layers::StackingContextHelper& aSc,
                                       mozilla::layers::RenderRootStateManager*
 aManager, nsIFrame* aFrame, StyleAppearance aAppearance, const nsRect& aRect) {
 }*/
 
 LayoutDeviceIntMargin nsNativeBasicTheme::GetWidgetBorder(
     nsDeviceContext* aContext, nsIFrame* aFrame, StyleAppearance aAppearance) {
-  return LayoutDeviceIntMargin();
+  uint32_t dpi = GetDPIRatio(aFrame);
+  switch (aAppearance) {
+    case StyleAppearance::Textfield:
+    case StyleAppearance::Textarea:
+    case StyleAppearance::NumberInput: {
+      const LayoutDeviceIntCoord w = kTextFieldBorderWidth * dpi;
+      return LayoutDeviceIntMargin(w, w, w, w);
+    }
+    case StyleAppearance::Listbox:
+    case StyleAppearance::Menulist:
+    case StyleAppearance::MenulistButton:
+    case StyleAppearance::MenulistTextfield: {
+      const LayoutDeviceIntCoord w = kMenulistBorderWidth * dpi;
+      return LayoutDeviceIntMargin(w, w, w, w);
+    }
+    case StyleAppearance::Button: {
+      const LayoutDeviceIntCoord w = kButtonBorderWidth * dpi;
+      return LayoutDeviceIntMargin(w, w, w, w);
+    }
+    default:
+      return LayoutDeviceIntMargin();
+  }
 }
 
 bool nsNativeBasicTheme::GetWidgetPadding(nsDeviceContext* aContext,
                                           nsIFrame* aFrame,
                                           StyleAppearance aAppearance,
                                           LayoutDeviceIntMargin* aResult) {
   if (aAppearance == StyleAppearance::Menulist ||
       aAppearance == StyleAppearance::MenulistTextfield ||
@@ -728,27 +749,27 @@ bool nsNativeBasicTheme::GetWidgetPaddin
       aResult->SizeTo(0, 0, 0, 0);
       return true;
     case StyleAppearance::Textarea:
     case StyleAppearance::Listbox:
     case StyleAppearance::Menulist:
     case StyleAppearance::MenulistButton:
     case StyleAppearance::MenulistTextfield:
     case StyleAppearance::NumberInput:
-      aResult->SizeTo(7 * dpi, 8 * dpi, 7 * dpi, 8 * dpi);
+      aResult->SizeTo(6 * dpi, 7 * dpi, 6 * dpi, 7 * dpi);
       return true;
     case StyleAppearance::Button:
-      aResult->SizeTo(7 * dpi, 22 * dpi, 7 * dpi, 22 * dpi);
+      aResult->SizeTo(6 * dpi, 21 * dpi, 6 * dpi, 21 * dpi);
       return true;
     case StyleAppearance::Textfield:
       if (IsDateTimeTextField(aFrame)) {
-        aResult->SizeTo(8 * dpi, 8 * dpi, 6 * dpi, 8 * dpi);
+        aResult->SizeTo(7 * dpi, 7 * dpi, 5 * dpi, 7 * dpi);
         return true;
       }
-      aResult->SizeTo(7 * dpi, 8 * dpi, 7 * dpi, 8 * dpi);
+      aResult->SizeTo(6 * dpi, 7 * dpi, 6 * dpi, 7 * dpi);
       return true;
     default:
       break;
   }
 
   return false;
 }