Bug 265894 - Part 3. Setup display prop value of the cloned symbol element. draft
authorcku <cku@mozilla.com>
Fri, 09 Jun 2017 23:44:45 +0800
changeset 593193 332645facff15586c6f761011ba8093c79097d85
parent 593192 edd913d0ca7b8f71094f77079d1a46c0e8b214bd
child 593194 a9f44072e5083c53f23535700ef3ec0a8eeda523
push id63626
push userbmo:cku@mozilla.com
push dateTue, 13 Jun 2017 09:27:54 +0000
bugs265894
milestone55.0a1
Bug 265894 - Part 3. Setup display prop value of the cloned symbol element. The spec said: The generated instance of a ‘symbol’ that is the direct referenced element of a ‘use’ element must always have a computed value of inline for the display property. In other words, it must be rendered whenever the host ‘use’ element is rendered. MozReview-Commit-ID: DpqOaQcUdI
dom/svg/SVGSVGElement.cpp
--- a/dom/svg/SVGSVGElement.cpp
+++ b/dom/svg/SVGSVGElement.cpp
@@ -1235,15 +1235,38 @@ SVGSVGElement::CloneFromSymbol(Element* 
   // move the children over
   uint32_t num = aSymbol->GetChildCount();
   for (i = 0; i < num; i++) {
     nsCOMPtr<nsIContent> child = aSymbol->GetFirstChild();
     aSymbol->RemoveChildAt(0, false);
     svgNode->InsertChildAt(child, i, true);
   }
 
+  // Read the display prop value of the host 'use' element.
+  nsAutoString displayOfHost;
+  if (aShadowHost->GetPrimaryFrame()) {
+    nsCSSKeyword keyword =
+      nsCSSProps::ValueToKeywordEnum(aShadowHost->GetPrimaryFrame()->StyleDisplay()->mDisplay,
+                                     nsCSSProps::kDisplayKTable);
+
+    AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), displayOfHost);
+
+    displayOfHost =
+      NS_LITERAL_STRING("display:") + displayOfHost + NS_LITERAL_STRING(";");
+  } else {
+    displayOfHost = NS_LITERAL_STRING("display:block;");
+  }
+
+  // The generated instance of a ‘symbol’ that is the direct referenced
+  // element of a ‘use’ element must always have a computed value of inline
+  // for the display property. In other words, it must be rendered whenever
+  // the host ‘use’ element is rendered.
+  nsAutoString inlineStyle;
+  svgNode->GetAttr(kNameSpaceID_None, nsGkAtoms::style, inlineStyle);
+  inlineStyle += displayOfHost;
+  svgNode->SetAttr(kNameSpaceID_None, nsGkAtoms::style, inlineStyle, true);
+
   static_cast<SVGSVGElement*>(svgNode.get())->mCloneFromSymbol = true;
-
   return svgNode.forget();
 }
 
 } // namespace dom
 } // namespace mozilla