Bug 1421088 - Don't pass an nsIFrame* to DrawProgress. r?spohl
MozReview-Commit-ID: 7fxBzCyp239
--- a/widget/cocoa/nsMacDockSupport.mm
+++ b/widget/cocoa/nsMacDockSupport.mm
@@ -152,22 +152,26 @@ bool nsMacDockSupport::InitProgress()
nsresult
nsMacDockSupport::RedrawIcon()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
if (InitProgress()) {
// TODO: - Implement ERROR and PAUSED states?
NSImage *icon = [mProgressBackground copyWithZone:nil];
- bool isIndeterminate = (mProgressState != STATE_NORMAL);
[icon lockFocus];
CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
- mTheme->DrawProgress(ctx, mProgressBounds, isIndeterminate,
- true, mProgressFraction, 1.0, NULL);
+ nsNativeThemeCocoa::ProgressParams params;
+ params.value = mProgressFraction;
+ params.max = 1.0;
+ params.insideActiveWindow = true;
+ params.indeterminate = (mProgressState != STATE_NORMAL);
+ params.horizontal = true;
+ mTheme->DrawProgress(ctx, mProgressBounds, params);
[icon unlockFocus];
[NSApp setApplicationIconImage:icon];
[icon release];
} else {
[NSApp setApplicationIconImage:mAppIcon];
}
return NS_OK;
--- a/widget/cocoa/nsNativeThemeCocoa.h
+++ b/widget/cocoa/nsNativeThemeCocoa.h
@@ -171,16 +171,26 @@ public:
struct SearchFieldParams {
float verticalAlignFactor = 0.5f;
bool insideToolbar = false;
bool disabled = false;
bool focused = false;
bool rtl = false;
};
+ struct ProgressParams {
+ double value = 0.0;
+ double max = 0.0;
+ float verticalAlignFactor = 0.5f;
+ bool insideActiveWindow = false;
+ bool indeterminate = false;
+ bool horizontal = false;
+ bool rtl = false;
+ };
+
struct TreeHeaderCellParams {
ControlParams controlParams;
TreeSortDirection sortDirection = eTreeSortDirection_Natural;
bool lastTreeHeaderCell = false;
};
nsNativeThemeCocoa();
@@ -226,18 +236,17 @@ public:
virtual bool WidgetAppearanceDependsOnWindowFocus(uint8_t aWidgetType) override;
virtual bool NeedToClearBackgroundBehindWidget(nsIFrame* aFrame,
uint8_t aWidgetType) override;
virtual ThemeGeometryType ThemeGeometryTypeForWidget(nsIFrame* aFrame,
uint8_t aWidgetType) override;
virtual Transparency GetWidgetTransparency(nsIFrame* aFrame, uint8_t aWidgetType) override;
void DrawProgress(CGContextRef context, const HIRect& inBoxRect,
- bool inIsIndeterminate, bool inIsHorizontal,
- double inValue, double inMaxValue, nsIFrame* aFrame);
+ const ProgressParams& aParams);
static void DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect,
CGFloat aUnifiedHeight, BOOL aIsMain, BOOL aIsFlipped);
protected:
virtual ~nsNativeThemeCocoa();
nsIntMargin DirectionAwareMargin(const nsIntMargin& aMargin, nsIFrame* aFrame);
@@ -253,16 +262,19 @@ protected:
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);
+ ProgressParams ComputeProgressParams(nsIFrame* aFrame,
+ mozilla::EventStates aEventState,
+ bool aIsHorizontal);
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);
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -2105,37 +2105,50 @@ static const CellRenderSettings progress
{1, 1, 1, 1}, // small
{0, 1, 0, 1} // regular
}
}
}
}
};
+nsNativeThemeCocoa::ProgressParams
+nsNativeThemeCocoa::ComputeProgressParams(nsIFrame* aFrame,
+ EventStates aEventState,
+ bool aIsHorizontal)
+{
+ ProgressParams params;
+ params.value = GetProgressValue(aFrame);
+ params.max = GetProgressMaxValue(aFrame);
+ params.verticalAlignFactor = VerticalAlignFactor(aFrame);
+ params.insideActiveWindow = FrameIsInActiveWindow(aFrame);
+ params.indeterminate = IsIndeterminateProgress(aFrame, aEventState);
+ params.horizontal = aIsHorizontal;
+ params.rtl = IsFrameRTL(aFrame);
+ return params;
+}
+
void
nsNativeThemeCocoa::DrawProgress(CGContextRef cgContext, const HIRect& inBoxRect,
- bool inIsIndeterminate, bool inIsHorizontal,
- double inValue, double inMaxValue,
- nsIFrame* aFrame)
+ const ProgressParams& aParams)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
NSProgressBarCell* cell = mProgressBarCell;
- [cell setValue:inValue];
- [cell setMax:inMaxValue];
- [cell setIndeterminate:inIsIndeterminate];
- [cell setHorizontal:inIsHorizontal];
- [cell setControlTint:(FrameIsInActiveWindow(aFrame) ? [NSColor currentControlTint]
- : NSClearControlTint)];
+ [cell setValue:aParams.value];
+ [cell setMax:aParams.max];
+ [cell setIndeterminate:aParams.indeterminate];
+ [cell setHorizontal:aParams.horizontal];
+ [cell setControlTint:(aParams.insideActiveWindow ? [NSColor currentControlTint]
+ : NSClearControlTint)];
DrawCellWithSnapping(cell, cgContext, inBoxRect,
- progressSettings[inIsHorizontal][inIsIndeterminate],
- VerticalAlignFactor(aFrame), mCellDrawView,
- IsFrameRTL(aFrame));
+ progressSettings[aParams.horizontal][aParams.indeterminate],
+ aParams.verticalAlignFactor, mCellDrawView, aParams.rtl);
NS_OBJC_END_TRY_ABORT_BLOCK;
}
static const CellRenderSettings meterSetting = {
{
NSMakeSize(0, 16), // mini
NSMakeSize(0, 16), // small
@@ -3000,34 +3013,31 @@ nsNativeThemeCocoa::DrawWidgetBackground
case NS_THEME_SEARCHFIELD:
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) {
+ if (GetProgressValue(aFrame) < GetProgressMaxValue(aFrame)) {
if (!QueueAnimatedContentForRefresh(aFrame->GetContent(), 30)) {
NS_WARNING("Unable to animate progressbar!");
}
}
- DrawProgress(cgContext, macRect, IsIndeterminateProgress(aFrame, eventState),
- !IsVerticalProgress(aFrame),
- value, maxValue, aFrame);
+ DrawProgress(cgContext, macRect,
+ ComputeProgressParams(aFrame, eventState,
+ !IsVerticalProgress(aFrame)));
break;
}
case NS_THEME_PROGRESSBAR_VERTICAL:
- DrawProgress(cgContext, macRect, IsIndeterminateProgress(aFrame, eventState),
- false, GetProgressValue(aFrame),
- GetProgressMaxValue(aFrame), aFrame);
+ DrawProgress(cgContext, macRect,
+ ComputeProgressParams(aFrame, eventState, false));
break;
case NS_THEME_METERBAR:
DrawMeter(cgContext, macRect, aFrame);
break;
case NS_THEME_PROGRESSCHUNK:
case NS_THEME_PROGRESSCHUNK_VERTICAL: