Bug 1421088 - Don't pass an nsIFrame* to DrawSearchField. r?spohl
MozReview-Commit-ID: 3hlBThgIDt5
--- 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) {