Bug 1421088 - Don't pass an nsIFrame* to DrawSearchField. r?spohl draft
authorMarkus Stange <mstange@themasta.com>
Thu, 30 Nov 2017 18:51:24 -0500
changeset 782231 884cdf26aa829a190e8563739e145dd0588a3ce6
parent 782230 4f55c7912867fdf58c79887aad652c7bbbae963c
child 782232 c7deaad83cb86b9430443940d44dd2a22511ce27
child 782250 7e319dffa6547425dd228aa038ea7cc669008345
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 DrawSearchField. r?spohl MozReview-Commit-ID: 3hlBThgIDt5
widget/cocoa/nsNativeThemeCocoa.h
widget/cocoa/nsNativeThemeCocoa.mm
--- a/widget/cocoa/nsNativeThemeCocoa.h
+++ b/widget/cocoa/nsNativeThemeCocoa.h
@@ -163,16 +163,24 @@ public:
     bool isMain = false;
   };
 
   struct TextBoxParams {
     bool disabled = false;
     bool focused = false;
   };
 
+  struct SearchFieldParams {
+    float verticalAlignFactor = 0.5f;
+    bool insideToolbar = false;
+    bool disabled = false;
+    bool focused = false;
+    bool rtl = false;
+  };
+
   struct TreeHeaderCellParams {
     ControlParams controlParams;
     TreeSortDirection sortDirection = eTreeSortDirection_Natural;
     bool lastTreeHeaderCell = false;
   };
 
   nsNativeThemeCocoa();
 
@@ -243,16 +251,18 @@ protected:
                                        mozilla::EventStates aEventState,
                                        MenuIcon aIcon);
   MenuItemParams ComputeMenuItemParams(nsIFrame* aFrame,
                                        mozilla::EventStates aEventState,
                                        bool aIsChecked);
   SegmentParams ComputeSegmentParams(nsIFrame* aFrame,
                                      mozilla::EventStates aEventState,
                                      SegmentType aSegmentType);
+  SearchFieldParams ComputeSearchFieldParams(nsIFrame* aFrame,
+                                             mozilla::EventStates aEventState);
   TreeHeaderCellParams ComputeTreeHeaderCellParams(nsIFrame* aFrame,
                                                    mozilla::EventStates aEventState);
 
   // HITheme drawing routines
   void DrawTextBox(CGContextRef context, const HIRect& inBoxRect,
                    TextBoxParams aParams);
   void DrawMeter(CGContextRef context, const HIRect& inBoxRect,
                  nsIFrame* aFrame);
@@ -262,17 +272,17 @@ protected:
   void DrawScale(CGContextRef context, const HIRect& inBoxRect,
                  mozilla::EventStates inState, bool inDirection,
                  bool inIsReverse, int32_t inCurrentValue, int32_t inMinValue,
                  int32_t inMaxValue, nsIFrame* aFrame);
   void DrawCheckboxOrRadio(CGContextRef cgContext, bool inCheckbox,
                            const HIRect& inBoxRect,
                            const CheckboxOrRadioParams& aParams);
   void DrawSearchField(CGContextRef cgContext, const HIRect& inBoxRect,
-                       nsIFrame* aFrame, mozilla::EventStates inState);
+                       const SearchFieldParams& aParams);
   void DrawRoundedBezelPushButton(CGContextRef cgContext,
                                   const HIRect& inBoxRect,
                                   ControlParams aControlParams);
   void DrawSquareBezelPushButton(CGContextRef cgContext,
                                  const HIRect& inBoxRect,
                                  ControlParams aControlParams);
   void DrawHelpButton(CGContextRef cgContext, const HIRect& inBoxRect,
                       ControlParams aControlParams);
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -1091,34 +1091,46 @@ IsInsideToolbar(nsIFrame* aFrame)
   for (nsIFrame* frame = aFrame; frame; frame = frame->GetParent()) {
     if (IsToolbarStyleContainer(frame)) {
       return true;
     }
   }
   return false;
 }
 
+nsNativeThemeCocoa::SearchFieldParams
+nsNativeThemeCocoa::ComputeSearchFieldParams(nsIFrame* aFrame,
+                                             EventStates aEventState)
+{
+  SearchFieldParams params;
+  params.insideToolbar = IsInsideToolbar(aFrame);
+  params.disabled = IsDisabled(aFrame, aEventState);
+  params.focused = IsFocused(aFrame);
+  params.rtl = IsFrameRTL(aFrame);
+  params.verticalAlignFactor = VerticalAlignFactor(aFrame);
+  return params;
+}
+
 void
 nsNativeThemeCocoa::DrawSearchField(CGContextRef cgContext, const HIRect& inBoxRect,
-                                    nsIFrame* aFrame, EventStates inState)
+                                    const SearchFieldParams& aParams)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   NSSearchFieldCell* cell =
-    IsInsideToolbar(aFrame) ? mToolbarSearchFieldCell : mSearchFieldCell;
-  [cell setEnabled:!IsDisabled(aFrame, inState)];
-  [cell setShowsFirstResponder:IsFocused(aFrame)];
+    aParams.insideToolbar ? mToolbarSearchFieldCell : mSearchFieldCell;
+  [cell setEnabled:!aParams.disabled];
+  [cell setShowsFirstResponder:aParams.focused];
 
   // When using the 10.11 SDK, the default string will be shown if we don't
   // set the placeholder string.
   [cell setPlaceholderString:@""];
 
   DrawCellWithSnapping(cell, cgContext, inBoxRect, searchFieldSettings,
-                       VerticalAlignFactor(aFrame), mCellDrawView,
-                       IsFrameRTL(aFrame));
+                       aParams.verticalAlignFactor, mCellDrawView, aParams.rtl);
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 static Color
 NSColorToColor(NSColor* aColor)
 {
   NSColor* deviceColor = [aColor colorUsingColorSpaceName:NSDeviceRGBColorSpace];
@@ -2982,17 +2994,18 @@ nsNativeThemeCocoa::DrawWidgetBackground
       }
 
       bool isDisabled = IsDisabled(aFrame, eventState) || IsReadOnly(aFrame);
       DrawTextBox(cgContext, macRect, TextBoxParams{isDisabled, isFocused});
       break;
     }
 
     case NS_THEME_SEARCHFIELD:
-      DrawSearchField(cgContext, macRect, aFrame, eventState);
+      DrawSearchField(cgContext, macRect,
+                      ComputeSearchFieldParams(aFrame, eventState));
       break;
 
     case NS_THEME_PROGRESSBAR:
     {
       double value = GetProgressValue(aFrame);
       double maxValue = GetProgressMaxValue(aFrame);
       // Don't request repaints for scrollbars at 100% because those don't animate.
       if (value < maxValue) {