Bug 1421088 - Don't pass an nsIFrame* to DrawMeter. r=spohl

MozReview-Commit-ID: 63ZuRb6VRSY

--HG--
extra : rebase_source : 4a2c47cf025069ed4fecb0d71befed283ed1436c
This commit is contained in:
Markus Stange 2017-11-30 18:59:27 -05:00
Родитель ceea95633b
Коммит 62c8f8f488
2 изменённых файлов: 63 добавлений и 34 удалений

Просмотреть файл

@ -84,6 +84,12 @@ public:
eTab
};
enum class OptimumState : uint8_t {
eOptimum,
eSubOptimum,
eSubSubOptimum
};
struct ControlParams {
ControlParams()
: disabled(false)
@ -186,6 +192,16 @@ public:
bool rtl = false;
};
struct MeterParams {
double value = 0;
double min = 0;
double max = 0;
OptimumState optimumState = OptimumState::eOptimum;
float verticalAlignFactor = 0.5f;
bool horizontal = true;
bool rtl = false;
};
struct TreeHeaderCellParams {
ControlParams controlParams;
TreeSortDirection sortDirection = eTreeSortDirection_Natural;
@ -270,6 +286,7 @@ protected:
ProgressParams ComputeProgressParams(nsIFrame* aFrame,
mozilla::EventStates aEventState,
bool aIsHorizontal);
MeterParams ComputeMeterParams(nsIFrame* aFrame);
TreeHeaderCellParams ComputeTreeHeaderCellParams(nsIFrame* aFrame,
mozilla::EventStates aEventState);
@ -277,7 +294,7 @@ protected:
void DrawTextBox(CGContextRef context, const HIRect& inBoxRect,
TextBoxParams aParams);
void DrawMeter(CGContextRef context, const HIRect& inBoxRect,
nsIFrame* aFrame);
const MeterParams& aParams);
void DrawSegment(CGContextRef cgContext, const HIRect& inBoxRect,
const SegmentParams& aParams);
void DrawTabPanel(CGContextRef context, const HIRect& inBoxRect, nsIFrame* aFrame);

Просмотреть файл

@ -2171,34 +2171,43 @@ static const CellRenderSettings meterSetting = {
}
};
void
nsNativeThemeCocoa::DrawMeter(CGContextRef cgContext, const HIRect& inBoxRect,
nsIFrame* aFrame)
nsNativeThemeCocoa::MeterParams
nsNativeThemeCocoa::ComputeMeterParams(nsIFrame* aFrame)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK
NS_PRECONDITION(aFrame, "aFrame should not be null here!");
// When using -moz-meterbar on an non meter element, we will not be able to
// get all the needed information so we just draw an empty meter.
nsIContent* content = aFrame->GetContent();
if (!(content && content->IsHTMLElement(nsGkAtoms::meter))) {
DrawCellWithSnapping(mMeterBarCell, cgContext, inBoxRect,
meterSetting, VerticalAlignFactor(aFrame),
mCellDrawView, IsFrameRTL(aFrame));
return;
return MeterParams();
}
HTMLMeterElement* meterElement = static_cast<HTMLMeterElement*>(content);
double value = meterElement->Value();
double min = meterElement->Min();
double max = meterElement->Max();
MeterParams params;
params.value = meterElement->Value();
params.min = meterElement->Min();
params.max = meterElement->Max();
EventStates states = meterElement->State();
if (states.HasState(NS_EVENT_STATE_SUB_OPTIMUM)) {
params.optimumState = OptimumState::eSubOptimum;
} else if (states.HasState(NS_EVENT_STATE_SUB_SUB_OPTIMUM)) {
params.optimumState = OptimumState::eSubSubOptimum;
}
params.horizontal = !IsVerticalMeter(aFrame);
params.verticalAlignFactor = VerticalAlignFactor(aFrame);
params.rtl = IsFrameRTL(aFrame);
return params;
}
void
nsNativeThemeCocoa::DrawMeter(CGContextRef cgContext, const HIRect& inBoxRect,
const MeterParams& aParams)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK
NSLevelIndicatorCell* cell = mMeterBarCell;
[cell setMinValue:min];
[cell setMaxValue:max];
[cell setDoubleValue:value];
[cell setMinValue:aParams.min];
[cell setMaxValue:aParams.max];
[cell setDoubleValue:aParams.value];
/**
* The way HTML and Cocoa defines the meter/indicator widget are different.
@ -2207,20 +2216,23 @@ nsNativeThemeCocoa::DrawMeter(CGContextRef cgContext, const HIRect& inBoxRect,
* value when we want to have the widget to be in the warning or critical
* state.
*/
EventStates states = aFrame->GetContent()->AsElement()->State();
// Reset previously set warning and critical values.
[cell setWarningValue:max+1];
[cell setCriticalValue:max+1];
if (states.HasState(NS_EVENT_STATE_SUB_OPTIMUM)) {
[cell setWarningValue:value];
} else if (states.HasState(NS_EVENT_STATE_SUB_SUB_OPTIMUM)) {
[cell setCriticalValue:value];
switch (aParams.optimumState) {
case OptimumState::eOptimum:
[cell setWarningValue:aParams.max+1];
[cell setCriticalValue:aParams.max+1];
break;
case OptimumState::eSubOptimum:
[cell setWarningValue:aParams.value];
[cell setCriticalValue:aParams.max+1];
break;
case OptimumState::eSubSubOptimum:
[cell setWarningValue:aParams.max+1];
[cell setCriticalValue:aParams.value];
break;
}
HIRect rect = CGRectStandardize(inBoxRect);
BOOL vertical = IsVerticalMeter(aFrame);
BOOL vertical = !aParams.horizontal;
CGContextSaveGState(cgContext);
@ -2247,8 +2259,8 @@ nsNativeThemeCocoa::DrawMeter(CGContextRef cgContext, const HIRect& inBoxRect,
}
DrawCellWithSnapping(cell, cgContext, rect,
meterSetting, VerticalAlignFactor(aFrame),
mCellDrawView, !vertical && IsFrameRTL(aFrame));
meterSetting, aParams.verticalAlignFactor,
mCellDrawView, !vertical && aParams.rtl);
CGContextRestoreGState(cgContext);
@ -3036,7 +3048,7 @@ nsNativeThemeCocoa::DrawWidgetBackground(gfxContext* aContext,
break;
case NS_THEME_METERBAR:
DrawMeter(cgContext, macRect, aFrame);
DrawMeter(cgContext, macRect, ComputeMeterParams(aFrame));
break;
case NS_THEME_PROGRESSCHUNK: