Bug 1421088 - Don't pass an nsIFrame* to DrawDropdown. r?spohl draft
authorMarkus Stange <mstange@themasta.com>
Sat, 14 Apr 2018 22:07:23 -0400
changeset 782226 2ecf2682ed2b8f3e3b7ff55f261e1d8809ba5ccc
parent 782225 958a6466b5e108f00960c6f339a3734479eef9a5
child 782227 cfe60fa49b7db0371b61c9705b6f6a8b4778fc80
push id106503
push userbmo:mstange@themasta.com
push dateSun, 15 Apr 2018 02:35:01 +0000
reviewersspohl
bugs1421088
milestone61.0a1
Bug 1421088 - Don't pass an nsIFrame* to DrawDropdown. r?spohl MozReview-Commit-ID: IdkoAb1rOjE
widget/cocoa/nsNativeThemeCocoa.h
widget/cocoa/nsNativeThemeCocoa.mm
--- a/widget/cocoa/nsNativeThemeCocoa.h
+++ b/widget/cocoa/nsNativeThemeCocoa.h
@@ -118,16 +118,22 @@ public:
     float verticalAlignFactor = 0.5f;
   };
 
   struct ButtonParams {
     ControlParams controlParams;
     ButtonType button = ButtonType::eRegularPushButton;
   };
 
+  struct DropdownParams {
+    ControlParams controlParams;
+    bool pullsDown = false;
+    bool editable = false;
+  };
+
   struct TreeHeaderCellParams {
     ControlParams controlParams;
     TreeSortDirection sortDirection = eTreeSortDirection_Natural;
     bool lastTreeHeaderCell = false;
   };
 
   nsNativeThemeCocoa();
 
@@ -249,18 +255,17 @@ protected:
   void DrawButton(CGContextRef context, const HIRect& inBoxRect,
                   const ButtonParams& aParams);
   void DrawTreeHeaderCell(CGContextRef context, const HIRect& inBoxRect,
                           const TreeHeaderCellParams& aParams);
   void DrawFocusOutline(CGContextRef cgContext, const HIRect& inBoxRect,
                         mozilla::EventStates inState, uint8_t aWidgetType,
                         nsIFrame* aFrame);
   void DrawDropdown(CGContextRef context, const HIRect& inBoxRect,
-                    mozilla::EventStates inState, uint8_t aWidgetType,
-                    nsIFrame* aFrame);
+                    const DropdownParams& aParams);
   void DrawSpinButtons(CGContextRef context, ThemeButtonKind inKind,
                        const HIRect& inBoxRect, ThemeDrawState inDrawState,
                        ThemeButtonAdornment inAdornment,
                        mozilla::EventStates inState, nsIFrame* aFrame);
   void DrawSpinButton(CGContextRef context, ThemeButtonKind inKind,
                       const HIRect& inBoxRect, ThemeDrawState inDrawState,
                       ThemeButtonAdornment inAdornment,
                       mozilla::EventStates inState,
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -1836,34 +1836,35 @@ static const CellRenderSettings editable
       {0, 0, 3, 2},    // small
       {0, 1, 3, 3}     // regular
     }
   }
 };
 
 void
 nsNativeThemeCocoa::DrawDropdown(CGContextRef cgContext, const HIRect& inBoxRect,
-                                 EventStates inState, uint8_t aWidgetType,
-                                 nsIFrame* aFrame)
+                                 const DropdownParams& aParams)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
-  [mDropdownCell setPullsDown:(aWidgetType == NS_THEME_BUTTON)];
-
-  BOOL isEditable = (aWidgetType == NS_THEME_MENULIST_TEXTFIELD);
-  NSCell* cell = isEditable ? (NSCell*)mComboBoxCell : (NSCell*)mDropdownCell;
-
-  [cell setEnabled:!IsDisabled(aFrame, inState)];
-  [cell setShowsFirstResponder:(IsFocused(aFrame) || inState.HasState(NS_EVENT_STATE_FOCUS))];
-  [cell setHighlighted:IsOpenButton(aFrame)];
-  [cell setControlTint:(FrameIsInActiveWindow(aFrame) ? [NSColor currentControlTint] : NSClearControlTint)];
-
-  const CellRenderSettings& settings = isEditable ? editableMenulistSettings : dropdownSettings;
+  [mDropdownCell setPullsDown:aParams.pullsDown];
+  NSCell* cell = aParams.editable ? (NSCell*)mComboBoxCell : (NSCell*)mDropdownCell;
+
+  ApplyControlParamsToNSCell(aParams.controlParams, cell);
+
+  if (aParams.controlParams.insideActiveWindow) {
+    [cell setControlTint:[NSColor currentControlTint]];
+   } else {
+    [cell setControlTint:NSClearControlTint];
+   }
+
+  const CellRenderSettings& settings =
+    aParams.editable ? editableMenulistSettings : dropdownSettings;
   DrawCellWithSnapping(cell, cgContext, inBoxRect, settings,
-                       0.5f, mCellDrawView, IsFrameRTL(aFrame));
+                       0.5f, mCellDrawView, aParams.controlParams.rtl);
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 static const CellRenderSettings spinnerSettings = {
   {
     NSMakeSize(11, 16), // mini (width trimmed by 2px to reduce blank border)
     NSMakeSize(15, 22), // small
@@ -2762,17 +2763,24 @@ nsNativeThemeCocoa::DrawWidgetBackground
           isInActiveWindow && !eventState.HasState(NS_EVENT_STATE_ACTIVE);
         ButtonType buttonType =
           hasDefaultButtonLook ? ButtonType::eDefaultPushButton
                                : ButtonType::eRegularPushButton;
         ControlParams params = ComputeControlParams(aFrame, eventState);
         params.insideActiveWindow = isInActiveWindow;
         DrawButton(cgContext, macRect, ButtonParams{params, buttonType});
       } else if (IsButtonTypeMenu(aFrame)) {
-        DrawDropdown(cgContext, macRect, eventState, aWidgetType, aFrame);
+        ControlParams controlParams = ComputeControlParams(aFrame, eventState);
+        controlParams.focused = controlParams.focused || IsFocused(aFrame);
+        controlParams.pressed = IsOpenButton(aFrame);
+        DropdownParams params;
+        params.controlParams = controlParams;
+        params.pullsDown = true;
+        params.editable = false;
+        DrawDropdown(cgContext, macRect, params);
       } else if (nativeWidgetHeight > DO_SQUARE_BUTTON_HEIGHT) {
         // If the button is tall enough, draw the square button style so that
         // buttons with non-standard content look good. Otherwise draw normal
         // rounded aqua buttons.
         // This comparison is done based on the height that is calculated without
         // the top, because the snapped height can be affected by the top of the
         // rect and that may result in different height depending on the top value.
         DrawButton(cgContext, macRect,
@@ -2903,18 +2911,26 @@ nsNativeThemeCocoa::DrawWidgetBackground
     }
       break;
 
     case NS_THEME_STATUSBAR:
       DrawStatusBar(cgContext, macRect, aFrame);
       break;
 
     case NS_THEME_MENULIST:
-    case NS_THEME_MENULIST_TEXTFIELD:
-      DrawDropdown(cgContext, macRect, eventState, aWidgetType, aFrame);
+    case NS_THEME_MENULIST_TEXTFIELD: {
+      ControlParams controlParams = ComputeControlParams(aFrame, eventState);
+      controlParams.focused = controlParams.focused || IsFocused(aFrame);
+      controlParams.pressed = IsOpenButton(aFrame);
+      DropdownParams params;
+      params.controlParams = controlParams;
+      params.pullsDown = false;
+      params.editable = aWidgetType == NS_THEME_MENULIST_TEXTFIELD;
+      DrawDropdown(cgContext, macRect, params);
+    }
       break;
 
     case NS_THEME_MENULIST_BUTTON:
       DrawButton(cgContext, macRect,
                  ButtonParams{ComputeControlParams(aFrame, eventState),
                               ButtonType::eArrowButton});
       break;