Bug 1500423. Paint the fill for menulist-textfield manually. r=agashlin
authorJonathan Watt <jwatt@jwatt.org>
Mon, 22 Oct 2018 16:17:22 +0100
changeset 491065 c5f42f6a73c541530a5d813f1ef349b3bcaa30a9
parent 491064 5722affcf49d606d48cd70349443baea978caa98
child 491066 7327a893e2a276779fe430920d2bf7c7822f1871
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersagashlin
bugs1500423
milestone65.0a1
Bug 1500423. Paint the fill for menulist-textfield manually. r=agashlin Differential Revision: https://phabricator.services.mozilla.com/D9410
widget/windows/nsNativeThemeWin.cpp
--- a/widget/windows/nsNativeThemeWin.cpp
+++ b/widget/windows/nsNativeThemeWin.cpp
@@ -137,16 +137,24 @@ static MARGINS
 GetCheckboxMargins(HANDLE theme, HDC hdc)
 {
     MARGINS checkboxContent = {0};
     GetThemeMargins(theme, hdc, MENU_POPUPCHECK, MCB_NORMAL,
                     TMT_CONTENTMARGINS, nullptr, &checkboxContent);
     return checkboxContent;
 }
 
+static COLORREF
+GetTextfieldFillColor(HANDLE theme, int32_t part, int32_t state)
+{
+    COLORREF color = {0};
+    GetThemeColor(theme, part, state, TMT_FILLCOLOR, &color);
+    return color;
+}
+
 static SIZE
 GetCheckboxBGSize(HANDLE theme, HDC hdc)
 {
     SIZE checkboxSize;
     GetThemePartSize(theme, hdc, MENU_POPUPCHECK, MC_CHECKMARKNORMAL,
                      nullptr, TS_TRUE, &checkboxSize);
 
     MARGINS checkboxMargins = GetCheckboxMargins(theme, hdc);
@@ -1870,21 +1878,29 @@ RENDER_AGAIN:
   {
     DrawThemeBGRTLAware(theme, hdc, part, state,
                         &widgetRect, &clipRect, IsFrameRTL(aFrame));
   }
   else if (aWidgetType == StyleAppearance::MenulistTextfield ||
            aWidgetType == StyleAppearance::NumberInput ||
            aWidgetType == StyleAppearance::Textfield ||
            aWidgetType == StyleAppearance::TextfieldMultiline) {
-    // Paint the border, except for 'menulist-textfield' that isn't focused:
-    if (aWidgetType != StyleAppearance::MenulistTextfield ||
-        state == TFS_EDITBORDER_FOCUSED) {
+    if (aWidgetType == StyleAppearance::MenulistTextfield &&
+        state != TFS_EDITBORDER_FOCUSED) {
+      // We want 'menulist-textfield' to behave like 'textfield', except we
+      // don't want a border unless it's focused.  We have to handle the
+      // non-focused case manually here.
+      COLORREF color = GetTextfieldFillColor(theme, part, state);
+      HBRUSH brush = CreateSolidBrush(color);
+      ::FillRect(hdc, &widgetRect, brush);
+      DeleteObject(brush);
+    } else {
       DrawThemeBackground(theme, hdc, part, state, &widgetRect, &clipRect);
     }
+
     if (state == TFS_EDITBORDER_DISABLED) {
       InflateRect(&widgetRect, -1, -1);
       ::FillRect(hdc, &widgetRect, reinterpret_cast<HBRUSH>(COLOR_BTNFACE+1));
     }
   }
   else if (aWidgetType == StyleAppearance::Progressbar ||
            aWidgetType == StyleAppearance::ProgressbarVertical) {
     // DrawThemeBackground renders each corner with a solid white pixel.