Bug 1299741 part 10 - Make nsStyleContext.cpp:ExtractColor return a Maybe so that ExtractColorLenient can reuse that. r=birtles
MozReview-Commit-ID: HtqoWoJW8i6
--- a/layout/style/nsStyleContext.cpp
+++ b/layout/style/nsStyleContext.cpp
@@ -2,16 +2,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* the interface (to internal code) for retrieving computed style data */
#include "CSSVariableImageTable.h"
#include "mozilla/DebugOnly.h"
+#include "mozilla/Maybe.h"
#include "nsCSSAnonBoxes.h"
#include "nsCSSPseudoElements.h"
#include "nsStyleConsts.h"
#include "nsString.h"
#include "nsPresContext.h"
#include "nsIStyleRule.h"
@@ -1472,39 +1473,37 @@ ExtractAnimationValue(nsCSSPropertyID aP
{
DebugOnly<bool> success =
StyleAnimationValue::ExtractComputedValue(aProperty, aStyleContext,
aResult);
MOZ_ASSERT(success,
"aProperty must be extractable by StyleAnimationValue");
}
-static nscolor
+static Maybe<nscolor>
ExtractColor(nsCSSPropertyID aProperty,
nsStyleContext *aStyleContext)
{
StyleAnimationValue val;
ExtractAnimationValue(aProperty, aStyleContext, val);
- return val.GetUnit() == StyleAnimationValue::eUnit_CurrentColor
- ? aStyleContext->StyleColor()->mColor
- : val.GetCSSValueValue()->GetColorValue();
+ switch (val.GetUnit()) {
+ case StyleAnimationValue::eUnit_Color:
+ return Some(val.GetCSSValueValue()->GetColorValue());
+ case StyleAnimationValue::eUnit_CurrentColor:
+ return Some(aStyleContext->StyleColor()->mColor);
+ default:
+ return Nothing();
+ }
}
static nscolor
ExtractColorLenient(nsCSSPropertyID aProperty,
nsStyleContext *aStyleContext)
{
- StyleAnimationValue val;
- ExtractAnimationValue(aProperty, aStyleContext, val);
- if (val.GetUnit() == StyleAnimationValue::eUnit_Color) {
- return val.GetCSSValueValue()->GetColorValue();
- } else if (val.GetUnit() == StyleAnimationValue::eUnit_CurrentColor) {
- return aStyleContext->StyleColor()->mColor;
- }
- return NS_RGBA(0, 0, 0, 0);
+ return ExtractColor(aProperty, aStyleContext).valueOr(NS_RGBA(0, 0, 0, 0));
}
struct ColorIndexSet {
uint8_t colorIndex, alphaIndex;
};
static const ColorIndexSet gVisitedIndices[2] = { { 0, 0 }, { 1, 0 } };
@@ -1527,25 +1526,25 @@ nsStyleContext::GetVisitedDependentColor
aProperty == eCSSProperty_stroke,
"we need to add to nsStyleContext::CalcStyleDifference");
bool isPaintProperty = aProperty == eCSSProperty_fill ||
aProperty == eCSSProperty_stroke;
nscolor colors[2];
colors[0] = isPaintProperty ? ExtractColorLenient(aProperty, this)
- : ExtractColor(aProperty, this);
+ : ExtractColor(aProperty, this).value();
nsStyleContext *visitedStyle = this->GetStyleIfVisited();
if (!visitedStyle) {
return colors[0];
}
colors[1] = isPaintProperty ? ExtractColorLenient(aProperty, visitedStyle)
- : ExtractColor(aProperty, visitedStyle);
+ : ExtractColor(aProperty, visitedStyle).value();
return nsStyleContext::CombineVisitedColors(colors,
this->RelevantLinkVisited());
}
/* static */ nscolor
nsStyleContext::CombineVisitedColors(nscolor *aColors, bool aLinkIsVisited)
{