Bug 1440961: Make canvas style-related code interact a bit better with Shadow DOM. r?smaug draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sun, 25 Feb 2018 02:37:44 +0100
changeset 759505 14f46e841aed3667c57145e726ab59805f4fb4ff
parent 759504 319210e2f742b3935869ed06f76a27c49b011c5d
child 759506 2f13f068b81ae0376e86e8d643a2138a1ee5d24b
child 759507 0b9687d7193a1712c85fbb905923c40cd58d23fa
push id100369
push userbmo:emilio@crisal.io
push dateSun, 25 Feb 2018 01:48:32 +0000
reviewerssmaug
bugs1440961
milestone60.0a1
Bug 1440961: Make canvas style-related code interact a bit better with Shadow DOM. r?smaug The only relevant spec reference unfortunately is for color parsing[1], which mentions: > Otherwise, set color to the computed value of the 'color' property of element. Using IsInComposedDoc there should be fine, since the computed style of an element is well defined there. The rest look like implementation limitations, for which should not be an issue to extend the check for the composed doc. [1]: https://html.spec.whatwg.org/#parsed-as-a-css-color-value MozReview-Commit-ID: ADnVPNqf3X1
dom/canvas/CanvasRenderingContext2D.cpp
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -1221,17 +1221,17 @@ CanvasRenderingContext2D::ParseColor(con
 
   if (value.IsNumericColorUnit()) {
     // if we already have a color we can just use it directly
     *aColor = value.GetColorValue();
   } else {
     // otherwise resolve it
     nsCOMPtr<nsIPresShell> presShell = GetPresShell();
     RefPtr<nsStyleContext> parentContext;
-    if (mCanvasElement && mCanvasElement->IsInUncomposedDoc()) {
+    if (mCanvasElement && mCanvasElement->IsInComposedDoc()) {
       // Inherit from the canvas element.
       parentContext =
         nsComputedDOMStyle::GetStyleContext(mCanvasElement, nullptr);
     }
 
     Unused << nsRuleNode::ComputeColor(
       value, presShell ? presShell->GetPresContext() : nullptr, parentContext,
       *aColor);
@@ -1997,17 +1997,17 @@ void
 CanvasRenderingContext2D::ClearTarget()
 {
   Reset();
 
   mResetLayer = true;
 
   SetInitialState();
 
-  if (!mCanvasElement || !mCanvasElement->IsInUncomposedDoc()) {
+  if (!mCanvasElement || !mCanvasElement->IsInComposedDoc()) {
     return;
   }
 
   // For vertical writing-mode, unless text-orientation is sideways,
   // we'll modify the initial value of textBaseline to 'middle'.
   RefPtr<nsStyleContext> canvasStyle =
     nsComputedDOMStyle::GetStyleContext(mCanvasElement, nullptr);
   if (canvasStyle) {
@@ -2734,17 +2734,17 @@ CreateFontDeclaration(const nsAString& a
     eCSSProperty_line_height, NS_LITERAL_STRING("normal"), &lineHeightChanged);
 }
 
 static already_AddRefed<GeckoStyleContext>
 GetFontParentStyleContext(Element* aElement,
                           nsIPresShell* aPresShell,
                           ErrorResult& aError)
 {
-  if (aElement && aElement->IsInUncomposedDoc()) {
+  if (aElement && aElement->IsInComposedDoc()) {
     // Inherit from the canvas element.
     RefPtr<nsStyleContext> result =
       nsComputedDOMStyle::GetStyleContext(aElement, nullptr);
     if (!result) {
       aError.Throw(NS_ERROR_FAILURE);
       return nullptr;
     }
     return GeckoStyleContext::TakeRef(result.forget());
@@ -2914,17 +2914,17 @@ GetFontStyleForServo(Element* aElement, 
     return nullptr;
   }
 
   ServoStyleSet* styleSet = aPresShell->StyleSet()->AsServo();
 
   RefPtr<nsStyleContext> parentStyle;
   // have to get a parent style context for inherit-like relative
   // values (2em, bolder, etc.)
-  if (aElement && aElement->IsInUncomposedDoc()) {
+  if (aElement && aElement->IsInComposedDoc()) {
     parentStyle = nsComputedDOMStyle::GetStyleContext(aElement, nullptr);
   } else {
     RefPtr<RawServoDeclarationBlock> declarations =
       CreateFontDeclarationForServo(NS_LITERAL_STRING("10px sans-serif"),
                                     aPresShell->GetDocument());
     MOZ_ASSERT(declarations);
 
     parentStyle = aPresShell->StyleSet()->AsServo()->
@@ -4571,17 +4571,17 @@ CanvasRenderingContext2D::DrawOrMeasureT
   if (aMaxWidth.WasPassed() && (aMaxWidth.Value() <= 0 || IsNaN(aMaxWidth.Value()))) {
     textToDraw.Truncate();
   }
 
   // for now, default to ltr if not in doc
   bool isRTL = false;
 
   RefPtr<nsStyleContext> canvasStyle;
-  if (mCanvasElement && mCanvasElement->IsInUncomposedDoc()) {
+  if (mCanvasElement && mCanvasElement->IsInComposedDoc()) {
     // try to find the closest context
     canvasStyle =
       nsComputedDOMStyle::GetStyleContext(mCanvasElement, nullptr);
     if (!canvasStyle) {
       return NS_ERROR_FAILURE;
     }
 
     isRTL = canvasStyle->StyleVisibility()->mDirection ==