Bug 1100401 - Keep the default button's background appearance in sync with the text color. r?spohl draft
authorMarkus Stange <mstange@themasta.com>
Fri, 02 Sep 2016 14:02:49 -0400
changeset 409371 e5458edf9a8551d7c2f1f22d67e6869edb55bba3
parent 409370 08e88923a86e9ed2c43a203b636d83c04b6aa9ab
child 530324 972284bffc01d7435016c17e6116000c82409f92
push id28453
push usermstange@themasta.com
push dateFri, 02 Sep 2016 18:03:17 +0000
reviewersspohl
bugs1100401
milestone51.0a1
Bug 1100401 - Keep the default button's background appearance in sync with the text color. r?spohl MozReview-Commit-ID: HzJ6cc2Fw40
widget/cocoa/nsNativeThemeCocoa.mm
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -1387,17 +1387,17 @@ nsNativeThemeCocoa::DrawButton(CGContext
       bdi.state = kThemeStateInactive;
     else
       bdi.state = kThemeStateActive;
   }
 
   if (inState.HasState(NS_EVENT_STATE_FOCUS) && isActive)
     bdi.adornment |= kThemeAdornmentFocus;
 
-  if (inIsDefault && !isDisabled && isActive &&
+  if (inIsDefault && !isDisabled &&
       !inState.HasState(NS_EVENT_STATE_ACTIVE)) {
     bdi.adornment |= kThemeAdornmentDefault;
     bdi.animation.time.start = 0;
     bdi.animation.time.current = CFAbsoluteTimeGetCurrent();
   }
 
   HIRect drawFrame = inBoxRect;
 
@@ -2463,21 +2463,32 @@ nsNativeThemeCocoa::DrawWidgetBackground
       bool isCheckbox = (aWidgetType == NS_THEME_CHECKBOX);
       DrawCheckboxOrRadio(cgContext, isCheckbox, macRect, GetCheckedOrSelected(aFrame, !isCheckbox),
                           eventState, aFrame);
     }
       break;
 
     case NS_THEME_BUTTON:
       if (IsDefaultButton(aFrame)) {
-        if (!IsDisabled(aFrame, eventState) && FrameIsInActiveWindow(aFrame) &&
+        // Check whether the default button is in a document that does not
+        // match the :-moz-window-inactive pseudoclass. This activeness check
+        // is different from the other "active window" checks in this file
+        // because we absolutely need the button's default button appearance to
+        // be in sync with its text color, and the text color is changed by
+        // such a :-moz-window-inactive rule. (That's because on 10.10 and up,
+        // default buttons in active windows have blue background and white
+        // text, and default buttons in inactive windows have white background
+        // and black text.)
+        EventStates docState = aFrame->GetContent()->OwnerDoc()->GetDocumentState();
+        bool isInActiveWindow = !docState.HasState(NS_DOCUMENT_STATE_WINDOW_INACTIVE);
+        if (!IsDisabled(aFrame, eventState) && isInActiveWindow &&
             !QueueAnimatedContentForRefresh(aFrame->GetContent(), 10)) {
           NS_WARNING("Unable to animate button!");
         }
-        DrawButton(cgContext, kThemePushButton, macRect, true,
+        DrawButton(cgContext, kThemePushButton, macRect, isInActiveWindow,
                    kThemeButtonOff, kThemeAdornmentNone, eventState, aFrame);
       } else if (IsButtonTypeMenu(aFrame)) {
         DrawDropdown(cgContext, macRect, eventState, aWidgetType, aFrame);
       } else {
         DrawPushButton(cgContext, macRect, eventState, aWidgetType, aFrame,
                        nativeWidgetHeight);
       }
       break;