Bug 1624708 - Make non-native theme keyboard navigable. r=spohl
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 24 Mar 2020 22:51:26 +0000
changeset 520306 fcba04973afc0462247576b9a097d972d7294e17
parent 520305 e2f021fe0c3e0f3c0653d153ba1448627471edf7
child 520307 47c0d3f679dcb1c2d0f2a5de9e83c088c2c483c9
push id37246
push useropoprus@mozilla.com
push dateWed, 25 Mar 2020 03:40:33 +0000
treeherdermozilla-central@14b59d4adc95 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl
bugs1624708
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 1624708 - Make non-native theme keyboard navigable. r=spohl By painting focus colors. I suspect this was mostly an oversight? But it is the most obvious issue I always find with this theme. I followed active > focus > hover, which seems to match what GTK does (and makes sense, generally). Differential Revision: https://phabricator.services.mozilla.com/D68088
widget/nsNativeBasicTheme.cpp
--- a/widget/nsNativeBasicTheme.cpp
+++ b/widget/nsNativeBasicTheme.cpp
@@ -102,16 +102,17 @@ static bool IsDateTimeTextField(nsIFrame
 
 static void ComputeCheckColors(const EventStates& aState,
                                sRGBColor& aBackgroundColor,
                                sRGBColor& aBorderColor) {
   bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
   bool isPressed = !isDisabled && aState.HasAllStates(NS_EVENT_STATE_HOVER |
                                                       NS_EVENT_STATE_ACTIVE);
   bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
+  bool isFocused = aState.HasState(NS_EVENT_STATE_FOCUS);
   bool isChecked = aState.HasState(NS_EVENT_STATE_CHECKED);
 
   sRGBColor fillColor = sBackgroundColor;
   sRGBColor borderColor = sBorderColor;
   if (isDisabled) {
     if (isChecked) {
       fillColor = borderColor = sCheckBackgroundColorDisabled;
     } else {
@@ -125,16 +126,19 @@ static void ComputeCheckColors(const Eve
       } else if (isHovered) {
         fillColor = borderColor = sCheckBackgroundHoverColor;
       } else {
         fillColor = borderColor = sCheckBackgroundColor;
       }
     } else if (isPressed) {
       fillColor = sBackgroundActiveColor;
       borderColor = sBorderHoverColor;
+    } else if (isFocused) {
+      fillColor = sBackgroundActiveColor;
+      borderColor = sBorderFocusColor;
     } else if (isHovered) {
       fillColor = sBackgroundColor;
       borderColor = sBorderHoverColor;
     } else {
       fillColor = sBackgroundColor;
       borderColor = sBorderColor;
     }
   }
@@ -293,24 +297,35 @@ static void PaintCheckedRadioButton(Draw
   rect.height -= 9.0f * aDpi;
 
   RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
   AppendEllipseToPath(builder, rect.Center(), rect.Size());
   RefPtr<Path> ellipse = builder->Finish();
   aDrawTarget->Fill(ellipse, ColorPattern(ToDeviceColor(sBackgroundColor)));
 }
 
+static sRGBColor ComputeBorderColor(const EventStates& aState) {
+  bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
+  bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
+  bool isFocused = aState.HasState(NS_EVENT_STATE_FOCUS);
+  if (isFocused) {
+    return sBorderFocusColor;
+  }
+  if (isHovered) {
+    return sBorderHoverColor;
+  }
+  return sBorderColor;
+}
+
 static void PaintTextField(DrawTarget* aDrawTarget, const Rect& aRect,
                            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 sRGBColor borderColor = ComputeBorderColor(aState);
 
   const CSSCoord kRadius = 4.0f;
 
   PaintRoundedRectWithBorder(aDrawTarget, aRect, backgroundColor, borderColor,
                              kTextFieldBorderWidth, kRadius, aDpi);
 }
 
 std::pair<sRGBColor, sRGBColor> ComputeButtonColors(
@@ -331,17 +346,17 @@ std::pair<sRGBColor, sRGBColor> ComputeB
       return sButtonActiveColor;
     }
     if (isHovered) {
       return sButtonHoverColor;
     }
     return sButtonColor;
   }();
 
-  const sRGBColor& borderColor = isHovered ? sBorderHoverColor : sBorderColor;
+  const sRGBColor borderColor = ComputeBorderColor(aState);
 
   return std::make_pair(backgroundColor, borderColor);
 }
 
 static void PaintMenulist(DrawTarget* aDrawTarget, const Rect& aRect,
                           const EventStates& aState, uint32_t aDpi) {
   const CSSCoord kRadius = 4.0f;