Bug 1063162 part 1 - Add auto value support to StyleComplexColor. r=birtles

MozReview-Commit-ID: E6EFICyY3dh

--HG--
extra : rebase_source : 8f0a037a8a7a460c46e70af5f54a899df212fed5
This commit is contained in:
Xidorn Quan 2016-12-22 11:03:37 +11:00
Родитель 3cead98957
Коммит 51c845d50b
4 изменённых файлов: 43 добавлений и 8 удалений

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

@ -4730,8 +4730,12 @@ StyleAnimationValue::ExtractComputedValue(nsCSSPropertyID aProperty,
StyleDataAtOffset<nscolor>(styleStruct, ssOffset));
return true;
case eStyleAnimType_ComplexColor: {
aComputedValue.SetComplexColorValue(
StyleDataAtOffset<StyleComplexColor>(styleStruct, ssOffset));
auto& color = StyleDataAtOffset<StyleComplexColor>(styleStruct, ssOffset);
if (color.mIsAuto) {
aComputedValue.SetAutoValue();
} else {
aComputedValue.SetComplexColorValue(color);
}
return true;
}
case eStyleAnimType_PaintServer: {
@ -5048,7 +5052,9 @@ StyleAnimationValue::SetCurrentColorValue()
void
StyleAnimationValue::SetComplexColorValue(const StyleComplexColor& aColor)
{
if (aColor.IsCurrentColor()) {
if (aColor.mIsAuto) {
SetAutoValue();
} else if (aColor.IsCurrentColor()) {
SetCurrentColorValue();
} else if (aColor.IsNumericColor()) {
SetColorValue(aColor.mColor);

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

@ -24,16 +24,29 @@ struct StyleComplexColor
{
nscolor mColor;
uint8_t mForegroundRatio;
// Whether the complex color represents a computed-value time auto
// value. This is only a flag indicating that this value should not
// be interpolatable with other colors, while other fields still
// represents the actual used color of this value.
bool mIsAuto;
static StyleComplexColor FromColor(nscolor aColor) { return {aColor, 0}; }
static StyleComplexColor CurrentColor() { return {NS_RGBA(0, 0, 0, 0), 255}; }
static StyleComplexColor FromColor(nscolor aColor) {
return {aColor, 0, false};
}
static StyleComplexColor CurrentColor() {
return {NS_RGBA(0, 0, 0, 0), 255, false};
}
static StyleComplexColor Auto() {
return {NS_RGBA(0, 0, 0, 0), 255, true};
}
bool IsNumericColor() const { return mForegroundRatio == 0; }
bool IsCurrentColor() const { return mForegroundRatio == 255; }
bool operator==(const StyleComplexColor& aOther) const {
return mForegroundRatio == aOther.mForegroundRatio &&
(IsCurrentColor() || mColor == aOther.mColor);
(IsCurrentColor() || mColor == aOther.mColor) &&
mIsAuto == aOther.mIsAuto;
}
bool operator!=(const StyleComplexColor& aOther) const {
return !(*this == aOther);

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

@ -1143,12 +1143,13 @@ SetComplexColor(const nsCSSValue& aValue,
} else if (unit == eCSSUnit_ComplexColor) {
aResult = aValue.GetStyleComplexColorValue();
} else {
nscolor resultColor;
if (!SetColor(aValue, aParentColor.mColor, aPresContext,
nullptr, aResult.mColor, aConditions)) {
nullptr, resultColor, aConditions)) {
MOZ_ASSERT_UNREACHABLE("Unknown color value");
return;
}
aResult.mForegroundRatio = 0;
aResult = StyleComplexColor::FromColor(resultColor);
}
}

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

@ -1379,6 +1379,21 @@ function test_true_currentcolor_transition(prop, get_color=(x => x), is_shorthan
div.style.removeProperty("color");
}
function test_auto_color_transition(prop, get_color=(x => x), is_shorthand=false) {
const msg_prefix = `color-valued property ${prop}: `;
const test_color = "rgb(51, 102, 153)";
div.style.setProperty("transition-property", "none", "");
div.style.setProperty(prop, "auto", "");
let used_value_of_auto = get_color(cs.getPropertyValue(prop));
isnot(used_value_of_auto, test_color,
msg_prefix + "ensure used auto value is different than our test color");
div.style.setProperty("transition-property", prop, "");
div.style.setProperty(prop, test_color, "");
is(get_color(cs.getPropertyValue(prop)), test_color,
msg_prefix + "not interpolatable between auto and rgb color");
}
function get_color_from_shorthand_value(value) {
var m = value.match(/rgba?\([^, ]*, [^, ]*, [^, ]*(?:, [^, ]*)?\)/);
isnot(m, null, "shorthand property value should contain color");