Bug 1420026 - Part 2: Replace one more use of nsCSSParser::ParseColor with ServoCSSParser::ComputeColor. r=TYLin
MozReview-Commit-ID: FIqhPFKS1IR
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -1162,16 +1162,37 @@ CanvasRenderingContext2D::WrapObject(JSC
bool
CanvasRenderingContext2D::ParseColor(const nsAString& aString,
nscolor* aColor)
{
nsIDocument* document = mCanvasElement
? mCanvasElement->OwnerDoc()
: nullptr;
+ if (document->IsStyledByServo()) {
+ nsCOMPtr<nsIPresShell> presShell = GetPresShell();
+ ServoStyleSet* set = presShell ? presShell->StyleSet()->AsServo() : nullptr;
+
+ // First, try computing the color without handling currentcolor.
+ bool wasCurrentColor = false;
+ if (!ServoCSSParser::ComputeColor(set, NS_RGB(0, 0, 0), aString, aColor,
+ &wasCurrentColor)) {
+ return false;
+ }
+
+ if (wasCurrentColor) {
+ // Otherwise, get the value of the color property, flushing style
+ // if necessary.
+ RefPtr<nsStyleContext> canvasStyle =
+ nsComputedDOMStyle::GetStyleContext(mCanvasElement, nullptr, presShell);
+ *aColor = canvasStyle->StyleColor()->mColor;
+ }
+ return true;
+ }
+
// Pass the CSS Loader object to the parser, to allow parser error
// reports to include the outer window ID.
nsCSSParser parser(document ? document->CSSLoader() : nullptr);
nsCSSValue value;
if (!parser.ParseColorString(aString, nullptr, 0, value)) {
return false;
}