[svg] Implement 'display:none'
The full 'display' presentation attribute [1] has a number of settings
that we likely don't want to support. However, 'display:none' has some
practical uses and is easy enough to support. This progresses some
local tests as well as a few W3C tests.
[1] https://www.w3.org/TR/SVG11/painting.html#DisplayProperty
Bug: skia:10842
Change-Id: I60fef959fb45c3cfb229b85b720dfa69fc458bc3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/403438
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
diff --git a/modules/svg/src/SkSVGNode.cpp b/modules/svg/src/SkSVGNode.cpp
index 9f3a3e6..13aefa5 100644
--- a/modules/svg/src/SkSVGNode.cpp
+++ b/modules/svg/src/SkSVGNode.cpp
@@ -63,9 +63,13 @@
ctx->applyPresentationAttributes(fPresentationAttributes,
this->hasChildren() ? 0 : SkSVGRenderContext::kLeaf);
- // visibility:hidden disables rendering
+ // visibility:hidden and display:none disable rendering.
+ // TODO: if display is not a value (true when display="inherit"), we currently
+ // ignore it. Eventually we should be able to add SkASSERT(display.isValue()).
const auto visibility = ctx->presentationContext().fInherited.fVisibility->type();
- return visibility != SkSVGVisibility::Type::kHidden;
+ const auto display = fPresentationAttributes.fDisplay; // display is uninherited
+ return visibility != SkSVGVisibility::Type::kHidden &&
+ (!display.isValue() || *display != SkSVGDisplay::kNone);
}
void SkSVGNode::setAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
@@ -94,6 +98,7 @@
|| PARSE_AND_SET("color" , Color)
|| PARSE_AND_SET("color-interpolation" , ColorInterpolation)
|| PARSE_AND_SET("color-interpolation-filters", ColorInterpolationFilters)
+ || PARSE_AND_SET("display" , Display)
|| PARSE_AND_SET("fill" , Fill)
|| PARSE_AND_SET("fill-opacity" , FillOpacity)
|| PARSE_AND_SET("fill-rule" , FillRule)