Bug 1420026 - Part 2: Replace one more use of nsCSSParser::ParseColor with ServoCSSParser::ComputeColor. r=TYLin draft
authorCameron McCormack <cam@mcc.id.au>
Fri, 24 Nov 2017 11:30:02 +0800
changeset 707333 17388783ac4f08b7a1ba34b0f36ed4fd4ea3e1dd
parent 707332 0fe2aed5d789096411fc1509b4d17b8ef11afdf2
child 707334 f0a2493efcf6033b90b116dd844c1805e1513b5f
push id92088
push userbmo:cam@mcc.id.au
push dateTue, 05 Dec 2017 05:26:04 +0000
reviewersTYLin
bugs1420026
milestone59.0a1
Bug 1420026 - Part 2: Replace one more use of nsCSSParser::ParseColor with ServoCSSParser::ComputeColor. r=TYLin MozReview-Commit-ID: FIqhPFKS1IR
dom/canvas/CanvasRenderingContext2D.cpp
--- 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;
   }