Skip to content

Commit

Permalink
Bug 1260543 - Treat currentcolor as computed value which is not inter…
Browse files Browse the repository at this point in the history
…polatable with actual color for text-emphasis-color and -webkit-text-fill-color. r=birtles

MozReview-Commit-ID: GUXEDHxOdNC
  • Loading branch information
upsuper committed Apr 8, 2016
1 parent 220de9f commit 78d5313
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 64 deletions.
10 changes: 10 additions & 0 deletions layout/reftests/bugs/1260543-1-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<style>
#outer {
font-size: 52px;
color: green;
}
</style>
<p>Test passes if the block below is green.</p>
<div id="outer"><span id="inner">&#x2588;</span></div>
35 changes: 35 additions & 0 deletions layout/reftests/bugs/1260543-1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html class="reftest-wait">
<style>
#outer {
font-size: 52px;
transition: all 100s step-start;
color: transparent;
}
#outer.red {
color: red;
}
#outer.red > #inner {
color: green;
}
</style>
<!--
This is testing that -webkit-text-fill-color should inherit currentcolor
keyword value, rather than the computed value of color (used value of
-webkit-text-fill-color) from the transition.
-->
<p>Test passes if the block below is green.</p>
<div id="outer"><span id="inner">&#x2588;</span></div>
<script>
window.addEventListener("load", () => {
// Wait for the second frame to ensure that we will
// actually start the transition.
requestAnimationFrame(() => {
requestAnimationFrame(() => {
let outer = document.getElementById("outer");
outer.className = "red";
document.documentElement.className = "";
});
});
});
</script>
1 change: 1 addition & 0 deletions layout/reftests/bugs/reftest.list
Original file line number Diff line number Diff line change
Expand Up @@ -1949,3 +1949,4 @@ random-if(OSX==1006) == 1238243-2.html 1238243-2-ref.html # fails on 10.6 with d
fuzzy(100,2000) == 1239564.html 1239564-ref.html
== 1242172-1.html 1242172-1-ref.html
== 1242172-2.html 1242172-2-ref.html
== 1260543-1.html 1260543-1-ref.html
36 changes: 32 additions & 4 deletions layout/style/StyleAnimationValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ StyleAnimationValue::ComputeDistance(nsCSSProperty aProperty,
case eUnit_Normal:
case eUnit_UnparsedString:
case eUnit_URL:
case eUnit_CurrentColor:
return false;

case eUnit_Enumerated:
Expand Down Expand Up @@ -2212,6 +2213,7 @@ StyleAnimationValue::AddWeighted(nsCSSProperty aProperty,
case eUnit_Normal:
case eUnit_UnparsedString:
case eUnit_URL:
case eUnit_CurrentColor:
return false;

case eUnit_Enumerated:
Expand Down Expand Up @@ -3007,6 +3009,9 @@ StyleAnimationValue::UncomputeValue(nsCSSProperty aProperty,
// colors can be alone, or part of a paint server
aSpecifiedValue.SetColorValue(aComputedValue.GetColorValue());
break;
case eUnit_CurrentColor:
aSpecifiedValue.SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor);
break;
case eUnit_Calc:
case eUnit_ObjectPosition:
case eUnit_URL: {
Expand Down Expand Up @@ -3148,6 +3153,17 @@ StyleDataAtOffset(void* aStyleStruct, ptrdiff_t aOffset)
return reinterpret_cast<char*>(aStyleStruct) + aOffset;
}

static void
SetCurrentOrActualColor(bool aIsForeground, nscolor aActualColor,
StyleAnimationValue& aComputedValue)
{
if (aIsForeground) {
aComputedValue.SetCurrentColorValue();
} else {
aComputedValue.SetColorValue(aActualColor);
}
}

static void
ExtractBorderColor(nsStyleContext* aStyleContext, const void* aStyleBorder,
mozilla::css::Side aSide,
Expand Down Expand Up @@ -3605,14 +3621,17 @@ StyleAnimationValue::ExtractComputedValue(nsCSSProperty aProperty,

case eCSSProperty_text_emphasis_color: {
auto styleText = static_cast<const nsStyleText*>(styleStruct);
nscolor color = styleText->mTextEmphasisColorForeground ?
aStyleContext->StyleColor()->mColor : styleText->mTextEmphasisColor;
aComputedValue.SetColorValue(color);
SetCurrentOrActualColor(styleText->mTextEmphasisColorForeground,
styleText->mTextEmphasisColor,
aComputedValue);
break;
}

case eCSSProperty__webkit_text_fill_color: {
aComputedValue.SetColorValue(aStyleContext->GetTextFillColor());
auto styleText = static_cast<const nsStyleText*>(styleStruct);
SetCurrentOrActualColor(styleText->mWebkitTextFillColorForeground,
styleText->mWebkitTextFillColor,
aComputedValue);
break;
}

Expand Down Expand Up @@ -4178,6 +4197,7 @@ StyleAnimationValue::operator=(const StyleAnimationValue& aOther)
case eUnit_Normal:
case eUnit_Auto:
case eUnit_None:
case eUnit_CurrentColor:
break;
case eUnit_Enumerated:
case eUnit_Visibility:
Expand Down Expand Up @@ -4319,6 +4339,13 @@ StyleAnimationValue::SetColorValue(nscolor aColor)
mValue.mColor = aColor;
}

void
StyleAnimationValue::SetCurrentColorValue()
{
FreeValue();
mUnit = eUnit_CurrentColor;
}

void
StyleAnimationValue::SetUnparsedStringValue(const nsString& aString)
{
Expand Down Expand Up @@ -4449,6 +4476,7 @@ StyleAnimationValue::operator==(const StyleAnimationValue& aOther) const
case eUnit_Normal:
case eUnit_Auto:
case eUnit_None:
case eUnit_CurrentColor:
return true;
case eUnit_Enumerated:
case eUnit_Visibility:
Expand Down
2 changes: 2 additions & 0 deletions layout/style/StyleAnimationValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class StyleAnimationValue {
eUnit_Percent,
eUnit_Float,
eUnit_Color,
eUnit_CurrentColor,
eUnit_Calc, // nsCSSValue* (never null), always with a single
// calc() expression that's either length or length+percent
eUnit_ObjectPosition, // nsCSSValue* (never null), always with a
Expand Down Expand Up @@ -433,6 +434,7 @@ class StyleAnimationValue {
void SetPercentValue(float aPercent);
void SetFloatValue(float aFloat);
void SetColorValue(nscolor aColor);
void SetCurrentColorValue();
void SetUnparsedStringValue(const nsString& aString);

// These setters take ownership of |aValue|, and are therefore named
Expand Down
5 changes: 4 additions & 1 deletion layout/style/nsStyleContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,8 @@ ExtractColor(nsCSSProperty aProperty,
{
StyleAnimationValue val;
ExtractAnimationValue(aProperty, aStyleContext, val);
return val.GetColorValue();
return val.GetUnit() == StyleAnimationValue::eUnit_CurrentColor
? aStyleContext->StyleColor()->mColor : val.GetColorValue();
}

static nscolor
Expand All @@ -1327,6 +1328,8 @@ ExtractColorLenient(nsCSSProperty aProperty,
ExtractAnimationValue(aProperty, aStyleContext, val);
if (val.GetUnit() == StyleAnimationValue::eUnit_Color) {
return val.GetColorValue();
} else if (val.GetUnit() == StyleAnimationValue::eUnit_CurrentColor) {
return aStyleContext->StyleColor()->mColor;
}
return NS_RGBA(0, 0, 0, 0);
}
Expand Down
22 changes: 0 additions & 22 deletions layout/style/test/test_transitions_events.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
-moz-column-rule-color: black; /* don't derive from color */
text-decoration-color: black; /* don't derive from color */
outline-color: black; /* don't derive from color */
text-emphasis-color: black; /* don't derive from color */
-webkit-text-fill-color: black; /* don't derive from color */
}

#four {
Expand Down Expand Up @@ -75,8 +73,6 @@
var got_one_target_borderleft = false;
var got_one_target_columnrule = false;
var got_one_target_textdecorationcolor = false;
var got_one_target_textemphasiscolor = false;
var got_one_target_webkittextfillcolor = false;
var got_one_target_outlinecolor = false;
var got_two_target = false;
var got_three_top = false;
Expand Down Expand Up @@ -194,18 +190,6 @@
got_one_target_textdecorationcolor = true;
event.stopPropagation();
break;
case "text-emphasis-color":
ok(!got_one_target_textemphasiscolor,
"transitionend on one on target (text-emphasis-color)");
got_one_target_textemphasiscolor = true;
event.stopPropagation();
break;
case "-webkit-text-fill-color":
ok(!got_one_target_webkittextfillcolor,
"transitionend on one on target (-webkit-text-fill-color)");
got_one_target_webkittextfillcolor = true;
event.stopPropagation();
break;
case "outline-color":
ok(!got_one_target_outlinecolor,
"transitionend on one on target (outline-color)");
Expand All @@ -231,12 +215,6 @@
started_test(); // border-left-color on #one
started_test(); // -moz-column-rule-color on #one
started_test(); // text-decoration-color on #one
if (SpecialPowers.getBoolPref("layout.css.text-emphasis.enabled")) {
started_test(); // text-emphasis-color on #one
}
if (SpecialPowers.getBoolPref("layout.css.prefixes.webkit")) {
started_test(); // -webkit-text-fill-color on #one
}
started_test(); // outline-color on #one
$("one").style.color = "lime";

Expand Down
Loading

0 comments on commit 78d5313

Please sign in to comment.