Bug 1642343 - Fix Mac themed focus outline to not show white edges. r=mstange, a=jcristau
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 02 Jun 2020 22:36:20 +0000
changeset 596954 c4c1941f5a8d1110f2a80aab1ddbd1954cca070a
parent 596953 dfa0b3855b9fad60a7fda4374db86c8bb5b623aa
child 596955 6bef5b17397610b6bc22813c0997094a881b830d
push id13215
push userjcristau@mozilla.com
push dateThu, 04 Jun 2020 13:33:19 +0000
treeherdermozilla-beta@d6fc47eb7f3b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, jcristau
bugs1642343
milestone78.0
Bug 1642343 - Fix Mac themed focus outline to not show white edges. r=mstange, a=jcristau This can be reproduced trivially on a MacBook on the test page with layout.css.devPixelsPerPx = 1. I wanted to fix this independently of following the outline radius. Differential Revision: https://phabricator.services.mozilla.com/D77943
widget/cocoa/nsNativeThemeCocoa.mm
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -1326,29 +1326,24 @@ void nsNativeThemeCocoa::DrawDisclosureB
                       kDisclosureButtonSize, NULL, mCellDrawView,
                       false);  // Don't mirror icon in RTL.
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 void nsNativeThemeCocoa::DrawFocusOutline(CGContextRef cgContext, const HIRect& inBoxRect) {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
-
-  HIThemeFrameDrawInfo fdi;
-  fdi.version = 0;
-  fdi.kind = kHIThemeFrameTextFieldSquare;
-  fdi.state = kThemeStateActive;
-  fdi.isFocused = TRUE;
-
-#if DRAW_IN_FRAME_DEBUG
-  CGContextSetRGBFillColor(cgContext, 0.0, 0.0, 0.5, 0.25);
-  CGContextFillRect(cgContext, inBoxRect);
-#endif
-
-  HIThemeDrawFrame(&inBoxRect, &fdi, cgContext, HITHEME_ORIENTATION);
+  NSGraphicsContext* savedContext = [NSGraphicsContext currentContext];
+  [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:cgContext
+                                                                                  flipped:YES]];
+  CGContextSaveGState(cgContext);
+  NSSetFocusRingStyle(NSFocusRingOnly);
+  NSRectFill(NSRectFromCGRect(inBoxRect));
+  CGContextRestoreGState(cgContext);
+  [NSGraphicsContext setCurrentContext:savedContext];
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 typedef void (*RenderHIThemeControlFunction)(CGContextRef cgContext, const HIRect& aRenderRect,
                                              void* aData);
 
 static void RenderTransformedHIThemeControl(CGContextRef aCGContext, const HIRect& aRect,