Bug 1417197 - Create constants for hardcoded theme fill colors. r=jrmuizel
authorMarkus Stange <mstange@themasta.com>
Tue, 14 Nov 2017 16:01:32 -0500
changeset 443535 4eebab7d065ec743f96343bd32906b4c1dfdd70c
parent 443534 d7af7d6aba30621a9c07b103a9ec25e5e6b576a3
child 443536 69e4021ca5407b40db6972dab22b90f7ca41aa5b
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1417197
milestone59.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 1417197 - Create constants for hardcoded theme fill colors. r=jrmuizel MozReview-Commit-ID: KnRKm3TyHIE
widget/cocoa/nsNativeThemeCocoa.mm
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -2294,16 +2294,28 @@ nsNativeThemeCocoa::IsParentScrollbarRol
 
 static bool
 IsHiDPIContext(nsDeviceContext* aContext)
 {
   return nsPresContext::AppUnitsPerCSSPixel() >=
     2 * aContext->AppUnitsPerDevPixelAtUnitFullZoom();
 }
 
+static void
+SetCGContextFillColor(CGContextRef cgContext, const Color& aColor)
+{
+  CGContextSetRGBFillColor(cgContext, aColor.r, aColor.g, aColor.b, aColor.a);
+}
+
+static const Color kTooltipBackgroundColor(0.996, 1.000, 0.792, 0.950);
+static const Color kMultilineTextFieldTopBorderColor(0.4510, 0.4510, 0.4510, 1.0);
+static const Color kMultilineTextFieldSidesAndBottomBorderColor(0.6, 0.6, 0.6, 1.0);
+static const Color kListboxTopBorderColor(0.557, 0.557, 0.557, 1.0);
+static const Color kListBoxSidesAndBottomBorderColor(0.745, 0.745, 0.745, 1.0);
+
 NS_IMETHODIMP
 nsNativeThemeCocoa::DrawWidgetBackground(gfxContext* aContext,
                                          nsIFrame* aFrame,
                                          uint8_t aWidgetType,
                                          const nsRect& aRect,
                                          const nsRect& aDirtyRect)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
@@ -2477,17 +2489,17 @@ nsNativeThemeCocoa::DrawWidgetBackground
                    aWidgetType == NS_THEME_BUTTON_ARROW_UP ?
                    kMenuUpScrollArrowImage : kMenuDownScrollArrowImage, true);
       break;
 
     case NS_THEME_TOOLTIP:
       if (VibrancyManager::SystemSupportsVibrancy()) {
         DrawVibrancyBackground(cgContext, macRect, aFrame, ThemeGeometryTypeForWidget(aFrame, aWidgetType));
       } else {
-        CGContextSetRGBFillColor(cgContext, 0.996, 1.000, 0.792, 0.950);
+        SetCGContextFillColor(cgContext, kTooltipBackgroundColor);
         CGContextFillRect(cgContext, macRect);
       }
       break;
 
     case NS_THEME_CHECKBOX:
     case NS_THEME_RADIO: {
       bool isCheckbox = (aWidgetType == NS_THEME_CHECKBOX);
       DrawCheckboxOrRadio(cgContext, isCheckbox, macRect, GetCheckedOrSelected(aFrame, !isCheckbox),
@@ -2850,22 +2862,21 @@ nsNativeThemeCocoa::DrawWidgetBackground
       break;
 
     case NS_THEME_TEXTFIELD_MULTILINE: {
       // we have to draw this by hand because there is no HITheme value for it
       CGContextSetRGBFillColor(cgContext, 1.0, 1.0, 1.0, 1.0);
 
       CGContextFillRect(cgContext, macRect);
 
-      // #737373 for the top border, #999999 for the rest.
       float x = macRect.origin.x, y = macRect.origin.y;
       float w = macRect.size.width, h = macRect.size.height;
-      CGContextSetRGBFillColor(cgContext, 0.4510, 0.4510, 0.4510, 1.0);
+      SetCGContextFillColor(cgContext, kMultilineTextFieldTopBorderColor);
       CGContextFillRect(cgContext, CGRectMake(x, y, w, 1));
-      CGContextSetRGBFillColor(cgContext, 0.6, 0.6, 0.6, 1.0);
+      SetCGContextFillColor(cgContext, kMultilineTextFieldSidesAndBottomBorderColor);
       CGContextFillRect(cgContext, CGRectMake(x, y + 1, 1, h - 1));
       CGContextFillRect(cgContext, CGRectMake(x + w - 1, y + 1, 1, h - 1));
       CGContextFillRect(cgContext, CGRectMake(x + 1, y + h - 1, w - 2, 1));
 
       // draw a focus ring
       if (eventState.HasState(NS_EVENT_STATE_FOCUS)) {
         NSGraphicsContext* savedContext = [NSGraphicsContext currentContext];
         [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:cgContext flipped:YES]];
@@ -2879,22 +2890,21 @@ nsNativeThemeCocoa::DrawWidgetBackground
       break;
 
     case NS_THEME_LISTBOX: {
       // We have to draw this by hand because kHIThemeFrameListBox drawing
       // is buggy on 10.5, see bug 579259.
       CGContextSetRGBFillColor(cgContext, 1.0, 1.0, 1.0, 1.0);
       CGContextFillRect(cgContext, macRect);
 
-      // #8E8E8E for the top border, #BEBEBE for the rest.
       float x = macRect.origin.x, y = macRect.origin.y;
       float w = macRect.size.width, h = macRect.size.height;
-      CGContextSetRGBFillColor(cgContext, 0.557, 0.557, 0.557, 1.0);
+      SetCGContextFillColor(cgContext, kListboxTopBorderColor);
       CGContextFillRect(cgContext, CGRectMake(x, y, w, 1));
-      CGContextSetRGBFillColor(cgContext, 0.745, 0.745, 0.745, 1.0);
+      SetCGContextFillColor(cgContext, kListBoxSidesAndBottomBorderColor);
       CGContextFillRect(cgContext, CGRectMake(x, y + 1, 1, h - 1));
       CGContextFillRect(cgContext, CGRectMake(x + w - 1, y + 1, 1, h - 1));
       CGContextFillRect(cgContext, CGRectMake(x + 1, y + h - 1, w - 2, 1));
     }
       break;
 
     case NS_THEME_MAC_SOURCE_LIST: {
       if (VibrancyManager::SystemSupportsVibrancy()) {
@@ -3023,17 +3033,17 @@ nsNativeThemeCocoa::CreateWebRenderComma
 
     case NS_THEME_TOOLTIP:
       if (VibrancyManager::SystemSupportsVibrancy()) {
         ThemeGeometryType type = ThemeGeometryTypeForWidget(aFrame, aWidgetType);
         aBuilder.PushRect(bounds, bounds, true,
                           wr::ToColorF(VibrancyFillColor(aFrame, type)));
       } else {
         aBuilder.PushRect(bounds, bounds, true,
-                          wr::ToColorF(Color(0.996, 1.000, 0.792, 0.950)));
+                          wr::ToColorF(kTooltipBackgroundColor));
       }
       return true;
 
     case NS_THEME_CHECKBOX:
     case NS_THEME_RADIO:
     case NS_THEME_BUTTON:
     case NS_THEME_FOCUS_OUTLINE:
     case NS_THEME_MAC_HELP_BUTTON:
@@ -3078,22 +3088,21 @@ nsNativeThemeCocoa::CreateWebRenderComma
         // drawing if we're focused.
         return false;
       }
 
       // White background
       aBuilder.PushRect(bounds, bounds, true,
                         wr::ToColorF(Color(1.0, 1.0, 1.0, 1.0)));
 
-      // #737373 for the top border, #999999 for the rest.
       wr::BorderSide side[4] = {
-        wr::ToBorderSide(Color(0.4510, 0.4510, 0.4510, 1.0), NS_STYLE_BORDER_STYLE_SOLID),
-        wr::ToBorderSide(Color(0.6, 0.6, 0.6, 1.0), NS_STYLE_BORDER_STYLE_SOLID),
-        wr::ToBorderSide(Color(0.6, 0.6, 0.6, 1.0), NS_STYLE_BORDER_STYLE_SOLID),
-        wr::ToBorderSide(Color(0.6, 0.6, 0.6, 1.0), NS_STYLE_BORDER_STYLE_SOLID),
+        wr::ToBorderSide(kMultilineTextFieldTopBorderColor, NS_STYLE_BORDER_STYLE_SOLID),
+        wr::ToBorderSide(kMultilineTextFieldSidesAndBottomBorderColor, NS_STYLE_BORDER_STYLE_SOLID),
+        wr::ToBorderSide(kMultilineTextFieldSidesAndBottomBorderColor, NS_STYLE_BORDER_STYLE_SOLID),
+        wr::ToBorderSide(kMultilineTextFieldSidesAndBottomBorderColor, NS_STYLE_BORDER_STYLE_SOLID),
       };
 
       wr::BorderRadius borderRadius = wr::EmptyBorderRadius();
       float borderWidth = presContext->CSSPixelsToDevPixels(1.0f);
       wr::BorderWidths borderWidths =
         wr::ToBorderWidths(borderWidth, borderWidth, borderWidth, borderWidth);
 
       mozilla::Range<const wr::BorderSide> wrsides(side, 4);
@@ -3102,22 +3111,21 @@ nsNativeThemeCocoa::CreateWebRenderComma
       return true;
     }
 
     case NS_THEME_LISTBOX: {
       // White background
       aBuilder.PushRect(bounds, bounds, true,
                         wr::ToColorF(Color(1.0, 1.0, 1.0, 1.0)));
 
-      // #8E8E8E for the top border, #BEBEBE for the rest.
       wr::BorderSide side[4] = {
-        wr::ToBorderSide(Color(0.557, 0.557, 0.557, 1.00), NS_STYLE_BORDER_STYLE_SOLID),
-        wr::ToBorderSide(Color(0.745, 0.745, 0.745, 1.0), NS_STYLE_BORDER_STYLE_SOLID),
-        wr::ToBorderSide(Color(0.745, 0.745, 0.745, 1.0), NS_STYLE_BORDER_STYLE_SOLID),
-        wr::ToBorderSide(Color(0.745, 0.745, 0.745, 1.0), NS_STYLE_BORDER_STYLE_SOLID),
+        wr::ToBorderSide(kListboxTopBorderColor, NS_STYLE_BORDER_STYLE_SOLID),
+        wr::ToBorderSide(kListBoxSidesAndBottomBorderColor, NS_STYLE_BORDER_STYLE_SOLID),
+        wr::ToBorderSide(kListBoxSidesAndBottomBorderColor, NS_STYLE_BORDER_STYLE_SOLID),
+        wr::ToBorderSide(kListBoxSidesAndBottomBorderColor, NS_STYLE_BORDER_STYLE_SOLID),
       };
 
       wr::BorderRadius borderRadius = wr::EmptyBorderRadius();
       float borderWidth = presContext->CSSPixelsToDevPixels(1.0f);
       wr::BorderWidths borderWidths =
         wr::ToBorderWidths(borderWidth, borderWidth, borderWidth, borderWidth);
 
       mozilla::Range<const wr::BorderSide> wrsides(side, 4);